tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1325844 - in /tomcat/maven-plugin/trunk/tomcat7-maven-plugin: pom.xml src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java
Date Fri, 13 Apr 2012 17:08:48 GMT
Author: olamy
Date: Fri Apr 13 17:08:48 2012
New Revision: 1325844

URL: http://svn.apache.org/viewvc?rev=1325844&view=rev
Log:
apply classic maven filtering on user context file

Modified:
    tomcat/maven-plugin/trunk/tomcat7-maven-plugin/pom.xml
    tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/RunMojo.java

Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/pom.xml?rev=1325844&r1=1325843&r2=1325844&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/pom.xml (original)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/pom.xml Fri Apr 13 17:08:48 2012
@@ -190,6 +190,12 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-filtering</artifactId>
+      <version>1.0</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.tomcat.maven</groupId>
       <artifactId>tomcat-maven-plugin-it</artifactId>
       <scope>test</scope>

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=1325844&r1=1325843&r2=1325844&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
Fri Apr 13 17:08:48 2012
@@ -22,7 +22,11 @@ import org.apache.catalina.loader.Webapp
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.apache.maven.shared.filtering.MavenFileFilterRequest;
+import org.apache.maven.shared.filtering.MavenFilteringException;
 import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculator;
 import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculatorRequest;
 import org.apache.tomcat.maven.common.run.ClassLoaderEntriesCalculatorResult;
@@ -126,6 +130,20 @@ public class RunMojo
     private File temporaryContextFile = null;
 
     /**
+     *
+     * @component role="org.apache.maven.shared.filtering.MavenFileFilter" role-hint="default"
+     * @required
+     */
+    private MavenFileFilter mavenFileFilter;
+
+    /**
+     * @parameter default-value="${session}"
+     * @readonly
+     * @required
+     */
+    protected MavenSession session;
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -147,7 +165,7 @@ public class RunMojo
         }
         //----------------------------------------------------------------------------
         // context attributes backgroundProcessorDelay reloadable cannot be modified at runtime.
-        // It looks only values from the file ared used
+        // It looks only values from the file are used
         // so here we create a temporary file with values modified
         //----------------------------------------------------------------------------
         FileReader fr = null;
@@ -157,14 +175,24 @@ public class RunMojo
         {
             temporaryContextFile = File.createTempFile( "tomcat-maven-plugin", "temp-ctx-file"
);
             temporaryContextFile.deleteOnExit();
-            fw = new FileWriter( temporaryContextFile );
+
             // format to modify/create <Context backgroundProcessorDelay="5" reloadable="false">
             if ( contextFile != null && contextFile.exists() )
             {
-                fr = new FileReader( contextFile );
+                MavenFileFilterRequest mavenFileFilterRequest = new MavenFileFilterRequest();
+                mavenFileFilterRequest.setFrom( contextFile );
+                mavenFileFilterRequest.setTo( temporaryContextFile );
+                mavenFileFilterRequest.setMavenProject( project );
+                mavenFileFilterRequest.setMavenSession( session );
+                mavenFileFilterRequest.setFiltering( true );
+
+                mavenFileFilter.copyFile( mavenFileFilterRequest );
+
+                fr = new FileReader( temporaryContextFile );
                 Xpp3Dom xpp3Dom = Xpp3DomBuilder.build( fr );
                 xpp3Dom.setAttribute( "backgroundProcessorDelay", Integer.toString( backgroundProcessorDelay
) );
                 xpp3Dom.setAttribute( "reloadable", Boolean.toString( isContextReloadable()
) );
+                fw = new FileWriter( temporaryContextFile );
                 Xpp3DomWriter.write( fw, xpp3Dom );
                 Xpp3DomWriter.write( sw, xpp3Dom );
                 getLog().debug( " generated context file " + sw.toString() );
@@ -199,6 +227,11 @@ public class RunMojo
             getLog().error( "error creating fake context.xml : " + e.getMessage(), e );
             throw new MojoExecutionException( "error creating fake context.xml : " + e.getMessage(),
e );
         }
+        catch ( MavenFilteringException e )
+        {
+            getLog().error( "error filtering context.xml : " + e.getMessage(), e );
+            throw new MojoExecutionException( "error filtering context.xml : " + e.getMessage(),
e );
+        }
         finally
         {
             IOUtil.close( fw );
@@ -266,16 +299,16 @@ public class RunMojo
             {
                 for ( String additionalClasspathDir : additionalClasspathDirs )
                 {
-                	if( StringUtils.isNotBlank(additionalClasspathDir))
-                	{
-	                    File file = new File( additionalClasspathDir );
-	                    if ( file.exists() )
-	                    {
-	                        String fileUri = file.toURI().toString();
-	                        getLog().debug( "add file:" + fileUri + " as a additionalClasspathDir"
);
-	                        loader.addRepository( fileUri );
-	                    }
-                	}
+                    if ( StringUtils.isNotBlank( additionalClasspathDir ) )
+                    {
+                        File file = new File( additionalClasspathDir );
+                        if ( file.exists() )
+                        {
+                            String fileUri = file.toURI().toString();
+                            getLog().debug( "add file:" + fileUri + " as a additionalClasspathDir"
);
+                            loader.addRepository( fileUri );
+                        }
+                    }
                 }
             }
         }



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


Mime
View raw message