tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1333929 - /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
Date Fri, 04 May 2012 13:06:23 GMT
Author: olamy
Date: Fri May  4 13:06:23 2012
New Revision: 1333929

URL: http://svn.apache.org/viewvc?rev=1333929&view=rev
Log:
[MTOMCAT-150] expose ports used with tomcat7:run as sys props: feature to dump ports in a
property file to be able to use later with a forked surefire execution

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

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=1333929&r1=1333928&r2=1333929&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
Fri May  4 13:06:23 2012
@@ -31,6 +31,7 @@ import org.apache.catalina.startup.Catal
 import org.apache.catalina.startup.CatalinaProperties;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.valves.AccessLogValve;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
@@ -69,6 +70,7 @@ import javax.xml.stream.XMLStreamReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -78,6 +80,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 /**
@@ -382,6 +385,14 @@ public abstract class AbstractRunMojo
      */
     protected MavenSession session;
 
+    /**
+     * Will dump port in a properties file (see ports for property names).
+     * If empty no file generated
+     *
+     * @parameter expression="${maven.tomcat.propertiesPortFilePath}"
+     */
+    protected String propertiesPortFilePath;
+
     // ----------------------------------------------------------------------
     // Fields
     // ----------------------------------------------------------------------
@@ -952,6 +963,10 @@ public abstract class AbstractRunMojo
 
                 embeddedTomcat.start();
 
+                Properties portProperties = new Properties();
+
+                portProperties.put( "tomcat.maven.http.port", Integer.toString( connector.getLocalPort()
) );
+
                 session.getExecutionProperties().put( "tomcat.maven.http.port",
                                                       Integer.toString( connector.getLocalPort()
) );
                 System.setProperty( "tomcat.maven.http.port", Integer.toString( connector.getLocalPort()
) );
@@ -960,6 +975,7 @@ public abstract class AbstractRunMojo
                 {
                     session.getExecutionProperties().put( "tomcat.maven.https.port",
                                                           Integer.toString( httpsConnector.getLocalPort()
) );
+                    portProperties.put( "tomcat.maven.https.port", Integer.toString( connector.getLocalPort()
) );
                     System.setProperty( "tomcat.maven.https.port", Integer.toString( httpsConnector.getLocalPort()
) );
                 }
 
@@ -967,8 +983,26 @@ public abstract class AbstractRunMojo
                 {
                     session.getExecutionProperties().put( "tomcat.maven.ajp.port",
                                                           Integer.toString( ajpConnector.getLocalPort()
) );
+                    portProperties.put( "tomcat.maven.ajp.port", Integer.toString( ajpConnector.getLocalPort()
) );
                     System.setProperty( "tomcat.maven.ajp.port", Integer.toString( ajpConnector.getLocalPort()
) );
                 }
+                if ( propertiesPortFilePath != null )
+                {
+                    File propertiesPortsFile = new File( propertiesPortFilePath );
+                    if ( propertiesPortsFile.exists() )
+                    {
+                        propertiesPortsFile.delete();
+                    }
+                    FileOutputStream fileOutputStream = new FileOutputStream( propertiesPortsFile
);
+                    try
+                    {
+                        portProperties.store( fileOutputStream, "Apache Tomcat Maven plugin
port used" );
+                    }
+                    finally
+                    {
+                        IOUtils.closeQuietly( fileOutputStream );
+                    }
+                }
 
                 EmbeddedRegistry.getInstance().register( embeddedTomcat );
 



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


Mime
View raw message