You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/06/27 08:13:11 UTC
svn commit: r417352 - 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
test/resources/unit/sample_wars/simple-updated.war
Author: brett
Date: Mon Jun 26 23:13:10 2006
New Revision: 417352
URL: http://svn.apache.org/viewvc?rev=417352&view=rev
Log:
[MWAR-47] correctly handle timestamps when unpacking files from WAR
Added:
maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/sample_wars/simple-updated.war
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=417352&r1=417351&r2=417352&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 Mon Jun 26 23:13:10 2006
@@ -16,19 +16,19 @@
* limitations under the License.
*/
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.archiver.MavenArchiver;
-import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
@@ -417,9 +417,7 @@
* @param filterProperties
* @throws java.io.IOException if an error occured while copying webResources
*/
- public void copyResources( Resource resource,
- File webappDirectory,
- Properties filterProperties )
+ public void copyResources( Resource resource, File webappDirectory, Properties filterProperties )
throws IOException
{
if ( !resource.getDirectory().equals( webappDirectory.getPath() ) )
@@ -458,8 +456,7 @@
* @param webappDirectory the target directory
* @throws java.io.IOException if an error occured while copying webResources
*/
- public void copyResources( File sourceDirectory,
- File webappDirectory )
+ public void copyResources( File sourceDirectory, File webappDirectory )
throws IOException
{
if ( !sourceDirectory.equals( webappDirectory ) )
@@ -518,8 +515,7 @@
* @param webappDirectory
* @throws java.io.IOException if an error occured while building the webapp
*/
- public void buildWebapp( MavenProject project,
- File webappDirectory )
+ public void buildWebapp( MavenProject project, File webappDirectory )
throws MojoExecutionException, IOException
{
getLog().info( "Assembling webapp " + project.getArtifactId() + " in " + webappDirectory );
@@ -689,8 +685,7 @@
* @param file File to be unpacked.
* @param location Location where to put the unpacked files.
*/
- private void unpack( File file,
- File location )
+ private void unpack( File file, File location )
throws MojoExecutionException, NoSuchArchiverException
{
String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase();
@@ -700,6 +695,7 @@
UnArchiver unArchiver = archiverManager.getUnArchiver( archiveExt );
unArchiver.setSourceFile( file );
unArchiver.setDestDirectory( location );
+ unArchiver.setOverwrite( true );
unArchiver.extract();
}
catch ( IOException e )
@@ -719,8 +715,7 @@
* @param srcDir Directory containing unpacked dependent war contents
* @param targetDir Directory to overlay srcDir into
*/
- private void copyDependentWarContents( File srcDir,
- File targetDir )
+ private void copyDependentWarContents( File srcDir, File targetDir )
throws MojoExecutionException
{
DirectoryScanner scanner = new DirectoryScanner();
@@ -744,19 +739,14 @@
{
File targetFile = new File( targetDir, files[j] );
- // Do not overwrite existing files.
- if ( !targetFile.exists() )
+ try
{
- try
- {
- targetFile.getParentFile().mkdirs();
- copyFileIfModified( new File( srcDir, files[j] ), targetFile );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error copying file '" + files[j] + "' to '" + targetFile + "'",
- e );
- }
+ targetFile.getParentFile().mkdirs();
+ copyFileIfModified( new File( srcDir, files[j] ), targetFile );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error copying file '" + files[j] + "' to '" + targetFile + "'", e );
}
}
}
@@ -828,8 +818,7 @@
* <p/>
* TO DO: Remove this method when Maven moves to plexus-utils version 1.4
*/
- private static void copyFileToDirectoryIfModified( File source,
- File destinationDirectory )
+ private static void copyFileToDirectoryIfModified( File source, File destinationDirectory )
throws IOException
{
// TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes
@@ -848,8 +837,7 @@
// support ${token}
new FilterWrapper()
{
- public Reader getReader( Reader fileReader,
- Properties filterProperties )
+ public Reader getReader( Reader fileReader, Properties filterProperties )
{
return new InterpolationFilterReader( fileReader, filterProperties, "${", "}" );
}
@@ -857,8 +845,7 @@
// support @token@
new FilterWrapper()
{
- public Reader getReader( Reader fileReader,
- Properties filterProperties )
+ public Reader getReader( Reader fileReader, Properties filterProperties )
{
return new InterpolationFilterReader( fileReader, filterProperties, "@", "@" );
}
@@ -873,10 +860,7 @@
* @param filterProperties
* @throws IOException TO DO: Remove this method when Maven moves to plexus-utils version 1.4
*/
- private static void copyFilteredFile( File from,
- File to,
- String encoding,
- FilterWrapper[] wrappers,
+ private static void copyFilteredFile( File from, File to, String encoding, FilterWrapper[] wrappers,
Properties filterProperties )
throws IOException
{
@@ -934,8 +918,7 @@
* <p/>
* TO DO: Remove this method when Maven moves to plexus-utils version 1.4
*/
- private static void copyFileIfModified( File source,
- File destination )
+ private static void copyFileIfModified( File source, File destination )
throws IOException
{
// TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes
@@ -943,6 +926,8 @@
if ( destination.lastModified() < source.lastModified() )
{
FileUtils.copyFile( source, destination );
+ // preserve timestamp
+ destination.setLastModified( source.lastModified() );
}
}
@@ -959,8 +944,7 @@
* @param destinationDirectory
* @throws IOException TO DO: Remove this method when Maven moves to plexus-utils version 1.4
*/
- private static void copyDirectoryStructureIfModified( File sourceDirectory,
- File destinationDirectory )
+ private static void copyDirectoryStructureIfModified( File sourceDirectory, File destinationDirectory )
throws IOException
{
if ( !sourceDirectory.exists() )
@@ -1010,8 +994,7 @@
*/
private interface FilterWrapper
{
- Reader getReader( Reader fileReader,
- Properties filterProperties );
+ Reader getReader( Reader fileReader, Properties filterProperties );
}
/**
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=417352&r1=417351&r2=417352&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 Mon Jun 26 23:13:10 2006
@@ -203,10 +203,94 @@
assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- // check simple.war in the unit test dir under resources to verify the list of files
+ // check simple.war in the unit test dir under resources to verify the list of files
assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
assertTrue( "manifest file not found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() );
+ }
+
+ /**
+ * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
+ */
+ public void testExplodedWarMergeWarLocalFileOverride()
+ throws Exception
+ {
+ // setup test data
+ MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
+ SimpleWarArtifactStub simpleWarArtifact = new SimpleWarArtifactStub( getBasedir() );
+
+ String testId = "testExplodedWarMergeWarLocalFileOverride";
+ File webAppDirectory = new File( getTestDirectory(), testId );
+ File webAppSource = new File( getTestDirectory(), "/" + testId + "-test-data/source" );
+ File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
+ createFile( simpleJSP );
+
+ File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
+ createDir( workDirectory );
+
+ File classesDir = createClassesDir( testId, true );
+
+ // configure mojo
+ project.addArtifact( simpleWarArtifact );
+ this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+ setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ mojo.execute();
+
+ // 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 ) );
+ }
+
+ /**
+ * Merge a dependent WAR that gets updated since the last run.
+ */
+ public void testExplodedWarMergeWarUpdated()
+ throws Exception
+ {
+ // setup test data
+ MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
+ SimpleWarArtifactStub simpleWarArtifact = new SimpleWarArtifactStub( getBasedir() );
+
+ String testId = "testExplodedWarMergeWarUpdated";
+ File webAppDirectory = new File( getTestDirectory(), testId );
+ FileUtils.deleteDirectory( webAppDirectory );
+
+ File webAppSource = new File( getTestDirectory(), "/" + testId + "-test-data/source" );
+
+ File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
+ createDir( workDirectory );
+
+ File classesDir = createClassesDir( testId, true );
+
+ // configure mojo
+ project.addArtifact( simpleWarArtifact );
+ this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+ setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ mojo.execute();
+
+ // validate operation
+ File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
+
+ assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
+ assertEquals( "file incorrect", "", FileUtils.fileRead( expectedFile ) );
+
+ // update file, so the local one is older
+ simpleWarArtifact.setFile( new File( simpleWarArtifact.getFile().getParentFile(), "simple-updated.war" ) );
+
+ mojo.execute();
+
+ assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
+ assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
+
+ // update file, so the local one is newer
+ simpleWarArtifact.setFile( new File( simpleWarArtifact.getFile().getParentFile(), "simple.war" ) );
+
+ mojo.execute();
+
+ assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
+ assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
}
/**
Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/sample_wars/simple-updated.war
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/sample_wars/simple-updated.war?rev=417352&view=auto
==============================================================================
Binary files /tmp/tmp8HP8m9 and /tmp/tmpAGkM3M differ