IT for MNG-5753: Allow plugin implementors to choose how they want the configuration created for a particular MojoExecution

This commit is contained in:
Jason van Zyl 2015-01-15 15:11:42 -05:00
parent 1694b175fe
commit 0d799949ac
7 changed files with 301 additions and 2 deletions

View File

@ -24,12 +24,12 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.codehaus.plexus.util.IOUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.codehaus.plexus.util.IOUtil;
/**
* The Core IT suite.
*/
@ -106,6 +106,7 @@ public class IntegrationTestSuite
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng5753CustomMojoExecutionConfiguratorTest.class );
suite.addTestSuite( MavenITmng5716ToolchainsTypeTest.class );
suite.addTestSuite( MavenITmng5663NestedImportScopePomResolutionTest.class );
suite.addTestSuite( MavenITmng2562Timestamp322Test.class );

View File

@ -0,0 +1,66 @@
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 java.io.File;
import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils;
public class MavenITmng5753CustomMojoExecutionConfiguratorTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng5753CustomMojoExecutionConfiguratorTest()
{
super( "[3.2.6-SNAPSHOT,)" );
}
public void testCustomMojoExecutionConfigurator()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5753-custom-mojo-execution-configurator" );
File pluginDir = new File( testDir, "plugin" );
File projectDir = new File( testDir, "project" );
Verifier verifier;
// install the test plugin
verifier = newVerifier( pluginDir.getAbsolutePath(), "remote" );
verifier.executeGoal( "install" );
verifier.resetStreams();
verifier.verifyErrorFreeLog();
// build the test project
verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
verifier.executeGoal( "validate" );
verifier.resetStreams();
verifier.verifyErrorFreeLog();
File configurationFile = new File(projectDir, "configuration.txt");
verifier.assertFilePresent( configurationFile.getCanonicalPath() );
//
// The <name/> element in the original configuration is "ORIGINAL". We want to assert that our
// custom MojoExecutionConfigurator made the transformation of the element from "ORIGINAL" to "TRANSFORMED"
//
String actual = FileUtils.fileRead( configurationFile );
assertEquals( "TRANSFORMED", actual );
}
}

View File

@ -0,0 +1,55 @@
<?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 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>mng-5753-custom-mojo-execution-configurator</groupId>
<artifactId>mng-5753-custom-mojo-execution-configurator-plugin</artifactId>
<version>0.1</version>
<packaging>maven-plugin</packaging>
<properties>
<maven-version>3.2.6-SNAPSHOT</maven-version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,68 @@
package org.apache.maven.its.mng5753.plugin;
/*
* 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 java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* @goal test
* @configurator test
*/
public class TestMojo
extends AbstractMojo
{
/** @parameter expression="${project}" */
private MavenProject project;
/** @parameter */
private String name;
public void execute()
throws MojoExecutionException
{
try
{
File file = new File( project.getBasedir(), "configuration.txt" );
file.getParentFile().mkdirs();
Writer w = new OutputStreamWriter( new FileOutputStream( file, true ), "UTF-8" );
try
{
w.write( name );
}
finally
{
w.close();
}
}
catch ( IOException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
}
}

View File

@ -0,0 +1,42 @@
package org.apache.maven.its.mng5753.plugin;
/*
* 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.lifecycle.internal.DefaultMojoExecutionConfigurator;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class TestMojoExecutionConfigurator
extends DefaultMojoExecutionConfigurator
{
@Override
public void configure( MavenProject project, MojoExecution mojoExecution, boolean allowPluginLevelConfig )
{
// We do exactly what the default mojo execution configurator does
super.configure( project, mojoExecution, allowPluginLevelConfig );
// And now we'll insert some additional configuration that we can assert was placed
// in the configuration in our test
Xpp3Dom mojoConfiguration = mojoExecution.getConfiguration();
mojoConfiguration.getChild( "name" ).setValue( "TRANSFORMED" );
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<component-set>
<components>
<component>
<role>org.codehaus.plexus.component.configurator.ComponentConfigurator</role>
<role-hint>test</role-hint>
<implementation>org.codehaus.plexus.component.configurator.BasicComponentConfigurator</implementation>
</component>
<component>
<role>org.apache.maven.lifecycle.MojoExecutionConfigurator</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.its.mng5753.plugin.TestMojoExecutionConfigurator</implementation>
</component>
</components>
</component-set>

View File

@ -0,0 +1,52 @@
<?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 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>mng-5753-custom-mojo-execution-configurator</groupId>
<artifactId>mng-5753-custom-mojo-execution-configurator-project</artifactId>
<version>0.1</version>
<build>
<plugins>
<plugin>
<groupId>mng-5753-custom-mojo-execution-configurator</groupId>
<artifactId>mng-5753-custom-mojo-execution-configurator-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
<phase>validate</phase>
<configuration>
<name>ORIGINAL</name>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>