Author: snicoll Date: Tue Aug 7 15:11:01 2007 New Revision: 563676 URL: http://svn.apache.org/viewvc?view=rev&rev=563676 Log: Removed the mess in AbstractWarMojo.
Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java?view=diff&rev=563676&r1=563675&r2=563676 ============================================================================== --- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java (original) +++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java Tue Aug 7 15:11:01 2007 @@ -20,9 +20,6 @@ */ import org.apache.maven.archiver.MavenArchiveConfiguration; -import org.apache.maven.archiver.MavenArchiver; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -33,38 +30,20 @@ import org.apache.maven.plugin.war.packaging.WarPackagingContext; import org.apache.maven.plugin.war.packaging.WarPackagingTask; import org.apache.maven.plugin.war.packaging.WarProjectPackagingTask; -import org.apache.maven.plugin.war.util.MappingUtils; import org.apache.maven.plugin.war.util.WebappStructure; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.UnArchiver; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.manager.ArchiverManager; -import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.InterpolationFilterReader; import org.codehaus.plexus.util.StringUtils; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.Set; public abstract class AbstractWarMojo extends AbstractMojo @@ -186,8 +165,6 @@ private static final String META_INF = "META-INF"; - private static final String[] DEFAULT_INCLUDES = {"**/**"}; - public static final String DEFAULT_FILE_NAME_MAPPING_CLASSIFIER = "${artifactId}-${version}-${classifier}.${extension}"; @@ -243,91 +220,6 @@ private static final String[] EMPTY_STRING_ARRAY = {}; - public MavenProject getProject() - { - return project; - } - - public void setProject( MavenProject project ) - { - this.project = project; - } - - public File getClassesDirectory() - { - return classesDirectory; - } - - public void setClassesDirectory( File classesDirectory ) - { - this.classesDirectory = classesDirectory; - } - - public File getWebappDirectory() - { - return webappDirectory; - } - - public void setWebappDirectory( File webappDirectory ) - { - this.webappDirectory = webappDirectory; - } - - public File getWarSourceDirectory() - { - return warSourceDirectory; - } - - public void setWarSourceDirectory( File warSourceDirectory ) - { - this.warSourceDirectory = warSourceDirectory; - } - - public File getWebXml() - { - return webXml; - } - - public void setWebXml( File webXml ) - { - this.webXml = webXml; - } - - public File getContainerConfigXML() - { - return containerConfigXML; - } - - public void setContainerConfigXML( File containerConfigXML ) - { - this.containerConfigXML = containerConfigXML; - } - - public String getOutputFileNameMapping() - { - return outputFileNameMapping; - } - - public void setOutputFileNameMapping( String outputFileNameMapping ) - { - this.outputFileNameMapping = outputFileNameMapping; - } - - public List getOverlays() - { - return overlays; - } - - public void setOverlays( List overlays ) - { - this.overlays = overlays; - } - - public void addOverlay( Overlay overlay ) - { - overlays.add( overlay ); - } - /** * Returns a string array of the excludes to be used * when assembling/copying the war. @@ -416,141 +308,6 @@ } } - private Map getBuildFilterProperties() - throws MojoExecutionException - { - - Map filterProperties = new Properties(); - - // System properties - filterProperties.putAll( System.getProperties() ); - - // Project properties - filterProperties.putAll( project.getProperties() ); - - for ( Iterator i = filters.iterator(); i.hasNext(); ) - { - String filtersfile = (String) i.next(); - - try - { - Properties properties = PropertyUtils.loadPropertyFile( new File( filtersfile ), true, true ); - - filterProperties.putAll( properties ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error loading property file '" + filtersfile + "'", e ); - } - } - - // can't putAll, as ReflectionProperties doesn't enumerate - so we make a composite map with the project variables as dominant - return new CompositeMap( new ReflectionProperties( project ), filterProperties ); - } - - /** - * Copies webapp webResources from the specified directory. - * <p/> - * Note that the <tt>webXml</tt> parameter could be null and may - * specify a file which is not named <tt>web.xml<tt>. If the file - * exists, it will be copied to the <tt>META-INF</tt> directory and - * renamed accordingly. - * - * @param resource the resource to copy - * @param webappDirectory the target directory - * @param filterProperties - * @throws java.io.IOException if an error occured while copying webResources - */ - public void copyResources( Resource resource, File webappDirectory, Map filterProperties ) - throws IOException - { - if ( !resource.getDirectory().equals( webappDirectory.getPath() ) ) - { - getLog().info( "Copy webapp webResources to " + webappDirectory.getAbsolutePath() ); - if ( webappDirectory.exists() ) - { - String[] fileNames = getWarFiles( resource ); - String targetPath = ( resource.getTargetPath() == null ) ? "" : resource.getTargetPath(); - File destination = new File( webappDirectory, targetPath ); - for ( int i = 0; i < fileNames.length; i++ ) - { - if ( resource.isFiltering() ) - { - copyFilteredFile( new File( resource.getDirectory(), fileNames[i] ), - new File( destination, fileNames[i] ), null, getFilterWrappers(), - filterProperties ); - } - else - { - copyFileIfModified( new File( resource.getDirectory(), fileNames[i] ), - new File( destination, fileNames[i] ) ); - } - } - } - } - } - - /** - * Copies webapp webResources from the specified directory. - * <p/> - * Note that the <tt>webXml</tt> parameter could be null and may - * specify a file which is not named <tt>web.xml<tt>. If the file - * exists, it will be copied to the <tt>META-INF</tt> directory and - * renamed accordingly. - * - * @param sourceDirectory the source directory - * @param webappDirectory the target directory - * @throws java.io.IOException if an error occured while copying webResources - */ - public void copyResources( File sourceDirectory, File webappDirectory ) - throws IOException - { - if ( !sourceDirectory.equals( webappDirectory ) ) - { - getLog().info( "Copy webapp webResources to " + webappDirectory.getAbsolutePath() ); - if ( warSourceDirectory.exists() ) - { - String[] fileNames = getWarFiles( sourceDirectory ); - for ( int i = 0; i < fileNames.length; i++ ) - { - copyFileIfModified( new File( sourceDirectory, fileNames[i] ), - new File( webappDirectory, fileNames[i] ) ); - } - } - } - } - - /** - * Generates the JAR. - * - * @todo Add license files in META-INF directory. - */ - public void createJarArchive( File libDirectory ) - throws MojoExecutionException - { - String archiveName = project.getBuild().getFinalName() + ".jar"; - - File jarFile = new File( libDirectory, archiveName ); - - MavenArchiver archiver = new MavenArchiver(); - - archiver.setArchiver( jarArchiver ); - - archiver.setOutputFile( jarFile ); - - try - { - archiver.getArchiver().addDirectory( classesDirectory, getIncludes(), getExcludes() ); - - archiver.createArchive( project, archive ); - } - catch ( Exception e ) - { - // TODO: improve error handling - throw new MojoExecutionException( "Error assembling JAR", e ); - } - } - /** * Builds the webapp for the specified project with the new packaging task @@ -558,13 +315,12 @@ * <p/> * Classes, libraries and tld files are copied to * the <tt>webappDirectory</tt> during this phase. - * <p/> - * TODO: this is a temporary branch code! rename and clean the mess here when we're done. * * @param project the maven project * @param webappDirectory the target directory * @throws MojoExecutionException if an error occured while packaging the webapp * @throws MojoFailureException if an unexpected error occured while packaging the webapp + * @throws IOException if an error occured while copying the files */ public void buildWebapp( MavenProject project, File webappDirectory ) throws MojoExecutionException, MojoFailureException, IOException @@ -594,7 +350,6 @@ //TODO save the cache } - /** * Returns a <tt>List</tt> of the [EMAIL PROTECTED] org.apache.maven.plugin.war.packaging.WarPackagingTask} * instances to invoke to perform the packaging. @@ -624,704 +379,310 @@ return packagingTasks; } + // War packaging implementation - /** - * Builds the webapp for the specified project. - * <p/> - * Classes, libraries and tld files are copied to - * the <tt>webappDirectory</tt> during this phase. - * - * @param project the maven project - * @param webappDirectory - * @throws java.io.IOException if an error occured while building the webapp - */ - public void buildWebapp2( MavenProject project, File webappDirectory ) - throws MojoExecutionException, IOException, MojoFailureException + private class DefaultWarPackagingContext + implements WarPackagingContext { - getLog().info( "Assembling webapp " + project.getArtifactId() + " in " + webappDirectory ); - File webinfDir = new File( webappDirectory, WEB_INF ); - webinfDir.mkdirs(); - File metainfDir = new File( webappDirectory, META_INF ); - metainfDir.mkdirs(); + private final WebappStructure webappStructure; + + private final File webappDirectory; + + private final OverlayManager overlayManager; - // DONE - List webResources = this.webResources != null ? Arrays.asList( this.webResources ) : null; - if ( webResources != null && webResources.size() > 0 ) + public DefaultWarPackagingContext( File webappDirectory, final WebappStructure webappStructure, + final OverlayManager overlayManager ) { - Map filterProperties = getBuildFilterProperties(); - for ( Iterator it = webResources.iterator(); it.hasNext(); ) + this.webappDirectory = webappDirectory; + this.webappStructure = webappStructure; + this.overlayManager = overlayManager; + + // This is kinda stupid but if we loop over the current overlays and we request the path structure + // it will register it. This will avoid wrong warning messages in a later phase + final Iterator it = overlayManager.getOverlayIds().iterator(); + while ( it.hasNext() ) { - Resource resource = (Resource) it.next(); - if ( !( new File( resource.getDirectory() ) ).isAbsolute() ) - { - resource.setDirectory( project.getBasedir() + File.separator + resource.getDirectory() ); - } - copyResources( resource, webappDirectory, filterProperties ); + String overlayId = (String) it.next(); + webappStructure.getStructure( overlayId ); } } - //DONE - copyResources( warSourceDirectory, webappDirectory ); + public MavenProject getProject() + { + return project; + } - // TODO - if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) ) + public File getWebappDirectory() { - if ( !webXml.exists() ) - { - throw new MojoFailureException( "The specified web.xml file '" + webXml + "' does not exist" ); - } + return webappDirectory; + } - //rename to web.xml - copyFileIfModified( webXml, new File( webinfDir, "/web.xml" ) ); + public File getClassesDirectory() + { + return classesDirectory; } - //TODO - if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) ) + public Log getLog() + { + return AbstractWarMojo.this.getLog(); + } + + public String getOutputFileNameMapping() { - metainfDir = new File( webappDirectory, META_INF ); - String xmlFileName = containerConfigXML.getName(); - copyFileIfModified( containerConfigXML, new File( metainfDir, xmlFileName ) ); + return outputFileNameMapping; } - File libDirectory = new File( webinfDir, "lib" ); + public File getWebappSourceDirectory() + { + return warSourceDirectory; + } - File servicesDirectory = new File( webinfDir, "services" ); + public String[] getWebappSourceIncludes() + { + return getIncludes(); + } - File tldDirectory = new File( webinfDir, "tld" ); + public String[] getWebappSourceExcludes() + { + return getExcludes(); + } - File webappClassesDirectory = new File( webappDirectory, WEB_INF + "/classes" ); + public boolean archiveClasses() + { + return archiveClasses; + } - //DONE - if ( classesDirectory.exists() && !classesDirectory.equals( webappClassesDirectory ) ) + public File getOverlaysWorkDirectory() { - if ( archiveClasses ) - { - createJarArchive( libDirectory ); - } - else - { - copyDirectoryStructureIfModified( classesDirectory, webappClassesDirectory ); - } + return workDirectory; + } + + public ArchiverManager getArchiverManager() + { + return archiverManager; } - //DONE - Set artifacts = project.getArtifacts(); + public MavenArchiveConfiguration getArchive() + { + return archive; + } - List duplicates = findDuplicates( artifacts ); + public JarArchiver getJarArchiver() + { + return jarArchiver; + } - List dependentWarDirectories = new ArrayList(); + public List getFilters() + { + return filters; + } - for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) + public Map getFilterProperties() + throws MojoExecutionException { - Artifact artifact = (Artifact) iter.next(); - String targetFileName = getFinalName( artifact ); + Map filterProperties = new Properties(); - getLog().debug( "Processing: " + targetFileName ); + // System properties + filterProperties.putAll( System.getProperties() ); - if ( duplicates.contains( targetFileName ) ) - { - getLog().debug( "Duplicate found: " + targetFileName ); - targetFileName = artifact.getGroupId() + "-" + targetFileName; - getLog().debug( "Renamed to: " + targetFileName ); - } + // Project properties + filterProperties.putAll( project.getProperties() ); - // TODO: utilise appropriate methods from project builder - ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); - if ( !artifact.isOptional() && filter.include( artifact ) ) + for ( Iterator i = filters.iterator(); i.hasNext(); ) { - String type = artifact.getType(); - if ( "tld".equals( type ) ) - { - copyFileIfModified( artifact.getFile(), new File( tldDirectory, targetFileName ) ); - } - else if ( "aar".equals( type ) ) + String filtersfile = (String) i.next(); + + try { - copyFileIfModified( artifact.getFile(), new File( servicesDirectory, targetFileName ) ); + Properties properties = PropertyUtils.loadPropertyFile( new File( filtersfile ), true, true ); + + filterProperties.putAll( properties ); } - else + catch ( IOException e ) { - if ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) || - "test-jar".equals( type ) ) - { - copyFileIfModified( artifact.getFile(), new File( libDirectory, targetFileName ) ); - } - else - { - if ( "par".equals( type ) ) - { - targetFileName = targetFileName.substring( 0, targetFileName.lastIndexOf( '.' ) ) + ".jar"; - - getLog().debug( - "Copying " + artifact.getFile() + " to " + new File( libDirectory, targetFileName ) ); - - copyFileIfModified( artifact.getFile(), new File( libDirectory, targetFileName ) ); - } - else - { - if ( "war".equals( type ) ) - { - dependentWarDirectories.add( unpackWarToTempDirectory( artifact ) ); - } - else - { - getLog().debug( "Skipping artifact of type " + type + " for WEB-INF/lib" ); - } - } - } + throw new MojoExecutionException( "Error loading property file '" + filtersfile + "'", e ); } } + + // can't putAll, as ReflectionProperties doesn't enumerate - so we make a composite map with the project variables as dominant + return new CompositeMap( new ReflectionProperties( project ), filterProperties ); } - if ( dependentWarDirectories.size() > 0 ) + public WebappStructure getWebappStructure() { - getLog().info( "Overlaying " + dependentWarDirectories.size() + " war(s)." ); + return webappStructure; + } - // overlay dependent wars - for ( Iterator iter = dependentWarDirectories.iterator(); iter.hasNext(); ) - { - copyDependentWarContents( (File) iter.next(), webappDirectory ); - } + public List getOwnerIds() + { + return overlayManager.getOverlayIds(); } } - /** - * Searches a set of artifacts for duplicate filenames and returns a list of duplicates. - * - * @param artifacts set of artifacts - * @return List of duplicated artifacts - */ - private List findDuplicates( Set artifacts ) + public MavenProject getProject() { - List duplicates = new ArrayList(); - List identifiers = new ArrayList(); - for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) - { - Artifact artifact = (Artifact) iter.next(); - String candidate = getFinalName( artifact ); - if ( identifiers.contains( candidate ) ) - { - duplicates.add( candidate ); - } - else - { - identifiers.add( candidate ); - } - } - return duplicates; + return project; } - /** - * Unpacks war artifacts into a temporary directory inside <tt>workDirectory</tt> - * named with the name of the war. - * - * @param artifact War artifact to unpack. - * @return Directory containing the unpacked war. - * @throws MojoExecutionException - */ - private File unpackWarToTempDirectory( Artifact artifact ) - throws MojoExecutionException + public void setProject( MavenProject project ) { - String name = artifact.getFile().getName(); - File tempLocation = new File( workDirectory, name.substring( 0, name.length() - 4 ) ); - - boolean process = false; - if ( !tempLocation.exists() ) - { - tempLocation.mkdirs(); - process = true; - } - else if ( artifact.getFile().lastModified() > tempLocation.lastModified() ) - { - process = true; - } - - if ( process ) - { - File file = artifact.getFile(); - try - { - unpack( file, tempLocation ); - } - catch ( NoSuchArchiverException e ) - { - this.getLog().info( "Skip unpacking dependency file with unknown extension: " + file.getPath() ); - } - } - - return tempLocation; + this.project = project; } - /** - * Unpacks the archive file. - * - * @param file File to be unpacked. - * @param location Location where to put the unpacked files. - */ - private void unpack( File file, File location ) - throws MojoExecutionException, NoSuchArchiverException + public File getClassesDirectory() { - String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase(); - - try - { - UnArchiver unArchiver = archiverManager.getUnArchiver( archiveExt ); - unArchiver.setSourceFile( file ); - unArchiver.setDestDirectory( location ); - unArchiver.setOverwrite( true ); - unArchiver.extract(); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e ); - } - catch ( ArchiverException e ) - { - throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e ); - } + return classesDirectory; } - /** - * Recursively copies contents of <tt>srcDir</tt> into <tt>targetDir</tt>. - * This will not overwrite any existing files. - * - * @param srcDir Directory containing unpacked dependent war contents - * @param targetDir Directory to overlay srcDir into - */ - private void copyDependentWarContents( File srcDir, File targetDir ) - throws MojoExecutionException + public void setClassesDirectory( File classesDirectory ) { - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( srcDir ); - scanner.setExcludes( getDependentWarExcludes() ); - scanner.addDefaultExcludes(); - - scanner.setIncludes( getDependentWarIncludes() ); - - scanner.scan(); - - String[] dirs = scanner.getIncludedDirectories(); - for ( int j = 0; j < dirs.length; j++ ) - { - new File( targetDir, dirs[j] ).mkdirs(); - } - - String[] files = scanner.getIncludedFiles(); - - for ( int j = 0; j < files.length; j++ ) - { - File targetFile = new File( targetDir, files[j] ); - - try - { - // Don't copy if it is in the source directory - if ( !new File( warSourceDirectory, files[j] ).exists() ) - { - targetFile.getParentFile().mkdirs(); - copyFileIfModified( new File( srcDir, files[j] ), targetFile ); - } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error copying file '" + files[j] + "' to '" + targetFile + "'", e ); - } - } + this.classesDirectory = classesDirectory; } - /** - * Returns a list of filenames that should be copied - * over to the destination directory. - * - * @param sourceDir the directory to be scanned - * @return the array of filenames, relative to the sourceDir - */ - private String[] getWarFiles( File sourceDir ) + public File getWebappDirectory() { - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( sourceDir ); - scanner.setExcludes( getExcludes() ); - scanner.addDefaultExcludes(); - - scanner.setIncludes( getIncludes() ); - - scanner.scan(); - - return scanner.getIncludedFiles(); + return webappDirectory; } - /** - * Returns a list of filenames that should be copied - * over to the destination directory. - * - * @param resource the resource to be scanned - * @return the array of filenames, relative to the sourceDir - */ - private String[] getWarFiles( Resource resource ) + public void setWebappDirectory( File webappDirectory ) { - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( resource.getDirectory() ); - if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() ) - { - scanner.setIncludes( (String[]) resource.getIncludes().toArray( EMPTY_STRING_ARRAY ) ); - } - else - { - scanner.setIncludes( DEFAULT_INCLUDES ); - } - if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() ) - { - scanner.setExcludes( (String[]) resource.getExcludes().toArray( EMPTY_STRING_ARRAY ) ); - } - - scanner.addDefaultExcludes(); - - scanner.scan(); - - return scanner.getIncludedFiles(); + this.webappDirectory = webappDirectory; } - /** - * Copy file from source to destination only if source is newer than the target file. - * If <code>destinationDirectory</code> does not exist, it - * (and any parent directories) will be created. If a file <code>source</code> in - * <code>destinationDirectory</code> exists, it will be overwritten. - * - * @param source An existing <code>File</code> to copy. - * @param destinationDirectory A directory to copy <code>source</code> into. - * @throws java.io.FileNotFoundException if <code>source</code> isn't a normal file. - * @throws IllegalArgumentException if <code>destinationDirectory</code> isn't a directory. - * @throws java.io.IOException if <code>source</code> does not exist, the file in - * <code>destinationDirectory</code> cannot be written to, or an IO error occurs during copying. - * <p/> - * TO DO: Remove this method when Maven moves to plexus-util version 1.4 - */ - private static void copyFileToDirectoryIfModified( File source, File destinationDirectory ) - throws IOException + public File getWarSourceDirectory() { - // TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes - // to plexus-util 1.2. - if ( destinationDirectory.exists() && !destinationDirectory.isDirectory() ) - { - throw new IllegalArgumentException( "Destination is not a directory" ); - } - - copyFileIfModified( source, new File( destinationDirectory, source.getName() ) ); + return warSourceDirectory; } - private FilterWrapper[] getFilterWrappers() + public void setWarSourceDirectory( File warSourceDirectory ) { - return new FilterWrapper[]{ - // support ${token} - new FilterWrapper() - { - public Reader getReader( Reader fileReader, Map filterProperties ) - { - return new InterpolationFilterReader( fileReader, filterProperties, "${", "}" ); - } - }, - // support @token@ - new FilterWrapper() - { - public Reader getReader( Reader fileReader, Map filterProperties ) - { - return new InterpolationFilterReader( fileReader, filterProperties, "@", "@" ); - } - }}; + this.warSourceDirectory = warSourceDirectory; } - /** - * @param from - * @param to - * @param encoding - * @param wrappers - * @param filterProperties - * @throws IOException TO DO: Remove this method when Maven moves to plexus-util version 1.4 - */ - private static void copyFilteredFile( File from, File to, String encoding, FilterWrapper[] wrappers, - Map filterProperties ) - throws IOException + public File getWebXml() { - // buffer so it isn't reading a byte at a time! - Reader fileReader = null; - Writer fileWriter = null; - try - { - // fix for MWAR-36, ensures that the parent dir are created first - to.getParentFile().mkdirs(); - - if ( encoding == null || encoding.length() < 1 ) - { - fileReader = new BufferedReader( new FileReader( from ) ); - fileWriter = new FileWriter( to ); - } - else - { - FileInputStream instream = new FileInputStream( from ); - - FileOutputStream outstream = new FileOutputStream( to ); - - fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) ); - - fileWriter = new OutputStreamWriter( outstream, encoding ); - } - - Reader reader = fileReader; - for ( int i = 0; i < wrappers.length; i++ ) - { - FilterWrapper wrapper = wrappers[i]; - reader = wrapper.getReader( reader, filterProperties ); - } - - IOUtil.copy( reader, fileWriter ); - } - finally - { - IOUtil.close( fileReader ); - IOUtil.close( fileWriter ); - } + return webXml; } - /** - * Copy file from source to destination only if source timestamp is later than the destination timestamp. - * The directories up to <code>destination</code> will be created if they don't already exist. - * <code>destination</code> will be overwritten if it already exists. - * - * @param source An existing non-directory <code>File</code> to copy bytes from. - * @param destination A non-directory <code>File</code> to write bytes to (possibly - * overwriting). - * @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be - * written to, or an IO error occurs during copying. - * @throws java.io.FileNotFoundException if <code>destination</code> is a directory - * <p/> - * TO DO: Remove this method when Maven moves to plexus-util version 1.4 - */ - private static void copyFileIfModified( File source, File destination ) - throws IOException + public void setWebXml( File webXml ) { - // TO DO: Remove this method and use the method in WarFileUtils when Maven 2 changes - // to plexus-util 1.2. - if ( destination.lastModified() < source.lastModified() ) - { - FileUtils.copyFile( source.getCanonicalFile(), destination ); - // preserve timestamp - destination.setLastModified( source.lastModified() ); - } + this.webXml = webXml; } - /** - * Copies a entire directory structure but only source files with timestamp later than the destinations'. - * <p/> - * Note: - * <ul> - * <li>It will include empty directories. - * <li>The <code>sourceDirectory</code> must exists. - * </ul> - * - * @param sourceDirectory - * @param destinationDirectory - * @throws IOException TO DO: Remove this method when Maven moves to plexus-util version 1.4 - */ - private static void copyDirectoryStructureIfModified( File sourceDirectory, File destinationDirectory ) - throws IOException + public File getContainerConfigXML() { - if ( !sourceDirectory.exists() ) - { - throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); - } - - File[] files = sourceDirectory.listFiles(); - - String sourcePath = sourceDirectory.getAbsolutePath(); - - for ( int i = 0; i < files.length; i++ ) - { - File file = files[i]; - - String dest = file.getAbsolutePath(); - - dest = dest.substring( sourcePath.length() + 1 ); - - File destination = new File( destinationDirectory, dest ); - - if ( file.isFile() ) - { - destination = destination.getParentFile(); - - copyFileToDirectoryIfModified( file, destination ); - } - else if ( file.isDirectory() ) - { - if ( !destination.exists() && !destination.mkdirs() ) - { - throw new IOException( - "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); - } - - copyDirectoryStructureIfModified( file, destination ); - } - else - { - throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); - } - } + return containerConfigXML; } - /** - * TO DO: Remove this interface when Maven moves to plexus-util version 1.4 - */ - private interface FilterWrapper + public void setContainerConfigXML( File containerConfigXML ) { - Reader getReader( Reader fileReader, Map filterProperties ); + this.containerConfigXML = containerConfigXML; } - /** - * Returns the final name of the specified artifact. - * <p/> - * If the <tt>outputFileNameMapping</tt> is set, it is used, otherwise - * the standard naming scheme is used. - * - * @param artifact the artifact - * @return the converted filename of the artifact - */ - private String getFinalName( Artifact artifact ) + public String getOutputFileNameMapping() { - if ( outputFileNameMapping != null ) - { - return MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact ); - } - - String classifier = artifact.getClassifier(); - if ( ( classifier != null ) && !( "".equals( classifier.trim() ) ) ) - { - return MappingUtils.evaluateFileNameMapping( DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, artifact ); - } - else - { - return MappingUtils.evaluateFileNameMapping( DEFAULT_FILE_NAME_MAPPING, artifact ); - } - + return outputFileNameMapping; } - // War packaging implementation - - private class DefaultWarPackagingContext - implements WarPackagingContext + public void setOutputFileNameMapping( String outputFileNameMapping ) { + this.outputFileNameMapping = outputFileNameMapping; + } + public List getOverlays() + { + return overlays; + } - private final WebappStructure webappStructure; - - private final File webappDirectory; - - private final OverlayManager overlayManager; - - - public DefaultWarPackagingContext( File webappDirectory, final WebappStructure webappStructure, - final OverlayManager overlayManager ) - { - this.webappDirectory = webappDirectory; - this.webappStructure = webappStructure; - this.overlayManager = overlayManager; - - // This is kinda stupid but if we loop over the current overlays and we request the path structure - // it will register it. This will avoid wrong warning messages in a later phase - final Iterator it = overlayManager.getOverlayIds().iterator(); - while ( it.hasNext() ) - { - String overlayId = (String) it.next(); - webappStructure.getStructure( overlayId ); - } - - - } - + public void setOverlays( List overlays ) + { + this.overlays = overlays; + } - public MavenProject getProject() - { - return project; - } + public void addOverlay( Overlay overlay ) + { + overlays.add( overlay ); + } - public File getWebappDirectory() - { - return webappDirectory; - } + public boolean isArchiveClasses() + { + return archiveClasses; + } - public File getClassesDirectory() - { - return classesDirectory; - } + public void setArchiveClasses( boolean archiveClasses ) + { + this.archiveClasses = archiveClasses; + } - public Log getLog() - { - return AbstractWarMojo.this.getLog(); - } + public JarArchiver getJarArchiver() + { + return jarArchiver; + } - public String getOutputFileNameMapping() - { - return outputFileNameMapping; - } + public void setJarArchiver( JarArchiver jarArchiver ) + { + this.jarArchiver = jarArchiver; + } - public File getWebappSourceDirectory() - { - return warSourceDirectory; - } + public Resource[] getWebResources() + { + return webResources; + } - public String[] getWebappSourceIncludes() - { - return getIncludes(); - } + public void setWebResources( Resource[] webResources ) + { + this.webResources = webResources; + } - public String[] getWebappSourceExcludes() - { - return getExcludes(); - } + public List getFilters() + { + return filters; + } - public boolean archiveClasses() - { - return archiveClasses; - } + public void setFilters( List filters ) + { + this.filters = filters; + } - public File getOverlaysWorkDirectory() - { - return workDirectory; - } + public File getWorkDirectory() + { + return workDirectory; + } - public ArchiverManager getArchiverManager() - { - return archiverManager; - } + public void setWorkDirectory( File workDirectory ) + { + this.workDirectory = workDirectory; + } - public MavenArchiveConfiguration getArchive() - { - return archive; - } + public File getWebappStructure() + { + return webappStructure; + } - public JarArchiver getJarArchiver() - { - return jarArchiver; - } + public void setWebappStructure( File webappStructure ) + { + this.webappStructure = webappStructure; + } - public List getFilters() - { - return filters; - } + public String getWarSourceIncludes() + { + return warSourceIncludes; + } - public Map getFilterProperties() - throws MojoExecutionException - { - //TODO refactor this - return getBuildFilterProperties(); - } + public void setWarSourceIncludes( String warSourceIncludes ) + { + this.warSourceIncludes = warSourceIncludes; + } - public WebappStructure getWebappStructure() - { - return webappStructure; - } + public String getWarSourceExcludes() + { + return warSourceExcludes; + } - public List getOwnerIds() - { - return overlayManager.getOverlayIds(); - } + public void setWarSourceExcludes( String warSourceExcludes ) + { + this.warSourceExcludes = warSourceExcludes; } }