Author: olamy
Date: Mon Oct 17 19:58:55 2011
New Revision: 1185344
URL: http://svn.apache.org/viewvc?rev=1185344&view=rev
Log:
fix code formatting
Modified:
tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
Modified:
tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
URL:
http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java?rev=1185344&r1=1185343&r2=1185344&view=diff
==============================================================================
---
tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
(original)
+++
tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
Mon Oct 17 19:58:55 2011
@@ -24,7 +24,11 @@ import org.apache.catalina.startup.Tomca
import org.apache.catalina.valves.AccessLogValve;
import org.apache.tomcat.util.http.fileupload.FileUtils;
-import java.io.*;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -37,7 +41,8 @@ import java.util.StringTokenizer;
* @author Olivier Lamy
* @since 2.0
*/
-public class Tomcat7Runner {
+public class Tomcat7Runner
+{
// true/false to use the server.xml located in the jar /conf/server.xml
public static final String USE_SERVER_XML_KEY = "useServerXml";
@@ -72,65 +77,80 @@ public class Tomcat7Runner {
/**
* key = context of the webapp, value = war path on file system
*/
- Map<String, String> webappWarPerContext = new HashMap<String, String>( );
+ Map<String, String> webappWarPerContext = new HashMap<String, String>();
- public Tomcat7Runner () {
+ public Tomcat7Runner()
+ {
// no op
}
- public void run ()
- throws Exception {
+ public void run()
+ throws Exception
+ {
// do we have to extract content
- if ( !new File( ".extract" ).exists( ) || resetExtract ) {
- extract( );
+ if ( !new File( ".extract" ).exists() || resetExtract )
+ {
+ extract();
+ }
+ else
+ {
+ String wars = runtimeProperties.getProperty( WARS_KEY );
+ populateWebAppWarPerContext( wars );
}
- System.setProperty( "catalina.base", extractDirectory.getAbsolutePath(
) );
- System.setProperty( "catalina.home", extractDirectory.getAbsolutePath(
) );
-
+ System.setProperty( "catalina.base",
extractDirectory.getAbsolutePath() );
+ System.setProperty( "catalina.home",
extractDirectory.getAbsolutePath() );
// start with a server.xml
- if ( serverXmlPath != null || useServerXml( ) ) {
- container = new Catalina( );
- container.setUseNaming( this.enableNaming( ) );
- if ( serverXmlPath != null && new File( serverXmlPath ).exists( )
) {
+ if ( serverXmlPath != null || useServerXml() )
+ {
+ container = new Catalina();
+ container.setUseNaming( this.enableNaming() );
+ if ( serverXmlPath != null && new File( serverXmlPath ).exists() )
+ {
container.setConfig( serverXmlPath );
- } else {
- container.setConfig( new File( extractDirectory,
"conf/server.xml" ).getAbsolutePath( ) );
}
- container.start( );
- } else {
- tomcat = new Tomcat( );
+ else
+ {
+ container.setConfig( new File( extractDirectory,
"conf/server.xml" ).getAbsolutePath() );
+ }
+ container.start();
+ }
+ else
+ {
+ tomcat = new Tomcat();
- if ( this.enableNaming( ) ) {
- tomcat.enableNaming( );
+ if ( this.enableNaming() )
+ {
+ tomcat.enableNaming();
}
- tomcat.getHost( ).setAppBase( new File( extractDirectory,
"webapps" ).getAbsolutePath( ) );
+ tomcat.getHost().setAppBase( new File( extractDirectory, "webapps"
).getAbsolutePath() );
Connector connector = new Connector( "HTTP/1.1" );
connector.setPort( httpPort );
- if ( httpsPort > 0 ) {
+ if ( httpsPort > 0 )
+ {
connector.setRedirectPort( httpsPort );
}
// FIXME parameter for that def ? ISO-8859-1
//connector.setURIEncoding(uriEncoding);
- tomcat.getService( ).addConnector( connector );
+ tomcat.getService().addConnector( connector );
tomcat.setConnector( connector );
// add a default acces log valve
- AccessLogValve alv = new AccessLogValve( );
- alv.setDirectory( new File( extractDirectory, "logs"
).getAbsolutePath( ) );
+ AccessLogValve alv = new AccessLogValve();
+ alv.setDirectory( new File( extractDirectory, "logs"
).getAbsolutePath() );
alv.setPattern( runtimeProperties.getProperty(
Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY ) );
- tomcat.getHost( ).getPipeline( ).addValve( alv );
-
+ tomcat.getHost().getPipeline().addValve( alv );
// create https connector
- if ( httpsPort > 0 ) {
+ if ( httpsPort > 0 )
+ {
Connector httpsConnector = new Connector( "HTTP/1.1" );
httpsConnector.setPort( httpsPort );
// FIXME parameters for that !!
@@ -143,95 +163,120 @@ public class Tomcat7Runner {
{
httpsConnector.setAttribute("keystorePass", keystorePass);
}*/
- tomcat.getService( ).addConnector( httpsConnector );
+ tomcat.getService().addConnector( httpsConnector );
}
// create ajp connector
- if ( ajpPort > 0 ) {
+ if ( ajpPort > 0 )
+ {
Connector ajpConnector = new Connector(
"org.apache.coyote.ajp.AjpProtocol" );
ajpConnector.setPort( ajpPort );
// FIXME parameter for that def ? ISO-8859-1
//ajpConnector.setURIEncoding(uriEncoding);
- tomcat.getService( ).addConnector( ajpConnector );
+ tomcat.getService().addConnector( ajpConnector );
}
// add webapps
- for ( Map.Entry<String, String> entry :
this.webappWarPerContext.entrySet( ) ) {
- if ( entry.getKey( ).equals( "/" ) ) {
- tomcat.addWebapp( entry.getKey( ), new File(
extractDirectory, "webapps/ROOT.war" ).getAbsolutePath( ) );
- } else {
- tomcat.addWebapp( entry.getKey( ), new File(
extractDirectory, "webapps/" + entry.getValue( ) ).getAbsolutePath( ) );
+ for ( Map.Entry<String, String> entry :
this.webappWarPerContext.entrySet() )
+ {
+ if ( entry.getKey().equals( "/" ) )
+ {
+ tomcat.addWebapp( entry.getKey(),
+ new File( extractDirectory,
"webapps/ROOT.war" ).getAbsolutePath() );
+ }
+ else
+ {
+ tomcat.addWebapp( entry.getKey(),
+ new File( extractDirectory, "webapps/" +
entry.getValue() ).getAbsolutePath() );
}
}
- tomcat.start( );
+ tomcat.start();
}
-
- waitIndefinitely( );
+ waitIndefinitely();
}
- private void waitIndefinitely () {
- Object lock = new Object( );
+ private void waitIndefinitely()
+ {
+ Object lock = new Object();
- synchronized ( lock ) {
- try {
- lock.wait( );
- } catch ( InterruptedException exception ) {
+ synchronized ( lock )
+ {
+ try
+ {
+ lock.wait();
+ }
+ catch ( InterruptedException exception )
+ {
System.exit( 1 );
}
}
}
- public void stop ()
- throws Exception {
- if ( container != null ) {
- container.stop( );
+ public void stop()
+ throws Exception
+ {
+ if ( container != null )
+ {
+ container.stop();
}
- if ( tomcat != null ) {
- tomcat.stop( );
+ if ( tomcat != null )
+ {
+ tomcat.stop();
}
}
- protected void extract ()
- throws Exception {
+ protected void extract()
+ throws Exception
+ {
- if ( extractDirectory.exists( ) ) {
+ if ( extractDirectory.exists() )
+ {
FileUtils.deleteDirectory( extractDirectory );
}
- extractDirectory.mkdirs( );
+ extractDirectory.mkdirs();
// create tomcat various paths
- new File( extractDirectory, "conf" ).mkdirs( );
- new File( extractDirectory, "logs" ).mkdirs( );
- new File( extractDirectory, "webapps" ).mkdirs( );
- new File( extractDirectory, "work" ).mkdirs( );
+ new File( extractDirectory, "conf" ).mkdirs();
+ new File( extractDirectory, "logs" ).mkdirs();
+ new File( extractDirectory, "webapps" ).mkdirs();
+ new File( extractDirectory, "work" ).mkdirs();
String wars = runtimeProperties.getProperty( WARS_KEY );
populateWebAppWarPerContext( wars );
-
- for ( Map.Entry<String, String> entry : webappWarPerContext.entrySet(
) ) {
- debugMessage( "webappWarPerContext entry key/value: " +
entry.getKey( ) + "/" + entry.getValue( ) );
+ for ( Map.Entry<String, String> entry : webappWarPerContext.entrySet()
)
+ {
+ debugMessage( "webappWarPerContext entry key/value: " +
entry.getKey() + "/" + entry.getValue() );
InputStream inputStream = null;
- try {
- inputStream =
- Thread.currentThread( ).getContextClassLoader(
).getResourceAsStream( entry.getValue( ) );
- if ( !useServerXml( ) ) {
- if ( entry.getKey( ).equals( "/" ) ) {
+ try
+ {
+ inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
entry.getValue() );
+ if ( !useServerXml() )
+ {
+ if ( entry.getKey().equals( "/" ) )
+ {
expand( inputStream, new File( extractDirectory,
"webapps/ROOT.war" ) );
- } else {
- expand( inputStream, new File( extractDirectory,
"webapps/" + entry.getValue( ) ) );
}
- } else {
- expand( inputStream, new File( extractDirectory,
"webapps/" + entry.getValue( ) ) );
+ else
+ {
+ expand( inputStream, new File( extractDirectory,
"webapps/" + entry.getValue() ) );
+ }
}
- } finally {
- if ( inputStream != null ) {
- inputStream.close( );
+ else
+ {
+ expand( inputStream, new File( extractDirectory,
"webapps/" + entry.getValue() ) );
+ }
+ }
+ finally
+ {
+ if ( inputStream != null )
+ {
+ inputStream.close();
}
}
}
@@ -247,18 +292,23 @@ public class Tomcat7Runner {
}
- private static void expandConfigurationFile ( String fileName, File
extractDirectory )
- throws Exception {
+ private static void expandConfigurationFile( String fileName, File
extractDirectory )
+ throws Exception
+ {
InputStream inputStream = null;
- try {
- inputStream =
- Thread.currentThread( ).getContextClassLoader(
).getResourceAsStream( "conf/" + fileName );
- if ( inputStream != null ) {
+ try
+ {
+ inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream( "conf/" +
fileName );
+ if ( inputStream != null )
+ {
expand( inputStream, new File( extractDirectory, "conf/" +
fileName ) );
}
- } finally {
- if ( inputStream != null ) {
- inputStream.close( );
+ }
+ finally
+ {
+ if ( inputStream != null )
+ {
+ inputStream.close();
}
}
@@ -268,19 +318,24 @@ public class Tomcat7Runner {
* @param warsValue we can value in format:
wars=foo.war|contextpath;bar.war ( |contextpath is optionnal if empty use the
war name)
* so here we return war file name and populate
webappWarPerContext
*/
- private void populateWebAppWarPerContext ( String warsValue ) {
+ private void populateWebAppWarPerContext( String warsValue )
+ {
StringTokenizer st = new StringTokenizer( warsValue, ";" );
- while ( st.hasMoreTokens( ) ) {
- String warValue = st.nextToken( );
+ while ( st.hasMoreTokens() )
+ {
+ String warValue = st.nextToken();
debugMessage( "populateWebAppWarPerContext warValue:" + warValue );
String warFileName = "";
String contextValue = "";
int separatorIndex = warValue.indexOf( "|" );
- if ( separatorIndex >= 0 ) {
+ if ( separatorIndex >= 0 )
+ {
warFileName = warValue.substring( 0, separatorIndex );
- contextValue = warValue.substring( separatorIndex + 1,
warValue.length( ) );
+ contextValue = warValue.substring( separatorIndex + 1,
warValue.length() );
- } else {
+ }
+ else
+ {
warFileName = contextValue;
}
debugMessage( "populateWebAppWarPerContext
contextValue/warFileName:" + contextValue + "/" + warFileName );
@@ -296,42 +351,56 @@ public class Tomcat7Runner {
* @param file The file to be created
* @throws java.io.IOException if an input/output error occurs
*/
- private static void expand ( InputStream input, File file )
- throws IOException {
+ private static void expand( InputStream input, File file )
+ throws IOException
+ {
BufferedOutputStream output = null;
- try {
- output =
- new BufferedOutputStream( new FileOutputStream( file ) );
- byte buffer[] = new byte[ 2048 ];
- while ( true ) {
+ try
+ {
+ output = new BufferedOutputStream( new FileOutputStream( file ) );
+ byte buffer[] = new byte[2048];
+ while ( true )
+ {
int n = input.read( buffer );
if ( n <= 0 )
+ {
break;
+ }
output.write( buffer, 0, n );
}
- } finally {
- if ( output != null ) {
- try {
- output.close( );
- } catch ( IOException e ) {
+ }
+ finally
+ {
+ if ( output != null )
+ {
+ try
+ {
+ output.close();
+ }
+ catch ( IOException e )
+ {
// Ignore
}
}
}
}
- public boolean useServerXml () {
- return Boolean.parseBoolean( runtimeProperties.getProperty(
USE_SERVER_XML_KEY, Boolean.FALSE.toString( ) ) );
+ public boolean useServerXml()
+ {
+ return Boolean.parseBoolean( runtimeProperties.getProperty(
USE_SERVER_XML_KEY, Boolean.FALSE.toString() ) );
}
- public void debugMessage ( String message ) {
- if ( debug ) {
+ public void debugMessage( String message )
+ {
+ if ( debug )
+ {
System.out.println( message );
}
}
- public boolean enableNaming () {
- return Boolean.parseBoolean( runtimeProperties.getProperty(
ENABLE_NAMING_KEY, Boolean.FALSE.toString( ) ) );
+ public boolean enableNaming()
+ {
+ return Boolean.parseBoolean( runtimeProperties.getProperty(
ENABLE_NAMING_KEY, Boolean.FALSE.toString() ) );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]