Index: D:/Work/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarMojoTest.java =================================================================== --- D:/Work/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarMojoTest.java (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarMojoTest.java (working copy) @@ -28,7 +28,7 @@ public class JarMojoTest extends AbstractMojoTestCase { - private File testPom = new File( getBasedir(), "src/test/resources/unit/jar-basic-test/pom.xml" ); + private File testPom = new File( getBasedir(), "src/test/unit-test-data/jar-basic-test/pom.xml" ); protected void setUp() throws Exception Index: D:/Work/maven-jar-plugin/src/test/unit-test-data/jar-basic-test/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/test/unit-test-data/jar-basic-test/pom.xml (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/unit-test-data/jar-basic-test/pom.xml (working copy) @@ -1,4 +1,6 @@ - + Index: D:/Work/maven-jar-plugin/src/test/unit-test-data/sign-0/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/test/unit-test-data/sign-0/pom.xml (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/unit-test-data/sign-0/pom.xml (working copy) @@ -1,5 +1,7 @@ - + 4.0.0 jar-mng-1130-0 org.apache.maven.plugins Index: D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java =================================================================== --- D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/src/main/java/TestCompile1.java (working copy) @@ -1,12 +0,0 @@ - - -public class TestCompile1 -{ - - public TestCompile1() - { - - System.out.println("Woo Hoo!"); - } - -} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/pom.xml (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/resources/unit/jar-basic-test/pom.xml (working copy) @@ -1,15 +0,0 @@ - - - - - maven-jar-plugin - - - foo - bar - - - - - - Index: D:/Work/maven-jar-plugin/src/test/resources/sign-0/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/test/resources/sign-0/pom.xml (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/resources/sign-0/pom.xml (working copy) @@ -1,31 +0,0 @@ - - - 4.0.0 - jar-mng-1130-0 - org.apache.maven.plugins - 1.0 - jar - Test Case for MNG-1130 - - - - org.apache.maven.plugins - maven-jar-plugin - - - - sign - - - - - keystore - m2 - m2m2m2 - - - - - - - Index: D:/Work/maven-jar-plugin/src/test/resources/sign-0/README =================================================================== --- D:/Work/maven-jar-plugin/src/test/resources/sign-0/README (revision 419822) +++ D:/Work/maven-jar-plugin/src/test/resources/sign-0/README (working copy) @@ -1,7 +0,0 @@ -A pom.xml that can be used to make some functional tests. -These values are of course specific to my environment. -Not sure what to do with this. Should I turn this into a fully automated functional test? - -The keystore was generated using: - -keytool -genkey -alias m2 -keypass m2m2m2 -keystore keystore -storepass m2m2m2 -dname "cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US" Index: D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java =================================================================== --- D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java (revision 419822) +++ D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java (working copy) @@ -16,16 +16,23 @@ * limitations under the License. */ +import java.io.File; +import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; -import java.io.File; - /** * Base class for creating a jar from project classes. * @@ -81,6 +88,14 @@ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); /** + * The set of dependencies required by the project + * @parameter default-value="${project.artifacts}" + * @required + * @readonly + */ + private java.util.Set dependencies; + + /** * @component */ private MavenProjectHelper projectHelper; @@ -161,6 +176,7 @@ public void execute() throws MojoExecutionException { + debugDependencies(); File jarFile = createArchive(); String classifier = getClassifier(); @@ -173,4 +189,115 @@ getProject().getArtifact().setFile( jarFile ); } } + + /** + * TODO: Delete this debugging code. Only for MJAR-28 debugging + * @throws MojoExecutionException + */ + private void debugDependencies() throws MojoExecutionException + { + if ( dependencies != null && !dependencies.isEmpty() ) + { + for ( Iterator it = dependencies.iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + getLog().error( "+++++++++++++++++++Artifact = " + artifact ); + getLog().error( "+++++++++++++++++++Artifact.getVersion() = " + artifact.getVersion() ); + getLog().error( "+++++++++++++++++++Artifact.getBaseVersion() = " + artifact.getBaseVersion() ); + getLog().error( "+++++++++++++++++++Artifact.isResolved() = " + artifact.isResolved() ); + getLog().error( "+++++++++++++++++++Artifact.isSnapshot() = " + artifact.isSnapshot() ); + getLog().error( "+++++++++++++++++++Artifact.getFile() = " + artifact.getFile().toString() ); + getLog().error( "+++++++++++++++++++Artifact evaluateFileNameMapping = " + evaluateFileNameMapping(artifact, "${artifactId}-${version}.${extension}") ); + } + } + } + + /** + * TODO: Delete this debugging code. Only for MJAR-28 debugging + * COPIED FROM org.apache.maven.plugin.assembly.AbstractAssemblyMojo + * + * @param artifact + * @param mapping + * @return + * @throws MojoExecutionException + */ + private String evaluateFileNameMapping( Artifact artifact, String mapping ) + throws MojoExecutionException + { + String fileNameMapping = mapping; + //insert the classifier if exist + if ( !StringUtils.isEmpty( artifact.getClassifier() ) ) + { + int dotIdx = fileNameMapping.lastIndexOf( "." ); + + if ( dotIdx >= 0 ) + { + String extension = fileNameMapping.substring( dotIdx + 1, fileNameMapping.length() ); + String artifactWithoutExt = fileNameMapping.substring( 0, dotIdx ); + + fileNameMapping = artifactWithoutExt + "-" + artifact.getClassifier() + "." + extension; + } + else + { + fileNameMapping = fileNameMapping + "-" + artifact.getClassifier(); + } + } + + return evaluateFileNameMapping( fileNameMapping, artifact ); + } + + /** + * TODO: Delete this debugging code. Only for MJAR-28 debugging + * COPIED FROM org.apache.maven.plugin.assembly.AbstractAssemblyMojo + * + * @param expression + * @param artifact + * @return expression + * @throws org.apache.maven.plugin.MojoExecutionException + * + */ + private String evaluateFileNameMapping( String expression, Artifact artifact ) + throws MojoExecutionException + { + String value = expression; + + // this matches the last ${...} string + Pattern pat = Pattern.compile( "^(.*)\\$\\{([^\\}]+)\\}(.*)$" ); + Matcher mat = pat.matcher( expression ); + + if ( mat.matches() ) + { + Object middle; + String left = evaluateFileNameMapping( mat.group( 1 ), artifact ); + try + { + middle = ReflectionValueExtractor.evaluate( mat.group( 2 ), artifact, false ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( + "Cannot evaluate filenameMapping: '" + mat.group( 1 ) + "': " + e.getMessage(), e ); + } + String right = mat.group( 3 ); + + if ( middle == null ) + { + // TODO: There should be a more generic way dealing with that. Having magic words is not good at all. + // probe for magic word + if ( "extension".equals( mat.group( 2 ).trim() ) ) + { + ArtifactHandler artifactHandler = artifact.getArtifactHandler(); + middle = artifactHandler.getExtension(); + } + else + { + middle = "${" + mat.group( 2 ) + "}"; + } + } + + value = left + middle + right; + } + + return value; + } } Index: D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignVerifyMojo.java =================================================================== --- D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignVerifyMojo.java (revision 419822) +++ D:/Work/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignVerifyMojo.java (working copy) @@ -16,27 +16,21 @@ * limitations under the License. */ -import org.apache.maven.plugin.logging.Log; -import org.apache.commons.lang.SystemUtils; +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.lang.SystemUtils; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; - +import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; -import org.codehaus.plexus.util.cli.DefaultConsumer; import org.codehaus.plexus.util.cli.StreamConsumer; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.InputStream; -import java.util.List; -import java.util.Iterator; -import java.util.StringTokenizer; -import java.util.ArrayList; - /** * Checks the signature of a signed jar using jarsigner. * @@ -207,7 +201,7 @@ getLog().info( line ); } } - + // taken from JavadocReport then slightly refactored // should probably share with other plugins that use $JAVA_HOME/bin tools @@ -270,63 +264,12 @@ } } - /** - * Convenience method to add an argument to the command line - * if the the value is not null or empty. - *

- * Moreover, the value could be comma separated. - * - * @param arguments - * @param key the argument name. - * @param value the argument value to be added. - * @see #addArgIfNotEmpty(java.util.List,String,String,boolean) - */ - private void addArgIfNotEmpty( List arguments, String key, String value ) - { - addArgIfNotEmpty( arguments, key, value, false ); - } - - /** - * Convenience method to add an argument to the command line - * if the the value is not null or empty. - *

- * Moreover, the value could be comma separated. - * - * @param arguments - * @param key the argument name. - * @param value the argument value to be added. - * @param repeatKey repeat or not the key in the command line - */ - private void addArgIfNotEmpty( List arguments, String key, String value, boolean repeatKey ) - { - if ( !StringUtils.isEmpty( value ) ) - { - arguments.add( key ); - - StringTokenizer token = new StringTokenizer( value, "," ); - while ( token.hasMoreTokens() ) - { - String current = token.nextToken().trim(); - - if ( !StringUtils.isEmpty( current ) ) - { - arguments.add( current ); - - if ( token.hasMoreTokens() && repeatKey ) - { - arguments.add( key ); - } - } - } - } - } - // // methods used for tests purposes - allow mocking and simulate automatic setters // protected int executeCommandLine( Commandline commandLine, InputStream inputStream, - StreamConsumer systemOut, StreamConsumer systemErr ) + StreamConsumer systemOut, StreamConsumer systemErr ) throws CommandLineException { return CommandLineUtils.executeCommandLine( commandLine, inputStream, systemOut, systemErr ); Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-Deployed-Snapshot-Classpath ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,deploy \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) @@ -0,0 +1,3 @@ +public class DummyMain { + +} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Deployed-Snapshot-Classpath/pom.xml (revision 0) @@ -0,0 +1,55 @@ + + 4.0.0 + test.maven-jar-plugin + MJAR-28-deployed-snapshot-jar + jar + MJAR-28 Deployed Snapshot Classpath jar-to-test + 1.0-SNAPSHOT + http://jira.codehaus.org/browse/MJAR-28. This test creates a deployed + snapshot and expects that the Class-Path in the Manifest is correctly resolved to the + latest deployed versions and not just -SNAPSHOT. This is the jar file that will have it's + Manifest Class-Path tested. + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + + + true + + + + + + + + + org.apache.maven.archetypes + maven-archetype-archetype + 1.0-alpha-4-SNAPSHOT + + + + + snapshots + snapshots.maven.codehaus.org for MJAR-28-Deployed-Snapshot-Classpath + Integration Tests + http://snapshots.maven.codehaus.org/maven2 + + true + + + + + + testing_snapshot + Snapshot Repository for Integration Tests + file://${basedir}/target/repo + + + \ No newline at end of file Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-Released-Classpath ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,install \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/src/main/java/Dummy.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/src/main/java/Dummy.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/src/main/java/Dummy.java (revision 0) @@ -0,0 +1,3 @@ +public class Dummy { + +} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Released-Classpath/pom.xml (revision 0) @@ -0,0 +1,55 @@ + + 4.0.0 + test.maven-jar-plugin + MJAR-28-released-classpath-jar + jar + MJAR-28 Released Classpath Test + 1.0 + http://jira.codehaus.org/browse/MJAR-28. This test uses only released + dependencies. Expect that the Class-Path in the Manifest is correctly resolved to the + released versions and does not include any dependencies of scope test or + provided. + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + + + true + + + + + + + + + commons-lang + commons-lang + 2.1 + + + commons-io + commons-io + 1.2 + provided + + + junit + junit + 3.8.1 + test + + + log4j + log4j + 1.2.13 + runtime + + + \ No newline at end of file Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-jar-to-depend-upon ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,deploy \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/src/main/java/Dummy.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/src/main/java/Dummy.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/src/main/java/Dummy.java (revision 0) @@ -0,0 +1,3 @@ +public class Dummy { + +} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-jar-to-depend-upon/pom.xml (revision 0) @@ -0,0 +1,38 @@ + + 4.0.0 + + test.maven-jar-plugin + MJAR-28-jar-to-depend-upon + jar + MJAR-28 Deployed Snapshot Classpath Test jar-to-depend-upon + 1.0-SNAPSHOT + http://jira.codehaus.org/browse/MJAR-28. This test creates a deployed + snapshot and expects that the Class-Path in the Manifest is correctly resolved to the + latest deployed versions and not just -SNAPSHOT. This is the jar that the jar to be tested + will depend upon and will be included in the classpath. + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + + + true + + + + + + + + + MJAR-28-Deployed-Snapshot-Classpath_jar-to-depend-upon-repository + Snapshot Repository for Integration Tests + file://${basedir}/target/repo + + + \ No newline at end of file Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-Installed-Snapshot-Classpath ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,install \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/src/main/java/DummyMain.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) @@ -0,0 +1,3 @@ +public class DummyMain { + +} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-Snapshot-Classpath/pom.xml (revision 0) @@ -0,0 +1,37 @@ + + 4.0.0 + test.maven-jar-plugin + MJAR-28-installed-snapshot-jar + jar + MJAR-28 Installed Snapshot Classpath jar-to-test + 1.0-SNAPSHOT + http://jira.codehaus.org/browse/MJAR-28. This test creates an + installed snapshot and expects that the Class-Path in the Manifest is correctly resolved + to the just -SNAPSHOT. This is the jar file that will have it's Manifest Class-Path + tested. + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + + + true + + + + + + + + + test.maven-jar-plugin + MJAR-28-jar-to-depend-upon + 1.0-SNAPSHOT + + + \ No newline at end of file Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-Installed-and-Deployed-Snapshot-Classpath ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,deploy \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/src/main/java/DummyMain.java (revision 0) @@ -0,0 +1,3 @@ +public class DummyMain { + +} \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Installed-and-Deployed-Snapshot-Classpath/pom.xml (revision 0) @@ -0,0 +1,56 @@ + + 4.0.0 + test.maven-jar-plugin + MJAR-28-installed-and-deployed-snapshot-jar + jar + MJAR-28 Installed and Deployed Snapshot Classpath jar-to-test + 1.0-SNAPSHOT + http://jira.codehaus.org/browse/MJAR-28. This test creates a locally + installed and deployed snapshot and expects that the Class-Path in the Manifest is + correctly resolved to the latest deployed versions and not just -SNAPSHOT. This is the jar + file that will have it's Manifest Class-Path tested. + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + + + true + + + + + + + + + test.maven-jar-plugin + MJAR-28-jar-to-depend-upon + 1.0-SNAPSHOT + + + + + MJAR-28-Deployed-Snapshot-Classpath_jar-to-depend-upon-repository + Snapshot Repository for MJAR-28-Deployed-Snapshot-Classpath Integration + Tests + + file://${basedir}/../MJAR-28-jar-to-depend-upon/target/repo + + true + + + + + + testing_snapshot + Snapshot Repository for Integration Tests + file://${basedir}/target/repo + + + \ No newline at end of file Property changes on: D:\Work\maven-jar-plugin\src\it\MJAR-28-Integration-Test-Verification ___________________________________________________________________ Name: svn:ignore + target Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/goals.txt =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/goals.txt (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/goals.txt (revision 0) @@ -0,0 +1 @@ +clean,test \ No newline at end of file Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/src/test/java/org/apache/maven/plugin/jar/MJAR_28IntegrationTest.java =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/src/test/java/org/apache/maven/plugin/jar/MJAR_28IntegrationTest.java (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/src/test/java/org/apache/maven/plugin/jar/MJAR_28IntegrationTest.java (revision 0) @@ -0,0 +1,143 @@ +package org.apache.maven.plugin.jar; + +import java.io.File; +import java.io.IOException; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; + +/* + * Copyright 2005 The Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Test case for http://jira.codehaus.org/browse/MJAR-28 + * + * Summary: + * If the pom dependencies are SNAPSHOT then the Manifest Class-Path entry + * is -SNAPSHOT. This works fine until the SNAPSHOT version is + * deployed, at which time it should be resolved to be a timestamped SNAPSHOT + * version. + * + * @author Bae + */ +public class MJAR_28IntegrationTest + extends AbstractMojoTestCase +{ + + /** + * Test that released dependencies of compile and runtime are the only + * ones on the classpath, and that provided and test are not included. + * + * @throws Exception + */ + public void testReleaseClasspath() + throws Exception + { + File testBasedir = getIntegrationTestBasedir( "MJAR-28-Released-Classpath" ); + File jarFileFile = getJarFileFile( testBasedir, "MJAR-28-released-classpath-jar", "1.0" ); + assertClasspathInJar(jarFileFile, "commons-lang-2.1.jar log4j-1.2.13.jar"); + } + + /** + * Test that installed (but not deployed) snapshot dependencies should be just + * -SNAPSHOT. + * + * @throws Exception + */ + public void testInstalledSnapshotClasspath() + throws Exception + { + File testBasedir = getIntegrationTestBasedir( "MJAR-28-Installed-Snapshot-Classpath" ); + File jarFileFile = getJarFileFile( testBasedir, "MJAR-28-installed-snapshot-jar", "1.0-SNAPSHOT" ); + assertClasspathInJar( jarFileFile, "MJAR-28-jar-to-depend-upon-1.0-SNAPSHOT.jar" ); + } + + /** + * Test that deployed snapshot dependencies should be just + * the resolved timestamped version and not -SNAPSHOT. + * + * @throws Exception + */ + public void testDeployedSnapshotClasspath() + throws Exception + { + File testBasedir = getIntegrationTestBasedir( "MJAR-28-Deployed-Snapshot-Classpath" ); + File jarFileFile = getJarFileFile( testBasedir, "MJAR-28-deployed-snapshot-jar", "1.0-SNAPSHOT" ); + String classpathInJar = getClasspathFromJar(jarFileFile); + Pattern deployedSnapshotClasspathPattern = Pattern.compile("maven-archetype-archetype-1.0-alpha-4-([0-9.]+).jar" ); + Matcher m = deployedSnapshotClasspathPattern.matcher(classpathInJar); +// TODO: Check off for now, looking into debug information as to why it is failing and need the build working. + assertTrue("Must match deployed snapshot pattern: " + deployedSnapshotClasspathPattern.pattern() + " but was " + classpathInJar, m.matches()); + } + + /** + * Test that a locally installed and deployed snapshot dependency should be just + * the resolved timestamped version and not -SNAPSHOT. + * + * @throws Exception + */ + public void testInstalledAndDeployedSnapshotClasspath() + throws Exception + { + File testBasedir = getIntegrationTestBasedir( "MJAR-28-Installed-and-Deployed-Snapshot-Classpath" ); + File jarFileFile = getJarFileFile( testBasedir, "MJAR-28-installed-and-deployed-snapshot-jar", "1.0-SNAPSHOT" ); + String classpathInJar = getClasspathFromJar(jarFileFile); + Pattern deployedSnapshotClasspathPattern = Pattern.compile("MJAR-28-jar-to-depend-upon-1.0-([0-9.]+).jar" ); + Matcher m = deployedSnapshotClasspathPattern.matcher(classpathInJar); +// TODO: Check off for now, looking into debug information as to why it is failing and need the build working. + assertTrue("Must match deployed snapshot pattern: " + deployedSnapshotClasspathPattern.pattern() + " but was " + classpathInJar, m.matches()); + } + + + private void assertClasspathInJar( File jarFileFile, String expectedClasspath ) + throws IOException + { + String classpath = getClasspathFromJar( jarFileFile ); + assertTrue( StringUtils.isNotEmpty( classpath ) ); + assertEquals(expectedClasspath, classpath); + } + + private String getClasspathFromJar( File jarFileFile ) + throws IOException + { + assertTrue( jarFileFile.getAbsolutePath() + " does not exist", jarFileFile.exists() ); + JarFile jarFile = new JarFile( jarFileFile ); + Manifest manifest = jarFile.getManifest(); + assertNotNull( manifest ); + Attributes mainAttributes = manifest.getMainAttributes(); + assertNotNull( mainAttributes ); + String classpath = mainAttributes.getValue( Attributes.Name.CLASS_PATH ); + return classpath; + } + + private File getJarFileFile( File testBasedir, String artifactId, String version ) throws Exception + { + // TODO: Refactor getJarFile to not be static and to return the correct File to the Jar. + return new File( testBasedir, "target/" + artifactId + "-" + version + ".jar" ); + } + + private File getIntegrationTestBasedir( String integrationTestName ) + { + // TODO: use pom value for src/it + return getTestFile( "../" + integrationTestName ); + } + +} Index: D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/pom.xml (revision 0) +++ D:/Work/maven-jar-plugin/src/it/MJAR-28-Integration-Test-Verification/pom.xml (revision 0) @@ -0,0 +1,50 @@ + + 4.0.0 + test.maven-jar-plugin + MJAR-28-verification-tests + jar + MJAR-28 Integration Test Verification of the Tests + 1.0 + http://jira.codehaus.org/browse/MJAR-28. + Verification of the integration tests. + + + maven-jar-plugin + org.apache.maven.plugins + 2.1-SNAPSHOT + test + + + org.apache.maven.shared + maven-plugin-testing-harness + 1.0-beta-1 + test + + + test.maven-jar-plugin + MJAR-28-deployed-snapshot-jar + 1.0-SNAPSHOT + test + + + test.maven-jar-plugin + MJAR-28-installed-and-deployed-snapshot-jar + 1.0-SNAPSHOT + test + + + test.maven-jar-plugin + MJAR-28-installed-snapshot-jar + 1.0-SNAPSHOT + test + + + test.maven-jar-plugin + MJAR-28-released-classpath-jar + 1.0 + test + + + \ No newline at end of file Index: D:/Work/maven-jar-plugin/pom.xml =================================================================== --- D:/Work/maven-jar-plugin/pom.xml (revision 419822) +++ D:/Work/maven-jar-plugin/pom.xml (working copy) @@ -24,17 +24,34 @@ - + + + + maven-it-plugin + + + integration-test + + test + + + goals.txt + + + + + + org.apache.maven maven-plugin-api - 2.0 + 2.0.1 org.apache.maven maven-project - 2.0 + 2.0.1 org.apache.maven @@ -42,6 +59,17 @@ 2.1 + org.apache.maven + maven-artifact + 2.0.1 + + + org.apache.maven + maven-embedder + 2.0.1 + test + + commons-lang commons-lang 2.1