From 754b8c123dbe23ffd5e4155ecadbdc26f660cfbb Mon Sep 17 00:00:00 2001 From: Pete Muir Date: Sat, 14 Aug 2010 12:47:35 +0100 Subject: [PATCH] rearchitect MavenArtifactResolver --- .../util/MavenArtifactPathResolverTest.java | 181 +++++++++++------- .../test/util/MavenArtifactResolver.java | 175 ++++++++++------- 2 files changed, 223 insertions(+), 133 deletions(-) diff --git a/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactPathResolverTest.java b/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactPathResolverTest.java index 228537c..1d59849 100644 --- a/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactPathResolverTest.java +++ b/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactPathResolverTest.java @@ -1,94 +1,143 @@ package org.jboss.weld.extensions.test.util; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import static org.junit.Assert.assertEquals; -import org.junit.Test; +import java.util.Arrays; +import java.util.List; -import static org.junit.Assert.assertTrue; +import org.junit.Test; public class MavenArtifactPathResolverTest { + + public static final String groupId = "org.jboss.weld"; + public static final String artifactId = "weld-extensions"; + + public static final char linuxFileSeparator = '/'; + public static final char linuxPathSeparator = ':'; - String groupId = "org.jboss.weld"; - String artifactId = "weld-extensions"; + public static final char windowsFileSeparator = '\\'; + public static final char windowsPathSeparator = ';'; @Test - public void testWindows() - { - char fileSeparator = '\\'; - char pathSeparator = ';'; - - String classPath = "V:\\workspace\\extensions\\impl\\target\\test-classes;V:\\workspace\\extensions\\impl\\target\\classes;C:\\Users\\john.doe\\.m2\\repository\\org\\javassist\\javassist\\3.13.0-GA\\javassist-3.13.0-GA.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\enterprise\\cdi-api\\1.0-SP2\\cdi-api-1.0-SP2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\spec\\javax\\interceptor\\jboss-interceptors-api_1.1_spec\\1.0.0.Beta1\\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\annotation\\jsr250-api\\1.0\\jsr250-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\inject\\javax.inject\\1\\javax.inject-1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-api\\1.5.10\\slf4j-api-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-core\\1.1.0-SNAPSHOT\\weld-core-1.1.0-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-api\\1.1-SNAPSHOT\\weld-api-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-spi\\1.1-SNAPSHOT\\weld-spi-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\com\\google\\guava\\guava\\r06\\guava-r06.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\interceptor\\jboss-interceptor\\1.0.0-CR11\\jboss-interceptor-1.0.0-CR11.jar;C:\\Users\\john.doe\\.m2\\repository\\javassist\\javassist\\3.11.0.GA\\javassist-3.11.0.GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-ext\\1.5.10\\slf4j-ext-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\ch\\qos\\cal10n\\cal10n-api\\0.7.2\\cal10n-api-0.7.2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\ejb3\\jboss-ejb3-api\\3.1.0\\jboss-ejb3-api-3.1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\servlet\\servlet-api\\2.5\\servlet-api-2.5.jar;C:\\Users\\john.doe\\.m2\\repository\\junit\\junit\\4.8.1\\junit-4.8.1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-junit\\1.0.0.Alpha3\\arquillian-junit-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-impl-base\\1.0.0.Alpha3\\arquillian-impl-base-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-api\\1.0.0.Alpha3\\arquillian-api-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-api\\1.0.0-alpha-11\\shrinkwrap-api-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-spi\\1.0.0.Alpha3\\arquillian-spi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-impl-base\\1.0.0-alpha-11\\shrinkwrap-impl-base-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-spi\\1.0.0-alpha-11\\shrinkwrap-spi-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\el\\el-api\\2.2\\el-api-2.2.jar;C:\\Users\\john.doe\\.m2\\repository\\el-impl\\el-impl\\1.0\\el-impl-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\container\\arquillian-weld-ee-embedded-1.1\\1.0.0.Alpha3\\arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\protocol\\arquillian-protocol-local\\1.0.0.Alpha3\\arquillian-protocol-local-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\testenricher\\arquillian-testenricher-cdi\\1.0.0.Alpha3\\arquillian-testenricher-cdi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-extension-classloader\\1.0.0-alpha-11\\shrinkwrap-extension-classloader-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\transaction\\jta\\1.1\\jta-1.1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\persistence\\persistence-api\\1.0\\persistence-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\validation\\validation-api\\1.0.0.GA\\validation-api-1.0.0.GA.jar;/V:/eclipse/configuration/org.eclipse.osgi/bundles/311/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/309/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/310/1/.cp/"; - - Matcher matches = MavenArtifactResolver.getRepoMatcher(groupId, artifactId, classPath, pathSeparator, fileSeparator); - - if(matches.find()) - { - //TODO What does this do? - } - - String localClasses = MavenArtifactResolver.getLocalClassesString(fileSeparator); - Matcher localClassesMatcher = MavenArtifactResolver.getLocalClassesMatcher(classPath, localClasses, pathSeparator); - - if(!localClassesMatcher.find()) - { - throw new IllegalArgumentException("Unable to find maven archive " + groupId + ":" + artifactId + " in the local build"); - } - - String path = localClassesMatcher.group(); - String trimmedPath = path.substring(0, path.length() - 8); - - assertTrue("Path was: " + path, path.equals("V:\\workspace\\extensions\\impl\\target\\classes")); - assertTrue("Trimmed was: " + trimmedPath, trimmedPath.equals("V:\\workspace\\extensions\\impl\\target")); + public void testWindowsInLocalModule() + { + List targetContents = Arrays.asList("V:\\workspace\\extensions\\impl\\target\\surefire-report", "V:\\workspace\\extensions\\impl\\target\\classes", "V:\\workspace\\extensions\\impl\\target\\test-classes", "V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3-SNAPSHOT-sources.jar", "V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3-SNAPSHOT.jar"); + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, null, windowsPathSeparator, windowsFileSeparator); + String path = resolver.scanForArtifact(targetContents); + assertEquals("V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3-SNAPSHOT.jar", path); } @Test - public void testLinux() - { - char fileSeparator = '/'; - char pathSeparator = ':'; - - String classPath = "/home/user/workspace/extensions/impl/target/test-classes:/home/jdoe/workspace/extensions/impl/target/classes:/home/jdoe/.m2/repository/org/javassist/javassist/3.13.0-GA/javassist-3.13.0-GA.jar:/home/jdoe/.m2/repository/javax/enterprise/cdi-api/1.0-SP2/cdi-api-1.0-SP2.jar:/home/jdoe/.m2/repository/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/home/jdoe/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/home/jdoe/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-core/1.1.0-SNAPSHOT/weld-core-1.1.0-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-api/1.1-SNAPSHOT/weld-api-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-spi/1.1-SNAPSHOT/weld-spi-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/com/google/guava/guava/r06/guava-r06.jar:/home/jdoe/.m2/repository/org/jboss/interceptor/jboss-interceptor/1.0.0-CR11/jboss-interceptor-1.0.0-CR11.jar:/home/jdoe/.m2/repository/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-ext/1.5.10/slf4j-ext-1.5.10.jar:/home/jdoe/.m2/repository/ch/qos/cal10n/cal10n-api/0.7.2/cal10n-api-0.7.2.jar:/home/jdoe/.m2/repository/org/jboss/ejb3/jboss-ejb3-api/3.1.0/jboss-ejb3-api-3.1.0.jar:/home/jdoe/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar:/home/jdoe/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-junit/1.0.0.Alpha3/arquillian-junit-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-impl-base/1.0.0.Alpha3/arquillian-impl-base-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-api/1.0.0.Alpha3/arquillian-api-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-api/1.0.0-alpha-11/shrinkwrap-api-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-spi/1.0.0.Alpha3/arquillian-spi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.0.0-alpha-11/shrinkwrap-impl-base-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-spi/1.0.0-alpha-11/shrinkwrap-spi-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/el/el-api/2.2/el-api-2.2.jar:/home/jdoe/.m2/repository/el-impl/el-impl/1.0/el-impl-1.0.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/container/arquillian-weld-ee-embedded-1.1/1.0.0.Alpha3/arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/protocol/arquillian-protocol-local/1.0.0.Alpha3/arquillian-protocol-local-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/testenricher/arquillian-testenricher-cdi/1.0.0.Alpha3/arquillian-testenricher-cdi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-extension-classloader/1.0.0-alpha-11/shrinkwrap-extension-classloader-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/jdoe/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/home/jdoe/.m2/repository/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/112/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/110/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/111/1/.cp/"; - - Matcher matches = MavenArtifactResolver.getRepoMatcher(groupId, artifactId, classPath, pathSeparator, fileSeparator); - - if(matches.find()) - { - //TODO What does this do? - } - - String localClasses = MavenArtifactResolver.getLocalClassesString(fileSeparator); - Matcher localClassesMatcher = MavenArtifactResolver.getLocalClassesMatcher(classPath, localClasses, pathSeparator); - - if(!localClassesMatcher.find()) - { - throw new IllegalArgumentException("Unable to find maven archive " + groupId + ":" + artifactId + " in the local build"); - } - - String path = localClassesMatcher.group(); - String trimmedPath = path.substring(0, path.length() - 8); - - assertTrue("Path was: " + path, path.equals("/home/jdoe/workspace/extensions/impl/target/classes")); - assertTrue("Trimmed was: " + trimmedPath, trimmedPath.equals("/home/jdoe/workspace/extensions/impl/target")); + public void testWindowsInLocalModuleWithDotQualifier() + { + List targetContents = Arrays.asList("V:\\workspace\\extensions\\impl\\target\\surefire-report", "V:\\workspace\\extensions\\impl\\target\\classes", "V:\\workspace\\extensions\\impl\\target\\test-classes", "V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3.Final-sources.jar", "V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3.Final.jar"); + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, null, windowsPathSeparator, windowsFileSeparator); + String path = resolver.scanForArtifact(targetContents); + assertEquals("V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3.Final.jar", path); } + + @Test + public void testLinuxInLocalModule() + { + List targetContents = Arrays.asList("/workspace/extensions/impl/target/surefire-report", "/workspace/extensions/impl/target/classes", "/workspace/extensions/impl/target/test-classes", "/workspace/extensions/impl/target/weld-extensions-1.2.3-SNAPSHOT-sources.jar", "/workspace/extensions/impl/target/weld-extensions-1.2.3-SNAPSHOT.jar"); + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, null, windowsPathSeparator, windowsFileSeparator); + String path = resolver.scanForArtifact(targetContents); + assertEquals("/workspace/extensions/impl/target/weld-extensions-1.2.3-SNAPSHOT.jar", path); + } - public Pattern getRepoPattern(char pathSeparator, char fileSeparator) + @Test + public void testLinuxInLocalModuleWithDotQualifier() + { + List targetContents = Arrays.asList("/workspace/extensions/impl/target/surefire-report", "/workspace/extensions/impl/target/classes", "/workspace/extensions/impl/target/test-classes", "/workspace/extensions/impl/target/weld-extensions-1.2.3.Final-sources.jar", "/workspace/extensions/impl/target/weld-extensions-1.2.3.Final.jar"); + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, null, windowsPathSeparator, windowsFileSeparator); + String path = resolver.scanForArtifact(targetContents); + assertEquals("/workspace/extensions/impl/target/weld-extensions-1.2.3.Final.jar", path); + } + + @Test + public void testWindows() { - return Pattern.compile("^[" + pathSeparator +"]*" + Pattern.quote(getPathString(fileSeparator)) + "^*[" + pathSeparator + "]*", Pattern.CASE_INSENSITIVE); + String classPath = "V:\\workspace\\extensions\\impl\\target\\test-classes;V:\\workspace\\extensions\\impl\\target\\classes;C:\\Users\\john.doe\\.m2\\repository\\org\\javassist\\javassist\\3.13.0-GA\\javassist-3.13.0-GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-extensions\\1.2.3-SNAPSHOT\\weld-extensions-1.2.3-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\enterprise\\cdi-api\\1.0-SP2\\cdi-api-1.0-SP2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\spec\\javax\\interceptor\\jboss-interceptors-api_1.1_spec\\1.0.0.Beta1\\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\annotation\\jsr250-api\\1.0\\jsr250-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\inject\\javax.inject\\1\\javax.inject-1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-api\\1.5.10\\slf4j-api-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-core\\1.1.0-SNAPSHOT\\weld-core-1.1.0-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-api\\1.1-SNAPSHOT\\weld-api-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-spi\\1.1-SNAPSHOT\\weld-spi-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\com\\google\\guava\\guava\\r06\\guava-r06.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\interceptor\\jboss-interceptor\\1.0.0-CR11\\jboss-interceptor-1.0.0-CR11.jar;C:\\Users\\john.doe\\.m2\\repository\\javassist\\javassist\\3.11.0.GA\\javassist-3.11.0.GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-ext\\1.5.10\\slf4j-ext-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\ch\\qos\\cal10n\\cal10n-api\\0.7.2\\cal10n-api-0.7.2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\ejb3\\jboss-ejb3-api\\3.1.0\\jboss-ejb3-api-3.1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\servlet\\servlet-api\\2.5\\servlet-api-2.5.jar;C:\\Users\\john.doe\\.m2\\repository\\junit\\junit\\4.8.1\\junit-4.8.1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-junit\\1.0.0.Alpha3\\arquillian-junit-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-impl-base\\1.0.0.Alpha3\\arquillian-impl-base-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-api\\1.0.0.Alpha3\\arquillian-api-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-api\\1.0.0-alpha-11\\shrinkwrap-api-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-spi\\1.0.0.Alpha3\\arquillian-spi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-impl-base\\1.0.0-alpha-11\\shrinkwrap-impl-base-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-spi\\1.0.0-alpha-11\\shrinkwrap-spi-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\el\\el-api\\2.2\\el-api-2.2.jar;C:\\Users\\john.doe\\.m2\\repository\\el-impl\\el-impl\\1.0\\el-impl-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\container\\arquillian-weld-ee-embedded-1.1\\1.0.0.Alpha3\\arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\protocol\\arquillian-protocol-local\\1.0.0.Alpha3\\arquillian-protocol-local-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\testenricher\\arquillian-testenricher-cdi\\1.0.0.Alpha3\\arquillian-testenricher-cdi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-extension-classloader\\1.0.0-alpha-11\\shrinkwrap-extension-classloader-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\transaction\\jta\\1.1\\jta-1.1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\persistence\\persistence-api\\1.0\\persistence-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\validation\\validation-api\\1.0.0.GA\\validation-api-1.0.0.GA.jar;/V:/eclipse/configuration/org.eclipse.osgi/bundles/311/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/309/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/310/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, windowsPathSeparator, windowsFileSeparator); + String path = resolver.resolve(); + assertEquals("C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-extensions\\1.2.3-SNAPSHOT\\weld-extensions-1.2.3-SNAPSHOT.jar", path); + } + + @Test + public void testWindowsInReactorWithDotQualifier() + { + String classPath = "V:\\workspace\\extensions\\impl\\target\\test-classes;V:\\workspace\\extensions\\impl\\target\\classes;V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3.Final.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\javassist\\javassist\\3.13.0-GA\\javassist-3.13.0-GA.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\enterprise\\cdi-api\\1.0-SP2\\cdi-api-1.0-SP2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\spec\\javax\\interceptor\\jboss-interceptors-api_1.1_spec\\1.0.0.Beta1\\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\annotation\\jsr250-api\\1.0\\jsr250-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\inject\\javax.inject\\1\\javax.inject-1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-api\\1.5.10\\slf4j-api-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-core\\1.1.0-SNAPSHOT\\weld-core-1.1.0-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-api\\1.1-SNAPSHOT\\weld-api-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-spi\\1.1-SNAPSHOT\\weld-spi-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\com\\google\\guava\\guava\\r06\\guava-r06.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\interceptor\\jboss-interceptor\\1.0.0-CR11\\jboss-interceptor-1.0.0-CR11.jar;C:\\Users\\john.doe\\.m2\\repository\\javassist\\javassist\\3.11.0.GA\\javassist-3.11.0.GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-ext\\1.5.10\\slf4j-ext-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\ch\\qos\\cal10n\\cal10n-api\\0.7.2\\cal10n-api-0.7.2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\ejb3\\jboss-ejb3-api\\3.1.0\\jboss-ejb3-api-3.1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\servlet\\servlet-api\\2.5\\servlet-api-2.5.jar;C:\\Users\\john.doe\\.m2\\repository\\junit\\junit\\4.8.1\\junit-4.8.1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-junit\\1.0.0.Alpha3\\arquillian-junit-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-impl-base\\1.0.0.Alpha3\\arquillian-impl-base-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-api\\1.0.0.Alpha3\\arquillian-api-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-api\\1.0.0-alpha-11\\shrinkwrap-api-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-spi\\1.0.0.Alpha3\\arquillian-spi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-impl-base\\1.0.0-alpha-11\\shrinkwrap-impl-base-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-spi\\1.0.0-alpha-11\\shrinkwrap-spi-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\el\\el-api\\2.2\\el-api-2.2.jar;C:\\Users\\john.doe\\.m2\\repository\\el-impl\\el-impl\\1.0\\el-impl-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\container\\arquillian-weld-ee-embedded-1.1\\1.0.0.Alpha3\\arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\protocol\\arquillian-protocol-local\\1.0.0.Alpha3\\arquillian-protocol-local-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\testenricher\\arquillian-testenricher-cdi\\1.0.0.Alpha3\\arquillian-testenricher-cdi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-extension-classloader\\1.0.0-alpha-11\\shrinkwrap-extension-classloader-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\transaction\\jta\\1.1\\jta-1.1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\persistence\\persistence-api\\1.0\\persistence-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\validation\\validation-api\\1.0.0.GA\\validation-api-1.0.0.GA.jar;/V:/eclipse/configuration/org.eclipse.osgi/bundles/311/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/309/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/310/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, windowsPathSeparator, windowsFileSeparator); + String path = resolver.resolve(); + assertEquals("V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3.Final.jar", path); } - public Pattern getLocalClassesPattern(String localClasses, char pathSeparator) + @Test + public void testWindowsWithDotQualifier() { - return Pattern.compile("[^" + pathSeparator + "]*" + localClasses + "[^" + pathSeparator + "]*", Pattern.CASE_INSENSITIVE); + String classPath = "V:\\workspace\\extensions\\impl\\target\\test-classes;V:\\workspace\\extensions\\impl\\target\\classes;C:\\Users\\john.doe\\.m2\\repository\\org\\javassist\\javassist\\3.13.0-GA\\javassist-3.13.0-GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-extensions\\1.2.3.Final\\weld-extensions-1.2.3.Final.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\enterprise\\cdi-api\\1.0-SP2\\cdi-api-1.0-SP2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\spec\\javax\\interceptor\\jboss-interceptors-api_1.1_spec\\1.0.0.Beta1\\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\annotation\\jsr250-api\\1.0\\jsr250-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\inject\\javax.inject\\1\\javax.inject-1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-api\\1.5.10\\slf4j-api-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-core\\1.1.0-SNAPSHOT\\weld-core-1.1.0-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-api\\1.1-SNAPSHOT\\weld-api-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-spi\\1.1-SNAPSHOT\\weld-spi-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\com\\google\\guava\\guava\\r06\\guava-r06.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\interceptor\\jboss-interceptor\\1.0.0-CR11\\jboss-interceptor-1.0.0-CR11.jar;C:\\Users\\john.doe\\.m2\\repository\\javassist\\javassist\\3.11.0.GA\\javassist-3.11.0.GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-ext\\1.5.10\\slf4j-ext-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\ch\\qos\\cal10n\\cal10n-api\\0.7.2\\cal10n-api-0.7.2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\ejb3\\jboss-ejb3-api\\3.1.0\\jboss-ejb3-api-3.1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\servlet\\servlet-api\\2.5\\servlet-api-2.5.jar;C:\\Users\\john.doe\\.m2\\repository\\junit\\junit\\4.8.1\\junit-4.8.1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-junit\\1.0.0.Alpha3\\arquillian-junit-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-impl-base\\1.0.0.Alpha3\\arquillian-impl-base-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-api\\1.0.0.Alpha3\\arquillian-api-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-api\\1.0.0-alpha-11\\shrinkwrap-api-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-spi\\1.0.0.Alpha3\\arquillian-spi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-impl-base\\1.0.0-alpha-11\\shrinkwrap-impl-base-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-spi\\1.0.0-alpha-11\\shrinkwrap-spi-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\el\\el-api\\2.2\\el-api-2.2.jar;C:\\Users\\john.doe\\.m2\\repository\\el-impl\\el-impl\\1.0\\el-impl-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\container\\arquillian-weld-ee-embedded-1.1\\1.0.0.Alpha3\\arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\protocol\\arquillian-protocol-local\\1.0.0.Alpha3\\arquillian-protocol-local-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\testenricher\\arquillian-testenricher-cdi\\1.0.0.Alpha3\\arquillian-testenricher-cdi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-extension-classloader\\1.0.0-alpha-11\\shrinkwrap-extension-classloader-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\transaction\\jta\\1.1\\jta-1.1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\persistence\\persistence-api\\1.0\\persistence-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\validation\\validation-api\\1.0.0.GA\\validation-api-1.0.0.GA.jar;/V:/eclipse/configuration/org.eclipse.osgi/bundles/311/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/309/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/310/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, windowsPathSeparator, windowsFileSeparator); + String path = resolver.resolve(); + assertEquals("C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-extensions\\1.2.3.Final\\weld-extensions-1.2.3.Final.jar", path); + } + + @Test + public void testWindowsInReactor() + { + String classPath = "V:\\workspace\\extensions\\impl\\target\\test-classes;V:\\workspace\\extensions\\impl\\target\\classes;V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\javassist\\javassist\\3.13.0-GA\\javassist-3.13.0-GA.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\enterprise\\cdi-api\\1.0-SP2\\cdi-api-1.0-SP2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\spec\\javax\\interceptor\\jboss-interceptors-api_1.1_spec\\1.0.0.Beta1\\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\annotation\\jsr250-api\\1.0\\jsr250-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\inject\\javax.inject\\1\\javax.inject-1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-api\\1.5.10\\slf4j-api-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-core\\1.1.0-SNAPSHOT\\weld-core-1.1.0-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-api\\1.1-SNAPSHOT\\weld-api-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\weld\\weld-spi\\1.1-SNAPSHOT\\weld-spi-1.1-SNAPSHOT.jar;C:\\Users\\john.doe\\.m2\\repository\\com\\google\\guava\\guava\\r06\\guava-r06.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\interceptor\\jboss-interceptor\\1.0.0-CR11\\jboss-interceptor-1.0.0-CR11.jar;C:\\Users\\john.doe\\.m2\\repository\\javassist\\javassist\\3.11.0.GA\\javassist-3.11.0.GA.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\slf4j\\slf4j-ext\\1.5.10\\slf4j-ext-1.5.10.jar;C:\\Users\\john.doe\\.m2\\repository\\ch\\qos\\cal10n\\cal10n-api\\0.7.2\\cal10n-api-0.7.2.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\ejb3\\jboss-ejb3-api\\3.1.0\\jboss-ejb3-api-3.1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\servlet\\servlet-api\\2.5\\servlet-api-2.5.jar;C:\\Users\\john.doe\\.m2\\repository\\junit\\junit\\4.8.1\\junit-4.8.1.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-junit\\1.0.0.Alpha3\\arquillian-junit-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-impl-base\\1.0.0.Alpha3\\arquillian-impl-base-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-api\\1.0.0.Alpha3\\arquillian-api-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-api\\1.0.0-alpha-11\\shrinkwrap-api-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\arquillian-spi\\1.0.0.Alpha3\\arquillian-spi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-impl-base\\1.0.0-alpha-11\\shrinkwrap-impl-base-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-spi\\1.0.0-alpha-11\\shrinkwrap-spi-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\el\\el-api\\2.2\\el-api-2.2.jar;C:\\Users\\john.doe\\.m2\\repository\\el-impl\\el-impl\\1.0\\el-impl-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\container\\arquillian-weld-ee-embedded-1.1\\1.0.0.Alpha3\\arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\protocol\\arquillian-protocol-local\\1.0.0.Alpha3\\arquillian-protocol-local-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\arquillian\\testenricher\\arquillian-testenricher-cdi\\1.0.0.Alpha3\\arquillian-testenricher-cdi-1.0.0.Alpha3.jar;C:\\Users\\john.doe\\.m2\\repository\\org\\jboss\\shrinkwrap\\shrinkwrap-extension-classloader\\1.0.0-alpha-11\\shrinkwrap-extension-classloader-1.0.0-alpha-11.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\transaction\\jta\\1.1\\jta-1.1.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\persistence\\persistence-api\\1.0\\persistence-api-1.0.jar;C:\\Users\\john.doe\\.m2\\repository\\javax\\validation\\validation-api\\1.0.0.GA\\validation-api-1.0.0.GA.jar;/V:/eclipse/configuration/org.eclipse.osgi/bundles/311/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/309/1/.cp/;/V:/eclipse/configuration/org.eclipse.osgi/bundles/310/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, windowsPathSeparator, windowsFileSeparator); + String path = resolver.resolve(); + assertEquals("V:\\workspace\\extensions\\impl\\target\\weld-extensions-1.2.3-SNAPSHOT.jar", path); + } + + @Test + public void testLinux() + { + String classPath = "/home/user/workspace/extensions/impl/target/test-classes:/home/jdoe/workspace/extensions/impl/target/classes:/home/jdoe/.m2/repository/org/javassist/javassist/3.13.0-GA/javassist-3.13.0-GA.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-extensions/1.2.3-SNAPSHOT/weld-extensions-1.2.3-SNAPSHOT.jar:/home/jdoe/.m2/repository/javax/enterprise/cdi-api/1.0-SP2/cdi-api-1.0-SP2.jar:/home/jdoe/.m2/repository/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/home/jdoe/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/home/jdoe/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-core/1.1.0-SNAPSHOT/weld-core-1.1.0-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-api/1.1-SNAPSHOT/weld-api-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-spi/1.1-SNAPSHOT/weld-spi-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/com/google/guava/guava/r06/guava-r06.jar:/home/jdoe/.m2/repository/org/jboss/interceptor/jboss-interceptor/1.0.0-CR11/jboss-interceptor-1.0.0-CR11.jar:/home/jdoe/.m2/repository/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-ext/1.5.10/slf4j-ext-1.5.10.jar:/home/jdoe/.m2/repository/ch/qos/cal10n/cal10n-api/0.7.2/cal10n-api-0.7.2.jar:/home/jdoe/.m2/repository/org/jboss/ejb3/jboss-ejb3-api/3.1.0/jboss-ejb3-api-3.1.0.jar:/home/jdoe/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar:/home/jdoe/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-junit/1.0.0.Alpha3/arquillian-junit-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-impl-base/1.0.0.Alpha3/arquillian-impl-base-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-api/1.0.0.Alpha3/arquillian-api-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-api/1.0.0-alpha-11/shrinkwrap-api-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-spi/1.0.0.Alpha3/arquillian-spi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.0.0-alpha-11/shrinkwrap-impl-base-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-spi/1.0.0-alpha-11/shrinkwrap-spi-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/el/el-api/2.2/el-api-2.2.jar:/home/jdoe/.m2/repository/el-impl/el-impl/1.0/el-impl-1.0.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/container/arquillian-weld-ee-embedded-1.1/1.0.0.Alpha3/arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/protocol/arquillian-protocol-local/1.0.0.Alpha3/arquillian-protocol-local-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/testenricher/arquillian-testenricher-cdi/1.0.0.Alpha3/arquillian-testenricher-cdi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-extension-classloader/1.0.0-alpha-11/shrinkwrap-extension-classloader-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/jdoe/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/home/jdoe/.m2/repository/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/112/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/110/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/111/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, linuxPathSeparator, linuxFileSeparator); + String path = resolver.resolve(); + assertEquals("/home/jdoe/.m2/repository/org/jboss/weld/weld-extensions/1.2.3-SNAPSHOT/weld-extensions-1.2.3-SNAPSHOT.jar", path); } - public String getPathString(char fileSeparator) + @Test + public void testLinuxWithDotQualifier() + { + String classPath = "/home/user/workspace/extensions/impl/target/test-classes:/home/jdoe/workspace/extensions/impl/target/classes:/home/jdoe/.m2/repository/org/javassist/javassist/3.13.0-GA/javassist-3.13.0-GA.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-extensions/1.2.3.Final/weld-extensions-1.2.3.Final.jar:/home/jdoe/.m2/repository/javax/enterprise/cdi-api/1.0-SP2/cdi-api-1.0-SP2.jar:/home/jdoe/.m2/repository/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/home/jdoe/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/home/jdoe/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-core/1.1.0-SNAPSHOT/weld-core-1.1.0-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-api/1.1-SNAPSHOT/weld-api-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-spi/1.1-SNAPSHOT/weld-spi-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/com/google/guava/guava/r06/guava-r06.jar:/home/jdoe/.m2/repository/org/jboss/interceptor/jboss-interceptor/1.0.0-CR11/jboss-interceptor-1.0.0-CR11.jar:/home/jdoe/.m2/repository/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-ext/1.5.10/slf4j-ext-1.5.10.jar:/home/jdoe/.m2/repository/ch/qos/cal10n/cal10n-api/0.7.2/cal10n-api-0.7.2.jar:/home/jdoe/.m2/repository/org/jboss/ejb3/jboss-ejb3-api/3.1.0/jboss-ejb3-api-3.1.0.jar:/home/jdoe/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar:/home/jdoe/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-junit/1.0.0.Alpha3/arquillian-junit-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-impl-base/1.0.0.Alpha3/arquillian-impl-base-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-api/1.0.0.Alpha3/arquillian-api-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-api/1.0.0-alpha-11/shrinkwrap-api-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-spi/1.0.0.Alpha3/arquillian-spi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.0.0-alpha-11/shrinkwrap-impl-base-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-spi/1.0.0-alpha-11/shrinkwrap-spi-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/el/el-api/2.2/el-api-2.2.jar:/home/jdoe/.m2/repository/el-impl/el-impl/1.0/el-impl-1.0.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/container/arquillian-weld-ee-embedded-1.1/1.0.0.Alpha3/arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/protocol/arquillian-protocol-local/1.0.0.Alpha3/arquillian-protocol-local-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/testenricher/arquillian-testenricher-cdi/1.0.0.Alpha3/arquillian-testenricher-cdi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-extension-classloader/1.0.0-alpha-11/shrinkwrap-extension-classloader-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/jdoe/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/home/jdoe/.m2/repository/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/112/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/110/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/111/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, linuxPathSeparator, linuxFileSeparator); + String path = resolver.resolve(); + assertEquals("/home/jdoe/.m2/repository/org/jboss/weld/weld-extensions/1.2.3.Final/weld-extensions-1.2.3.Final.jar", path); + } + + @Test + public void testLinuxInReactor() { - return groupId.replace('.', fileSeparator) + fileSeparator + artifactId; + String classPath = "/home/user/workspace/extensions/impl/target/test-classes:/home/jdoe/workspace/extensions/impl/target/classes:/home/jdoe/workspace/extensions/impl/target/weld-extensions-1.2.3-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/javassist/javassist/3.13.0-GA/javassist-3.13.0-GA.jar:/home/jdoe/.m2/repository/javax/enterprise/cdi-api/1.0-SP2/cdi-api-1.0-SP2.jar:/home/jdoe/.m2/repository/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/home/jdoe/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/home/jdoe/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-core/1.1.0-SNAPSHOT/weld-core-1.1.0-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-api/1.1-SNAPSHOT/weld-api-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-spi/1.1-SNAPSHOT/weld-spi-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/com/google/guava/guava/r06/guava-r06.jar:/home/jdoe/.m2/repository/org/jboss/interceptor/jboss-interceptor/1.0.0-CR11/jboss-interceptor-1.0.0-CR11.jar:/home/jdoe/.m2/repository/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-ext/1.5.10/slf4j-ext-1.5.10.jar:/home/jdoe/.m2/repository/ch/qos/cal10n/cal10n-api/0.7.2/cal10n-api-0.7.2.jar:/home/jdoe/.m2/repository/org/jboss/ejb3/jboss-ejb3-api/3.1.0/jboss-ejb3-api-3.1.0.jar:/home/jdoe/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar:/home/jdoe/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-junit/1.0.0.Alpha3/arquillian-junit-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-impl-base/1.0.0.Alpha3/arquillian-impl-base-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-api/1.0.0.Alpha3/arquillian-api-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-api/1.0.0-alpha-11/shrinkwrap-api-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-spi/1.0.0.Alpha3/arquillian-spi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.0.0-alpha-11/shrinkwrap-impl-base-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-spi/1.0.0-alpha-11/shrinkwrap-spi-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/el/el-api/2.2/el-api-2.2.jar:/home/jdoe/.m2/repository/el-impl/el-impl/1.0/el-impl-1.0.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/container/arquillian-weld-ee-embedded-1.1/1.0.0.Alpha3/arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/protocol/arquillian-protocol-local/1.0.0.Alpha3/arquillian-protocol-local-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/testenricher/arquillian-testenricher-cdi/1.0.0.Alpha3/arquillian-testenricher-cdi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-extension-classloader/1.0.0-alpha-11/shrinkwrap-extension-classloader-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/jdoe/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/home/jdoe/.m2/repository/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/112/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/110/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/111/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, linuxPathSeparator, linuxFileSeparator); + String path = resolver.resolve(); + assertEquals("/home/jdoe/workspace/extensions/impl/target/weld-extensions-1.2.3-SNAPSHOT.jar", path); } + @Test + public void testLinuxInReactorWithDotQualifier() + { + String classPath = "/home/user/workspace/extensions/impl/target/test-classes:/home/jdoe/workspace/extensions/impl/target/classes:/home/jdoe/workspace/extensions/impl/target/weld-extensions-1.2.3.Final.jar:/home/jdoe/.m2/repository/org/javassist/javassist/3.13.0-GA/javassist-3.13.0-GA.jar:/home/jdoe/.m2/repository/javax/enterprise/cdi-api/1.0-SP2/cdi-api-1.0-SP2.jar:/home/jdoe/.m2/repository/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/home/jdoe/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/home/jdoe/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-core/1.1.0-SNAPSHOT/weld-core-1.1.0-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-api/1.1-SNAPSHOT/weld-api-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/org/jboss/weld/weld-spi/1.1-SNAPSHOT/weld-spi-1.1-SNAPSHOT.jar:/home/jdoe/.m2/repository/com/google/guava/guava/r06/guava-r06.jar:/home/jdoe/.m2/repository/org/jboss/interceptor/jboss-interceptor/1.0.0-CR11/jboss-interceptor-1.0.0-CR11.jar:/home/jdoe/.m2/repository/javassist/javassist/3.11.0.GA/javassist-3.11.0.GA.jar:/home/jdoe/.m2/repository/org/slf4j/slf4j-ext/1.5.10/slf4j-ext-1.5.10.jar:/home/jdoe/.m2/repository/ch/qos/cal10n/cal10n-api/0.7.2/cal10n-api-0.7.2.jar:/home/jdoe/.m2/repository/org/jboss/ejb3/jboss-ejb3-api/3.1.0/jboss-ejb3-api-3.1.0.jar:/home/jdoe/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar:/home/jdoe/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-junit/1.0.0.Alpha3/arquillian-junit-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-impl-base/1.0.0.Alpha3/arquillian-impl-base-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-api/1.0.0.Alpha3/arquillian-api-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-api/1.0.0-alpha-11/shrinkwrap-api-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/arquillian-spi/1.0.0.Alpha3/arquillian-spi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.0.0-alpha-11/shrinkwrap-impl-base-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-spi/1.0.0-alpha-11/shrinkwrap-spi-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/el/el-api/2.2/el-api-2.2.jar:/home/jdoe/.m2/repository/el-impl/el-impl/1.0/el-impl-1.0.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/container/arquillian-weld-ee-embedded-1.1/1.0.0.Alpha3/arquillian-weld-ee-embedded-1.1-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/protocol/arquillian-protocol-local/1.0.0.Alpha3/arquillian-protocol-local-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/arquillian/testenricher/arquillian-testenricher-cdi/1.0.0.Alpha3/arquillian-testenricher-cdi-1.0.0.Alpha3.jar:/home/jdoe/.m2/repository/org/jboss/shrinkwrap/shrinkwrap-extension-classloader/1.0.0-alpha-11/shrinkwrap-extension-classloader-1.0.0-alpha-11.jar:/home/jdoe/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar:/home/jdoe/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/home/jdoe/.m2/repository/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/112/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/110/1/.cp/:/home/jdoe/.eclipse/org.eclipse.platform_3.5.0_155965261/configuration/org.eclipse.osgi/bundles/111/1/.cp/"; + + MavenArtifactResolver resolver = new MavenArtifactResolver(groupId, artifactId, classPath, linuxPathSeparator, linuxFileSeparator); + String path = resolver.resolve(); + assertEquals("/home/jdoe/workspace/extensions/impl/target/weld-extensions-1.2.3.Final.jar", path); + } + } diff --git a/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactResolver.java b/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactResolver.java index 11f3124..bea0106 100644 --- a/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactResolver.java +++ b/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactResolver.java @@ -1,9 +1,7 @@ package org.jboss.weld.extensions.test.util; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -19,105 +17,148 @@ public class MavenArtifactResolver public static File resolve(String groupId, String artifactId) { - String classPath = System.getProperty("java.class.path"); - // first look for an artifact from the repo - Matcher matches = getRepoMatcher(groupId, artifactId, classPath, File.pathSeparatorChar, File.separatorChar); - - if (!matches.find()) + if (groupId == null) { - // find a resource from the local build - String localClasses = getLocalClassesString(File.separatorChar); - Matcher localClassesMatcher = getLocalClassesMatcher(classPath, localClasses, File.pathSeparatorChar); - if (!localClassesMatcher.find()) - { - throw new IllegalArgumentException("Unable to find maven archive " + groupId + ":" + artifactId + " in the local build"); - } - else - { - List targetPaths = new ArrayList(); - do - { - String path = localClassesMatcher.group(); - targetPaths.add(path.substring(0, path.length() - 8)); - } - while (localClassesMatcher.find()); - String fileName = findBuiltArtifact(targetPaths, artifactId); - if (fileName == null) - { - throw new IllegalStateException("Unable to locate artifact for " + groupId + ":" + artifactId); - } - else - { - return new File(fileName); - } - } + throw new IllegalArgumentException("groupId cannot be null"); } - else + if (artifactId == null) { - return new File(matches.group(0)); + throw new IllegalArgumentException("artifactId cannot be null"); } + String path = new MavenArtifactResolver(groupId.trim(), artifactId.trim(), System.getProperty("java.class.path"), File.pathSeparatorChar, File.separatorChar).resolve(); + if (path == null) + { + throw new IllegalArgumentException("Cannot locate artifact for " + groupId + ":" + artifactId); + } + return new File(path); } public static File resolve(String qualifiedArtifactId) { String[] segments = qualifiedArtifactId.split(":"); - return resolve(segments[0], segments[1]); + if (segments.length == 2) + { + return resolve(segments[0], segments[1]); + } + else + { + throw new IllegalArgumentException("Unable to parse " + qualifiedArtifactId + " as a groupId:artifactId"); + } + } + + private final String classPathSeparatorRegex; + private final char fileSeparator; + private final String groupId; + private final String artifactId; + private final String classPath; + + MavenArtifactResolver(String groupId, String artifactId, String classPath, char pathSeparator, char fileSeparator) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.classPath = classPath; + this.classPathSeparatorRegex = "[^" + pathSeparator + "]*"; + this.fileSeparator = fileSeparator; } - public static String findBuiltArtifact(List targetPaths, String artifactId) + String resolve() { - final String regex = "^" + artifactId + "-[\\d+\\.]+(?:\\-\\p{Upper}*)?.jar$"; - for (String targetPath : targetPaths) + Matcher matches = createFullyQualifiedMatcher(); + if (!matches.find()) { - File target = new File(targetPath); - if (target.exists()) + matches = createUnqualifiedMatcher(); + if (!matches.find()) { - if (!target.isDirectory()) + matches = createTargetClassesMatcher(); + if (!matches.find()) { - throw new IllegalStateException("Found ${project.dir}/target/ but it is not a directory!"); + return null; } - String[] possibleFiles = target.list(new FilenameFilter() + else { - - public boolean accept(File dir, String name) + String fileName = scanForArtifact(matches); + if (fileName == null) + { + return null; + } + else { - return name.matches(regex); + return fileName; } - - }); - if (possibleFiles.length == 1) + } + } + } + return matches.group(0); + } + + private String scanForArtifact(Matcher targetClassesMatcher) + { + // Locate all target/classes in classpath and store the path to all files target/ + List paths = new ArrayList(); + do + { + String path = targetClassesMatcher.group(); + File target = new File(path.substring(0, path.length() - 8)); + if (target.exists()) + { + if (!target.isDirectory()) { - return "target" + File.separatorChar + possibleFiles[0]; + throw new IllegalStateException("Found ${project.dir}/target/ but it is not a directory!"); } - if (possibleFiles.length > 0) + for (File file : target.listFiles()) { - throw new IllegalStateException("Found multiple matching files " + Arrays.asList(possibleFiles) + " for " + artifactId + " not sure which one to choose"); + paths.add(file.getPath()); } } } - return null; + while (targetClassesMatcher.find()); + return scanForArtifact(paths); } - public static Matcher getRepoMatcher(String groupId, String artifactId, String classPath, char pathSeparator, char fileSeparator) + String scanForArtifact(List paths) { - String pathString = getPathString(groupId, artifactId, File.separatorChar); - Pattern p = Pattern.compile("[^:]*" + Pattern.quote(pathString) + "[^:]*", Pattern.CASE_INSENSITIVE); - return p.matcher(classPath); + Pattern pattern = Pattern.compile(artifactId + "-[\\d+\\.]+(?:[\\-\\.]\\p{Alpha}*)?.jar$"); + for (String path : paths) + { + if (pattern.matcher(path).find()) + { + return path; + } + } + return null; } - - public static Matcher getLocalClassesMatcher(String classPath, String localClasses, char pathSeparator) + + /** + * Creates a matcher that returns any fully qualified matches of the form + * com/acme/acme-core/1.0/acme-core-1.0.jar. This will match + * artifacts on the classpath from the Maven repo. + */ + private Matcher createFullyQualifiedMatcher() { - Pattern p = Pattern.compile("[^" + pathSeparator + "]*" + localClasses + "[^" + pathSeparator + "]*", Pattern.CASE_INSENSITIVE); + String pathString = groupId.replace('.', fileSeparator) + fileSeparator + artifactId; + Pattern p = Pattern.compile(classPathSeparatorRegex + Pattern.quote(pathString) + classPathSeparatorRegex, Pattern.CASE_INSENSITIVE); return p.matcher(classPath); } - - public static String getPathString(String groupId, String artifactId, char fileSeparator) + + /** + * Creates a matcher that returns any unqualified matches of the form + * target/acme-foo-1.0.jar. This will match artifacts on the + * classpath from the reactor. + */ + private Matcher createUnqualifiedMatcher() { - return groupId.replace('.', fileSeparator) + fileSeparator + artifactId; + Pattern p = Pattern.compile(classPathSeparatorRegex + Pattern.quote("target" + fileSeparator + artifactId) + classPathSeparatorRegex, Pattern.CASE_INSENSITIVE); + return p.matcher(classPath); } - - public static String getLocalClassesString(char fileSeparator) + + /** + * Creates a matcher that returns any unqualified matches of the form + * target/acme-foo-1.0.jar. This locates all + * + */ + private Matcher createTargetClassesMatcher() { - return Pattern.quote("target" + fileSeparator + "classes"); + Pattern p = Pattern.compile(classPathSeparatorRegex + Pattern.quote("target" + fileSeparator + "classes") + classPathSeparatorRegex, Pattern.CASE_INSENSITIVE); + return p.matcher(classPath); } }