[seam-commits] Seam SVN: r13496 - modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Jul 24 21:28:58 EDT 2010


Author: swd847
Date: 2010-07-24 21:28:57 -0400 (Sat, 24 Jul 2010)
New Revision: 13496

Modified:
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/MavenArtifactResolver.java
Log:
update maven artifact resolver so that version numbers are inferred from the pom



Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java	2010-07-23 14:16:46 UTC (rev 13495)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java	2010-07-25 01:28:57 UTC (rev 13496)
@@ -2,7 +2,7 @@
 
 public class ArtifactNames
 {
-   public static final String WELD_EXTENSIONS = "org.jboss.weld:weld-extensions:1.0.0-SNAPSHOT";
-   public static final String SEAM_PERSISTENCE_API = "org.jboss.seam.persistence:seam-persistence-api:3.0.0-SNAPSHOT";
+   public static final String WELD_EXTENSIONS = "org.jboss.weld:weld-extensions";
+   public static final String SEAM_PERSISTENCE_API = "org.jboss.seam.persistence:seam-persistence-api";
 
 }

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/MavenArtifactResolver.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/MavenArtifactResolver.java	2010-07-23 14:16:46 UTC (rev 13495)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/MavenArtifactResolver.java	2010-07-25 01:28:57 UTC (rev 13496)
@@ -1,25 +1,46 @@
 package org.jboss.seam.transactions.test.util;
 
 import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+/**
+ * Resolves a maven artifact present on the test classpath.
+ * 
+ * @author Stuart Douglas
+ * 
+ */
 public class MavenArtifactResolver
 {
-   private static final String LOCAL_MAVEN_REPO =
-         System.getProperty("user.home") + File.separatorChar +
-         ".m2" + File.separatorChar + "repository";
+   private static final String LOCAL_MAVEN_REPO = System.getProperty("user.home") + File.separatorChar + ".m2" + File.separatorChar + "repository";
 
-   public static File resolve(String groupId, String artifactId, String version)
+   public static File resolve(String groupId, String artifactId)
    {
-      return new File(LOCAL_MAVEN_REPO + File.separatorChar +
-            groupId.replace(".", File.separator) + File.separatorChar +
-            artifactId + File.separatorChar +
-            version + File.separatorChar +
-            artifactId + "-" + version + ".jar");
+      String classPath = System.getProperty("java.class.path");
+      // first look for an artefact from the repo
+      String pathString = groupId.replace('.', File.separatorChar) + File.separatorChar + artifactId;
+      String regex = "[^:]*" + Pattern.quote(pathString) + "[^:]*";
+      Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+      Matcher matches = p.matcher(classPath);
+
+      if (!matches.find())
+      {
+         // find a resource from the local build
+         String localResource = Pattern.quote("target" + File.separatorChar + artifactId);
+         regex = "[^:]*" + localResource + "[^:]*";
+         p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+         matches = p.matcher(classPath);
+         if (!matches.find())
+         {
+            throw new RuntimeException("Unable to find maven archive " + groupId + ":" + artifactId + " on the test classpath");
+         }
+      }
+      return new File(matches.group(0));
    }
 
    public static File resolve(String qualifiedArtifactId)
    {
       String[] segments = qualifiedArtifactId.split(":");
-      return resolve(segments[0], segments[1], segments[2]);
+      return resolve(segments[0], segments[1]);
    }
 }



More information about the seam-commits mailing list