
Property changes on: src\it\MJAR-20-notest
___________________________________________________________________
Added: svn:ignore
   + build.log


Index: src/it/MJAR-20-notest/pom.xml
===================================================================
--- src/it/MJAR-20-notest/pom.xml	(revision 0)
+++ src/it/MJAR-20-notest/pom.xml	(revision 0)
@@ -0,0 +1,52 @@
+<?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-20-01</artifactId>
+  <version>1.0</version>
+  <name>Maven</name>
+  <packaging>jar</packaging>
+  <url>http://maven.apache.org</url>
+  <description>Tests that empty test jars are not created.</description>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>jar</goal>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file

Property changes on: src\it\MJAR-20-notest\pom.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:keywords
   + "Date Author Revision"
Added: svn:eol-style
   + native

Index: src/it/MJAR-20-notest/verify.bsh
===================================================================
--- src/it/MJAR-20-notest/verify.bsh	(revision 0)
+++ src/it/MJAR-20-notest/verify.bsh	(revision 0)
@@ -0,0 +1,52 @@
+
+/*
+ * 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.*;
+
+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-20-01-1.0.jar" );
+    if ( !artifact.exists() || artifact.isDirectory() )
+    {
+        System.err.println( "no artifact archive was generated." );
+        return false;
+    }
+
+    File testArtifact = new File ( target, "maven-jar-plugin-test-mjar-20-01-1.0-tests.jar" );
+    if ( testArtifact.isFile() )
+    {
+        System.err.println( "empty test artifact archive was generated." );
+        return false;
+    }
+
+    return true;
+}
+catch( Throwable e )
+{
+    e.printStackTrace();
+    return false;
+}

Property changes on: src\it\MJAR-20-onlytest
___________________________________________________________________
Added: svn:ignore
   + build.log


Index: src/it/MJAR-20-onlytest/pom.xml
===================================================================
--- src/it/MJAR-20-onlytest/pom.xml	(revision 0)
+++ src/it/MJAR-20-onlytest/pom.xml	(revision 0)
@@ -0,0 +1,60 @@
+<?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-20-02</artifactId>
+  <version>1.0</version>
+  <name>Maven</name>
+  <packaging>jar</packaging>
+  <url>http://maven.apache.org</url>
+  <description>Tests that empty main jars are not created.</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>
+            <goals>
+              <goal>jar</goal>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file

Property changes on: src\it\MJAR-20-onlytest\pom.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:keywords
   + "Date Author Revision"
Added: svn:eol-style
   + native

Index: src/it/MJAR-20-onlytest/src/test/java/dummy/DummyTest.java
===================================================================
--- src/it/MJAR-20-onlytest/src/test/java/dummy/DummyTest.java	(revision 0)
+++ src/it/MJAR-20-onlytest/src/test/java/dummy/DummyTest.java	(revision 0)
@@ -0,0 +1,44 @@
+
+/*
+ * 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.
+ */
+package dummy;
+
+import junit.framework.TestCase;
+
+/**
+ * Dummy test-case, just for having something in src/test/java.
+ */
+public class DummyTest extends TestCase {
+    /**
+     * Creates a new instance.
+     *
+     * @param name Test name
+     */
+    public DummyTest( String name )
+    {
+        super( name );
+    }
+
+    /**
+     * Empty test. Avoids Surefire complains.
+     */
+    public void testDummy()
+    {
+    }
+}

Property changes on: src\it\MJAR-20-onlytest\src\test\java\dummy\DummyTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + "Date Author Revision"
Added: svn:eol-style
   + native

Index: src/it/MJAR-20-onlytest/verify.bsh
===================================================================
--- src/it/MJAR-20-onlytest/verify.bsh	(revision 0)
+++ src/it/MJAR-20-onlytest/verify.bsh	(revision 0)
@@ -0,0 +1,52 @@
+
+/*
+ * 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.*;
+
+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-20-02-1.0.jar" );
+    if ( artifact.isFile() )
+    {
+        System.err.println( "empty artifact archive was generated." );
+        return false;
+    }
+
+    File testArtifact = new File ( target, "maven-jar-plugin-test-mjar-20-02-1.0-tests.jar" );
+    if ( !testArtifact.exists() || testArtifact.isDirectory() )
+    {
+        System.err.println( "no test artifact archive was generated." );
+        return false;
+    }
+
+    return true;
+}
+catch( Throwable e )
+{
+    e.printStackTrace();
+    return false;
+}
Index: src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java	(revision 680945)
+++ src/main/java/org/apache/maven/plugin/jar/AbstractJarMojo.java	(working copy)
@@ -182,6 +182,13 @@
     public File createArchive()
         throws MojoExecutionException
     {
+        File contentDirectory = getClassesDirectory();
+        if ( !contentDirectory.exists() )
+        {
+            getLog().warn( "JAR will be empty - no content was marked for inclusion!" );
+            return null;
+        }
+
         File jarFile = getJarFile( outputDirectory, finalName, getClassifier() );
 
         MavenArchiver archiver = new MavenArchiver();
@@ -194,15 +201,7 @@
 
         try
         {
-            File contentDirectory = getClassesDirectory();
-            if ( !contentDirectory.exists() )
-            {
-                getLog().warn( "JAR will be empty - no content was marked for inclusion!" );
-            }
-            else
-            {
-                archiver.getArchiver().addDirectory( contentDirectory, getIncludes(), getExcludes() );
-            }
+            archiver.getArchiver().addDirectory( contentDirectory, getIncludes(), getExcludes() );
 
             File existingManifest = getDefaultManifestFile();
 
@@ -233,15 +232,18 @@
     {
         File jarFile = createArchive();
 
-        String classifier = getClassifier();
-        if ( classifier != null )
+        if ( jarFile != null )
         {
-            projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
+            String classifier = getClassifier();
+            if ( classifier != null )
+            {
+                projectHelper.attachArtifact( getProject(), getType(), classifier, jarFile );
+            }
+            else
+            {
+                getProject().getArtifact().setFile( jarFile );
+            }
         }
-        else
-        {
-            getProject().getArtifact().setFile( jarFile );
-        }
     }
 
     private String[] getIncludes()

