Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tomcat7-maven-plugin deploy path from command line #22

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common-tomcat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<artifactId>tomcat-maven-plugin</artifactId>
<groupId>org.apache.tomcat.maven</groupId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
</parent>
<artifactId>common-tomcat-maven-plugin</artifactId>
<name>Apache Tomcat Maven Plugin :: Common API</name>
Expand Down
28 changes: 21 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<artifactId>tomcat-maven-plugin</artifactId>
<packaging>pom</packaging>
<name>Apache Tomcat Maven Plugin</name>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
<description>The Tomcat Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet
container.
</description>
Expand All @@ -41,8 +41,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<mavenVersion>2.2.1</mavenVersion>

<mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
Expand Down Expand Up @@ -73,8 +73,8 @@
<its.ajp.port>2001</its.ajp.port>
<!-- server port for it tests -->
<its.server.port>2008</its.server.port>
<tomcat7Version>7.0.59</tomcat7Version>
<tomcat8Version>8.0.14</tomcat8Version>
<tomcat7Version>7.0.62</tomcat7Version>
<tomcat8Version>8.5.20</tomcat8Version>

<!-- to prevent isssues with last apache parent pom -->
<arguments />
Expand All @@ -83,6 +83,7 @@
<tomcat-maven.siteUrlDeployment>file://${tomcat-maven.siteFilePath}</tomcat-maven.siteUrlDeployment>
<tomcat-maven.scmPubCheckoutDirectory>${user.home}/tomcat-maven-plugin-${project.version}-content</tomcat-maven.scmPubCheckoutDirectory>

<tomcatEmbed8Version>8.5.20</tomcatEmbed8Version>
</properties>

<prerequisites>
Expand Down Expand Up @@ -325,7 +326,7 @@
<module>tomcat7-maven-plugin</module>
<module>tomcat8-war-runner</module>
<module>tomcat8-maven-plugin</module>
<module>tomcat-maven-archetype</module>
<!-- <module>tomcat-maven-archetype</module>-->
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -467,7 +468,7 @@
<artifactId>tomcat7-war-runner</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-war-runner</artifactId>
Expand Down Expand Up @@ -786,6 +787,7 @@
<exclude>.extract/**</exclude>
<exclude>*.patch</exclude>
<exclude>**/access_log.*</exclude>
<exclude>tomcat-maven-archetype/**</exclude>
</excludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -847,6 +849,7 @@
</build>

<distributionManagement>
<!--
<repository>
<id>apache.releases.https</id>
<name>Apache Release Distribution Repository</name>
Expand All @@ -862,6 +865,17 @@
<id>apache.website</id>
<url>${tomcat-maven.siteUrlDeployment}</url>
</site>
-->
<repository>
<id>central</id>
<name>plugins-release</name>
<url>http://poisson.jalios.net:8081/artifactory/plugins-release-local</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://poisson.jalios.net:8081/artifactory/plugins-snapshot-local</url>
</snapshotRepository>
</distributionManagement>

<reporting>
Expand Down
2 changes: 1 addition & 1 deletion tomcat-maven-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion tomcat-maven-plugin-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion tomcat6-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion tomcat7-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>tomcat-maven-plugin</artifactId>
<groupId>org.apache.tomcat.maven</groupId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
</parent>
<artifactId>tomcat7-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Adjust Tomcat Version
<project>
[...]
<properties>
<tomcat.version>7.0.50</tomcat.version>
<tomcat.version>7.0.62</tomcat.version>
[...]
</properties>
[...]
Expand Down
4 changes: 2 additions & 2 deletions tomcat7-war-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<parent>
<artifactId>tomcat-maven-plugin</artifactId>
<groupId>org.apache.tomcat.maven</groupId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
</parent>
<artifactId>tomcat7-war-runner</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
<name>Apache Tomcat Maven Plugin :: Tomcat 7.x War Runner</name>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class Tomcat7Runner

public int ajpPort;

public String wars;

public String serverXmlPath;

public Properties runtimeProperties;
Expand Down Expand Up @@ -610,7 +612,6 @@ protected void extract()

}

String wars = runtimeProperties.getProperty( WARS_KEY );
populateWebAppWarPerContext( wars );

for ( Map.Entry<String, String> entry : webappWarPerContext.entrySet() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public class Tomcat7RunnerCli
OptionBuilder.withArgName( "serverXmlPath" ).hasArg().withDescription( "server.xml to use, optional" ).create(
"serverXmlPath" );

static Option path =
OptionBuilder.withArgName( "contextPath" ).hasArg().withDescription( "custom deployment context path, optional" ).create(
"path" );

static Option resetExtract =
OptionBuilder.withArgName( "resetExtract" ).withDescription( "clean previous extract directory" ).create(
"resetExtract" );
Expand Down Expand Up @@ -114,6 +118,7 @@ public class Tomcat7RunnerCli
.addOption( help ) //
.addOption( debug ) //
.addOption( sysProps ) //
.addOption( path ) //
.addOption( httpProtocol ) //
.addOption( clientAuth ) //
.addOption( keyAlias ) //
Expand Down Expand Up @@ -208,6 +213,19 @@ public static void main( String[] args )
tomcat7Runner.httpProtocol = line.getOptionValue( httpProtocol.getOpt() );
}

tomcat7Runner.wars = tomcat7Runner.runtimeProperties.getProperty( Tomcat7Runner.WARS_KEY );
if( line.hasOption( path.getOpt() ) ) {
String pathOption = line.getOptionValue( path.getOpt() );
if ( pathOption != null && !pathOption.isEmpty() ) {
String[] split = tomcat7Runner.wars.split("\\|");
if(split.length != 2) {
System.err.println( "JAR contains more than one WAR to deploy. Cannot set custom deploy path." );
System.exit( 1 );
}
tomcat7Runner.wars = split[0] + "|" + pathOption;
}
}

if ( line.hasOption( sysProps.getOpt() ) )
{
Properties systemProperties = line.getOptionProperties( sysProps.getOpt() );
Expand Down
14 changes: 2 additions & 12 deletions tomcat8-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>tomcat-maven-plugin</artifactId>
<groupId>org.apache.tomcat.maven</groupId>
<version>3.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT-context</version>
</parent>
<artifactId>tomcat8-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat8Version}</version>
<version>${tomcatEmbed8Version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
Expand Down Expand Up @@ -134,16 +134,6 @@
<version>${tomcat8Version}</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat8Version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
<version>${tomcat8Version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ protected static class MyDirContext
String buildOutputDirectory;

String webAppPath;

File webAppFile;

WebResourceSet webResourceSet;

Expand All @@ -803,6 +805,7 @@ protected static class MyDirContext

this.buildOutputDirectory = buildOutputDirectory;
this.webAppPath = webAppPath;
this.webAppFile = new File(webAppPath);
this.log = log;
}

Expand All @@ -813,17 +816,21 @@ public WebResource getResource( String path )
log.debug( "MyDirContext#getResource: " + path );
if ( "/WEB-INF/classes".equals( path ) )
{
return new FileResource( this, this.webAppPath, new File( this.buildOutputDirectory ), true );
return new FileResource( this, this.webAppPath, new File( this.buildOutputDirectory ), true, null );
}

File file = new File( path );
if ( file.exists() )
if ( file.exists() && isRelativeToWebAppPath(file) )
{
return new FileResource( this, this.webAppPath, file, true );
return new FileResource( this, this.webAppPath, file, true, null );
}
WebResource webResource = super.getResource( path );
return webResource;
}

private boolean isRelativeToWebAppPath(File file){
return file != null && file.toPath().startsWith(webAppFile.toPath());
}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import org.apache.catalina.WebResourceSet;
import org.apache.catalina.loader.WebappClassLoaderBase;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.webresources.AbstractArchiveResourceSet;
import org.apache.catalina.webresources.EmptyResource;
import org.apache.catalina.webresources.FileResource;
import org.apache.catalina.webresources.FileResourceSet;
import org.apache.catalina.webresources.JarResource;
import org.apache.catalina.webresources.JarResourceSet;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -476,25 +478,15 @@ private WebResource urlToWebResource( URL url, String path )
{
String filePath = StringUtils.removeStart( url.getFile().substring( 0, idx ), "file:" );

jarFile = new JarFile( filePath );

JarEntry jarEntry = jarFile.getJarEntry( StringUtils.removeStart( path, "/" ) );

return new JarResource( this, //
getPath(), //
filePath, //
url.getPath().substring( 0, idx ), //
jarEntry, //
"", //
null );
return new JarResourceSet(this,webAppPath,filePath, null).getResource(StringUtils.removeStart( path, "/" ));
}
else
{
return new FileResource( this, webAppPath, new File( url.getFile() ), true );
return new FileResource( this, webAppPath, new File( url.getFile() ), true, null );
}

}
catch ( IOException e )
catch ( IllegalArgumentException e )
{
throw new RuntimeException( e.getMessage(), e );
}
Expand Down Expand Up @@ -537,18 +529,18 @@ public WebResource getResource( String path )
if ( StringUtils.startsWithIgnoreCase( path, "/WEB-INF/LIB" ) )
{
File file = new File( StringUtils.removeStartIgnoreCase( path, "/WEB-INF/LIB" ) );
return new FileResource( context.getResources(), getPath(), file, true );
return new FileResource( context.getResources(), getPath(), file, true, null);
}
if ( StringUtils.equalsIgnoreCase( path, "/WEB-INF/classes" ) )
{
return new FileResource( context.getResources(), getPath(),
new File( project.getBuild().getOutputDirectory() ), true );
new File( project.getBuild().getOutputDirectory() ), true, null );
}

File file = new File( project.getBuild().getOutputDirectory(), path );
if ( file.exists() )
{
return new FileResource( context.getResources(), getPath(), file, true );
return new FileResource( context.getResources(), getPath(), file, true, null );
}

//if ( StringUtils.endsWith( path, ".class" ) )
Expand All @@ -564,21 +556,9 @@ public WebResource getResource( String path )

try
{
JarFile jarFile = new JarFile( jar );
JarEntry jarEntry =
(JarEntry) jarFile.getEntry( StringUtils.removeStart( path, "/" ) );
if ( jarEntry != null )
{
return new JarResource( context.getResources(), //
getPath(), //
jarFile.getName(), //
jar.toURI().toString(), //
jarEntry, //
path, //
jarFile.getManifest() );
}
return new JarResourceSet(context.getResources(),getPath(),jar.toURI().toString(), null).getResource(StringUtils.removeStart( path, "/" ));
}
catch ( IOException e )
catch ( IllegalArgumentException e )
{
getLog().debug( "skip error building jar file: " + e.getMessage(), e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Adjust Tomcat Version
<project>
[...]
<properties>
<tomcat.version>7.0.50</tomcat.version>
<tomcat.version>7.0.62</tomcat.version>
[...]
</properties>
[...]
Expand Down
Loading