You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ol...@apache.org on 2012/12/06 22:02:07 UTC
svn commit: r1418074 - in /tomcat/maven-plugin/trunk:
tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/
tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/
Author: olamy
Date: Thu Dec 6 21:02:06 2012
New Revision: 1418074
URL: http://svn.apache.org/viewvc?rev=1418074&view=rev
Log:
[MTOMCAT-188] Allow for the creation of a war that is both executable and deployable
Submitted by Mitch Kyle
Patch applied with reformating code
Added:
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java (with props)
tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java (with props)
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-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.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=1418074&r1=1418073&r2=1418074&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 Thu Dec 6 21:02:06 2012
@@ -69,45 +69,45 @@ public abstract class AbstractExecWarMoj
extends AbstractTomcat7Mojo
{
- @Parameter (defaultValue = "${project.artifact}", required = true, readonly = true)
- private Artifact projectArtifact;
+ @Parameter( defaultValue = "${project.artifact}", required = true, readonly = true )
+ protected Artifact projectArtifact;
/**
* The maven project.
*/
- @Parameter (defaultValue = "${project}", required = true, readonly = true)
+ @Parameter( defaultValue = "${project}", required = true, readonly = true )
protected MavenProject project;
- @Parameter (defaultValue = "${plugin.artifacts}", required = true)
- private List<Artifact> pluginArtifacts;
+ @Parameter( defaultValue = "${plugin.artifacts}", required = true )
+ protected List<Artifact> pluginArtifacts;
- @Parameter (defaultValue = "${project.build.directory}")
- private File buildDirectory;
+ @Parameter( defaultValue = "${project.build.directory}" )
+ protected File buildDirectory;
/**
* Path under {@link #buildDirectory} where this mojo may do temporary work.
*/
- @Parameter (defaultValue = "${project.build.directory}/tomcat7-maven-plugin-exec")
+ @Parameter( defaultValue = "${project.build.directory}/tomcat7-maven-plugin-exec" )
private File pluginWorkDirectory;
- @Parameter (property = "maven.tomcat.exec.war.tomcatConf", defaultValue = "src/main/tomcatconf")
- private File tomcatConfigurationFilesDirectory;
+ @Parameter( property = "maven.tomcat.exec.war.tomcatConf", defaultValue = "src/main/tomcatconf" )
+ protected File tomcatConfigurationFilesDirectory;
- @Parameter (defaultValue = "src/main/tomcatconf/server.xml", property = "maven.tomcat.exec.war.serverXml")
- private File serverXml;
+ @Parameter( defaultValue = "src/main/tomcatconf/server.xml", property = "maven.tomcat.exec.war.serverXml" )
+ protected File serverXml;
/**
* Name of the generated exec JAR.
*/
- @Parameter (property = "tomcat.jar.finalName",
- defaultValue = "${project.artifactId}-${project.version}-war-exec.jar", required = true)
- private String finalName;
+ @Parameter( property = "tomcat.jar.finalName",
+ defaultValue = "${project.artifactId}-${project.version}-war-exec.jar", required = true )
+ protected String finalName;
/**
* The webapp context path to use for the web application being run.
* The name to store webapp in exec jar. Do not use /
*/
- @Parameter (property = "maven.tomcat.path", defaultValue = "${project.artifactId}", required = true)
+ @Parameter( property = "maven.tomcat.path", defaultValue = "${project.artifactId}", required = true )
protected String path;
@Parameter
@@ -120,82 +120,82 @@ public abstract class AbstractExecWarMoj
* Maven Artifact Factory component.
*/
@Component
- private ArtifactFactory artifactFactory;
+ protected ArtifactFactory artifactFactory;
/**
* Location of the local repository.
*/
- @Parameter (defaultValue = "${localRepository}", required = true, readonly = true)
- private ArtifactRepository local;
+ @Parameter( defaultValue = "${localRepository}", required = true, readonly = true )
+ protected ArtifactRepository local;
/**
* List of Remote Repositories used by the resolver
*/
- @Parameter (defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
+ @Parameter( defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true )
protected List<ArtifactRepository> remoteRepos;
@Component
- private MavenProjectHelper projectHelper;
+ protected MavenProjectHelper projectHelper;
/**
* Attach or not the generated artifact to the build (use true if you want to install or deploy it)
*/
- @Parameter (property = "maven.tomcat.exec.war.attachArtifact", defaultValue = "true", required = true)
- private boolean attachArtifact;
+ @Parameter( property = "maven.tomcat.exec.war.attachArtifact", defaultValue = "true", required = true )
+ protected boolean attachArtifact;
/**
* the classifier to use for the attached/generated artifact
*/
- @Parameter (property = "maven.tomcat.exec.war.attachArtifactClassifier", defaultValue = "exec-war",
- required = true)
- private String attachArtifactClassifier;
+ @Parameter( property = "maven.tomcat.exec.war.attachArtifactClassifier", defaultValue = "exec-war",
+ required = true )
+ protected String attachArtifactClassifier;
/**
* the type to use for the attached/generated artifact
*/
- @Parameter (property = "maven.tomcat.exec.war.attachArtifactType", defaultValue = "jar", required = true)
- private String attachArtifactClassifierType;
+ @Parameter( property = "maven.tomcat.exec.war.attachArtifactType", defaultValue = "jar", required = true )
+ protected String attachArtifactClassifierType;
/**
* to enable naming when starting tomcat
*/
- @Parameter (property = "maven.tomcat.exec.war.enableNaming", defaultValue = "false", required = true)
- private boolean enableNaming;
+ @Parameter( property = "maven.tomcat.exec.war.enableNaming", defaultValue = "false", required = true )
+ protected boolean enableNaming;
/**
* see http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html
*/
- @Parameter (property = "maven.tomcat.exec.war.accessLogValveFormat", defaultValue = "%h %l %u %t %r %s %b %I %D",
- required = true)
- private String accessLogValveFormat;
+ @Parameter( property = "maven.tomcat.exec.war.accessLogValveFormat", defaultValue = "%h %l %u %t %r %s %b %I %D",
+ required = true )
+ protected String accessLogValveFormat;
/**
* list of extra dependencies to add in the standalone tomcat jar: your jdbc driver, mail.jar etc..
* <b>Those dependencies will be in root classloader.</b>
*/
@Parameter
- private List<ExtraDependency> extraDependencies;
+ protected List<ExtraDependency> extraDependencies;
/**
* list of extra resources to add in the standalone tomcat jar: your logger configuration etc
*/
@Parameter
- private List<ExtraResource> extraResources;
+ protected List<ExtraResource> extraResources;
/**
* Main class to use for starting the standalone jar.
*/
- @Parameter (property = "maven.tomcat.exec.war.mainClass",
- defaultValue = "org.apache.tomcat.maven.runner.Tomcat7RunnerCli", required = true)
- private String mainClass;
+ @Parameter( property = "maven.tomcat.exec.war.mainClass",
+ defaultValue = "org.apache.tomcat.maven.runner.Tomcat7RunnerCli", required = true )
+ protected String mainClass;
/**
* which connector protocol to use HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
*/
- @Parameter (property = "maven.tomcat.exec.war.connectorHttpProtocol", defaultValue = "HTTP/1.1", required = true)
- private String connectorHttpProtocol;
+ @Parameter( property = "maven.tomcat.exec.war.connectorHttpProtocol", defaultValue = "HTTP/1.1", required = true )
+ protected String connectorHttpProtocol;
public void execute()
throws MojoExecutionException, MojoFailureException
@@ -348,16 +348,7 @@ public abstract class AbstractExecWarMoj
|| StringUtils.equals( "tomcat7-war-runner", pluginArtifact.getArtifactId() ) )
{
JarFile jarFile = new JarFile( pluginArtifact.getFile() );
- Enumeration<JarEntry> jarEntries = jarFile.entries();
- while ( jarEntries.hasMoreElements() )
- {
- JarEntry jarEntry = jarEntries.nextElement();
- InputStream jarEntryIs = jarFile.getInputStream( jarEntry );
-
- os.putArchiveEntry( new JarArchiveEntry( jarEntry.getName() ) );
- IOUtils.copy( jarEntryIs, os );
- os.closeArchiveEntry();
- }
+ extractJarToArchive( jarFile, os );
}
}
@@ -374,16 +365,7 @@ public abstract class AbstractExecWarMoj
artifactResolver.resolve( artifact, this.remoteRepos, this.local );
JarFile jarFile = new JarFile( artifact.getFile() );
- Enumeration<JarEntry> jarEntries = jarFile.entries();
- while ( jarEntries.hasMoreElements() )
- {
- JarEntry jarEntry = jarEntries.nextElement();
- InputStream jarEntryIs = jarFile.getInputStream( jarEntry );
-
- os.putArchiveEntry( new JarArchiveEntry( jarEntry.getName() ) );
- IOUtils.copy( jarEntryIs, os );
- os.closeArchiveEntry();
- }
+ extractJarToArchive( jarFile, os );
}
}
@@ -468,8 +450,8 @@ public abstract class AbstractExecWarMoj
}
}
- private void copyDirectoryContentIntoArchive( File pSourceFolder, String pDestinationPath,
- ArchiveOutputStream pArchiveOutputSteam )
+ protected void copyDirectoryContentIntoArchive( File pSourceFolder, String pDestinationPath,
+ ArchiveOutputStream pArchiveOutputSteam )
throws FileNotFoundException, IOException
{
@@ -514,7 +496,7 @@ public abstract class AbstractExecWarMoj
}
- private String[] toStringArray( List list )
+ protected String[] toStringArray( List list )
{
if ( list == null || list.isEmpty() )
{
@@ -533,7 +515,7 @@ public abstract class AbstractExecWarMoj
/**
* return file can be deleted
*/
- private File addContextXmlToWar( File contextXmlFile, File warFile )
+ protected File addContextXmlToWar( File contextXmlFile, File warFile )
throws IOException, ArchiveException
{
ArchiveOutputStream os = null;
@@ -550,14 +532,7 @@ public abstract class AbstractExecWarMoj
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();
- }
+ extractJarToArchive( jarFile, os );
os.flush();
}
finally
@@ -567,4 +542,28 @@ public abstract class AbstractExecWarMoj
}
return tmpWar;
}
+
+ /**
+ * Copy the contents of a jar file to another archive
+ *
+ * @param file The input jar file
+ * @param os The output archive
+ * @throws IOException
+ */
+ protected void extractJarToArchive( JarFile file, ArchiveOutputStream os )
+ throws IOException
+ {
+ Enumeration<? extends JarEntry> entries = file.entries();
+ while ( entries.hasMoreElements() )
+ {
+ JarEntry j = entries.nextElement();
+ os.putArchiveEntry( new JarArchiveEntry( j.getName() ) );
+ IOUtils.copy( file.getInputStream( j ), os );
+ os.closeArchiveEntry();
+ }
+ if ( file != null )
+ {
+ IOUtils.closeQuietly( file );
+ }
+ }
}
Added: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java?rev=1418074&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java Thu Dec 6 21:02:06 2012
@@ -0,0 +1,279 @@
+package org.apache.tomcat.maven.plugin.tomcat7.run;
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Properties;
+import java.util.jar.JarFile;
+
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.tomcat.maven.runner.Tomcat7Runner;
+import org.apache.tomcat.maven.runner.Tomcat7RunnerCli;
+import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ * Abstract Mojo for building deployable and executable war files
+ *
+ * @author Mitch Kyle
+ * @since 2.1
+ */
+public abstract class AbstractStandaloneWarMojo
+ extends AbstractExecWarMojo
+{
+
+ /**
+ * Name of the generated WAR.
+ */
+ @Parameter(property = "tomcat.jar.finalName",
+ defaultValue = "${project.artifactId}-${project.version}-standalone.war", required = true)
+ protected String finalName;
+
+ /**
+ * the classifier to use for the attached/generated artifact
+ */
+ @Parameter(property = "maven.tomcat.exec.war.attachArtifactClassifier", defaultValue = "standalone",
+ required = true)
+ protected String attachArtifactClassifier;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ if ( !"war".equals( project.getPackaging() ) )
+ {
+ throw new MojoFailureException( "Pacakaging must be of type war for standalone-war goal." );
+ }
+
+ File warExecFile = new File( buildDirectory, finalName );
+ if ( warExecFile.exists() )
+ {
+ warExecFile.delete();
+ }
+
+ File execWarJar = new File( buildDirectory, finalName );
+
+ FileOutputStream execWarJarOutputStream = null;
+ ArchiveOutputStream os = null;
+ File tmpPropertiesFile = null;
+ File tmpManifestFile = null;
+ FileOutputStream tmpPropertiesFileOutputStream = null;
+ PrintWriter tmpManifestWriter = null;
+
+ try
+ {
+ tmpPropertiesFile = new File( buildDirectory, "war-exec.properties" );
+ if ( tmpPropertiesFile.exists() )
+ {
+ tmpPropertiesFile.delete();
+ }
+ tmpPropertiesFile.getParentFile().mkdirs();
+
+ tmpManifestFile = new File( buildDirectory, "war-exec.manifest" );
+ if ( tmpManifestFile.exists() )
+ {
+ tmpManifestFile.delete();
+ }
+ tmpPropertiesFileOutputStream = new FileOutputStream( tmpPropertiesFile );
+ execWarJar.getParentFile().mkdirs();
+ execWarJar.createNewFile();
+ execWarJarOutputStream = new FileOutputStream( execWarJar );
+
+ tmpManifestWriter = new PrintWriter( tmpManifestFile );
+
+ // store :
+ //* wars in the root: foo.war
+ //* tomcat jars
+ //* file tomcat.standalone.properties with possible values :
+ // * useServerXml=true/false to use directly the one provided
+ // * enableNaming=true/false
+ // * wars=foo.war|contextpath;bar.war ( |contextpath is optionnal if empty use the war name )
+ // * accessLogValveFormat=
+ // * connectorhttpProtocol: HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
+ // * codeSourceContextPath=path parameter, default is project.artifactId
+ //* optionnal: conf/ with usual tomcat configuration files
+ //* MANIFEST with Main-Class
+
+ Properties properties = new Properties();
+
+ properties.put( Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY,
+ Long.toString( System.currentTimeMillis() ) );
+ properties.put( Tomcat7Runner.ENABLE_NAMING_KEY, Boolean.toString( enableNaming ) );
+ properties.put( Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY, accessLogValveFormat );
+ properties.put( Tomcat7Runner.HTTP_PROTOCOL_KEY, connectorHttpProtocol );
+ properties.put( Tomcat7Runner.CODE_SOURCE_CONTEXT_PATH, path );
+
+ os = new ArchiveStreamFactory().createArchiveOutputStream( ArchiveStreamFactory.JAR,
+ execWarJarOutputStream );
+
+ extractJarToArchive( new JarFile( projectArtifact.getFile() ), os );
+
+ if ( serverXml != null && serverXml.exists() )
+ {
+ os.putArchiveEntry( new JarArchiveEntry( "conf/server.xml" ) );
+ IOUtils.copy( new FileInputStream( serverXml ), os );
+ os.closeArchiveEntry();
+ properties.put( Tomcat7Runner.USE_SERVER_XML_KEY, Boolean.TRUE.toString() );
+ }
+ else
+ {
+ properties.put( Tomcat7Runner.USE_SERVER_XML_KEY, Boolean.FALSE.toString() );
+ }
+
+ os.putArchiveEntry( new JarArchiveEntry( "conf/web.xml" ) );
+ IOUtils.copy( getClass().getResourceAsStream( "/conf/web.xml" ), os );
+ os.closeArchiveEntry();
+
+ properties.store( tmpPropertiesFileOutputStream, "created by Apache Tomcat Maven plugin" );
+
+ tmpPropertiesFileOutputStream.flush();
+ tmpPropertiesFileOutputStream.close();
+
+ os.putArchiveEntry( new JarArchiveEntry( Tomcat7RunnerCli.STAND_ALONE_PROPERTIES_FILENAME ) );
+ IOUtils.copy( new FileInputStream( tmpPropertiesFile ), os );
+ os.closeArchiveEntry();
+
+ // add tomcat classes
+ for ( Artifact pluginArtifact : pluginArtifacts )
+ {
+ if ( StringUtils.equals( "org.apache.tomcat", pluginArtifact.getGroupId() ) || StringUtils.equals(
+ "org.apache.tomcat.embed", pluginArtifact.getGroupId() ) || StringUtils.equals(
+ "org.eclipse.jdt.core.compiler", pluginArtifact.getGroupId() ) || StringUtils.equals( "commons-cli",
+ pluginArtifact.getArtifactId() )
+ || StringUtils.equals( "tomcat7-war-runner", pluginArtifact.getArtifactId() ) )
+ {
+ JarFile jarFile = new JarFile( pluginArtifact.getFile() );
+ extractJarToArchive( jarFile, os );
+ }
+ }
+
+ // add extra dependencies
+ if ( extraDependencies != null && !extraDependencies.isEmpty() )
+ {
+ for ( Dependency dependency : extraDependencies )
+ {
+ // String groupId, String artifactId, String version, String scope, String type
+ Artifact artifact =
+ artifactFactory.createArtifact( dependency.getGroupId(), dependency.getArtifactId(),
+ dependency.getVersion(), dependency.getScope(),
+ dependency.getType() );
+
+ artifactResolver.resolve( artifact, this.remoteRepos, this.local );
+ JarFile jarFile = new JarFile( artifact.getFile() );
+ extractJarToArchive( jarFile, os );
+ }
+ }
+
+ Manifest manifest = new Manifest();
+
+ Manifest.Attribute mainClassAtt = new Manifest.Attribute();
+ mainClassAtt.setName( "Main-Class" );
+ mainClassAtt.setValue( mainClass );
+ manifest.addConfiguredAttribute( mainClassAtt );
+
+ manifest.write( tmpManifestWriter );
+ tmpManifestWriter.flush();
+ tmpManifestWriter.close();
+
+ os.putArchiveEntry( new JarArchiveEntry( "META-INF/MANIFEST.MF" ) );
+ IOUtils.copy( new FileInputStream( tmpManifestFile ), os );
+ os.closeArchiveEntry();
+
+ if ( attachArtifact )
+ {
+ //MavenProject project, String artifactType, String artifactClassifier, File artifactFile
+ projectHelper.attachArtifact( project, attachArtifactClassifierType, attachArtifactClassifier,
+ execWarJar );
+ }
+
+ if ( extraResources != null )
+ {
+ for ( ExtraResource extraResource : extraResources )
+ {
+
+ DirectoryScanner directoryScanner = new DirectoryScanner();
+ directoryScanner.setBasedir( extraResource.getDirectory() );
+ directoryScanner.addDefaultExcludes();
+ directoryScanner.setExcludes( toStringArray( extraResource.getExcludes() ) );
+ directoryScanner.setIncludes( toStringArray( extraResource.getIncludes() ) );
+ directoryScanner.scan();
+ for ( String includeFile : directoryScanner.getIncludedFiles() )
+ {
+ getLog().debug( "include file:" + includeFile );
+ os.putArchiveEntry( new JarArchiveEntry( includeFile ) );
+ IOUtils.copy( new FileInputStream( new File( extraResource.getDirectory(), includeFile ) ),
+ os );
+ os.closeArchiveEntry();
+ }
+ }
+ }
+
+ if ( tomcatConfigurationFilesDirectory != null && tomcatConfigurationFilesDirectory.exists() )
+ {
+ // Because its the tomcat default dir for configs
+ String aConfigOutputDir = "conf/";
+ copyDirectoryContentIntoArchive( tomcatConfigurationFilesDirectory, aConfigOutputDir, os );
+ }
+ }
+ catch ( ManifestException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ catch ( ArchiveException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtils.closeQuietly( os );
+ IOUtils.closeQuietly( tmpManifestWriter );
+ IOUtils.closeQuietly( execWarJarOutputStream );
+ IOUtils.closeQuietly( tmpPropertiesFileOutputStream );
+ }
+
+ }
+}
Propchange: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractStandaloneWarMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java?rev=1418074&view=auto
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java (added)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java Thu Dec 6 21:02:06 2012
@@ -0,0 +1,37 @@
+package org.apache.tomcat.maven.plugin.tomcat7.run;
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugins.annotations.Execute;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+
+/**
+ * This Mojo will create an executable war file with embedded tomcat that is also capable of being deployed elsewhere
+ *
+ * @author Mitch Kyle
+ * @since 2.1
+ */
+@Mojo(name = "standalone-war")
+@Execute(phase = LifecyclePhase.PACKAGE)
+public class StandaloneWarMojo
+ extends AbstractStandaloneWarMojo
+{
+ // no op
+}
Propchange: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/StandaloneWarMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java?rev=1418074&r1=1418073&r2=1418074&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java (original)
+++ tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java Thu Dec 6 21:02:06 2012
@@ -38,7 +38,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.URISyntaxException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -59,12 +62,16 @@ public class Tomcat7Runner
// contains war name wars=foo.war,bar.war
public static final String WARS_KEY = "wars";
+ |
+
public static final String ARCHIVE_GENERATION_TIMESTAMP_KEY = "generationTimestamp";
public static final String ENABLE_NAMING_KEY = "enableNaming";
public static final String ACCESS_LOG_VALVE_FORMAT_KEY = "accessLogValveFormat";
+ public static final String CODE_SOURCE_CONTEXT_PATH = "codeSourceContextPath";
+
/**
* key of the property which contains http protocol : HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
*/
@@ -95,6 +102,10 @@ public class Tomcat7Runner
public File extractDirectoryFile;
+ public String codeSourceContextPath = null;
+
+ public File codeSourceWar = null;
+
public String loggerName;
Catalina container;
@@ -151,6 +162,36 @@ public class Tomcat7Runner
}
+ codeSourceContextPath = runtimeProperties.getProperty( CODE_SOURCE_CONTEXT_PATH );
+ if ( codeSourceContextPath != null && !codeSourceContextPath.isEmpty() )
+ {
+ codeSourceWar = AccessController.doPrivileged( new PrivilegedAction<File>()
+ {
+ public File run()
+ {
+ try
+ {
+ File src =
+ new File( Tomcat7Runner.class.getProtectionDomain().getCodeSource().getLocation().toURI() );
+ if ( src.getName().endsWith( ".war" ) )
+ {
+ return src;
+ }
+ else
+ {
+ debugMessage( "ERROR: Code source is not a war file, ignoring." );
+ }
+ }
+ catch ( URISyntaxException e )
+ {
+ debugMessage( "ERROR: Could not find code source. " + e.getMessage() );
+
+ }
+ return null;
+ }
+ } );
+ }
+
// do we have to extract content
{
if ( !extractDirectoryFile.exists() || resetExtract || archiveTimestampChanged )
@@ -348,6 +389,17 @@ public class Tomcat7Runner
}
}
+ if ( codeSourceWar != null )
+ {
+ String baseDir = new File( extractDirectory, "webapps/" + codeSourceWar.getName() ).getAbsolutePath();
+ Context context = tomcat.addWebapp( codeSourceContextPath, baseDir );
+ URL contextFileUrl = getContextXml( baseDir );
+ if ( contextFileUrl != null )
+ {
+ context.setConfigFile( contextFileUrl );
+ }
+ }
+
tomcat.start();
}
@@ -481,6 +533,26 @@ public class Tomcat7Runner
}
}
+ //Copy code source to webapps folder
+ if ( codeSourceWar != null )
+ {
+ FileInputStream inputStream = null;
+ try
+ {
+ File expandFile = new File( extractDirectory, "webapps/" + codeSourceContextPath + ".war" );
+ inputStream = new FileInputStream( codeSourceWar );
+ debugMessage( "move code source to file:" + expandFile.getPath() );
+ expand( inputStream, expandFile );
+ }
+ finally
+ {
+ if ( inputStream != null )
+ {
+ inputStream.close();
+ }
+ }
+ }
+
// expand tomcat configuration files if there
expandConfigurationFile( "catalina.properties", extractDirectoryFile );
expandConfigurationFile( "logging.properties", extractDirectoryFile );
@@ -525,6 +597,11 @@ public class Tomcat7Runner
*/
private void populateWebAppWarPerContext( String warsValue )
{
+ if ( warsValue == null )
+ {
+ return;
+ }
+
StringTokenizer st = new StringTokenizer( warsValue, ";" );
while ( st.hasMoreTokens() )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1418074 - in /tomcat/maven-plugin/trunk:
tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/
tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/12/7 <ol...@apache.org>:
> + * @author Mitch Kyle
Use of @author tags is rather discouraged. ASF-released software is
collective work, contributed by many people.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org