You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by tc...@apache.org on 2013/10/31 08:14:51 UTC
svn commit: r1537390 - in /maven/plugins/trunk/maven-rar-plugin/src:
main/java/org/apache/maven/plugin/rar/RarMojo.java
test/java/org/apache/maven/plugin/rar/RarMojoTest.java
Author: tchemit
Date: Thu Oct 31 07:14:51 2013
New Revision: 1537390
URL: http://svn.apache.org/r1537390
Log:
MRAR-28 - Add Support for Classifier
Submitted by: Marvin Addison
Modified:
maven/plugins/trunk/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java
Modified: maven/plugins/trunk/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java?rev=1537390&r1=1537389&r2=1537390&view=diff
==============================================================================
--- maven/plugins/trunk/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java (original)
+++ maven/plugins/trunk/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java Thu Oct 31 07:14:51 2013
@@ -98,7 +98,7 @@ public class RarMojo
* The directory for the generated RAR.
*/
@Parameter( defaultValue = "${project.build.directory}", required = true )
- private String outputDirectory;
+ private File outputDirectory;
/**
* The name of the RAR file to generate.
@@ -113,6 +113,13 @@ public class RarMojo
private MavenProject project;
/**
+ * Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.
+ *
+ * @parameter
+ */
+ private String classifier;
+
+ /**
* The Jar archiver.
*/
@Component( role = Archiver.class, hint = "jar" )
@@ -293,6 +300,7 @@ public class RarMojo
getLog().debug( "workDirectory[" + workDirectory + "]" );
getLog().debug( "outputDirectory[" + outputDirectory + "]" );
getLog().debug( "finalName[" + finalName + "]" );
+ getLog().debug( "classifier[" + classifier + "]" );
// Check if jar file is there and if requested, copy it
try
@@ -419,7 +427,7 @@ public class RarMojo
try
{
- File rarFile = new File( outputDirectory, finalName + ".rar" );
+ File rarFile = getRarFile(outputDirectory, finalName, classifier);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( rarFile );
@@ -447,6 +455,20 @@ public class RarMojo
return buildDir;
}
+ protected static File getRarFile( File basedir, String finalName, String classifier )
+ {
+ if ( classifier == null )
+ {
+ classifier = "";
+ }
+ else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
+ {
+ classifier = "-" + classifier;
+ }
+
+ return new File( basedir, finalName + classifier + ".rar" );
+ }
+
private void includeCustomManifestFile()
throws IOException
{
Modified: maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java?rev=1537390&r1=1537389&r2=1537390&view=diff
==============================================================================
--- maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java (original)
+++ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java Thu Oct 31 07:14:51 2013
@@ -19,20 +19,19 @@ package org.apache.maven.plugin.rar;
* under the License.
*/
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.codehaus.plexus.archiver.zip.ZipEntry;
-import org.codehaus.plexus.archiver.zip.ZipFile;
-import org.codehaus.plexus.util.FileUtils;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.archiver.zip.ZipEntry;
+import org.codehaus.plexus.archiver.zip.ZipFile;
+import org.codehaus.plexus.util.FileUtils;
+
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
-@SuppressWarnings("ConstantConditions")
public class RarMojoTest
extends AbstractMojoTestCase
{
@@ -59,7 +58,7 @@ public class RarMojoTest
String workDir = (String) getVariableValueFromObject( mojo, "workDirectory" );
- String outputDir = (String) getVariableValueFromObject( mojo, "outputDirectory" );
+ File outputDir = ( File ) getVariableValueFromObject( mojo, "outputDirectory" );
Boolean includeJar = (Boolean) getVariableValueFromObject( mojo, "includeJar" );
@@ -68,7 +67,7 @@ public class RarMojoTest
//include the project jar to the rar
File projectJar = new File( getBasedir(), "src/test/resources/unit/basic-rar-test/target/test-rar.jar" );
- FileUtils.copyFileToDirectory( projectJar, new File( outputDir ) );
+ FileUtils.copyFileToDirectory( projectJar, outputDir );
mojo.execute();
@@ -105,7 +104,7 @@ public class RarMojoTest
assertEquals( 0, expectedFiles.size() );
//check the generated rar file
- File rarFile = new File( outputDir, finalName + ".rar" );
+ File rarFile = new File( outputDir.getPath(), finalName + ".rar" );
assertTrue( rarFile.exists() );
@@ -135,17 +134,18 @@ public class RarMojoTest
public void testBasicRarWithDescriptor()
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-rar-with-descriptor/plugin-config.xml" );
+ File testPom = new File( getBasedir(),
+ "target/test-classes/unit/basic-rar-with-descriptor/plugin-config.xml" );
- RarMojo mojo = (RarMojo) lookupMojo( "rar", testPom );
+ RarMojo mojo = ( RarMojo ) lookupMojo( "rar", testPom );
assertNotNull( mojo );
- String finalName = (String) getVariableValueFromObject( mojo, "finalName" );
+ String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" );
- String workDir = (String) getVariableValueFromObject( mojo, "workDirectory" );
+ String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" );
- String outputDir = (String) getVariableValueFromObject( mojo, "outputDirectory" );
+ File outputDir = ( File ) getVariableValueFromObject( mojo, "outputDirectory" );
mojo.execute();
@@ -175,7 +175,7 @@ public class RarMojoTest
assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
//check the generated rar file
- File rarFile = new File( outputDir, finalName + ".rar" );
+ File rarFile = new File( outputDir.getPath(), finalName + ".rar" );
assertTrue( rarFile.exists() );
@@ -205,17 +205,18 @@ public class RarMojoTest
public void testBasicRarWithManifest()
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-rar-with-manifest/plugin-config.xml" );
+ File testPom = new File( getBasedir(),
+ "target/test-classes/unit/basic-rar-with-manifest/plugin-config.xml" );
- RarMojo mojo = (RarMojo) lookupMojo( "rar", testPom );
+ RarMojo mojo = ( RarMojo ) lookupMojo( "rar", testPom );
assertNotNull( mojo );
- String finalName = (String) getVariableValueFromObject( mojo, "finalName" );
+ String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" );
- String workDir = (String) getVariableValueFromObject( mojo, "workDirectory" );
+ String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" );
- String outputDir = (String) getVariableValueFromObject( mojo, "outputDirectory" );
+ File outputDir = ( File ) getVariableValueFromObject( mojo, "outputDirectory" );
mojo.execute();
@@ -247,7 +248,7 @@ public class RarMojoTest
assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
//check the generated rar file
- File rarFile = new File( outputDir, finalName + ".rar" );
+ File rarFile = new File( outputDir.getPath(), finalName + ".rar" );
assertTrue( rarFile.exists() );