maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r417747 - in /maven/plugins/trunk/maven-war-plugin/src: main/java/org/apache/maven/plugin/war/AbstractWarMojo.java test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java
Date Wed, 28 Jun 2006 12:57:39 GMT
Author: brett
Date: Wed Jun 28 05:57:39 2006
New Revision: 417747

URL: http://svn.apache.org/viewvc?rev=417747&view=rev
Log:
[MWAR-55] make sure webapp sources take precedence over overlaid wars

Modified:
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
    maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java

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=417747&r1=417746&r2=417747&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
Wed Jun 28 05:57:39 2006
@@ -337,45 +337,8 @@
 
         webappDirectory.mkdirs();
 
-        File webinfDir = new File( webappDirectory, WEB_INF );
-        webinfDir.mkdirs();
-
-        File metainfDir = new File( webappDirectory, META_INF );
-        metainfDir.mkdirs();
-
         try
         {
-            List webResources = this.webResources != null ? Arrays.asList( this.webResources
) : null;
-            if ( webResources != null && webResources.size() > 0 )
-            {
-                Map filterProperties = getBuildFilterProperties();
-                for ( Iterator it = webResources.iterator(); it.hasNext(); )
-                {
-                    Resource resource = (Resource) it.next();
-                    copyResources( resource, webappDirectory, filterProperties );
-                }
-            }
-
-            copyResources( warSourceDirectory, webappDirectory );
-
-            if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) )
-            {
-                if ( !webXml.exists() )
-                {
-                    throw new MojoFailureException( "The specified web.xml file '" + webXml
+ "' does not exist" );
-                }
-
-                //rename to web.xml
-                copyFileIfModified( webXml, new File( webinfDir, "/web.xml" ) );
-            }
-
-            if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName()
) )
-            {
-                metainfDir = new File( webappDirectory, META_INF );
-                String xmlFileName = containerConfigXML.getName();
-                copyFileIfModified( containerConfigXML, new File( metainfDir, xmlFileName
) );
-            }
-
             buildWebapp( project, webappDirectory );
         }
         catch ( IOException e )
@@ -525,13 +488,50 @@
      * @throws java.io.IOException if an error occured while building the webapp
      */
     public void buildWebapp( MavenProject project, File webappDirectory )
-        throws MojoExecutionException, IOException
+        throws MojoExecutionException, IOException, MojoFailureException
     {
         getLog().info( "Assembling webapp " + project.getArtifactId() + " in " + webappDirectory
);
 
-        File libDirectory = new File( webappDirectory, WEB_INF + "/lib" );
+        File webinfDir = new File( webappDirectory, WEB_INF );
+        webinfDir.mkdirs();
+
+        File metainfDir = new File( webappDirectory, META_INF );
+        metainfDir.mkdirs();
+
+        List webResources = this.webResources != null ? Arrays.asList( this.webResources
) : null;
+        if ( webResources != null && webResources.size() > 0 )
+        {
+            Map filterProperties = getBuildFilterProperties();
+            for ( Iterator it = webResources.iterator(); it.hasNext(); )
+            {
+                Resource resource = (Resource) it.next();
+                copyResources( resource, webappDirectory, filterProperties );
+            }
+        }
+
+        copyResources( warSourceDirectory, webappDirectory );
+
+        if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) )
+        {
+            if ( !webXml.exists() )
+            {
+                throw new MojoFailureException( "The specified web.xml file '" + webXml +
"' does not exist" );
+            }
 
-        File tldDirectory = new File( webappDirectory, WEB_INF + "/tld" );
+            //rename to web.xml
+            copyFileIfModified( webXml, new File( webinfDir, "/web.xml" ) );
+        }
+
+        if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName()
) )
+        {
+            metainfDir = new File( webappDirectory, META_INF );
+            String xmlFileName = containerConfigXML.getName();
+            copyFileIfModified( containerConfigXML, new File( metainfDir, xmlFileName ) );
+        }
+
+        File libDirectory = new File( webinfDir, "lib" );
+
+        File tldDirectory = new File( webinfDir, "tld" );
 
         File webappClassesDirectory = new File( webappDirectory, WEB_INF + "/classes" );
 
@@ -750,8 +750,12 @@
 
             try
             {
-                targetFile.getParentFile().mkdirs();
-                copyFileIfModified( new File( srcDir, files[j] ), targetFile );
+                // Don't copy if it is in the source directory
+                if ( !new File( warSourceDirectory, files[j] ).exists() )
+                {
+                    targetFile.getParentFile().mkdirs();
+                    copyFileIfModified( new File( srcDir, files[j] ), targetFile );
+                }
             }
             catch ( IOException e )
             {

Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java?rev=417747&r1=417746&r2=417747&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java
(original)
+++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java
Wed Jun 28 05:57:39 2006
@@ -33,8 +33,10 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.StringReader;
+import java.text.SimpleDateFormat;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 
 public class WarExplodedMojoTest
     extends AbstractWarMojoTest
@@ -232,6 +234,19 @@
 
         // validate operation
         File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
+
+        assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
+        assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile
) );
+
+        // check when the merged war file is newer - so set an old time on the local file
+        long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
+        simpleJSP.setLastModified( time );
+        expectedFile.setLastModified( time );
+
+        project.addArtifact( simpleWarArtifact );
+        this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory,
project );
+        setVariableValueToObject( mojo, "workDirectory", workDirectory );
+        mojo.execute();
 
         assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
         assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile
) );



Mime
View raw message