You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/01/24 21:22:30 UTC
svn commit: r1235468 - in /maven/plugins/trunk/maven-jar-plugin/src:
it/mjar-139/ it/mjar-139/src/ it/mjar-139/src/main/
it/mjar-139/src/main/java/ main/java/org/apache/maven/plugin/jar/
Author: krosenvold
Date: Tue Jan 24 20:22:30 2012
New Revision: 1235468
URL: http://svn.apache.org/viewvc?rev=1235468&view=rev
Log:
[MJAR-139] New option to avoid empty jar creation
Patch by Mark Rekveld, IT by me
Added:
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml (with props)
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java (with props)
maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh (with props)
Modified:
maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java
Added: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml?rev=1235468&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml (added)
+++ maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml Tue Jan 24 20:22:30 2012
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin-test-mjar-139</artifactId>
+ <version>1.0</version>
+ <name>Maven</name>
+ <packaging>jar</packaging>
+ <description>Avoid creating jars</description>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>@pom.version@</version>
+ <executions>
+ <execution>
+ <configuration>
+ <skipIfEmpty>true</skipIfEmpty>
+ </configuration>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java?rev=1235468&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java (added)
+++ maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java Tue Jan 24 20:22:30 2012
@@ -0,0 +1,31 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class Foo
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
Propchange: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/src/main/java/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh?rev=1235468&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh (added)
+++ maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh Tue Jan 24 20:22:30 2012
@@ -0,0 +1,51 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+ File target = new File( basedir, "target" );
+ if ( !target.exists() || !target.isDirectory() )
+ {
+ System.err.println( "target file is missing or not a directory." );
+ return false;
+ }
+
+ File artifact = new File( target, "maven-jar-plugin-test-mjar-139-1.0-tests.jar" );
+ if ( artifact.exists() )
+ {
+ System.err.println( "test artifact should not exist." );
+ return false;
+ }
+ return true;
+}
+catch( Throwable e )
+{
+ e.printStackTrace();
+ return false;
+}
+
+return false;
Propchange: maven/plugins/trunk/maven-jar-plugin/src/it/mjar-139/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java?rev=1235468&r1=1235467&r2=1235468&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java (original)
+++ maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java Tue Jan 24 20:22:30 2012
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.jar;
* under the License.
*/
+import java.io.File;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.execution.MavenSession;
@@ -28,8 +29,6 @@ import org.apache.maven.project.MavenPro
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.jar.JarArchiver;
-import java.io.File;
-
/**
* Base class for creating a jar from project classes.
*
@@ -138,6 +137,13 @@ public abstract class AbstractJarMojo
* @parameter expression="${jar.forceCreation}" default-value="false"
*/
private boolean forceCreation;
+
+ /**
+ * Skip creating empty archives
+ *
+ * @parameter expression="${jar.skipIfEmpty}" default-value="false"
+ */
+ private boolean skipIfEmpty;
/**
* Return the specific output directory to serve as the root for the archive.
@@ -240,16 +246,23 @@ public abstract class AbstractJarMojo
public void execute()
throws MojoExecutionException
{
- File jarFile = createArchive();
-
- String classifier = getClassifier();
- if ( classifier != null )
+ if ( skipIfEmpty && !getClassesDirectory().exists() )
{
- projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
+ getLog().info( "Skipping packaging of the test-jar" );
}
else
{
- getProject().getArtifact().setFile( jarFile );
+ File jarFile = createArchive();
+
+ String classifier = getClassifier();
+ if ( classifier != null )
+ {
+ projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
+ }
+ else
+ {
+ getProject().getArtifact().setFile( jarFile );
+ }
}
}