Author: olamy Date: Mon Oct 17 14:03:38 2011 New Revision: 1185180 URL: http://svn.apache.org/viewvc?rev=1185180&view=rev Log: [MTOMCAT-102] option to add dynamically a context.xml to a war before packaging it
Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/WarRunDependency.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=1185180&r1=1185179&r2=1185180&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 14:03:38 2011 @@ -45,9 +45,11 @@ import org.codehaus.plexus.archiver.jar. import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintWriter; import java.util.Enumeration; import java.util.List; @@ -271,12 +273,12 @@ public abstract class AbstractExecWarMoj properties.put( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY, accessLogValveFormat ); os = - new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR, execWarJarOutputStream); + new ArchiveStreamFactory().createArchiveOutputStream( ArchiveStreamFactory.JAR, execWarJarOutputStream ); if ( "war".equals( project.getPackaging() ) ) { os.putArchiveEntry( new JarArchiveEntry( path + ".war" ) ); - IOUtils.copy( new FileInputStream(projectArtifact.getFile()), os ); + IOUtils.copy( new FileInputStream( projectArtifact.getFile() ), os ); os.closeArchiveEntry(); properties.put( Tomcat7Runner.WARS_KEY , path + ".war|" + path ); } @@ -295,8 +297,13 @@ public abstract class AbstractExecWarMoj artifactFactory.createArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType() ); artifactResolver.resolve( artifact, this.remoteRepos , this.local ); - os.putArchiveEntry( new JarArchiveEntry( artifact.getFile().getName() ) ); - IOUtils.copy( new FileInputStream(artifact.getFile()), os ); + File warFile = artifact.getFile(); + if ( warRunDependency.contextXml != null ) + { + addContextXmlToWar( warRunDependency.contextXml, warFile ); + } + os.putArchiveEntry( new JarArchiveEntry( warFile.getName() ) ); + IOUtils.copy( new FileInputStream( warFile ), os ); os.closeArchiveEntry(); String propertyWarValue = properties.getProperty( Tomcat7Runner.WARS_KEY ); // FIXME check contextPath is not empty or at least only / for root app @@ -424,7 +431,28 @@ public abstract class AbstractExecWarMoj IOUtils.closeQuietly( os ); IOUtils.closeQuietly( tmpManifestWriter ); IOUtils.closeQuietly( execWarJarOutputStream ); - IOUtils.closeQuietly(tmpPropertiesFileOutputStream); + IOUtils.closeQuietly( tmpPropertiesFileOutputStream ); + } + } + + + private void addContextXmlToWar(File contextXmlFile, File warFile) + throws IOException, ArchiveException + { + ArchiveOutputStream os = null; + OutputStream warOutputStream = null; + try + { + warOutputStream = new FileOutputStream( warFile ); + os = + new ArchiveStreamFactory().createArchiveOutputStream( ArchiveStreamFactory.JAR, warOutputStream ); + os.putArchiveEntry( new JarArchiveEntry( "META-INF/context.xml" ) ); + IOUtils.copy( new FileInputStream( contextXmlFile ), os ); + os.closeArchiveEntry(); + } finally + { + IOUtils.closeQuietly( os ); + IOUtils.closeQuietly( warOutputStream ); } } } Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/WarRunDependency.java URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/WarRunDependency.java?rev=1185180&r1=1185179&r2=1185180&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/WarRunDependency.java (original) +++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/WarRunDependency.java Mon Oct 17 14:03:38 2011 @@ -20,6 +20,8 @@ package org.apache.tomcat.maven.plugin.t import org.apache.maven.model.Dependency; +import java.io.File; + /** * @author Olivier Lamy * @since 2.0 @@ -31,6 +33,8 @@ public class WarRunDependency public String contextPath; + public File contextXml; + public WarRunDependency() { // no op --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org