[MNG-4615] [regression] @required plugin parameters are not validated

o Added IT

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@982993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-08-06 14:38:43 +00:00
parent 0944566b76
commit 63dacc9dff
4 changed files with 273 additions and 0 deletions

View File

@ -98,6 +98,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITmng4629NoPomValidationErrorUponMissingSystemDepTest.class ); suite.addTestSuite( MavenITmng4629NoPomValidationErrorUponMissingSystemDepTest.class );
suite.addTestSuite( MavenITmng4625SettingsXmlInterpolationWithXmlMarkupTest.class ); suite.addTestSuite( MavenITmng4625SettingsXmlInterpolationWithXmlMarkupTest.class );
suite.addTestSuite( MavenITmng4618AggregatorBuiltAfterModulesTest.class ); suite.addTestSuite( MavenITmng4618AggregatorBuiltAfterModulesTest.class );
suite.addTestSuite( MavenITmng4615ValidateRequiredPluginParameterTest.class );
suite.addTestSuite( MavenITmng4600DependencyOptionalFlagManagementTest.class ); suite.addTestSuite( MavenITmng4600DependencyOptionalFlagManagementTest.class );
suite.addTestSuite( MavenITmng4590ImportedPomUsesSystemPropertiesTest.class ); suite.addTestSuite( MavenITmng4590ImportedPomUsesSystemPropertiesTest.class );
suite.addTestSuite( MavenITmng4586PluginPrefixResolutionFromVersionlessPluginMngtTest.class ); suite.addTestSuite( MavenITmng4586PluginPrefixResolutionFromVersionlessPluginMngtTest.class );

View File

@ -0,0 +1,86 @@
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;
import java.util.Properties;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4615">MNG-4615</a>.
*
* @author Benjamin Bentmann
*/
public class MavenITmng4615ValidateRequiredPluginParameterTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng4615ValidateRequiredPluginParameterTest()
{
super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
}
/**
* Verify that Maven validates required mojo parameters (and doesn't just have the plugins die with NPEs).
*/
public void testit()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615" );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
try
{
verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog();
fail( "Build did not fail despite required plugin parameter missing" );
}
catch ( VerificationException e )
{
// expected
}
// sanity check that adding the param makes it work
verifier.setLogFileName( "log-2.txt" );
verifier.getCliOptions().add( "-Pmng4615" );
verifier.deleteDirectory( "target" );
verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog();
Properties props = verifier.loadProperties( "target/config.properties" );
assertEquals( "PROFILE", props.get( "requiredParam" ) );
verifier.setLogFileName( "log-3.txt" );
verifier.getCliOptions().remove( "-Pmng4615" );
verifier.setSystemProperty( "config.requiredParam", "CLI" );
verifier.deleteDirectory( "target" );
verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog();
props = verifier.loadProperties( "target/config.properties" );
assertEquals( "CLI", props.get( "requiredParam" ) );
verifier.resetStreams();
}
}

View File

@ -0,0 +1,73 @@
<?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.mng4615</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>Maven Integration Test :: MNG-4615</name>
<description>
Verify that Maven validates required mojo parameters (and doesn't just have the plugins die with NPEs).
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<propertiesFile>target/config.properties</propertiesFile>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>validate</phase>
<goals>
<goal>required-config</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>mng4615</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<configuration>
<requiredParam>PROFILE</requiredParam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,113 @@
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 java.io.File;
import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/**
* Dumps this mojo's configuration into a properties file.
*
* @goal required-config
* @phase validate
*
* @author Benjamin Bentmann
*/
public class RequiredConfigMojo
extends AbstractMojo
{
/**
* The current project's base directory, used for path alignment.
*
* @parameter default-value="${basedir}"
* @readonly
*/
private File basedir;
/**
* The path to the properties file into which to save the mojo configuration.
*
* @parameter expression="${config.propertiesFile}"
*/
private File propertiesFile;
/**
* A required parameter.
*
* @parameter expression="${config.requiredParam}"
* @required
*/
private String requiredParam;
/**
* A required parameter that is actually backed by default value from the POM.
*
* @parameter default-value="${project.artifactId}"
* @required
*/
private String requiredParamWithDefault;
/**
* Runs this mojo.
*
* @throws MojoExecutionException If the output file could not be created.
*/
public void execute()
throws MojoExecutionException
{
getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + propertiesFile );
if ( propertiesFile == null )
{
throw new MojoExecutionException( "Path name for output file has not been specified" );
}
if ( !propertiesFile.isAbsolute() )
{
propertiesFile = new File( basedir, propertiesFile.getPath() ).getAbsoluteFile();
}
Properties configProps = new Properties();
dumpConfiguration( configProps );
getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + propertiesFile );
PropertiesUtil.write( propertiesFile, configProps );
getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + propertiesFile );
}
/**
* Dumps the mojo configuration into the specified properties.
*
* @param props The properties to dump the configuration into, must not be <code>null</code>.
*/
private void dumpConfiguration( Properties props )
{
PropertiesUtil.serialize( props, "requiredParam", requiredParam );
PropertiesUtil.serialize( props, "requiredParamWithDefault", requiredParamWithDefault );
}
}