From 70ff85fdef87332a616af86db5876b1612b9eec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Thu, 17 Mar 2016 00:27:53 +0100 Subject: [PATCH 1/5] add support for deploy path from command line --- .../tomcat/maven/runner/Tomcat7Runner.java | 3 ++- .../tomcat/maven/runner/Tomcat7RunnerCli.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java b/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java index 4bcf0f0a..ae1f7707 100644 --- a/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java +++ b/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java @@ -95,6 +95,8 @@ public class Tomcat7Runner public int ajpPort; + public String wars; + public String serverXmlPath; public Properties runtimeProperties; @@ -599,7 +601,6 @@ protected void extract() } - String wars = runtimeProperties.getProperty( WARS_KEY ); populateWebAppWarPerContext( wars ); for ( Map.Entry entry : webappWarPerContext.entrySet() ) diff --git a/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7RunnerCli.java b/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7RunnerCli.java index 8955862e..e31155f4 100644 --- a/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7RunnerCli.java +++ b/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7RunnerCli.java @@ -59,6 +59,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" ); @@ -110,6 +114,7 @@ public class Tomcat7RunnerCli .addOption( help ) // .addOption( debug ) // .addOption( sysProps ) // + .addOption( path ) // .addOption( httpProtocol ) // .addOption( clientAuth ) // .addOption( keyAlias ) // @@ -199,6 +204,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() ); From 46d1eb421c63bb152f3fa222bfab1b1a3358cb69 Mon Sep 17 00:00:00 2001 From: Ludovic SMADJA Date: Wed, 7 Jun 2017 10:13:54 +0200 Subject: [PATCH 2/5] some change to be compatible with 8.5.14 tomcat version --- pom.xml | 20 ++++++++-- tomcat8-maven-plugin/pom.xml | 12 +----- .../plugin/tomcat8/run/AbstractRunMojo.java | 13 ++++-- .../maven/plugin/tomcat8/run/RunMojo.java | 40 +++++-------------- 4 files changed, 38 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index 3bcf3ceb..5fa59f35 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 2008 7.0.59 - 8.0.14 + 8.5.14 @@ -83,6 +83,7 @@ file://${tomcat-maven.siteFilePath} ${user.home}/tomcat-maven-plugin-${project.version}-content + 8.5.14 @@ -325,7 +326,7 @@ tomcat7-maven-plugin tomcat8-war-runner tomcat8-maven-plugin - tomcat-maven-archetype + @@ -785,7 +786,8 @@ out/** .extract/** *.patch - **/access_log.* + **/access_log.* + tomcat-maven-archetype/** @@ -847,6 +849,7 @@ + + + central + plugins-release + http://poisson.jalios.net:8081/artifactory/plugins-release-local + + + snapshots + plugins-snapshot + http://poisson.jalios.net:8081/artifactory/plugins-snapshot-local + diff --git a/tomcat8-maven-plugin/pom.xml b/tomcat8-maven-plugin/pom.xml index 6bb68859..5e0374fb 100644 --- a/tomcat8-maven-plugin/pom.xml +++ b/tomcat8-maven-plugin/pom.xml @@ -41,7 +41,7 @@ org.apache.tomcat.embed tomcat-embed-core - ${tomcat8Version} + ${tomcatEmbed8Version} org.apache.tomcat @@ -134,16 +134,6 @@ ${tomcat8Version} - - org.apache.tomcat.embed - tomcat-embed-logging-juli - ${tomcat8Version} - - - org.apache.tomcat.embed - tomcat-embed-logging-log4j - ${tomcat8Version} - org.eclipse.jdt.core.compiler diff --git a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java index 237d6454..d233de8b 100644 --- a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java +++ b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java @@ -793,6 +793,8 @@ protected static class MyDirContext String buildOutputDirectory; String webAppPath; + + File webAppFile; WebResourceSet webResourceSet; @@ -803,6 +805,7 @@ protected static class MyDirContext this.buildOutputDirectory = buildOutputDirectory; this.webAppPath = webAppPath; + this.webAppFile = new File(webAppPath); this.log = log; } @@ -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 diff --git a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java index e141ef4e..f972ddd4 100644 --- a/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java +++ b/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java @@ -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; @@ -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 ); } @@ -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" ) ) @@ -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 ); } From 6a40de7c8ac83dd3549db2513320aff480ea3bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Fri, 25 Aug 2017 13:35:15 +0200 Subject: [PATCH 3/5] Add support for context path in cmdline. Bump Java to 1.8. --- common-tomcat-maven-plugin/pom.xml | 2 +- pom.xml | 6 +++--- tomcat-maven-archetype/pom.xml | 2 +- tomcat-maven-plugin-it/pom.xml | 2 +- tomcat6-maven-plugin/pom.xml | 2 +- tomcat7-maven-plugin/pom.xml | 2 +- tomcat7-war-runner/pom.xml | 4 ++-- tomcat8-maven-plugin/pom.xml | 2 +- tomcat8-war-runner/pom.xml | 4 ++-- .../tomcat/maven/runner/Tomcat8Runner.java | 3 ++- .../tomcat/maven/runner/Tomcat8RunnerCli.java | 20 ++++++++++++++++++- 11 files changed, 34 insertions(+), 15 deletions(-) diff --git a/common-tomcat-maven-plugin/pom.xml b/common-tomcat-maven-plugin/pom.xml index ddd6f943..477da174 100644 --- a/common-tomcat-maven-plugin/pom.xml +++ b/common-tomcat-maven-plugin/pom.xml @@ -24,7 +24,7 @@ tomcat-maven-plugin org.apache.tomcat.maven - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context common-tomcat-maven-plugin Apache Tomcat Maven Plugin :: Common API diff --git a/pom.xml b/pom.xml index 3bcf3ceb..d098d09c 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ tomcat-maven-plugin pom Apache Tomcat Maven Plugin - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context The Tomcat Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet container. @@ -41,8 +41,8 @@ UTF-8 - 1.5 - 1.5 + 1.8 + 1.8 2.2.1 3.2 diff --git a/tomcat-maven-archetype/pom.xml b/tomcat-maven-archetype/pom.xml index 128680b0..422b9c4f 100644 --- a/tomcat-maven-archetype/pom.xml +++ b/tomcat-maven-archetype/pom.xml @@ -23,7 +23,7 @@ org.apache.tomcat.maven tomcat-maven-plugin - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context ../pom.xml diff --git a/tomcat-maven-plugin-it/pom.xml b/tomcat-maven-plugin-it/pom.xml index 7569339b..a257f1e1 100644 --- a/tomcat-maven-plugin-it/pom.xml +++ b/tomcat-maven-plugin-it/pom.xml @@ -22,7 +22,7 @@ org.apache.tomcat.maven tomcat-maven-plugin - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context 4.0.0 diff --git a/tomcat6-maven-plugin/pom.xml b/tomcat6-maven-plugin/pom.xml index 2b84d418..8d12cec6 100644 --- a/tomcat6-maven-plugin/pom.xml +++ b/tomcat6-maven-plugin/pom.xml @@ -21,7 +21,7 @@ org.apache.tomcat.maven tomcat-maven-plugin - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context ../pom.xml diff --git a/tomcat7-maven-plugin/pom.xml b/tomcat7-maven-plugin/pom.xml index 8bf9d293..dac75a46 100644 --- a/tomcat7-maven-plugin/pom.xml +++ b/tomcat7-maven-plugin/pom.xml @@ -23,7 +23,7 @@ tomcat-maven-plugin org.apache.tomcat.maven - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context tomcat7-maven-plugin maven-plugin diff --git a/tomcat7-war-runner/pom.xml b/tomcat7-war-runner/pom.xml index 3ba1ac2f..b503a965 100644 --- a/tomcat7-war-runner/pom.xml +++ b/tomcat7-war-runner/pom.xml @@ -23,10 +23,10 @@ tomcat-maven-plugin org.apache.tomcat.maven - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context tomcat7-war-runner - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context Apache Tomcat Maven Plugin :: Tomcat 7.x War Runner diff --git a/tomcat8-maven-plugin/pom.xml b/tomcat8-maven-plugin/pom.xml index 6bb68859..d6647247 100644 --- a/tomcat8-maven-plugin/pom.xml +++ b/tomcat8-maven-plugin/pom.xml @@ -23,7 +23,7 @@ tomcat-maven-plugin org.apache.tomcat.maven - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context tomcat8-maven-plugin maven-plugin diff --git a/tomcat8-war-runner/pom.xml b/tomcat8-war-runner/pom.xml index ca580c65..9e20d304 100644 --- a/tomcat8-war-runner/pom.xml +++ b/tomcat8-war-runner/pom.xml @@ -23,10 +23,10 @@ tomcat-maven-plugin org.apache.tomcat.maven - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context tomcat8-war-runner - 3.0-SNAPSHOT + 3.0-SNAPSHOT-context Apache Tomcat Maven Plugin :: Tomcat 8.x War Runner diff --git a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java index 0ccd4a23..0c1f4b7a 100644 --- a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java +++ b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java @@ -91,6 +91,8 @@ public class Tomcat8Runner public int ajpPort; + public String wars; + public String serverXmlPath; public Properties runtimeProperties; @@ -554,7 +556,6 @@ protected void extract() } - String wars = runtimeProperties.getProperty( WARS_KEY ); populateWebAppWarPerContext( wars ); for ( Map.Entry entry : webappWarPerContext.entrySet() ) diff --git a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8RunnerCli.java b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8RunnerCli.java index 527e8fac..7977736e 100644 --- a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8RunnerCli.java +++ b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8RunnerCli.java @@ -59,6 +59,10 @@ public class Tomcat8RunnerCli 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" ); @@ -105,7 +109,8 @@ public class Tomcat8RunnerCli .addOption( resetExtract ) // .addOption( help ) // .addOption( debug ) // - .addOption( sysProps ) // + .addOption( sysProps ) + .addOption(path) .addOption( httpProtocol ) // .addOption( clientAuth ) // .addOption( keyAlias ) // @@ -194,6 +199,19 @@ public static void main( String[] args ) tomcat8Runner.httpProtocol = line.getOptionValue( httpProtocol.getOpt() ); } + tomcat8Runner.wars = tomcat8Runner.runtimeProperties.getProperty( Tomcat8Runner.WARS_KEY ); + if( line.hasOption( path.getOpt() ) ) { + String pathOption = line.getOptionValue( path.getOpt() ); + if ( pathOption != null && !pathOption.isEmpty() ) { + String[] split = tomcat8Runner.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 ); + } + tomcat8Runner.wars = split[0] + "|" + pathOption; + } + } + if ( line.hasOption( sysProps.getOpt() ) ) { Properties systemProperties = line.getOptionProperties( sysProps.getOpt() ); From 7786fbe1204acbce47d9b12bfbd83b84118b47eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Fri, 25 Aug 2017 14:18:37 +0200 Subject: [PATCH 4/5] Bump Tomcat to 8.5.20, fix path error. --- pom.xml | 4 ++-- .../java/org/apache/tomcat/maven/runner/Tomcat8Runner.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b94c0fb3..aea0fd58 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 2008 7.0.59 - 8.5.14 + 8.5.20 @@ -83,7 +83,7 @@ file://${tomcat-maven.siteFilePath} ${user.home}/tomcat-maven-plugin-${project.version}-content - 8.5.14 + 8.5.20 diff --git a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java index 0c1f4b7a..0cb61e87 100644 --- a/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java +++ b/tomcat8-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat8Runner.java @@ -216,7 +216,6 @@ public File run() } else { - String wars = runtimeProperties.getProperty( WARS_KEY ); populateWebAppWarPerContext( wars ); } } From 2d77085dab209ff1d89cd4b274bde1e89be1b4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Mon, 28 Aug 2017 12:40:32 +0200 Subject: [PATCH 5/5] Bump Tomcat 7 to 7.0.62. It's the latest version which supports Struts. --- pom.xml | 12 ++++++------ .../site/apt/adjust-embedded-tomcat-version.apt.vm | 2 +- .../site/apt/adjust-embedded-tomcat-version.apt.vm | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index aea0fd58..3ccdbd61 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 2001 2008 - 7.0.59 + 7.0.62 8.5.20 @@ -468,7 +468,7 @@ tomcat7-war-runner ${project.version} - + org.apache.tomcat.maven tomcat8-war-runner @@ -786,8 +786,8 @@ out/** .extract/** *.patch - **/access_log.* - tomcat-maven-archetype/** + **/access_log.* + tomcat-maven-archetype/** @@ -849,7 +849,7 @@ -