Author: olamy Date: Mon Oct 3 22:15:17 2011 New Revision: 1178614 URL: http://svn.apache.org/viewvc?rev=1178614&view=rev Log: formatting: no code change
Modified: tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/RunMojo.java Modified: tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/RunMojo.java URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/RunMojo.java?rev=1178614&r1=1178613&r2=1178614&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/RunMojo.java (original) +++ tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/RunMojo.java Mon Oct 3 22:15:17 2011 @@ -19,15 +19,6 @@ package org.apache.tomcat.maven.plugin; * under the License. */ -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collection; -import java.util.List; -import java.util.Set; - import org.apache.catalina.Context; import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Embedded; @@ -42,18 +33,27 @@ import org.codehaus.plexus.util.xml.Xpp3 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.StringWriter; +import java.util.Collection; +import java.util.List; +import java.util.Set; + /** * Runs the current project as a dynamic web application using an embedded Tomcat server. - * - * @goal run - * @execute phase="compile" - * @requiresDependencyResolution runtime + * * @author Jurgen Lust * @author Mark Hobson <markhob...@gmail.com> * @version $Id: RunMojo.java 13551 2011-02-09 16:05:47Z olamy $ + * @goal run + * @execute phase="compile" + * @requiresDependencyResolution runtime */ public class RunMojo - extends AbstractRunMojo + extends AbstractRunMojo { // ---------------------------------------------------------------------- // Mojo Parameters @@ -61,14 +61,14 @@ public class RunMojo /** * The classes directory for the web application being run. - * + * * @parameter expression = "${project.build.outputDirectory}" */ private File classesDir; /** * The set of dependencies for the web application being run. - * + * * @parameter default-value = "${project.artifacts}" * @required * @readonly @@ -77,27 +77,29 @@ public class RunMojo /** * The web resources directory for the web application being run. - * + * * @parameter expression="${basedir}/src/main/webapp" */ private File warSourceDirectory; - + /** * Set the "follow standard delegation model" flag used to configure our ClassLoader. - * @see http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/loader/WebappLoader.html#setDelegate(boolean) + * * @parameter expression = "${tomcat.delegate}" default-value="true" + * @see http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/loader/WebappLoader.html#setDelegate(boolean) * @since 1.0 - */ + */ private boolean delegate = true; - + /** * represents the delay in seconds between each classPathScanning change invocation - * @see <a href="http://tomcat.apache.org/tomcat-6.0-doc/config/context.html">http://tomcat.apache.org/tomcat-6.0-doc/config/context.html</a> + * * @parameter expression="${maven.tomcat.backgroundProcessorDelay}" default-value="-1" + * @see <a href="http://tomcat.apache.org/tomcat-6.0-doc/config/context.html">http://tomcat.apache.org/tomcat-6.0-doc/config/context.html</a> */ - protected int backgroundProcessorDelay = -1; - + protected int backgroundProcessorDelay = -1; + private File temporaryContextFile = null; // ---------------------------------------------------------------------- @@ -106,7 +108,8 @@ public class RunMojo /** * {@inheritDoc} - * @throws MojoExecutionException + * + * @throws MojoExecutionException */ @Override protected Context createContext( Embedded container ) @@ -114,48 +117,49 @@ public class RunMojo { Context context = super.createContext( container ); - context.setReloadable( isContextReloadable() ); - + context.setReloadable( isContextReloadable( ) ); + return context; } /** * {@inheritDoc} - * @throws MojoExecutionException + * + * @throws MojoExecutionException */ @Override - protected WebappLoader createWebappLoader() + protected WebappLoader createWebappLoader( ) throws IOException, MojoExecutionException { - WebappLoader loader = super.createWebappLoader(); + WebappLoader loader = super.createWebappLoader( ); //super.project. if ( useSeparateTomcatClassLoader ) { loader.setDelegate( delegate ); } - + // add classes directories to loader if ( classesDir != null ) { try { - @SuppressWarnings("unchecked") - List<String> classPathElements = project.getCompileClasspathElements(); - for (String classPathElement : classPathElements) + @SuppressWarnings( "unchecked" ) List<String> classPathElements = + project.getCompileClasspathElements( ); + for ( String classPathElement : classPathElements ) { - File classPathElementFile = new File(classPathElement); - if (classPathElementFile.exists() && classPathElementFile.isDirectory()) + File classPathElementFile = new File( classPathElement ); + if ( classPathElementFile.exists( ) && classPathElementFile.isDirectory( ) ) { - getLog().debug( "adding classPathElementFile " + classPathElementFile.toURI().toString() ); - loader.addRepository( classPathElementFile.toURI().toString() ); + getLog( ).debug( "adding classPathElementFile " + classPathElementFile.toURI( ).toString( ) ); + loader.addRepository( classPathElementFile.toURI( ).toString( ) ); } } } catch ( DependencyResolutionRequiredException e ) { - throw new MojoExecutionException( e.getMessage(), e ); + throw new MojoExecutionException( e.getMessage( ), e ); } - + //loader.addRepository( classesDir.toURI().toString() ); } @@ -164,22 +168,21 @@ public class RunMojo { for ( Artifact artifact : dependencies ) { - String scope = artifact.getScope(); + String scope = artifact.getScope( ); // skip provided and test scoped artifacts if ( !Artifact.SCOPE_PROVIDED.equals( scope ) && !Artifact.SCOPE_TEST.equals( scope ) ) { - getLog().debug( - "add dependency to webapploader " + artifact.getGroupId() + ":" - + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" - + artifact.getScope() ); + getLog( ).debug( + "add dependency to webapploader " + artifact.getGroupId( ) + ":" + artifact.getArtifactId( ) + + ":" + artifact.getVersion( ) + ":" + artifact.getScope( ) ); if ( !isInProjectReferences( artifact ) ) { - loader.addRepository( artifact.getFile().toURI().toString() ); + loader.addRepository( artifact.getFile( ).toURI( ).toString( ) ); } else { - getLog().debug( "skip adding artifact " + artifact.getArtifactId() + " as it's in reactors" ); + getLog( ).debug( "skip adding artifact " + artifact.getArtifactId( ) + " as it's in reactors" ); } } } @@ -187,18 +190,18 @@ public class RunMojo return loader; } - - protected boolean isInProjectReferences(Artifact artifact) + + protected boolean isInProjectReferences( Artifact artifact ) { - if ( project.getProjectReferences() == null || project.getProjectReferences().isEmpty() ) + if ( project.getProjectReferences( ) == null || project.getProjectReferences( ).isEmpty( ) ) { return false; } - @SuppressWarnings("unchecked") - Collection<MavenProject> mavenProjects = project.getProjectReferences().values(); + @SuppressWarnings( "unchecked" ) Collection<MavenProject> mavenProjects = + project.getProjectReferences( ).values( ); for ( MavenProject mavenProject : mavenProjects ) { - if (StringUtils.equals( mavenProject.getId(), artifact.getId() )) + if ( StringUtils.equals( mavenProject.getId( ), artifact.getId( ) ) ) { return true; } @@ -210,7 +213,7 @@ public class RunMojo * {@inheritDoc} */ @Override - protected File getDocBase() + protected File getDocBase( ) { return warSourceDirectory; } @@ -219,7 +222,8 @@ public class RunMojo * {@inheritDoc} */ @Override - protected File getContextFile() throws MojoExecutionException + protected File getContextFile( ) + throws MojoExecutionException { if ( temporaryContextFile != null ) { @@ -232,35 +236,37 @@ public class RunMojo //---------------------------------------------------------------------------- FileReader fr = null; FileWriter fw = null; - StringWriter sw = new StringWriter(); + StringWriter sw = new StringWriter( ); try { temporaryContextFile = File.createTempFile( "tomcat-maven-plugin", "temp-ctx-file" ); fw = new FileWriter( temporaryContextFile ); // format to modify/create <Context backgroundProcessorDelay="5" reloadable="false"> - if ( contextFile != null && contextFile.exists() ) + if ( contextFile != null && contextFile.exists( ) ) { fr = new FileReader( contextFile ); Xpp3Dom xpp3Dom = Xpp3DomBuilder.build( fr ); xpp3Dom.setAttribute( "backgroundProcessorDelay", Integer.toString( backgroundProcessorDelay ) ); - xpp3Dom.setAttribute( "reloadable", Boolean.toString( isContextReloadable() ) ); + xpp3Dom.setAttribute( "reloadable", Boolean.toString( isContextReloadable( ) ) ); Xpp3DomWriter.write( fw, xpp3Dom ); Xpp3DomWriter.write( sw, xpp3Dom ); - getLog().debug( " generated context file " + sw.toString() ); + getLog( ).debug( " generated context file " + sw.toString( ) ); } else { if ( contextReloadable ) { // don't care about using a complicated xml api to create one xml line :-) - StringBuilder sb = new StringBuilder( "<Context " ).append( "backgroundProcessorDelay=\"" ) - .append( Integer.toString( backgroundProcessorDelay ) ).append( "\"" ) - .append( " reloadable=\"" + Boolean.toString( isContextReloadable() ) + "\"/>" ); - - getLog().debug( " generated context file " + sb.toString() ); - - fw.write( sb.toString() ); - } else { + StringBuilder sb = new StringBuilder( "<Context " ).append( "backgroundProcessorDelay=\"" ).append( + Integer.toString( backgroundProcessorDelay ) ).append( "\"" ).append( + " reloadable=\"" + Boolean.toString( isContextReloadable( ) ) + "\"/>" ); + + getLog( ).debug( " generated context file " + sb.toString( ) ); + + fw.write( sb.toString( ) ); + } + else + { // no user context file and contextReloadable false so no need about creating a hack one return null; } @@ -268,19 +274,21 @@ public class RunMojo } catch ( IOException e ) { - getLog().error( "error creating fake context.xml : " + e.getMessage(), e ); - throw new MojoExecutionException( "error creating fake context.xml : " + e.getMessage(), e ); + getLog( ).error( "error creating fake context.xml : " + e.getMessage( ), e ); + throw new MojoExecutionException( "error creating fake context.xml : " + e.getMessage( ), e ); } catch ( XmlPullParserException e ) { - getLog().error( "error creating fake context.xml : " + e.getMessage(), e ); - throw new MojoExecutionException( "error creating fake context.xml : " + e.getMessage(), e ); - } finally { + getLog( ).error( "error creating fake context.xml : " + e.getMessage( ), e ); + throw new MojoExecutionException( "error creating fake context.xml : " + e.getMessage( ), e ); + } + finally + { IOUtil.close( fw ); IOUtil.close( fr ); IOUtil.close( sw ); - } - + } + return temporaryContextFile; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org