Author: olamy
Date: Mon Oct 17 19:58:35 2011
New Revision: 1185343
URL: http://svn.apache.org/viewvc?rev=1185343&view=rev
Log:
[MTOMCAT-102] fix creation of war when adding META-INF/context.xml
Modified:
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
Modified:
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
URL:
http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java?rev=1185343&r1=1185342&r2=1185343&view=diff
==============================================================================
---
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
(original)
+++
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
Mon Oct 17 19:58:35 2011
@@ -304,12 +304,13 @@ public abstract class AbstractExecWarMoj
artifactResolver.resolve( artifact, this.remoteRepos,
this.local );
File warFile = new File( buildDirectory,
artifact.getFile().getName() );
+ String warFileName = artifact.getFile().getName();
FileUtils.copyFile( artifact.getFile(), warFile );
if ( warRunDependency.contextXml != null )
{
- addContextXmlToWar( warRunDependency.contextXml,
warFile );
+ warFile = addContextXmlToWar(
warRunDependency.contextXml, warFile );
}
- os.putArchiveEntry( new JarArchiveEntry(
warFile.getName() ) );
+ os.putArchiveEntry( new JarArchiveEntry( warFileName )
);
IOUtils.copy( new FileInputStream( warFile ), os );
os.closeArchiveEntry();
String propertyWarValue = properties.getProperty(
Tomcat7Runner.WARS_KEY );
@@ -453,23 +454,41 @@ public abstract class AbstractExecWarMoj
}
- private void addContextXmlToWar( File contextXmlFile, File warFile )
+ /**
+ * return file can be deleted
+ */
+ private File addContextXmlToWar( File contextXmlFile, File warFile )
throws IOException, ArchiveException
{
ArchiveOutputStream os = null;
OutputStream warOutputStream = null;
+ File tmpWar = File.createTempFile( "tomcat", "war-exec" );
+ tmpWar.deleteOnExit();
+
try
{
- warOutputStream = new FileOutputStream( warFile );
+ warOutputStream = new FileOutputStream( tmpWar );
os = new ArchiveStreamFactory().createArchiveOutputStream(
ArchiveStreamFactory.JAR, warOutputStream );
os.putArchiveEntry( new JarArchiveEntry( "META-INF/context.xml" )
);
IOUtils.copy( new FileInputStream( contextXmlFile ), os );
os.closeArchiveEntry();
+
+ JarFile jarFile = new JarFile( warFile );
+ Enumeration<JarEntry> jarEntries = jarFile.entries();
+ while ( jarEntries.hasMoreElements() )
+ {
+ JarEntry jarEntry = jarEntries.nextElement();
+ os.putArchiveEntry( new JarArchiveEntry( jarEntry.getName() )
);
+ IOUtils.copy( jarFile.getInputStream( jarEntry ), os );
+ os.closeArchiveEntry();
+ }
+ os.flush();
}
finally
{
IOUtils.closeQuietly( os );
IOUtils.closeQuietly( warOutputStream );
}
+ return tmpWar;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]