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/01 04:03:02 UTC
svn commit: r1621660 - in /tomcat/maven-plugin/branches/tc8.x: ./
tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/
Author: olamy
Date: Mon Sep 1 02:03:01 2014
New Revision: 1621660
URL: http://svn.apache.org/r1621660
Log:
more work but still issue loading resources
Modified:
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/MavenWebappClassLoader.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/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/branches/tc8.x/pom.xml?rev=1621660&r1=1621659&r2=1621660&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/pom.xml (original)
+++ tomcat/maven-plugin/branches/tc8.x/pom.xml Mon Sep 1 02:03:01 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.9</tomcat8Version>
+ <tomcat8Version>8.0.11</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=1621660&r1=1621659&r2=1621660&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 Mon Sep 1 02:03:01 2014
@@ -784,7 +784,7 @@ public abstract class AbstractRunMojo
}
- private static class MyDirContext
+ protected static class MyDirContext
extends StandardRoot
{
String buildOutputDirectory;
@@ -802,6 +802,12 @@ public abstract class AbstractRunMojo
@Override
public WebResource getResource( String path )
{
+
+ if ( "/WEB-INF/classes".equals( path ) )
+ {
+ return new FileResource( this, this.webAppPath, new File( this.buildOutputDirectory ), true );
+ }
+
File file = new File( path );
if ( file.exists() )
{
@@ -811,6 +817,20 @@ public abstract class AbstractRunMojo
return webResource;
}
+
+ @Override
+ public WebResource getClassLoaderResource( String path )
+ {
+ // here get resources from various pathsss
+ return super.getClassLoaderResource( path );
+ }
+
+
+ @Override
+ public WebResource[] listResources( String path )
+ {
+ return super.listResources( path );
+ }
}
/**
@@ -833,7 +853,7 @@ public abstract class AbstractRunMojo
else
{
webappLoader = new WebappLoader( getTomcatClassLoader() );
- webappLoader.setLoaderClass( MavenWebappClassLoader.class.getName() );
+ //webappLoader.setLoaderClass( MavenWebappClassLoader.class.getName() );
}
}
else
@@ -847,7 +867,7 @@ public abstract class AbstractRunMojo
else
{
webappLoader = new WebappLoader( Thread.currentThread().getContextClassLoader() );
- webappLoader.setLoaderClass( MavenWebappClassLoader.class.getName() );
+ //webappLoader.setLoaderClass( MavenWebappClassLoader.class.getName() );
}
}
return webappLoader;
@@ -1345,9 +1365,9 @@ public abstract class AbstractRunMojo
ClassWorld world = new ClassWorld();
ClassRealm root = world.newRealm( "tomcat", Thread.currentThread().getContextClassLoader() );
- for ( @SuppressWarnings( "rawtypes" ) Iterator i = pluginArtifacts.iterator(); i.hasNext(); )
+ for ( Iterator<Artifact> i = pluginArtifacts.iterator(); i.hasNext(); )
{
- Artifact pluginArtifact = (Artifact) i.next();
+ Artifact pluginArtifact = i.next();
// add all plugin artifacts see https://issues.apache.org/jira/browse/MTOMCAT-122
if ( pluginArtifact.getFile() != null )
{
Modified: tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/MavenWebappClassLoader.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/MavenWebappClassLoader.java?rev=1621660&r1=1621659&r2=1621660&view=diff
==============================================================================
--- tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/MavenWebappClassLoader.java (original)
+++ tomcat/maven-plugin/branches/tc8.x/tomcat8-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat8/run/MavenWebappClassLoader.java Mon Sep 1 02:03:01 2014
@@ -86,7 +86,9 @@ public class MavenWebappClassLoader
{
// go to top
}
- return super.loadClass( name );
+
+ Class<?> clazz = super.loadClass( name );
+ return clazz;
}
@Override
@@ -101,7 +103,8 @@ public class MavenWebappClassLoader
{
// go to top
}
- return super.loadClass( name, resolve );
+ Class<?> clazz = super.loadClass( name, resolve );
+ return clazz;
}
@Override
@@ -112,7 +115,6 @@ public class MavenWebappClassLoader
@Override
protected Class<?> findClassInternal( String name )
- throws ClassNotFoundException
{
return super.findClassInternal( name );
}
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=1621660&r1=1621659&r2=1621660&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 Mon Sep 1 02:03:01 2014
@@ -18,22 +18,6 @@ package org.apache.tomcat.maven.plugin.t
* under the License.
*/
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
import org.apache.catalina.Context;
import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceSet;
@@ -43,6 +27,7 @@ import org.apache.catalina.webresources.
import org.apache.catalina.webresources.FileResourceSet;
import org.apache.catalina.webresources.JarResource;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
@@ -58,20 +43,40 @@ import org.apache.tomcat.maven.common.ru
import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculatorRequest;
import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculatorResult;
import org.apache.tomcat.maven.common.run.TomcatRunException;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.Xpp3DomWriter;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
/**
* Runs the current project as a dynamic web application using an embedded Tomcat server.
*
* @author Olivier Lamy
* @since 2.0
*/
-@Mojo(name = "run", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
-@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
+@Mojo( name = "run", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
+@Execute( phase = LifecyclePhase.PROCESS_CLASSES )
public class RunMojo
extends AbstractRunMojo
{
@@ -83,13 +88,13 @@ public class RunMojo
/**
* The set of dependencies for the web application being run.
*/
- @Parameter(defaultValue = "${project.artifacts}", required = true, readonly = true)
+ @Parameter( defaultValue = "${project.artifacts}", required = true, readonly = true )
private Set<Artifact> dependencies;
/**
* The web resources directory for the web application being run.
*/
- @Parameter(defaultValue = "${basedir}/src/main/webapp", property = "tomcat.warSourceDirectory")
+ @Parameter( defaultValue = "${basedir}/src/main/webapp", property = "tomcat.warSourceDirectory" )
private File warSourceDirectory;
@@ -99,7 +104,7 @@ public class RunMojo
* @see http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/loader/WebappLoader.html#setDelegate(boolean)
* @since 1.0
*/
- @Parameter(property = "tomcat.delegate", defaultValue = "true")
+ @Parameter( property = "tomcat.delegate", defaultValue = "true" )
private boolean delegate = true;
/**
@@ -113,7 +118,7 @@ public class RunMojo
*
* @since 2.0
*/
- @Parameter(property = "maven.tomcat.addWarDependenciesInClassloader", defaultValue = "true")
+ @Parameter( property = "maven.tomcat.addWarDependenciesInClassloader", defaultValue = "true" )
private boolean addWarDependenciesInClassloader;
/**
@@ -121,7 +126,7 @@ public class RunMojo
*
* @since 2.0
*/
- @Parameter(property = "maven.tomcat.useTestClasspath", defaultValue = "false")
+ @Parameter( property = "maven.tomcat.useTestClasspath", defaultValue = "false" )
private boolean useTestClasspath;
/**
@@ -129,7 +134,7 @@ public class RunMojo
*
* @since 2.0
*/
- @Parameter(alias = "additionalClassesDirs")
+ @Parameter( alias = "additionalClassesDirs" )
private List<String> additionalClasspathDirs;
@@ -317,6 +322,78 @@ public class RunMojo
final List<String> jarPaths = extractJars( classLoaderEntries );
+ List<URL> urls = new ArrayList<URL>( jarPaths.size() );
+
+ for ( String jarPath : jarPaths )
+ {
+ try
+ {
+ urls.add( new File( jarPath ).toURI().toURL() );
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ }
+
+ 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() )
+ {
+ @Override
+ public WebResource getClassLoaderResource( String path )
+ {
+ URL url = urlClassLoader.getResource( StringUtils.removeStart( path, "/" ) );
+ // search in parent (plugin) classloader
+ if ( url == null )
+ {
+ url = pluginRealm.getResource( StringUtils.removeStart( path, "/" ) );
+ }
+
+ if ( url == null )
+ {
+ return new EmptyResource( this, getPath() );
+ }
+
+ JarFile jarFile = null;
+
+ try
+ {
+ // url.getFile is
+ // file:/Users/olamy/mvn-repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar!/org/springframework/web/context/ContextLoaderListener.class
+
+ int idx = url.getFile().indexOf( '!' );
+
+ 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 );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtils.closeQuietly( jarFile );
+ }
+
+
+ }
+ } );
+
Runtime.getRuntime().addShutdownHook( new Thread()
{
@Override
@@ -375,10 +452,17 @@ public class RunMojo
try
{
JarFile jarFile = new JarFile( jar );
- JarEntry jarEntry = (JarEntry) jarFile.getEntry( StringUtils.removeStart( path, "/" ) );
+ JarEntry jarEntry =
+ (JarEntry) jarFile.getEntry( StringUtils.removeStart( path, "/" ) );
if ( jarEntry != null )
{
- return new JarResource( context.getResources(), getPath(), jarFile.getName(), jar.toURI().toASCIIString(), jarEntry, path, jarFile.getManifest());
+ return new JarResource( context.getResources(), //
+ getPath(), //
+ jarFile.getName(), //
+ jar.toURI().toString(), //
+ jarEntry, //
+ path, //
+ jarFile.getManifest() );
}
}
catch ( IOException e )
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org