Author: olamy
Date: Sat Oct 29 21:17:44 2011
New Revision: 1195041
URL: http://svn.apache.org/viewvc?rev=1195041&view=rev
Log:
[ARCHETYPE-388] enhance IntegrationTestMojo to be able to run verify script to
do some asserts.
add integration test and fix paths to run script
Added:
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
(with props)
Modified:
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
Added:
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
URL:
http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy?rev=1195041&view=auto
==============================================================================
---
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
(added)
+++
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
Sat Oct 29 21:17:44 2011
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert new File(context.projectDir, 'pom.xml').exists();
+content = new File(context.projectDir, 'pom.xml').text;
+assert content.contains( '<foo>bar</foo>' );
\ No newline at end of file
Propchange:
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archetype/trunk/maven-archetype-plugin/src/it/property-setting-cli/src/test/resources/projects/basic/verify.groovy
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
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=1195041&r1=1195040&r2=1195041&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
Sat Oct 29 21:17:44 2011
@@ -49,6 +49,7 @@ import java.io.StringWriter;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
/**
@@ -361,7 +362,7 @@ public class IntegrationTestMojo
String goals = FileUtils.fileRead( goalFile );
- invokePostArchetypeGenerationGoals( goals, new File( basedir,
request.getArtifactId() ) );
+ invokePostArchetypeGenerationGoals( goals, new File( basedir,
request.getArtifactId() ), goalFile );
}
catch ( IOException ioe )
{
@@ -377,55 +378,58 @@ public class IntegrationTestMojo
return loadProperties( propertiesFile );
}
- private void invokePostArchetypeGenerationGoals( String goals, File
basedir )
+ private void invokePostArchetypeGenerationGoals( String goals, File
basedir, File goalFile )
throws IntegrationTestFailure, IOException, MojoExecutionException
{
- if ( StringUtils.isBlank( goals ) )
- {
- getLog().info( "No post-archetype-generation goals to invoke." );
-
- return;
- }
+ FileLogger logger = setupLogger( basedir );
- getLog().info( "Invoking post-archetype-generation goals: " + goals );
+ if ( !StringUtils.isBlank( goals ) )
+ {
- FileLogger logger = setupLogger( basedir );
+ getLog().info( "Invoking post-archetype-generation goals: " +
goals );
- InvocationRequest request = new
DefaultInvocationRequest().setBaseDirectory( basedir ).setGoals(
- Arrays.asList( StringUtils.split( goals, "," ) ) );
+ InvocationRequest request = new
DefaultInvocationRequest().setBaseDirectory( basedir ).setGoals(
+ Arrays.asList( StringUtils.split( goals, "," ) ) );
- if ( logger != null )
- {
- request.setErrorHandler( logger );
+ if ( logger != null )
+ {
+ request.setErrorHandler( logger );
- request.setOutputHandler( logger );
- }
+ request.setOutputHandler( logger );
+ }
- try
- {
- InvocationResult result = invoker.execute( request );
+ try
+ {
+ InvocationResult result = invoker.execute( request );
- getLog().info( "Post-archetype-generation invoker exit code: " +
result.getExitCode() );
+ getLog().info( "Post-archetype-generation invoker exit code: "
+ result.getExitCode() );
- if ( result.getExitCode() != 0 )
+ if ( result.getExitCode() != 0 )
+ {
+ throw new IntegrationTestFailure( "Execution failure: exit
code = " + result.getExitCode(),
+
result.getExecutionException() );
+ }
+ }
+ catch ( MavenInvocationException e )
{
- throw new IntegrationTestFailure( "Execution failure: exit
code = " + result.getExitCode(),
-
result.getExecutionException() );
+ throw new IntegrationTestFailure( "Cannot run additions
goals.", e );
}
}
- catch ( MavenInvocationException e )
+ else
{
- throw new IntegrationTestFailure( "Cannot run additions goals.", e
);
+ getLog().info( "No post-archetype-generation goals to invoke." );
}
-
// verify result
ScriptRunner scriptRunner = new ScriptRunner( getLog() );
scriptRunner.setScriptEncoding( encoding );
+ Map<String, Object> context = new LinkedHashMap<String, Object>();
+ context.put( "projectDir", basedir );
+
try
{
- scriptRunner.run( "post-build script", basedir,
postBuildHookScript, new LinkedHashMap<String, Object>(),
- logger, "failure post script", true );
+ scriptRunner.run( "post-build script", goalFile.getParentFile(),
postBuildHookScript, context, logger,
+ "failure post script", true );
}
catch ( BuildFailureException e )
{