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 2014/09/23 07:00:08 UTC
svn commit: r1626940 - in /tomcat/maven-plugin/branches/tc8.x: ./
common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/
tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/
Author: olamy
Date: Tue Sep 23 05:00:07 2014
New Revision: 1626940
URL: http://svn.apache.org/r1626940
Log:
get classloader resources from reactor modules as well
Modified:
tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java
tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
tomcat/maven-plugin/branches/tc8.x/pom.xml
tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java
tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java
Modified: tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java?rev=1626940&r1=1626939&r2=1626940&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java (original)
+++ tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java Tue Sep 23 05:00:07 2014
@@ -37,10 +37,23 @@ public class ClassLoaderEntriesCalculato
*/
private List<File> tmpDirectories;
- public ClassLoaderEntriesCalculatorResult( List<String> classPathEntries, List<File> tmpDirectories )
+
+ /**
+ * directory part of webapp classpath (project.build.directory and reactor projects)
+ */
+ private List<String> buildDirectories;
+
+ /**
+ * @param classPathEntries
+ * @param tmpDirectories
+ * @param buildDirectories
+ */
+ public ClassLoaderEntriesCalculatorResult( List<String> classPathEntries, List<File> tmpDirectories,
+ List<String> buildDirectories )
{
this.classPathEntries = classPathEntries;
this.tmpDirectories = tmpDirectories;
+ this.buildDirectories = buildDirectories;
}
public List<String> getClassPathEntries()
@@ -62,4 +75,9 @@ public class ClassLoaderEntriesCalculato
{
this.tmpDirectories = tmpDirectories;
}
+
+ public List<String> getBuildDirectories()
+ {
+ return buildDirectories;
+ }
}
Modified: tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java?rev=1626940&r1=1626939&r2=1626940&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java (original)
+++ tomcat/maven-plugin/branches/tc8.x/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java Tue Sep 23 05:00:07 2014
@@ -45,7 +45,7 @@ import java.util.Set;
* @author Olivier Lamy
* @since 2.0
*/
-@Component (role = ClassLoaderEntriesCalculator.class)
+@Component( role = ClassLoaderEntriesCalculator.class )
public class DefaultClassLoaderEntriesCalculator
implements ClassLoaderEntriesCalculator
{
@@ -63,10 +63,12 @@ public class DefaultClassLoaderEntriesCa
List<File> tmpDirectories = new ArrayList<File>();
+ List<String> buildDirectories = new ArrayList<String>();
+
// add classes directories to loader
try
{
- @SuppressWarnings ("unchecked") List<String> classPathElements = request.isUseTestClassPath()
+ @SuppressWarnings( "unchecked" ) List<String> classPathElements = request.isUseTestClassPath()
? request.getMavenProject().getTestClasspathElements()
: request.getMavenProject().getRuntimeClasspathElements();
if ( classPathElements != null )
@@ -79,6 +81,7 @@ public class DefaultClassLoaderEntriesCa
request.getLog().debug(
"adding classPathElementFile " + classPathElementFile.toURI().toString() );
classLoaderEntries.add( classPathElementFile.toURI().toString() );
+ buildDirectories.add( classPathElement );
}
}
}
@@ -101,15 +104,15 @@ public class DefaultClassLoaderEntriesCa
String scope = artifact.getScope();
// skip provided and test scoped artifacts
- if ( !Artifact.SCOPE_PROVIDED.equals( scope ) && ( !Artifact.SCOPE_TEST.equals( scope )
- || request.isUseTestClassPath() ) )
+ if ( !Artifact.SCOPE_PROVIDED.equals( scope ) //
+ && ( !Artifact.SCOPE_TEST.equals( scope ) || request.isUseTestClassPath() ) )
{
request.getLog().debug(
"add dependency to webapploader " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ artifact.getVersion() + ":" + artifact.getScope() );
// we add artifact dependencies and projects from reactor if file (ie jar) as users can go to install/package phase
// so artifact.getFile is a file not a directory and not added when iterate on project.classPathElements
- if ( !isInProjectReferences( artifact, request.getMavenProject() ) || artifact.getFile().isFile() )
+ if ( !isInProjectReferences( artifact, request.getMavenProject() ) || artifact.getFile().isFile() )
{
String fileName = artifact.getGroupId() + "-" + artifact.getFile().getName();
if ( !fileInClassLoaderEntries.contains( fileName ) )
@@ -134,16 +137,16 @@ public class DefaultClassLoaderEntriesCa
boolean existed = !tmpDir.mkdirs();
// does a directory for this artifact already exist?
- if (existed)
+ if ( existed )
{
// check timestamp to see if artifact is newer than extracted directory
long dirLastMod = tmpDir.lastModified();
long warLastMod = artifact.getFile().lastModified();
- if (warLastMod == 0L || warLastMod > dirLastMod)
+ if ( warLastMod == 0L || warLastMod > dirLastMod )
{
request.getLog().debug(
- "re-exploding artifact " + artifact.getArtifactId() + " due to newer WAR");
+ "re-exploding artifact " + artifact.getArtifactId() + " due to newer WAR" );
deleteDirectory( tmpDir, request.getLog() );
tmpDir = new File( tmpExtractDatas, artifact.getArtifactId() );
@@ -153,7 +156,7 @@ public class DefaultClassLoaderEntriesCa
else
{
request.getLog().debug(
- "using existing exploded war for artifact " + artifact.getArtifactId());
+ "using existing exploded war for artifact " + artifact.getArtifactId() );
}
}
@@ -162,7 +165,7 @@ public class DefaultClassLoaderEntriesCa
try
{
// explode the archive if it is not already exploded
- if (!existed)
+ if ( !existed )
{
File warFile = artifact.getFile();
UnArchiver unArchiver = archiverManager.getUnArchiver( "jar" );
@@ -216,7 +219,9 @@ public class DefaultClassLoaderEntriesCa
}
}
- return new ClassLoaderEntriesCalculatorResult( new ArrayList<String>( classLoaderEntries ), tmpDirectories );
+ return new ClassLoaderEntriesCalculatorResult( new ArrayList<String>( classLoaderEntries ), //
+ tmpDirectories, //
+ buildDirectories );
}
@@ -240,7 +245,7 @@ public class DefaultClassLoaderEntriesCa
{
return false;
}
- @SuppressWarnings ("unchecked") Collection<MavenProject> mavenProjects =
+ @SuppressWarnings( "unchecked" ) Collection<MavenProject> mavenProjects =
project.getProjectReferences().values();
for ( MavenProject mavenProject : mavenProjects )
{
Modified: tomcat/maven-plugin/branches/tc8.x/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/pom.xml?rev=1626940&r1=1626939&r2=1626940&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/pom.xml (original)
+++ tomcat/maven-plugin/branches/tc8.x/pom.xml Tue Sep 23 05:00:07 2014
@@ -74,7 +74,7 @@
<!-- server port for it tests -->
<its.server.port>2008</its.server.port>
<tomcat7Version>7.0.54</tomcat7Version>
- <tomcat8Version>8.0.11</tomcat8Version>
+ <tomcat8Version>8.0.12</tomcat8Version>
<!-- to prevent isssues with last apache parent pom -->
<arguments />
Modified: tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java?rev=1626940&r1=1626939&r2=1626940&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java (original)
+++ tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/AbstractRunMojo.java Tue Sep 23 05:00:07 2014
@@ -49,6 +49,7 @@ import org.apache.maven.artifact.version
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
@@ -693,7 +694,9 @@ public abstract class AbstractRunMojo
Context context = container.addWebapp( contextPath, baseDir );
context.setResources(
- new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), getPath() ) );
+ new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //
+ getPath(), //
+ getLog() ) );
if ( useSeparateTomcatClassLoader )
{
@@ -793,16 +796,23 @@ public abstract class AbstractRunMojo
WebResourceSet webResourceSet;
- MyDirContext( String buildOutputDirectory, String webAppPath )
+ Log log;
+
+ MyDirContext( String buildOutputDirectory, String webAppPath, Log log )
{
+
this.buildOutputDirectory = buildOutputDirectory;
this.webAppPath = webAppPath;
+ this.log = log;
}
+
+
@Override
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 );
@@ -821,7 +831,8 @@ public abstract class AbstractRunMojo
@Override
public WebResource getClassLoaderResource( String path )
{
- // here get resources from various pathsss
+ log.debug( "MyDirContext#getClassLoaderResource: " + path );
+ // here get resources from various paths
return super.getClassLoaderResource( path );
}
@@ -829,8 +840,30 @@ public abstract class AbstractRunMojo
@Override
public WebResource[] listResources( String path )
{
+ log.debug( "MyDirContext#listResources: " + path );
return super.listResources( path );
}
+
+ @Override
+ public WebResource[] getClassLoaderResources( String path )
+ {
+ log.debug( "MyDirContext#getClassLoaderResources: " + path );
+ return super.getClassLoaderResources( path );
+ }
+
+ @Override
+ public WebResource[] getResources( String path )
+ {
+ log.debug( "MyDirContext#getResources: " + path );
+ return super.getResources( path );
+ }
+
+ @Override
+ protected WebResource[] getResourcesInternal( String path, boolean useClassLoaderResources )
+ {
+ log.debug( "MyDirContext#getResourcesInternal: " + path );
+ return super.getResourcesInternal( path, useClassLoaderResources );
+ }
}
/**
Modified: tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java?rev=1626940&r1=1626939&r2=1626940&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java (original)
+++ tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/RunMojo.java Tue Sep 23 05:00:07 2014
@@ -63,6 +63,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -315,7 +316,7 @@ public class RunMojo
.setMavenProject( project ) //
.setAddWarDependenciesInClassloader( addWarDependenciesInClassloader ) //
.setUseTestClassPath( useTestClasspath );
- ClassLoaderEntriesCalculatorResult classLoaderEntriesCalculatorResult =
+ final ClassLoaderEntriesCalculatorResult classLoaderEntriesCalculatorResult =
classLoaderEntriesCalculator.calculateClassPathEntries( request );
final List<String> classLoaderEntries = classLoaderEntriesCalculatorResult.getClassPathEntries();
final List<File> tmpDirectories = classLoaderEntriesCalculatorResult.getTmpDirectories();
@@ -336,16 +337,21 @@ public class RunMojo
}
}
+ getLog().debug( "classLoaderEntriesCalculator urls: " + urls );
+
final URLClassLoader urlClassLoader = new URLClassLoader( urls.toArray( new URL[urls.size()] ) );
final ClassRealm pluginRealm = getTomcatClassLoader();
context.setResources(
- new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), getPath() )
+ new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //
+ getPath(), //
+ getLog() )
{
@Override
public WebResource getClassLoaderResource( String path )
{
+ log.debug( "RunMojo#getClassLoaderResource: " + path );
URL url = urlClassLoader.getResource( StringUtils.removeStart( path, "/" ) );
// search in parent (plugin) classloader
if ( url == null )
@@ -358,6 +364,89 @@ public class RunMojo
return new EmptyResource( this, getPath() );
}
+ return urlToWebResource( url, path );
+ }
+
+ @Override
+ public WebResource getResource( String path )
+ {
+ log.debug( "RunMojo#getResource: " + path );
+ return super.getResource( path );
+ }
+
+ @Override
+ public WebResource[] getResources( String path )
+ {
+ log.debug( "RunMojo#getResources: " + path );
+ return super.getResources( path );
+ }
+
+ @Override
+ protected WebResource[] getResourcesInternal( String path, boolean useClassLoaderResources )
+ {
+ log.debug( "RunMojo#getResourcesInternal: " + path );
+ return super.getResourcesInternal( path, useClassLoaderResources );
+ }
+
+ @Override
+ public WebResource[] getClassLoaderResources( String path )
+ {
+ try
+ {
+ Enumeration<URL> enumeration =
+ urlClassLoader.findResources( StringUtils.removeStart( path, "/" ) );
+ List<URL> urlsFound = new ArrayList<URL>();
+ List<WebResource> webResources = new ArrayList<WebResource>();
+ while ( enumeration.hasMoreElements() )
+ {
+ URL url = enumeration.nextElement();
+ urlsFound.add( url );
+ webResources.add( urlToWebResource( url, path ) );
+ }
+ log.debug(
+ "RunMojo#getClassLoaderResources: " + path + " found : " + urlsFound.toString() );
+
+ webResources.addAll( findResourcesInDirectories( path,
+ classLoaderEntriesCalculatorResult.getBuildDirectories() ) );
+
+ return webResources.toArray( new WebResource[webResources.size()] );
+
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e.getMessage(), e );
+ }
+ }
+
+
+ private List<WebResource> findResourcesInDirectories( String path, List<String> directories )
+ {
+ try
+ {
+ List<WebResource> webResources = new ArrayList<WebResource>();
+
+ for ( String directory : directories )
+ {
+
+ File file = new File( directory, path );
+ if ( file.exists() )
+ {
+ webResources.add( urlToWebResource( file.toURI().toURL(), path ) );
+ }
+
+ }
+
+ return webResources;
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new RuntimeException( e.getMessage(), e );
+ }
+ }
+
+
+ private WebResource urlToWebResource( URL url, String path )
+ {
JarFile jarFile = null;
try
@@ -367,19 +456,27 @@ public class RunMojo
int idx = url.getFile().indexOf( '!' );
- String filePath = StringUtils.removeStart( url.getFile().substring( 0, idx ), "file:" );
+ if ( idx >= 0 )
+ {
+ String filePath = StringUtils.removeStart( url.getFile().substring( 0, idx ), "file:" );
- jarFile = new JarFile( filePath );
+ jarFile = new JarFile( filePath );
- JarEntry jarEntry = jarFile.getJarEntry( StringUtils.removeStart( path, "/" ) );
+ JarEntry jarEntry = jarFile.getJarEntry( StringUtils.removeStart( path, "/" ) );
+
+ return new JarResource( this, //
+ getPath(), //
+ filePath, //
+ url.getPath().substring( 0, idx ), //
+ jarEntry, //
+ "", //
+ null );
+ }
+ else
+ {
+ return new FileResource( this, webAppPath, new File( url.getFile() ), true );
+ }
- return new JarResource( this, //
- getPath(), //
- filePath, //
- url.getPath().substring( 0, idx ), //
- jarEntry, //
- "", //
- null );
}
catch ( IOException e )
{
@@ -389,9 +486,9 @@ public class RunMojo
{
IOUtils.closeQuietly( jarFile );
}
+ }
- }
} );
Runtime.getRuntime().addShutdownHook( new Thread()
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org