[MNG-3710] Use generated reader/writer to create clean deep clones of Model and Build instances, rather than trying to reuse logic meant for assembling inheritance and/or injecting defaults. Also including integration tests to check for plugin pollution.

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@685999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-08-14 19:19:15 +00:00
parent 0e62f46ec9
commit 693fb14fe2
13 changed files with 464 additions and 1 deletions

View File

@ -76,11 +76,11 @@ MavenITmng3415JunkRepositoryMetadataTest
MavenITmng3645POMSyntaxErrorTest
*/
suite.addTestSuite( MavenITmng3710PollutedClonedPluginsTest.class );
suite.addTestSuite( MavenITmng3704LifecycleExecutorWrapperTest.class );
suite.addTestSuite( MavenITmng3703ExecutionProjectWithRelativePathsTest.class );
suite.addTestSuite( MavenITmng3694ReactorProjectsDynamismTest.class );
suite.addTestSuite( MavenITmng3693PomFileBasedirChangeTest.class );
suite.addTestSuite( MavenITmng3599useHttpProxyForWebDAV.class );
suite.addTestSuite( MavenITmng3684BuildPluginParameterTest.class );
suite.addTestSuite( MavenITmng3680InvalidDependencyPOMTest.class );
suite.addTestSuite( MavenITmng3679PluginExecIdInterpolationTest.class );
@ -88,6 +88,7 @@ MavenITmng3645POMSyntaxErrorTest
suite.addTestSuite( MavenITmng3667ResolveDepsWithBadPomVersionTest.class );
suite.addTestSuite( MavenITmng3652UserAgentHeader.class );
suite.addTestSuite( MavenITmng3642DynamicResourcesTest.class );
suite.addTestSuite( MavenITmng3599useHttpProxyForWebDAV.class );
suite.addTestSuite( MavenITmng3581PluginUsesWagonDependency.class );
suite.addTestSuite( MavenITmng3545ProfileDeactivation.class );
suite.addTestSuite( MavenITmng3536AppendedAbsolutePaths.class );

View File

@ -0,0 +1,107 @@
/*
* 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.
*/
package org.apache.maven.integrationtests;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3710">MNG-3710</a>.
*
* @todo Fill in a better description of what this test verifies!
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @author jdcasey
*/
public class MavenITmng3710PollutedClonedPluginsTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng3710PollutedClonedPluginsTest()
throws InvalidVersionSpecificationException
{
super( "(2.0.8,)" ); // only test in 2.0.9+
}
public void testitMNG3710_POMInheritance()
throws Exception
{
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710-pollutedClonedPlugins/pom-inheritance" );
File pluginDir = new File( testDir, "maven-mng3710-pomInheritance-plugin" );
File projectsDir = new File( testDir, "projects" );
Verifier verifier;
verifier = new Verifier( pluginDir.getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
verifier = new Verifier( projectsDir.getAbsolutePath() );
verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
File topLevelTouchFile = new File( projectsDir, "target/touch.txt" );
assertFalse( "Top-level touch file should NOT be created in projects tree.", topLevelTouchFile.exists() );
File midLevelTouchFile = new File( projectsDir, "middle/target/touch.txt" );
assertTrue( "Mid-level touch file should have been created in projects tree.", midLevelTouchFile.exists() );
File childLevelTouchFile = new File( projectsDir, "middle/child/target/touch.txt" );
assertTrue( "Child-level touch file should have been created in projects tree.", childLevelTouchFile.exists() );
}
public void testitMNG3710_OriginalModel()
throws Exception
{
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710-pollutedClonedPlugins/original-model" );
File pluginsDir = new File( testDir, "plugins" );
File projectDir = new File( testDir, "project" );
Verifier verifier;
verifier = new Verifier( pluginsDir.getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
verifier = new Verifier( projectDir.getAbsolutePath() );
List goals = new ArrayList();
goals.add( "org.apache.maven.its.mng3710:maven-mng3710-directInvoke-plugin:1:run" );
goals.add( "validate" );
verifier.executeGoals( goals );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-directInvoke-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,33 @@
package jar;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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;
/**
* @goal run
*/
public class MyMojo
extends AbstractMojo
{
public void execute()
throws MojoExecutionException
{
getLog().info( "Direct-invoke mojo executed." );
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-originalModel-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,61 @@
package jar;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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 java.util.Map;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* @goal check
*/
public class MyMojo
extends AbstractMojo
{
/**
* @parameter default-value="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute()
throws MojoExecutionException
{
Model originalModel = project.getOriginalModel();
Build originalBuild = originalModel.getBuild();
Map originalPluginMap = originalBuild.getPluginsAsMap();
if ( originalPluginMap.containsKey( Plugin.constructKey( "org.apache.maven.its.mng3710", "maven-mng3710-directInvoke-plugin" ) ) )
{
throw new MojoExecutionException( "Project's original model has been polluted by an entry for a plugin that was invoked directly from the command line." );
}
if ( originalPluginMap.containsKey( Plugin.constructKey( "org.apache.maven.plugins", "maven-compiler-plugin" ) ) )
{
throw new MojoExecutionException( "Project's original model has been polluted by an entry for a plugin that is specified in the lifecycle mapping for this project's packaging." );
}
getLog().info( "Original-model verification completed successfully." );
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>plugins</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>maven-mng3710-directInvoke-plugin</module>
<module>maven-mng3710-originalModel-plugin</module>
</modules>
</project>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>project</artifactId>
<version>1</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-originalModel-plugin</artifactId>
<version>1</version>
<executions>
<execution>
<id>check</id>
<phase>package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-pomInheritance-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,79 @@
package jar;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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;
import java.io.FileWriter;
import java.io.IOException;
/**
* Goal which touches a timestamp file.
*
* @goal touch
*
* @phase process-sources
*/
public class MyMojo
extends AbstractMojo
{
/**
* Location of the file.
* @parameter expression="${project.build.directory}/touch.txt"
* @required
*/
private File touchFile;
public void execute()
throws MojoExecutionException
{
File dir = touchFile.getParentFile();
if ( dir != null && !dir.exists() )
{
dir.mkdirs();
}
FileWriter w = null;
try
{
w = new FileWriter( touchFile );
w.write( "touch.txt" );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error creating file " + touchFile, e );
}
finally
{
if ( w != null )
{
try
{
w.close();
}
catch ( IOException e )
{
// ignore
}
}
}
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>middle</artifactId>
<groupId>org.apache.maven.its.mng3710</groupId>
<version>1</version>
</parent>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>child</artifactId>
<version>1</version>
<packaging>pom</packaging>
</project>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>projects</artifactId>
<groupId>org.apache.maven.its.mng3710</groupId>
<version>1</version>
</parent>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>middle</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>child</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-pomInheritance-plugin</artifactId>
<executions>
<execution>
<id>touch</id>
<phase>validate</phase>
<goals>
<goal>touch</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>projects</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>middle</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.mng3710</groupId>
<artifactId>maven-mng3710-pomInheritance-plugin</artifactId>
<version>1</version>
</plugin>
</plugins>
</build>
</project>