Author: sebb Date: Tue Jun 25 00:20:09 2013 New Revision: 1496302 URL: http://svn.apache.org/r1496302 Log: More fixups to work as a Maven plugin
Added: maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelperMojo.java - copied, changed from r1496291, maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelpMojo.java Removed: maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelpMojo.java Modified: maven/sandbox/trunk/plugins/maven-digest-plugin/NOTICE.txt maven/sandbox/trunk/plugins/maven-digest-plugin/pom.xml maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/DigestMojo.java Modified: maven/sandbox/trunk/plugins/maven-digest-plugin/NOTICE.txt URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-digest-plugin/NOTICE.txt?rev=1496302&r1=1496301&r2=1496302&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-digest-plugin/NOTICE.txt (original) +++ maven/sandbox/trunk/plugins/maven-digest-plugin/NOTICE.txt Tue Jun 25 00:20:09 2013 @@ -1,4 +1,4 @@ -Apache Commons Digest Plugin +Apache Maven Digest Plugin Copyright 2013 The Apache Software Foundation This product includes software developed at Modified: maven/sandbox/trunk/plugins/maven-digest-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-digest-plugin/pom.xml?rev=1496302&r1=1496301&r2=1496302&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-digest-plugin/pom.xml (original) +++ maven/sandbox/trunk/plugins/maven-digest-plugin/pom.xml Tue Jun 25 00:20:09 2013 @@ -20,26 +20,28 @@ <modelVersion>4.0.0</modelVersion> <parent> - <groupId>org.apache.commons</groupId> - <artifactId>commons-parent</artifactId> - <version>30</version> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugins</artifactId> + <version>24</version> </parent> - <groupId>org.apache.commons</groupId> - <artifactId>commons-digest-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-digest-plugin</artifactId> <version>0.1-SNAPSHOT</version> <packaging>maven-plugin</packaging> - <name>Apache Commons Digest Maven Mojo</name> + <name>maven-digest-plugin Apache Maven Mojo</name> <inceptionYear>2013</inceptionYear> - <url>http://commons.apache.org/proper/commons-digest-plugin/</url> + <!-- TODO fix URL --> + <url>http://maven.apache.org/</url> <description> -Apache Commons Digest Maven plugin provides digest (hashing) facilities for files +The Apache Maven Digest Mojo provides digest (hashing) facilities for files </description> <issueManagement> <system>jira</system> - <url>http://issues.apache.org/jira/browse/COMMONSSITE</url> + <!-- TODO fix --> + <url>http://jira.codehaus.org/browse/M-TODO-FIX</url> </issueManagement> <scm> @@ -57,17 +59,6 @@ Apache Commons Digest Maven plugin provi <mavenPluginPluginVersion>3.2</mavenPluginPluginVersion> <maven.compiler.source>1.5</maven.compiler.source> <maven.compiler.target>1.5</maven.compiler.target> - <commons.release.version>0.1</commons.release.version> - <commons.componentid>commons-digest-plugin</commons.componentid> - <commons.rc.version>RC2</commons.rc.version> - <commons.release.desc>(Requires Maven ${mavenVersion} or later)</commons.release.desc> - <!-- Avoid problems with jar & osgi builds in CP --> - <commons.manifestfile /> - <!-- Temporary fix until CP31 is released --> - <maven.compile.source>${maven.compiler.source}</maven.compile.source> - <maven.compile.target>${maven.compiler.target}</maven.compile.target> - <!-- This should move to parent pom --> - <commons.packages.directory>target/packages</commons.packages.directory> </properties> <dependencies> @@ -121,156 +112,16 @@ Apache Commons Digest Maven plugin provi </dependencies> <build> - - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-plugin-plugin</artifactId> - <version>${mavenPluginPluginVersion}</version> - <configuration> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> - <descriptor>src/main/assembly/bin.xml</descriptor> <descriptor>src/main/assembly/src.xml</descriptor> </descriptors> <tarLongFileMode>gnu</tarLongFileMode> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <configuration> - <!-- see http://jira.codehaus.org/browse/MNG-5346 --> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - </configuration> - <executions> - <execution> - <id>generate-descriptor</id> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - <!-- The generated Mojo does not handle annotations properly, - and does not show any "User property" names. - Since this is misleading, it is better to drop the goal - The Maven Help plugin does show property names, so we create - our own Help Mojo that extends it. - <execution> - <id>generated-helpmojo</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - --> - </executions> - </plugin> </plugins> - </build> - - <profiles> - <!-- This will eventually be merged into the parent pom --> - <profile> - <id>release</id> - <build> - <plugins> - <!-- We want to create the assemblies in their own directory --> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <!-- Stop assemblies from being deployed to Nexus --> - <attach>false</attach> - <!-- put them here instead --> - <outputDirectory>${commons.packages.directory}</outputDirectory> - </configuration> - </plugin> - <!-- Create the hashes --> - <plugin> - <groupId>org.apache.commons</groupId> - <artifactId>commons-digest-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>digest</goal> - </goals> - <!-- must run after assembly and before deploy --> - <phase>verify</phase> - </execution> - </executions> - <configuration> - <includes> - <include>${commons.packages.directory}/*.zip</include> - <include>${commons.packages.directory}/*.tar.gz</include> - </includes> - </configuration> - </plugin> - </plugins> - </build> - </profile> - - <!-- - Temporary helper profile that can be used if gpg and staging plugins are installed locally - Will eventually be merged int release profile. - --> - <profile> - <id>release-part2</id> - <build> - <plugins> - <!-- Create the signatures --> - <plugin> - <groupId>org.apache.commons</groupId> - <artifactId>commons-gpg-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>signfiles</goal> - </goals> - <!-- must run after assembly and before deploy --> - <phase>verify</phase> - </execution> - </executions> - <configuration> - <includes> - <include>${commons.packages.directory}/*.zip</include> - <include>${commons.packages.directory}/*.tar.gz</include> - </includes> - </configuration> - </plugin> - <!-- Now create the staging scripts--> - <plugin> - <groupId>org.apache.commons</groupId> - <artifactId>commons-staging-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>create-scripts</goal> - </goals> - <!-- must run after assembly and before deploy --> - <phase>verify</phase> - </execution> - </executions> - <!-- This needs to be configured for the local project; sample below is for Apache Commons --> - <configuration> - <packageDirectory>${commons.packages.directory}</packageDirectory> - <asfProject>commons</asfProject> - <asfComponent>${commons.componentid}</asfComponent> - <stagingDirectory>${commons.release.name}-${commons.rc.version}</stagingDirectory> - <releaseNotes>RELEASE-NOTES.txt</releaseNotes> - <!-- safe place for upload and release testing --> - <rootUrl>https://dist.apache.org/repos/dist/dev/commons/TEST_PLS_IGNORE/</rootUrl> - </configuration> - </plugin> - </plugins> - </build> - </profile> - - </profiles> + </build> </project> Modified: maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/DigestMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/DigestMojo.java?rev=1496302&r1=1496301&r2=1496302&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/DigestMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/DigestMojo.java Tue Jun 25 00:20:09 2013 @@ -19,6 +19,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.MessageDigest; +import java.util.HashSet; +import java.util.Locale; import java.util.Set; import org.apache.commons.codec.binary.Hex; @@ -63,25 +65,22 @@ public class DigestMojo extends Abstract * Overrides includes and excludes; uses same syntax as for {@code <include>} * Patterns are assumed to be relative to the project base directory. */ - @Parameter (property="digest.files") + @Parameter (property="maven.digest.files") private String files; /** - * Whether to create the MD5 hash, default {@code true} + * The list of algorithm names with which to create digests. + * If none specified, the default is {@code MD5} and {@code SHA1}. + * By default the file extension is assumed to be the algorithm name + * converted to lower-case, and any "-" characters removed. */ - @Parameter( property = "digest.md5", defaultValue = "true" ) - private boolean createMD5; - - /** - * Whether to create the SHA1 hash, default {@code true} - */ - @Parameter( property = "digest.sha1", defaultValue = "true" ) - private boolean createSHA1; + @Parameter + private Set<String> algorithms; /** * Whether to append ' *filename' to the hash in the generated file, default {@code false} */ - @Parameter( property = "digest.appendFilename", defaultValue = "false" ) + @Parameter( property = "maven.digest.appendFilename", defaultValue = "false" ) private boolean appendFilename; public void execute() throws MojoExecutionException { @@ -90,13 +89,23 @@ public class DigestMojo extends Abstract if (files.length == 0) { log.warn("No files found. Please configure at least one <include> item or use -Ddigest.files"); } else { + if (algorithms == null || algorithms.size() == 0) { + algorithms = new HashSet<String>(2); + algorithms.add("MD5"); + algorithms.add("SHA-1"); + } try { for(String file : files) { - if (createMD5) { - createDigest("MD5", ".md5", file); - } - if (createSHA1) { - createDigest("SHA-1", ".sha1", file); + for(String algorithm : algorithms) { + String[] parts = algorithm.split("|"); + String extension; + if (parts.length == 2) { + algorithm = parts[0]; + extension = parts[1]; + } else { + extension = getExtension(algorithm); + } + createDigest(algorithm, extension, file); } } } catch (Exception ex) { @@ -105,6 +114,17 @@ public class DigestMojo extends Abstract } } + /** + * Creates the extension from the algortithm name, by converting to lower-case + * and dropping any "-" characters. The result is prefixed with ".". + * + * @param algorithm the algorithm name + * @return the extension, e.g. ".md5", ".sha1" + */ + private String getExtension(String algorithm) { + return "." + algorithm.toLowerCase(Locale.ENGLISH).replace("-", ""); + } + private void createDigest(String algorithm, String extension, String file) throws Exception { FileInputStream is = new FileInputStream(file); PrintWriter pw = new PrintWriter(file+extension, "UTF-8"); Copied: maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelperMojo.java (from r1496291, maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelpMojo.java) URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelperMojo.java?p2=maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelperMojo.java&p1=maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelpMojo.java&r1=1496291&r2=1496302&rev=1496302&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelpMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-digest-plugin/src/main/java/org/apache/maven/plugins/digest/HelperMojo.java Tue Jun 25 00:20:09 2013 @@ -28,12 +28,12 @@ import org.apache.maven.plugins.help.Des import org.apache.maven.project.MavenProject; /** - * Help Mojo that extends the standard Maven help plugin describe goal. + * Helper Mojo that extends the standard Maven help plugin describe goal. * This is needed because the generated help mojo * does not handle annotation property names at present. */ -@Mojo (name = "help") -public class HelpMojo extends DescribeMojo { +@Mojo (name = "helper") +public class HelperMojo extends DescribeMojo { @Component private MavenProject myProject; // Must not use same name as DescribeMojo