You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/10/03 19:36:25 UTC
svn commit: r1004009 -
/maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
Author: hboutemy
Date: Sun Oct 3 17:36:25 2010
New Revision: 1004009
URL: http://svn.apache.org/viewvc?rev=1004009&view=rev
Log:
o code simplification and cleanup
o javadoc improvement
o avoid stream leaks when reading files
Modified:
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
Modified: maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java?rev=1004009&r1=1004008&r2=1004009&view=diff
==============================================================================
--- maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java (original)
+++ maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java Sun Oct 3 17:36:25 2010
@@ -29,18 +29,28 @@ import org.apache.maven.plugin.MojoExecu
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringWriter;
import java.util.List;
import java.util.Properties;
/**
- * Execute the archetype integration tests.
+ * Execute the archetype integration tests, consisting of a creation of a project from the current archetype with
+ * defined properties and optional comparison with reference copy. An IT consists of a directory in
+ * <code>src/test/resources/projects</code> containing:
+ * <ul>
+ * <li><code>goal.txt</code> (content actually not used, but future version should interpret it as a goal to run against
+ * the generated project: see <a href="http://http://jira.codehaus.org/browse/ARCHETYPE-334/">ARCHETYPE-334</a>),</li>
+ * <li><code>archetype.properties</code> with properties for project generation,</li>
+ * <li>optional <code>reference/</code> directory containing a reference copy of the expected project created from the IT.</li>
+ * </ul>
*
* @author rafale
* @requiresProject true
@@ -72,46 +82,50 @@ public class IntegrationTestMojo
public void execute()
throws MojoExecutionException, MojoFailureException
{
- if ( !skip )
+ if ( skip )
{
- try
- {
- File projectsDirectory = new File( project.getBasedir(), "target/test-classes/projects" );
+ return;
+ }
- if ( projectsDirectory.exists() )
- {
- File archetypeFile = project.getArtifact().getFile();
+ File projectsDirectory = new File( project.getBasedir(), "target/test-classes/projects" );
- List<File> projectsGoalFiles = FileUtils.getFiles( projectsDirectory, "*/goal.txt", "" );
+ if ( !projectsDirectory.exists() )
+ {
+ return;
+ }
- StringWriter errorWriter = new StringWriter();
- for ( File goalFile : projectsGoalFiles )
- {
- try
- {
- processIntegrationTest( goalFile, archetypeFile );
- }
- catch ( IntegrationTestFailure ex )
- {
- errorWriter.write( "Test " + goalFile.getParentFile().getName() + " failed\n" );
- errorWriter.write( ex.getStackTrace() + "\n" );
- errorWriter.write( ex.getMessage() + "\n" );
- errorWriter.write( "\n" );
- }
- }
+ try
+ {
+ List<File> projectsGoalFiles = FileUtils.getFiles( projectsDirectory, "*/goal.txt", "" );
- String errors = errorWriter.toString();
- if ( !StringUtils.isEmpty( errors ) )
- {
- throw new MojoExecutionException( errors );
- }
+ File archetypeFile = project.getArtifact().getFile();
+
+ StringWriter errorWriter = new StringWriter();
+ for ( File goalFile : projectsGoalFiles )
+ {
+ try
+ {
+ processIntegrationTest( goalFile, archetypeFile );
+ }
+ catch ( IntegrationTestFailure ex )
+ {
+ errorWriter.write( "Test " + goalFile.getParentFile().getName() + " failed\n" );
+ errorWriter.write( ex.getStackTrace() + "\n" );
+ errorWriter.write( ex.getMessage() + "\n" );
+ errorWriter.write( "\n" );
}
}
- catch ( IOException ex )
+
+ String errors = errorWriter.toString();
+ if ( !StringUtils.isEmpty( errors ) )
{
- throw new MojoFailureException( ex, ex.getMessage(), ex.getMessage() );
+ throw new MojoExecutionException( errors );
}
}
+ catch ( IOException ex )
+ {
+ throw new MojoFailureException( ex, ex.getMessage(), ex.getMessage() );
+ }
}
private void assertTest( File reference, File basedir )
@@ -173,7 +187,17 @@ public class IntegrationTestMojo
{
Properties properties = new Properties();
- properties.load( new FileInputStream( propertiesFile ) );
+ InputStream in = null;
+ try
+ {
+ in = new FileInputStream( propertiesFile );
+
+ properties.load( in );
+ }
+ finally
+ {
+ IOUtil.close( in );
+ }
return properties;
}
@@ -189,8 +213,6 @@ public class IntegrationTestMojo
{
try
{
- Properties testProperties = getTestProperties( goalFile );
-
Properties properties = getProperties( goalFile );
String basedir = goalFile.getParentFile().getPath() + "/project";
@@ -214,6 +236,11 @@ public class IntegrationTestMojo
archetypeGenerator.generateArchetype( request, archetypeFile, result );
+ if ( result.getCause() != null )
+ {
+ throw new IntegrationTestFailure( result.getCause() );
+ }
+
File reference = new File( goalFile.getParentFile(), "reference" );
if ( reference.exists() )
@@ -221,11 +248,6 @@ public class IntegrationTestMojo
// compare generated project with reference
assertTest( reference, new File( basedir, request.getArtifactId() ) );
}
-
- if ( result.getCause() != null )
- {
- throw new IntegrationTestFailure( result.getCause() );
- }
}
catch ( IOException ioe )
{
@@ -237,17 +259,10 @@ public class IntegrationTestMojo
throws IOException
{
File propertiesFile = new File( goalFile.getParentFile(), "archetype.properties" );
- System.out.println( propertiesFile );
return loadProperties( propertiesFile );
}
- private Properties getTestProperties( File goalFile )
- throws IOException
- {
- return loadProperties( goalFile );
- }
-
class IntegrationTestFailure
extends Exception
{