Author: brett Date: Mon Jun 26 22:30:00 2006 New Revision: 417345 URL: http://svn.apache.org/viewvc?rev=417345&view=rev Log: [MWAR-52] add tests to verify problem can't be reproduced, improve formatting and usability of some tests
Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/AbstractWarMojoTest.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java?rev=417345&r1=417344&r2=417345&view=diff ============================================================================== --- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java (original) +++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/AbstractAssemblyMojo.java Mon Jun 26 22:30:00 2006 @@ -22,7 +22,6 @@ import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Build; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -442,9 +441,9 @@ } Set allModuleProjects = getModulesFromReactor( getExecutedProject() ); - + Set moduleProjects = new HashSet( allModuleProjects ); - + FilterUtils.filterProjects( moduleProjects, moduleSet.getIncludes(), moduleSet.getExcludes(), false ); List moduleFileSets = new ArrayList(); @@ -471,8 +470,7 @@ excludesList.add( PathUtils.toRelative( moduleProject.getBasedir(), moduleProject.getBuild().getDirectory() ) + "/**" ); excludesList.add( PathUtils.toRelative( moduleProject.getBasedir(), - moduleProject.getBuild().getOutputDirectory() ) + - "/**" ); + moduleProject.getBuild().getOutputDirectory() ) + "/**" ); excludesList.add( PathUtils.toRelative( moduleProject.getBasedir(), moduleProject.getBuild().getTestOutputDirectory() ) + "/**" ); @@ -508,12 +506,12 @@ Integer.toString( archiver.getDefaultFileMode(), 8 ) ); Set binaryDependencies = moduleProject.getArtifacts(); - + List includes = binaries.getIncludes(); List excludes = binaries.getExcludes(); - + FilterUtils.filterArtifacts( binaryDependencies, includes, excludes, true, Collections.EMPTY_LIST ); - + if ( binaries.isUnpack() ) { // TODO: something like zipfileset in plexus-archiver @@ -540,7 +538,8 @@ if ( binaries.isIncludeDependencies() ) { - for ( Iterator dependencyIterator = binaryDependencies.iterator(); dependencyIterator.hasNext(); ) + for ( Iterator dependencyIterator = binaryDependencies.iterator(); + dependencyIterator.hasNext(); ) { Artifact dependencyArtifact = (Artifact) dependencyIterator.next(); @@ -550,8 +549,7 @@ } catch ( NoSuchArchiverException e ) { - throw new MojoExecutionException( "Unable to obtain unarchiver: " + e.getMessage(), - e ); + throw new MojoExecutionException( "Unable to obtain unarchiver: " + e.getMessage(), e ); } /* @@ -591,8 +589,8 @@ { String outputFileNameMapping = binaries.getOutputFileNameMapping(); - archiver.addFile( moduleArtifact.getFile(), - output + evaluateFileNameMapping( moduleArtifact, outputFileNameMapping ) ); + archiver.addFile( moduleArtifact.getFile(), output + + evaluateFileNameMapping( moduleArtifact, outputFileNameMapping ) ); if ( binaries.isIncludeDependencies() ) { @@ -607,8 +605,7 @@ } catch ( ArchiverException e ) { - throw new MojoExecutionException( "Error adding file to archive: " + e.getMessage(), - e ); + throw new MojoExecutionException( "Error adding file to archive: " + e.getMessage(), e ); } } } @@ -619,13 +616,13 @@ processFileSets( archiver, moduleFileSets, includeBaseDirectory ); } } - + allModuleProjects.removeAll( moduleProjects ); - + for ( Iterator it = allModuleProjects.iterator(); it.hasNext(); ) { MavenProject excludedProject = (MavenProject) it.next(); - + // would be better to have a way to find out when a specified include or exclude // is never triggered and warn() it. getLog().debug( "module: " + excludedProject.getId() + " not included" ); @@ -971,17 +968,17 @@ Set allDependencyArtifacts = ProjectUtils.getDependencies( getExecutedProject() ); Set dependencyArtifacts = new HashSet( allDependencyArtifacts ); - + AssemblyScopeArtifactFilter scopeFilter = new AssemblyScopeArtifactFilter( dependencySet.getScope() ); - - FilterUtils.filterArtifacts( dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(), true, Collections.singletonList( scopeFilter ) ); + + FilterUtils.filterArtifacts( dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(), + true, Collections.singletonList( scopeFilter ) ); for ( Iterator j = dependencyArtifacts.iterator(); j.hasNext(); ) { Artifact artifact = (Artifact) j.next(); - String fileNameMapping = - evaluateFileNameMapping( artifact, dependencySet.getOutputFileNameMapping() ); + String fileNameMapping = evaluateFileNameMapping( artifact, dependencySet.getOutputFileNameMapping() ); if ( dependencySet.isUnpack() ) { // TODO: something like zipfileset in plexus-archiver @@ -1034,8 +1031,8 @@ } catch ( IOException e ) { - throw new MojoExecutionException( - "Failed to delete security files: " + e.getMessage(), e ); + throw new MojoExecutionException( "Failed to delete security files: " + e.getMessage(), + e ); } } } @@ -1055,13 +1052,13 @@ } } } - + allDependencyArtifacts.removeAll( dependencyArtifacts ); - + for ( Iterator it = allDependencyArtifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); - + // would be better to have a way to find out when a specified include or exclude // is never triggered and warn() it. getLog().debug( "artifact: " + artifact + " not included" ); @@ -1138,11 +1135,10 @@ archiver.setDefaultFileMode( Integer.parseInt( fileSet.getFileMode(), 8 ) ); - getLog() - .debug( "FileSet[" + output + "]" + " dir perms: " + - Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) + " file perms: " + - Integer.toString( archiver.getDefaultFileMode(), 8 ) + - ( fileSet.getLineEnding() == null ? "" : " lineEndings: " + fileSet.getLineEnding() ) ); + getLog().debug( "FileSet[" + output + "]" + " dir perms: " + + Integer.toString( archiver.getDefaultDirectoryMode(), 8 ) + " file perms: " + + Integer.toString( archiver.getDefaultFileMode(), 8 ) + + ( fileSet.getLineEnding() == null ? "" : " lineEndings: " + fileSet.getLineEnding() ) ); if ( directory == null ) { @@ -1227,12 +1223,12 @@ FileItem fileItem = (FileItem) i.next(); //ensure source file is in absolute path for reactor build to work - File source = new File ( fileItem.getSource() ); + File source = new File( fileItem.getSource() ); if ( ! source.isAbsolute() ) { - source = new File( this.basedir, fileItem.getSource() ); + source = new File( this.basedir, fileItem.getSource() ); } - + if ( fileItem.isFiltered() ) { source = filterFile( source ).getAbsoluteFile(); @@ -1264,7 +1260,7 @@ } File tempRootFile = File.createTempFile( source.getName() + ".", "", tempRoot ); - + tempRootFile.deleteOnExit(); copyReplacingLineEndings( source, tempRootFile, lineEnding ); Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/AbstractWarMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/AbstractWarMojoTest.java?rev=417345&r1=417344&r2=417345&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/AbstractWarMojoTest.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/AbstractWarMojoTest.java Mon Jun 26 22:30:00 2006 @@ -16,14 +16,15 @@ * limitations under the License. */ +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.war.stub.MavenProjectBasicStub; +import org.codehaus.plexus.util.FileUtils; + import java.io.File; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.war.stub.MavenProjectBasicStub; - public abstract class AbstractWarMojoTest extends AbstractMojoTestCase { @@ -33,7 +34,7 @@ /** * initialize required parameters - * + * * @param mojo * @param filters * @param classesDir @@ -43,7 +44,7 @@ * @throws Exception */ protected void configureMojo( AbstractWarMojo mojo, List filters, File classesDir, File webAppSource, - File webAppDir, MavenProjectBasicStub project ) + File webAppDir, MavenProjectBasicStub project ) throws Exception { setVariableValueToObject( mojo, "filters", filters ); @@ -55,7 +56,7 @@ /** * create an isolated xml dir - * + * * @param id * @param xmlFiles * @return @@ -84,7 +85,7 @@ /** * create an isolated web source with a sample jsp file - * + * * @param id * @return * @throws Exception @@ -103,7 +104,7 @@ /** * create a class directory with or without a sample class - * + * * @param id * @param empty * @return @@ -135,10 +136,9 @@ protected void createFile( File testFile ) throws Exception { - if ( !testFile.exists() ) - { - createDir( testFile.getParentFile() ); - assertTrue( "can not create test file: " + testFile.toString(), testFile.createNewFile() ); - } + createDir( testFile.getParentFile() ); + FileUtils.fileWrite( testFile.toString(), testFile.toString() ); + + assertTrue( "could not create file: " + testFile, testFile.exists() ); } } Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java?rev=417345&r1=417344&r2=417345&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarExplodedMojoTest.java Mon Jun 26 22:30:00 2006 @@ -132,6 +132,7 @@ assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); assertTrue( "WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); assertTrue( "META-INF not found", expectedMETAINFDir.exists() ); + assertEquals( "WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead( expectedWEBXMLFile ) ); } /** @@ -500,8 +501,8 @@ assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() ); assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() ); assertTrue( "resource file not found:" + expectedResourceFile.toString(), expectedResourceFile.exists() ); - assertTrue( "resource file with dir not found:" + expectedResourceWDirFile.toString(), expectedResourceWDirFile - .exists() ); + assertTrue( "resource file with dir not found:" + expectedResourceWDirFile.toString(), + expectedResourceWDirFile.exists() ); // validate filtered file FileReader reader = new FileReader( expectedResourceWDirFile ); Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java?rev=417345&r1=417344&r2=417345&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java Mon Jun 26 22:30:00 2006 @@ -19,26 +19,28 @@ import org.apache.maven.plugin.war.stub.MavenProject4CopyConstructor; import org.apache.maven.plugin.war.stub.ProjectHelperStub; import org.apache.maven.plugin.war.stub.SimpleWarArtifact4CCStub; +import org.codehaus.plexus.util.IOUtil; import java.io.File; import java.util.Enumeration; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import java.util.zip.ZipEntry; /** * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest - * - * */ public class WarMojoTest extends AbstractWarMojoTest { WarMojo mojo; - private static File pomFile = new File( getBasedir(), - "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" ); + private static File pomFile = + new File( getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" ); protected File getTestDirectory() { @@ -69,7 +71,7 @@ String warName = "simple"; File webAppSource = createWebAppSource( testId ); File classesDir = createClassesDir( testId, true ); - File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + File xmlSource = createXMLConfigDir( testId, new String[]{"web.xml"} ); project.setArtifact( warArtifact ); this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); @@ -81,7 +83,7 @@ //validate jar file File expectedJarFile = new File( outputDir, "simple.war" ); - HashSet jarContent = new HashSet(); + Map jarContent = new HashMap(); assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() ); @@ -92,18 +94,20 @@ while ( enumeration.hasMoreElements() ) { entry = (JarEntry) enumeration.nextElement(); - jarContent.add( entry.getName() ); + jarContent.put( entry.getName(), entry ); } - assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) ); - assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) ); - assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) ); - assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent - .contains( "org/web/app/last-exile.jsp" ) ); - assertTrue( "pom file not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); - assertTrue( "pom properties not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); + assertTrue( "manifest file not found", jarContent.containsKey( "META-INF/MANIFEST.MF" ) ); + assertTrue( "web xml not found", jarContent.containsKey( "WEB-INF/web.xml" ) ); + assertEquals( "web xml file incorrect", mojo.getWebXml().toString(), + IOUtil.toString( jarFile.getInputStream( (ZipEntry) jarContent.get( "WEB-INF/web.xml" ) ) ) ); + assertTrue( "web source not found: pansit.jsp", jarContent.containsKey( "pansit.jsp" ) ); + assertTrue( "web source not found: org/web/app/last-exile.jsp", + jarContent.containsKey( "org/web/app/last-exile.jsp" ) ); + assertTrue( "pom file not found", + jarContent.containsKey( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); + assertTrue( "pom properties not found", + jarContent.containsKey( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); } public void testClassifier() @@ -118,7 +122,7 @@ String warName = "simple"; File webAppSource = createWebAppSource( testId ); File classesDir = createClassesDir( testId, true ); - File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + File xmlSource = createXMLConfigDir( testId, new String[]{"web.xml"} ); project.setArtifact( warArtifact ); this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project ); @@ -150,12 +154,12 @@ assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) ); assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) ); assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) ); - assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent - .contains( "org/web/app/last-exile.jsp" ) ); - assertTrue( "pom file not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); - assertTrue( "pom properties not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); + assertTrue( "web source not found: org/web/app/last-exile.jsp", + jarContent.contains( "org/web/app/last-exile.jsp" ) ); + assertTrue( "pom file not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); + assertTrue( "pom properties not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); } public void testPrimaryArtifact() @@ -170,7 +174,7 @@ String warName = "simple"; File webAppSource = createWebAppSource( testId ); File classesDir = createClassesDir( testId, true ); - File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + File xmlSource = createXMLConfigDir( testId, new String[]{"web.xml"} ); warArtifact.setFile( new File( "error.war" ) ); project.setArtifact( warArtifact ); @@ -187,8 +191,8 @@ HashSet jarContent = new HashSet(); assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() ); - assertTrue( "war file was not set as primary artifact", project.getArtifact().getFile().getName() - .equals( "simple.war" ) ); + assertTrue( "war file was not set as primary artifact", + project.getArtifact().getFile().getName().equals( "simple.war" ) ); JarFile jarFile = new JarFile( expectedJarFile ); JarEntry entry; @@ -203,12 +207,12 @@ assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) ); assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) ); assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) ); - assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent - .contains( "org/web/app/last-exile.jsp" ) ); - assertTrue( "pom file not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); - assertTrue( "pom properties not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); + assertTrue( "web source not found: org/web/app/last-exile.jsp", + jarContent.contains( "org/web/app/last-exile.jsp" ) ); + assertTrue( "pom file not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); + assertTrue( "pom properties not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); } public void testNotPrimaryArtifact() @@ -227,7 +231,7 @@ String warName = "simple"; File webAppSource = createWebAppSource( testId ); File classesDir = createClassesDir( testId, true ); - File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } ); + File xmlSource = createXMLConfigDir( testId, new String[]{"web.xml"} ); warArtifact.setFile( new File( "error.war" ) ); project.setArtifact( warArtifact ); @@ -259,11 +263,11 @@ assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) ); assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) ); assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) ); - assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent - .contains( "org/web/app/last-exile.jsp" ) ); - assertTrue( "pom file not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); - assertTrue( "pom properties not found", jarContent - .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); + assertTrue( "web source not found: org/web/app/last-exile.jsp", + jarContent.contains( "org/web/app/last-exile.jsp" ) ); + assertTrue( "pom file not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) ); + assertTrue( "pom properties not found", + jarContent.contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) ); } } Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java?rev=417345&r1=417344&r2=417345&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java Mon Jun 26 22:30:00 2006 @@ -48,14 +48,10 @@ { List artifacts = new ArrayList(); - String basedir = System.getProperty( "basedir" ); - - artifacts - .add( basedir + - "/src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar" ); - artifacts - .add( basedir + - "/src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar" ); + artifacts.add( + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar" ); + artifacts.add( + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar" ); return artifacts; }