mirror of https://github.com/apache/maven.git
[MNG-5011] Allow to configure array/collection type plugin parameters via system properties
o Added IT git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@1070118 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d99165125d
commit
88c23aff61
|
@ -83,6 +83,7 @@ public class IntegrationTestSuite
|
|||
// -------------------------------------------------------------------------------------------------------------
|
||||
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
|
||||
|
||||
suite.addTestSuite( MavenITmng5011ConfigureCollectionArrayFromSystemPropTest.class );
|
||||
suite.addTestSuite( MavenITmng5009AggregationCycleTest.class );
|
||||
suite.addTestSuite( MavenITmng4992MapStylePropertiesParamConfigTest.class );
|
||||
suite.addTestSuite( MavenITmng4975ProfileInjectedPluginExecutionOrderTest.class );
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
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-5011">MNG-5011</a>.
|
||||
*/
|
||||
public class MavenITmng5011ConfigureCollectionArrayFromSystemPropTest
|
||||
extends AbstractMavenIntegrationTestCase
|
||||
{
|
||||
|
||||
public MavenITmng5011ConfigureCollectionArrayFromSystemPropTest()
|
||||
{
|
||||
super( "[3.0.3,)" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that plugin parameters of type array/collection can be configured using system properties from the CLI.
|
||||
*/
|
||||
public void testit()
|
||||
throws Exception
|
||||
{
|
||||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5011" );
|
||||
|
||||
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
|
||||
verifier.setAutoclean( false );
|
||||
verifier.deleteDirectory( "target" );
|
||||
verifier.setSystemProperty( "config.stringParams", "" );
|
||||
verifier.setSystemProperty( "config.fileParams", "foo,bar" );
|
||||
verifier.setSystemProperty( "config.listParam", ",two,,four," );
|
||||
verifier.executeGoal( "validate" );
|
||||
verifier.verifyErrorFreeLog();
|
||||
verifier.resetStreams();
|
||||
|
||||
Properties props = verifier.loadProperties( "target/config.properties" );
|
||||
|
||||
assertEquals( "0", props.getProperty( "stringParams" ) );
|
||||
|
||||
assertEquals( "2", props.getProperty( "fileParams" ) );
|
||||
assertEquals( new File( testDir, "foo" ), new File( props.getProperty( "fileParams.0" ) ) );
|
||||
assertEquals( new File( testDir, "bar" ), new File( props.getProperty( "fileParams.1" ) ) );
|
||||
|
||||
assertEquals( "5", props.getProperty( "listParam" ) );
|
||||
assertEquals( "", props.getProperty( "listParam.0", "" ) );
|
||||
assertEquals( "two", props.getProperty( "listParam.1", "" ) );
|
||||
assertEquals( "", props.getProperty( "listParam.2", "" ) );
|
||||
assertEquals( "four", props.getProperty( "listParam.3", "" ) );
|
||||
assertEquals( "", props.getProperty( "listParam.4", "" ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -50,7 +50,7 @@ under the License.
|
|||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>custom-config</goal>
|
||||
<goal>config</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?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.mng5011</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<name>Maven Integration Test :: MNG-5011</name>
|
||||
<description>
|
||||
Verify that plugin parameters of type array/collection can be configured using system properties from the CLI.
|
||||
</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>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>cli-config</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,152 @@
|
|||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
/**
|
||||
* Dumps this mojo's configuration into a properties file.
|
||||
*
|
||||
* @goal cli-config
|
||||
* @phase validate
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CliConfigMojo
|
||||
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 simple parameter of type {@link java.lang.String}.
|
||||
*
|
||||
* @parameter expression="${config.stringParam}"
|
||||
*/
|
||||
private String stringParam;
|
||||
|
||||
/**
|
||||
* A simple parameter of type {@link java.io.File}.
|
||||
*
|
||||
* @parameter expression="${config.fileParam}"
|
||||
*/
|
||||
private File fileParam;
|
||||
|
||||
/**
|
||||
* An array parameter of component type {@link java.lang.String}.
|
||||
*
|
||||
* @parameter expression="${config.stringParams}"
|
||||
*/
|
||||
private String[] stringParams;
|
||||
|
||||
/**
|
||||
* An array parameter of component type {@link java.io.File}.
|
||||
*
|
||||
* @parameter expression="${config.fileParams}"
|
||||
*/
|
||||
private File[] fileParams;
|
||||
|
||||
/**
|
||||
* A collection parameter of type {@link java.util.List}.
|
||||
*
|
||||
* @parameter expression="${config.listParam}"
|
||||
*/
|
||||
private List listParam;
|
||||
|
||||
/**
|
||||
* A collection parameter of type {@link java.util.Set}.
|
||||
*
|
||||
* @parameter expression="${config.setParam}"
|
||||
*/
|
||||
private Set setParam;
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
/*
|
||||
* NOTE: This intentionally does not dump the absolute path of a file to check the actual value that was
|
||||
* injected by Maven.
|
||||
*/
|
||||
PropertiesUtil.serialize( props, "propertiesFile", propertiesFile );
|
||||
PropertiesUtil.serialize( props, "stringParam", stringParam );
|
||||
PropertiesUtil.serialize( props, "fileParam", fileParam );
|
||||
PropertiesUtil.serialize( props, "stringParams", stringParams );
|
||||
PropertiesUtil.serialize( props, "fileParams", fileParams );
|
||||
PropertiesUtil.serialize( props, "listParam", listParam );
|
||||
PropertiesUtil.serialize( props, "setParam", setParam );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue