tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1198103 - in /tomcat/maven-plugin/trunk: common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/ tomcat7-maven-plugin/src/main/java/org/apache/...
Date Sat, 05 Nov 2011 22:49:59 GMT
Author: olamy
Date: Sat Nov  5 22:49:59 2011
New Revision: 1198103

URL: http://svn.apache.org/viewvc?rev=1198103&view=rev
Log:
[MTOMCAT-100] support war overlay to add war external dependencies in tomcat run
delete temporary directories used for extract after plugin shutdown.

Added:
    tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java
      - copied, changed from r1196544, tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
Modified:
    tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
    tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorRequest.java
    tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
    tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/RunMojo.java
    tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
    tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java

Modified: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
(original)
+++ tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
Sat Nov  5 22:49:59 2011
@@ -27,6 +27,6 @@ import java.util.List;
  */
 public interface ClassLoaderEntriesCalculator
 {
-    List<String> calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest classLoaderEntriesCalculatorRequest
)
+    ClassLoaderEntriesCalculatorResult calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest
classLoaderEntriesCalculatorRequest )
         throws TomcatRunException;
 }

Modified: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorRequest.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorRequest.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorRequest.java
(original)
+++ tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorRequest.java
Sat Nov  5 22:49:59 2011
@@ -22,6 +22,7 @@ import org.apache.maven.artifact.Artifac
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 
+import java.io.File;
 import java.util.Set;
 
 /**
@@ -95,4 +96,5 @@ public class ClassLoaderEntriesCalculato
         this.useTestClassPath = useTestClassPath;
         return this;
     }
+
 }

Copied: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java
(from r1196544, tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java)
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java?p2=tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java&p1=tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java&r1=1196544&r2=1198103&rev=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculator.java
(original)
+++ tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/ClassLoaderEntriesCalculatorResult.java
Sat Nov  5 22:49:59 2011
@@ -1,5 +1,4 @@
 package org.apache.tomcat.maven.common.run;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -19,14 +18,48 @@ package org.apache.tomcat.maven.common.r
  * under the License.
  */
 
+import java.io.File;
 import java.util.List;
 
 /**
  * @author Olivier Lamy
  * @since 2.0
  */
-public interface ClassLoaderEntriesCalculator
+public class ClassLoaderEntriesCalculatorResult
 {
-    List<String> calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest classLoaderEntriesCalculatorRequest
)
-        throws TomcatRunException;
+    /**
+     * classpath entries File .toURI().toString()
+     */
+    private List<String> classPathEntries;
+
+    /**
+     * List of files to cleanup after execution
+     */
+    private List<File> tmpDirectories;
+
+    public ClassLoaderEntriesCalculatorResult( List<String> classPathEntries, List<File>
tmpDirectories )
+    {
+        this.classPathEntries = classPathEntries;
+        this.tmpDirectories = tmpDirectories;
+    }
+
+    public List<String> getClassPathEntries()
+    {
+        return classPathEntries;
+    }
+
+    public void setClassPathEntries( List<String> classPathEntries )
+    {
+        this.classPathEntries = classPathEntries;
+    }
+
+    public List<File> getTmpDirectories()
+    {
+        return tmpDirectories;
+    }
+
+    public void setTmpDirectories( List<File> tmpDirectories )
+    {
+        this.tmpDirectories = tmpDirectories;
+    }
 }

Modified: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
(original)
+++ tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/run/DefaultClassLoaderEntriesCalculator.java
Sat Nov  5 22:49:59 2011
@@ -19,7 +19,6 @@ package org.apache.tomcat.maven.common.r
  * under the License.
  */
 
-import com.google.common.io.Files;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -55,11 +54,13 @@ public class DefaultClassLoaderEntriesCa
     private ArchiverManager archiverManager;
 
 
-    public List<String> calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest
request )
+    public ClassLoaderEntriesCalculatorResult calculateClassPathEntries( ClassLoaderEntriesCalculatorRequest
request )
         throws TomcatRunException
     {
         Set<String> classLoaderEntries = new LinkedHashSet<String>();
 
+        List<File> tmpDirectories = new ArrayList<File>();
+
         // add classes directories to loader
         try
         {
@@ -85,6 +86,17 @@ public class DefaultClassLoaderEntriesCa
             throw new TomcatRunException( e.getMessage(), e );
         }
 
+        // TODO find a solution to use a timestamp marker to not delete/extract all the time
+
+        File tmpExtractDatas =
+            new File( request.getMavenProject().getBuild().getDirectory(), "apache-tomcat-maven-plugin"
);
+
+        if ( tmpExtractDatas.exists() )
+        {
+            deleteDirectory( tmpExtractDatas, request.getLog() );
+        }
+        tmpExtractDatas.mkdirs();
+
         // add artifacts to loader
         if ( request.getDependencies() != null )
         {
@@ -109,13 +121,19 @@ public class DefaultClassLoaderEntriesCa
                             "skip adding artifact " + artifact.getArtifactId() + " as it's
in reactors" );
                     }
                 }
+
+
+
                 // in case of war dependency we must add /WEB-INF/lib/*.jar in entries and
WEB-INF/classes
                 if ( "war".equals( artifact.getType() ) && request.isAddWarDependenciesInClassloader()
)
                 {
-                    File tmpDir = null;
+
+                    File tmpDir = new File( tmpExtractDatas, artifact.getArtifactId() );
+
+                    tmpDirectories.add( tmpDir );
+
                     try
                     {
-                        tmpDir = Files.createTempDir();
                         tmpDir.deleteOnExit();
                         File warFile = artifact.getFile();
                         UnArchiver unArchiver = archiverManager.getUnArchiver( "jar" );
@@ -153,14 +171,12 @@ public class DefaultClassLoaderEntriesCa
                             "fail to extract war file " + artifact.getFile() + ", reason:"
+ e.getMessage(), e );
                         throw new TomcatRunException( e.getMessage(), e );
                     }
-                    finally
-                    {
-                        deleteDirectory( tmpDir, request.getLog() );
-                    }
                 }
             }
         }
-        return new ArrayList<String>( classLoaderEntries );
+
+        return new ClassLoaderEntriesCalculatorResult( new ArrayList<String>( classLoaderEntries
), tmpDirectories );
+
     }
 
     private void deleteDirectory( File directory, Log log )

Modified: tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/RunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/RunMojo.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/RunMojo.java
(original)
+++ tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/RunMojo.java
Sat Nov  5 22:49:59 2011
@@ -22,10 +22,12 @@ package org.apache.tomcat.maven.plugin.t
 import org.apache.catalina.Context;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.catalina.startup.Embedded;
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculator;
 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.util.IOUtil;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -167,7 +169,29 @@ public class RunMojo
                 new ClassLoaderEntriesCalculatorRequest().setDependencies( dependencies ).setLog(
                     getLog() ).setMavenProject( project ).setAddWarDependenciesInClassloader(
                     addWarDependenciesInClassloader ).setUseTestClassPath( useTestClasspath
);
-            List<String> classLoaderEntries = classLoaderEntriesCalculator.calculateClassPathEntries(
request );
+            ClassLoaderEntriesCalculatorResult classLoaderEntriesCalculatorResult =
+                classLoaderEntriesCalculator.calculateClassPathEntries( request );
+            List<String> classLoaderEntries = classLoaderEntriesCalculatorResult.getClassPathEntries();
+            final List<File> tmpDirectories = classLoaderEntriesCalculatorResult.getTmpDirectories();
+
+            Runtime.getRuntime().addShutdownHook( new Thread()
+            {
+                @Override
+                public void run()
+                {
+                    for ( File tmpDir : tmpDirectories )
+                    {
+                        try
+                        {
+                            FileUtils.deleteDirectory( tmpDir );
+                        }
+                        catch ( IOException e )
+                        {
+                            // ignore
+                        }
+                    }
+                }
+            } );
 
             if ( classLoaderEntries != null )
             {

Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
(original)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
Sat Nov  5 22:49:59 2011
@@ -70,7 +70,7 @@ import java.util.Set;
  * @since 2.0
  */
 public abstract class AbstractRunMojo
-    extends AbstractTomcat7Mojo
+    extends AbstractTomcat7Mojo             
 {
 // ----------------------------------------------------------------------
     // Mojo Parameters
@@ -314,6 +314,7 @@ public abstract class AbstractRunMojo
      */
     private File tomcatLoggingFile;
 
+
     // ----------------------------------------------------------------------
     // Fields
     // ----------------------------------------------------------------------

Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java?rev=1198103&r1=1198102&r2=1198103&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java
(original)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java
Sat Nov  5 22:49:59 2011
@@ -19,10 +19,12 @@ package org.apache.tomcat.maven.plugin.t
  */
 
 import org.apache.catalina.loader.WebappLoader;
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculator;
 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.util.IOUtil;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -227,7 +229,29 @@ public class RunMojo
                 new ClassLoaderEntriesCalculatorRequest().setDependencies( dependencies ).setLog(
                     getLog() ).setMavenProject( project ).setAddWarDependenciesInClassloader(
                     addWarDependenciesInClassloader ).setUseTestClassPath( useTestClasspath
);
-            List<String> classLoaderEntries = classLoaderEntriesCalculator.calculateClassPathEntries(
request );
+            ClassLoaderEntriesCalculatorResult classLoaderEntriesCalculatorResult =
+                classLoaderEntriesCalculator.calculateClassPathEntries( request );
+            List<String> classLoaderEntries = classLoaderEntriesCalculatorResult.getClassPathEntries();
+            final List<File> tmpDirectories = classLoaderEntriesCalculatorResult.getTmpDirectories();
+
+            Runtime.getRuntime().addShutdownHook( new Thread()
+            {
+                @Override
+                public void run()
+                {
+                    for ( File tmpDir : tmpDirectories )
+                    {
+                        try
+                        {
+                            FileUtils.deleteDirectory( tmpDir );
+                        }
+                        catch ( IOException e )
+                        {
+                            // ignore
+                        }
+                    }
+                }
+            } );
 
             if ( classLoaderEntries != null )
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message