[MNG-4536] Long build time - enforcer running too many times

o Added IT

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@904187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-01-28 17:54:32 +00:00
parent c28d4c9cb3
commit 8e1f46931a
9 changed files with 273 additions and 81 deletions

View File

@ -86,6 +86,7 @@ public class IntegrationTestSuite
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng4544ActiveComponentCollectionThreadSafeTest.class );
suite.addTestSuite( MavenITmng4536RequiresNoProjectForkingMojoTest.class );
suite.addTestSuite( MavenITmng4522FailUponMissingDependencyParentPomTest.class );
suite.addTestSuite( MavenITmng4500NoUpdateOfTimestampedSnapshotsTest.class );
suite.addTestSuite( MavenITmng4498IgnoreBrokenMetadataTest.class );

View File

@ -0,0 +1,62 @@
package org.apache.maven.it;
/*
* 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.
*/
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4536">MNG-4536</a>.
*
* @author Benjamin Bentmann
*/
public class MavenITmng4536RequiresNoProjectForkingMojoTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng4536RequiresNoProjectForkingMojoTest()
{
super( "[2.0.3,3.0-alpha-1),[3.0-alpha-7,)" );
}
/**
* Test that forking mojos that require no project only fork the current project and not the entire reactor.
*/
public void testit()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4536" );
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteDirectory( "mod-a/target" );
verifier.deleteDirectory( "mod-b/target" );
verifier.executeGoal( "generate-sources" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
assertEquals( 2, verifier.loadLines( "mod-a/target/touch.log", "UTF-8" ).size() );
assertEquals( 2, verifier.loadLines( "mod-b/target/touch.log", "UTF-8" ).size() );
}
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng4536</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
</parent>
<groupId>org.apache.maven.its.mng4536</groupId>
<artifactId>moda</artifactId>
<version>0.1</version>
<name>Maven Integration Test :: MNG-4536 :: Module A</name>
</project>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng4536</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
</parent>
<groupId>org.apache.maven.its.mng4536</groupId>
<artifactId>modb</artifactId>
<version>0.1</version>
<name>Maven Integration Test :: MNG-4536 :: Module B</name>
</project>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4536</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-4536</name>
<description>
Test that forking mojos that require no project only fork the current project and not the entire reactor.
</description>
<modules>
<module>mod-a</module>
<module>mod-b</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-fork</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>test</id>
<phase>generate-sources</phase>
<goals>
<goal>fork-lifecycle-no-project</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -34,6 +34,10 @@ under the License.
<name>Maven Integration Test Plugin :: Fork</name>
<inceptionYear>2006</inceptionYear>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -44,6 +48,16 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -51,7 +51,7 @@ public class ForkLifecycleMojo
public void execute()
throws MojoExecutionException
{
TouchMojo.touch( touchDirectory, "fork-lifecycle.txt", true );
TouchMojo.touch( touchDirectory, "fork-lifecycle.txt" );
if ( !executedProject.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) )
{

View File

@ -0,0 +1,59 @@
package org.apache.maven.plugin.coreit;
/*
* 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.
*/
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
/**
* @goal fork-lifecycle-no-project
* @requiresProject false
*
* @execute phase="generate-sources" lifecycle="foo"
*/
public class ForkLifecycleNoProjectMojo
extends AbstractMojo
{
/**
* @parameter default-value="${project.build.finalName}"
*/
private String finalName;
/**
* @parameter default-value="target"
*/
private File touchDirectory;
public void execute()
throws MojoExecutionException
{
TouchMojo.touch( touchDirectory, "fork-lifecycle-no-project.txt" );
if ( TouchMojo.FINAL_NAME.equals( finalName ) )
{
throw new MojoExecutionException( "forked project was polluted. (should NOT be \'" + TouchMojo.FINAL_NAME
+ "\')." );
}
}
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.plugin.coreit;
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
@ -28,14 +27,11 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.Map;
/**
* @goal touch
*
* @phase process-sources
*
* @description Goal which cleans the build
*/
public class TouchMojo
extends AbstractMojo
@ -54,94 +50,22 @@ public class TouchMojo
*/
private File outputDirectory;
/** Test setting of plugin-artifacts on the PluginDescriptor instance.
* @parameter expression="${plugin.artifactMap}"
* @required
*/
private Map pluginArtifacts;
/**
* @parameter expression="target/test-basedir-alignment"
*/
private File basedirAlignmentDirectory;
/**
* @parameter alias="pluginFile"
*/
private String pluginItem = "foo";
/**
* @parameter
*/
private String goalItem = "bar";
/**
* @parameter expression="${artifactToFile}"
*/
private String artifactToFile;
/**
* @parameter expression="${fail}"
*/
private boolean fail = false;
public void execute()
throws MojoExecutionException
{
if ( fail )
{
throw new MojoExecutionException( "Failing per \'fail\' parameter (specified in pom or system properties)" );
}
getLog().info( "[MAVEN-CORE-IT-LOG] Project build directory " + project.getBuild().getDirectory() );
touch( new File( project.getBuild().getDirectory() ), "touch.log" );
getLog().info( "[MAVEN-CORE-IT-LOG] Using output directory " + outputDirectory );
touch( outputDirectory, "touch.txt" );
// This parameter should be aligned to the basedir as the parameter type is specified
// as java.io.File
if ( basedirAlignmentDirectory.getPath().equals( "target/test-basedir-alignment" ) )
{
throw new MojoExecutionException( "basedirAlignmentDirectory not aligned" );
}
touch( basedirAlignmentDirectory, "touch.txt" );
// Test parameter setting
if ( pluginItem != null )
{
touch( outputDirectory, pluginItem );
}
if ( goalItem != null )
{
touch( outputDirectory, goalItem );
}
if ( artifactToFile != null )
{
Artifact artifact = (Artifact) pluginArtifacts.get( artifactToFile );
File artifactFile = artifact.getFile();
String filename = artifactFile.getAbsolutePath().replace('/', '_').replace(':', '_') + ".txt";
touch( outputDirectory, filename );
}
project.getBuild().setFinalName( FINAL_NAME );
}
static void touch( File dir, String file )
throws MojoExecutionException
{
touch( dir, file, false );
}
static void touch( File dir, String file, boolean append )
throws MojoExecutionException
{
try
{
@ -152,7 +76,8 @@ public class TouchMojo
File touch = new File( dir, file );
OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( touch, append ), "UTF-8" );
// NOTE: Using append mode to track execution count
OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( touch, true ), "UTF-8" );
w.write( file );
w.write( "\n" );
@ -164,4 +89,5 @@ public class TouchMojo
throw new MojoExecutionException( "Error touching file", e );
}
}
}