You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/06/30 16:04:20 UTC

svn commit: r1498124 - in /maven/plugins/trunk/maven-war-plugin/src: it/MWAR-128/ it/MWAR-128/src/ it/MWAR-128/src/main/ it/MWAR-128/src/main/webapp/ it/MWAR-128/src/main/webapp/WEB-INF/ it/MWAR-128/src/main/webapp/WEB-INF/logs/ main/java/org/apache/ma...

Author: rfscholte
Date: Sun Jun 30 14:04:20 2013
New Revision: 1498124

URL: http://svn.apache.org/r1498124
Log:
[MWAR-128] war goal does not copy empty directories from webapp directory 

Added:
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/pom.xml
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/WEB-INF/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/WEB-INF/logs/
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml
    maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/verify.groovy
Modified:
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java

Added: maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/pom.xml?rev=1498124&view=auto
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/pom.xml (added)
+++ maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/pom.xml Sun Jun 30 14:04:20 2013
@@ -0,0 +1,38 @@
+<?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: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' xmlns='http://maven.apache.org/POM/4.0.0'>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>testwar</groupId>
+  <artifactId>MWAR-128</artifactId>
+  <packaging>war</packaging>
+  <version>1.0-SNAPSHOT</version>
+
+ <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <includeEmptyDirectories>true</includeEmptyDirectories>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/src/main/webapp/WEB-INF/web.xml?rev=1498124&view=auto
==============================================================================
    (empty)

Added: maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/verify.groovy?rev=1498124&view=auto
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/verify.groovy (added)
+++ maven/plugins/trunk/maven-war-plugin/src/it/MWAR-128/verify.groovy Sun Jun 30 14:04:20 2013
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+def warFile = new java.util.jar.JarFile( new File( basedir, "target/MWAR-128-1.0-SNAPSHOT.war" ), false );
+assert warFile.getEntry( 'WEB-INF/logs' ) != null
+

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java?rev=1498124&r1=1498123&r2=1498124&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java Sun Jun 30 14:04:20 2013
@@ -314,6 +314,12 @@ public abstract class AbstractWarMojo
      */
     @Parameter( defaultValue = "true" )
     private boolean recompressZippedFiles;
+    
+    /**
+     * @since 2.4
+     */
+    @Parameter( defaultValue = "false" )
+    private boolean includeEmptyDirectories;
 
     /**
      * Stop searching endToken at the end of line
@@ -649,6 +655,11 @@ public abstract class AbstractWarMojo
         {
             return getExcludes();
         }
+        
+        public boolean isWebappSourceIncludeEmptyDirectories()
+        {
+            return includeEmptyDirectories;
+        }
 
         public boolean archiveClasses()
         {
@@ -941,4 +952,9 @@ public abstract class AbstractWarMojo
     {
         return recompressZippedFiles;
     }
+    
+    protected boolean isIncludeEmptyDirectories()
+    {
+        return includeEmptyDirectories;
+    }
 }

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java?rev=1498124&r1=1498123&r2=1498124&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java Sun Jun 30 14:04:20 2013
@@ -232,6 +232,8 @@ public class WarMojo
         }
 
         warArchiver.setRecompressAddedZips( isRecompressZippedFiles()  );
+        
+        warArchiver.setIncludeEmptyDirs( isIncludeEmptyDirectories() );
 
         if ( !failOnMissingWebXml )
         {

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java?rev=1498124&r1=1498123&r2=1498124&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java Sun Jun 30 14:04:20 2013
@@ -144,45 +144,53 @@ public abstract class AbstractWarPackagi
         throws IOException
     {
         final File targetFile = new File( context.getWebappDirectory(), targetFilename );
-        context.getWebappStructure().registerFile( sourceId, targetFilename, new WebappStructure.RegistrationCallback()
+        
+        if( file.isFile() )
         {
-            public void registered( String ownerId, String targetFilename )
-                throws IOException
+            context.getWebappStructure().registerFile( sourceId, targetFilename, new WebappStructure.RegistrationCallback()
             {
-                copyFile( context, file, targetFile, targetFilename, false );
-            }
+                public void registered( String ownerId, String targetFilename )
+                    throws IOException
+                {
+                    copyFile( context, file, targetFile, targetFilename, false );
+                }
 
-            public void alreadyRegistered( String ownerId, String targetFilename )
-                throws IOException
-            {
-                copyFile( context, file, targetFile, targetFilename, true );
-            }
+                public void alreadyRegistered( String ownerId, String targetFilename )
+                    throws IOException
+                {
+                    copyFile( context, file, targetFile, targetFilename, true );
+                }
 
-            public void refused( String ownerId, String targetFilename, String actualOwnerId )
-                throws IOException
-            {
-                context.getLog().debug( " - " + targetFilename + " wasn't copied because it has "
-                    + "already been packaged for overlay [" + actualOwnerId + "]." );
-            }
+                public void refused( String ownerId, String targetFilename, String actualOwnerId )
+                    throws IOException
+                {
+                    context.getLog().debug( " - " + targetFilename + " wasn't copied because it has "
+                        + "already been packaged for overlay [" + actualOwnerId + "]." );
+                }
 
-            public void superseded( String ownerId, String targetFilename, String deprecatedOwnerId )
-                throws IOException
-            {
-                context.getLog().info( "File [" + targetFilename + "] belonged to overlay [" + deprecatedOwnerId
-                    + "] so it will be overwritten." );
-                copyFile( context, file, targetFile, targetFilename, false );
-            }
+                public void superseded( String ownerId, String targetFilename, String deprecatedOwnerId )
+                    throws IOException
+                {
+                    context.getLog().info( "File [" + targetFilename + "] belonged to overlay [" + deprecatedOwnerId
+                        + "] so it will be overwritten." );
+                    copyFile( context, file, targetFile, targetFilename, false );
+                }
 
-            public void supersededUnknownOwner( String ownerId, String targetFilename, String unknownOwnerId )
-                throws IOException
-            {
-                context.getLog()
-                    .warn( "File [" + targetFilename + "] belonged to overlay [" + unknownOwnerId
-                        + "] which does not exist anymore in the current project. It is recommended to invoke "
-                        + "clean if the dependencies of the project changed." );
-                copyFile( context, file, targetFile, targetFilename, false );
-            }
-        } );
+                public void supersededUnknownOwner( String ownerId, String targetFilename, String unknownOwnerId )
+                    throws IOException
+                {
+                    context.getLog()
+                        .warn( "File [" + targetFilename + "] belonged to overlay [" + unknownOwnerId
+                            + "] which does not exist anymore in the current project. It is recommended to invoke "
+                            + "clean if the dependencies of the project changed." );
+                    copyFile( context, file, targetFile, targetFilename, false );
+                }
+            } );
+        }
+        else if ( !targetFile.exists() && !targetFile.mkdirs() )
+        {
+            context.getLog().info( "Failed to create directory " + targetFile.getAbsolutePath() );
+        }
     }
 
     /**
@@ -353,7 +361,7 @@ public abstract class AbstractWarPackagi
             IOUtil.close( xmlReader );
         }
     }
-
+    
     /**
      * Returns the file to copy. If the includes are <tt>null</tt> or empty, the
      * default includes are used.
@@ -365,6 +373,20 @@ public abstract class AbstractWarPackagi
      */
     protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes )
     {
+        return getFilesToIncludes( baseDir, includes, excludes, false );
+    }
+
+    /**
+     * Returns the file to copy. If the includes are <tt>null</tt> or empty, the
+     * default includes are used.
+     *
+     * @param baseDir  the base directory to start from
+     * @param includes the includes
+     * @param excludes the excludes
+     * @return the files to copy
+     */
+    protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes, boolean includeDirectories )
+    {
         final DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir( baseDir );
 
@@ -385,8 +407,14 @@ public abstract class AbstractWarPackagi
 
         scanner.scan();
 
-        return new PathSet( scanner.getIncludedFiles() );
-
+        PathSet pathSet = new PathSet( scanner.getIncludedFiles() );
+        
+        if ( includeDirectories )
+        {
+            pathSet.addAll( scanner.getIncludedDirectories() );
+        }
+        
+        return pathSet;
     }
 
     /**

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java?rev=1498124&r1=1498123&r2=1498124&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java Sun Jun 30 14:04:20 2013
@@ -71,6 +71,13 @@ public interface WarPackagingContext
     String[] getWebappSourceIncludes();
 
     /**
+     * Returns {@code true} if empty directories should be includes, othewrwise {@code false}
+     *
+     * @return {@code true} if empty directories should be includes, othewrwise {@code false}
+     */
+    boolean isWebappSourceIncludeEmptyDirectories();
+
+    /**
      * Returns the webapp source excludes.
      *
      * @return the webapp source excludes

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java?rev=1498124&r1=1498123&r2=1498124&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java Sun Jun 30 14:04:20 2013
@@ -166,7 +166,7 @@ public class WarProjectPackagingTask
             context.getLog().info( "Copying webapp resources [" + context.getWebappSourceDirectory() + "]" );
             final PathSet sources =
                 getFilesToIncludes( context.getWebappSourceDirectory(), context.getWebappSourceIncludes(),
-                                    context.getWebappSourceExcludes() );
+                                    context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories() );
 
             try
             {