You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/01/20 03:45:48 UTC
svn commit: r370706 - in /maven/plugins/trunk/maven-jar-plugin/src:
main/java/org/apache/maven/plugin/jar/JarSignMojo.java
test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java
test/java/org/apache/maven/plugin/jar/MockArtifact.java
Author: brett
Date: Thu Jan 19 18:45:46 2006
New Revision: 370706
URL: http://svn.apache.org/viewcvs?rev=370706&view=rev
Log:
update the jar signing mojo so that the signed jar can be installed
Added:
maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java (with props)
Modified:
maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignMojo.java
maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java
Modified: maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignMojo.java?rev=370706&r1=370705&r2=370706&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignMojo.java (original)
+++ maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarSignMojo.java Thu Jan 19 18:45:46 2006
@@ -20,6 +20,8 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -73,7 +75,6 @@
* Path of the jar to sign. When specified, the finalName is ignored.
*
* @parameter alias="jarpath"
- * @required
*/
private File jarPath;
@@ -111,9 +112,8 @@
*
* @parameter expression="${signedjar}" default-value="${project.build.directory}/signed/${project.build.finalName}.jar"
* @required
- * @todo make a File?
*/
- private String signedjar;
+ private File signedjar;
/**
* See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jarsigner.html#Options">options</a>.
@@ -132,7 +132,7 @@
/**
* Automatically verify a jar after signing it.
- *
+ * <p/>
* See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jarsigner.html#Options">options</a>.
*
* @parameter expression="${verify}" default-value="false"
@@ -147,31 +147,59 @@
*/
private boolean verbose;
+ /**
+ * @component
+ */
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * Classifier to use for the generated artifact. If not specified, the generated artifact becomes the primary artifact.
+ *
+ * @parameter expression="${classifier}"
+ */
+ private String classifier;
+
public void execute()
throws MojoExecutionException
{
signJar();
- if ( verify ) {
- JarSignVerifyMojo verify = new JarSignVerifyMojo();
- verify.setWorkingDir( workingDirectory );
- verify.setBasedir( basedir );
- verify.setJarPath( getJarFile() );
- verify.setVerbose( verbose );
- verify.execute();
+ if ( verify )
+ {
+ JarSignVerifyMojo verify = new JarSignVerifyMojo();
+ verify.setWorkingDir( workingDirectory );
+ verify.setBasedir( basedir );
+ verify.setJarPath( getJarFile() );
+ verify.setVerbose( verbose );
+ verify.execute();
}
}
- File getJarFile() {
- if ( jarPath != null ) {
+ File getJarFile()
+ {
+ if ( jarPath != null )
+ {
return jarPath;
- } else {
- return AbstractJarMojo.getJarFile( basedir, finalName, null);
+ }
+ else
+ {
+ return AbstractJarMojo.getJarFile( basedir, finalName, null );
}
}
- void signJar() throws MojoExecutionException {
+ void signJar()
+ throws MojoExecutionException
+ {
List arguments = new ArrayList();
Commandline commandLine = new Commandline();
@@ -186,7 +214,7 @@
addArgIfNotEmpty( arguments, "-keystore", this.keystore );
addArgIfNotEmpty( arguments, "-storepass", this.storepass );
addArgIfNotEmpty( arguments, "-keypass", this.keypass );
- addArgIfNotEmpty( arguments, "-signedjar", this.signedjar );
+ addArgIfNotEmpty( arguments, "-signedjar", this.signedjar.getPath() );
addArgIfNotEmpty( arguments, "-storetype", this.type );
addArgIfNotEmpty( arguments, "-sigfile", this.sigfile );
@@ -244,13 +272,22 @@
{
throw new MojoExecutionException( "command execution failed", e );
}
+
+ if ( classifier != null )
+ {
+ projectHelper.attachArtifact( project, "jar", classifier, signedjar );
+ }
+ else
+ {
+ project.getArtifact().setFile( signedjar );
+ }
}
- private void createParentDirIfNecessary( final String file )
+ private void createParentDirIfNecessary( File file )
{
if ( file != null )
{
- final File fileDir = new File( file ).getParentFile();
+ File fileDir = file.getParentFile();
if ( fileDir != null )
{ // not a relative path
@@ -310,8 +347,8 @@
* conditionally based on the given flag.
*
* @param arguments
- * @param b the flag which controls if the argument is added or not.
- * @param value the argument value to be added.
+ * @param b the flag which controls if the argument is added or not.
+ * @param value the argument value to be added.
*/
private void addArgIf( List arguments, boolean b, String value )
{
@@ -324,12 +361,12 @@
/**
* Convenience method to add an argument to the <code>command line</code>
* if the the value is not null or empty.
- * <p>
+ * <p/>
* Moreover, the value could be comma separated.
*
* @param arguments
- * @param key the argument name.
- * @param value the argument value to be added.
+ * @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 )
@@ -340,12 +377,12 @@
/**
* Convenience method to add an argument to the <code>command line</code>
* if the the value is not null or empty.
- * <p>
+ * <p/>
* Moreover, the value could be comma separated.
*
* @param arguments
- * @param key the argument name.
- * @param value the argument value to be added.
+ * @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 )
@@ -377,7 +414,7 @@
//
protected int executeCommandLine( Commandline commandLine, InputStream inputStream, StreamConsumer stream1,
- StreamConsumer stream2 )
+ StreamConsumer stream2 )
throws CommandLineException
{
return CommandLineUtils.executeCommandLine( commandLine, inputStream, stream1, stream2 );
@@ -403,7 +440,7 @@
this.keypass = keypass;
}
- public void setSignedJar( String signedjar )
+ public void setSignedJar( File signedjar )
{
this.signedjar = signedjar;
}
@@ -445,7 +482,13 @@
this.verbose = verbose;
}
- public void setVerify( boolean verify ) {
+ public void setProject( MavenProject project )
+ {
+ this.project = project;
+ }
+
+ public void setVerify( boolean verify )
+ {
this.verify = verify;
}
}
Modified: maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java?rev=370706&r1=370705&r2=370706&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java (original)
+++ maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/JarSignMojoTest.java Thu Jan 19 18:45:46 2006
@@ -17,8 +17,9 @@
*/
import junit.framework.TestCase;
-
+import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.StreamConsumer;
@@ -36,7 +37,7 @@
* Really running the command would mean checking the results, which is too painful and not really a unit test.
* It would probably require to 'jarsigner -verify' the resulting signed jar and I believe it would make the code
* too complex with very few benefits.
- *
+ *
* @author Jerome Lacoste <je...@coffeebreaks.org>
* @version $Id$
*/
@@ -57,7 +58,7 @@
public Map systemProperties = new HashMap();
protected int executeCommandLine( Commandline commandLine, InputStream inputStream, StreamConsumer stream1,
- StreamConsumer stream2 )
+ StreamConsumer stream2 )
throws CommandLineException
{
commandLines.add( commandLine );
@@ -83,10 +84,18 @@
File basedir = new File( System.getProperty( "java.io.tmpdir" ) );
mojo.setBasedir( basedir );
mojo.setWorkingDir( basedir );
- mojo.setSignedJar( "/tmp/signed/file-version.jar" );
+ mojo.setSignedJar( new File( "/tmp/signed/file-version.jar" ) );
mojo.setAlias( "alias" );
mojo.setKeystore( "/tmp/keystore" );
mojo.setKeypass( "secretpassword" );
+ MavenProject project = new MavenProject( new Model() );
+ MockArtifact mockArtifact = new MockArtifact();
+ mockArtifact.setGroupId( "test" );
+ mockArtifact.setArtifactId( "test" );
+ mockArtifact.setVersion( "1.0" );
+ mockArtifact.setType( "jar" );
+ project.setArtifact( mockArtifact );
+ mojo.setProject( project );
}
public void tearDown()
@@ -94,11 +103,6 @@
mojo = null;
}
- public void testPleaseMaven()
- {
- assertTrue( true );
- }
-
/**
*/
public void testRunOK()
@@ -106,15 +110,8 @@
{
mojo.execute();
- String[] expectedArguments = {
- "-keystore",
- "/tmp/keystore",
- "-keypass",
- "secretpassword",
- "-signedjar",
- "/tmp/signed/file-version.jar",
- getNullJar(),
- "alias" };
+ String[] expectedArguments = {"-keystore", "/tmp/keystore", "-keypass", "secretpassword", "-signedjar",
+ "/tmp/signed/file-version.jar", getNullJar(), "alias"};
checkMojo( expectedArguments );
}
@@ -138,14 +135,8 @@
assertTrue( e.getMessage().startsWith( "Result of " ) );
}
- String[] expectedArguments = {
- "-keystore",
- "/tmp/keystore",
- "-keypass",
- "secretpassword",
- "-signedjar",
- "/tmp/signed/file-version.jar",
- getNullJar() };
+ String[] expectedArguments = {"-keystore", "/tmp/keystore", "-keypass", "secretpassword", "-signedjar",
+ "/tmp/signed/file-version.jar", getNullJar()};
checkMojo( expectedArguments );
}
@@ -177,15 +168,8 @@
assertEquals( "command execution failed", e.getMessage() );
}
- String[] expectedArguments = {
- "-keystore",
- "/tmp/keystore",
- "-keypass",
- "secretpassword",
- "-signedjar",
- "/tmp/signed/file-version.jar",
- getNullJar(),
- "alias" };
+ String[] expectedArguments = {"-keystore", "/tmp/keystore", "-keypass", "secretpassword", "-signedjar",
+ "/tmp/signed/file-version.jar", getNullJar(), "alias"};
checkMojo( expectedArguments );
}
@@ -204,7 +188,7 @@
assertEquals( "Differing number of arguments", expectedCommandLineArguments.length, arguments.length );
for ( int i = 0; i < arguments.length; i++ )
{
- assertEquals( expectedCommandLineArguments[i], arguments[i] );
+ assertEquals( expectedCommandLineArguments[i].replace( '\\', '/' ), arguments[i].replace( '\\', '/' ) );
}
}
}
Added: maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java?rev=370706&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java (added)
+++ maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java Thu Jan 19 18:45:46 2006
@@ -0,0 +1,310 @@
+package org.apache.maven.plugin.jar;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @todo move to maven-artifact-test
+ */
+class MockArtifact
+ implements Artifact
+{
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ private File file;
+
+ private String scope;
+
+ private String type;
+
+ private String classifier;
+
+ private String baseVersion;
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String string )
+ {
+ this.version = string;
+ }
+
+ public String getScope()
+ {
+ return scope;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public boolean hasClassifier()
+ {
+ return classifier != null;
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ public void setFile( File file )
+ {
+ this.file = file;
+ }
+
+ public String getBaseVersion()
+ {
+ return baseVersion;
+ }
+
+ public void setBaseVersion( String string )
+ {
+ this.baseVersion = string;
+ }
+
+ public String getId()
+ {
+ // TODO
+ return null;
+ }
+
+ public String getDependencyConflictId()
+ {
+ // TODO
+ return null;
+ }
+
+ public void addMetadata( ArtifactMetadata artifactMetadata )
+ {
+ // TODO
+ }
+
+ public Collection getMetadataList()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setRepository( ArtifactRepository artifactRepository )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void updateVersion( String string, ArtifactRepository artifactRepository )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public String getDownloadUrl()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDownloadUrl( String string )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ArtifactHandler getArtifactHandler()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List getDependencyTrail()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDependencyTrail( List list )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public void setScope( String string )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public VersionRange getVersionRange()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setVersionRange( VersionRange versionRange )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void selectVersion( String string )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isSnapshot()
+ {
+ // TODO
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setResolved( boolean b )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isResolved()
+ {
+ // TODO
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setResolvedVersion( String string )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setArtifactHandler( ArtifactHandler artifactHandler )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isRelease()
+ {
+ // TODO
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setRelease( boolean b )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List getAvailableVersions()
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setAvailableVersions( List list )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isOptional()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public void setOptional( boolean b )
+ {
+ // TODO
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ArtifactVersion getSelectedVersion()
+ throws OverConstrainedVersionException
+ {
+ // TODO
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isSelectedVersionKnown()
+ throws OverConstrainedVersionException
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ public void setClassifier( String classifier )
+ {
+ this.classifier = classifier;
+ }
+
+ public int compareTo( Object o )
+ {
+ // TODO
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Propchange: maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-jar-plugin/src/test/java/org/apache/maven/plugin/jar/MockArtifact.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision