mirror of https://github.com/apache/maven.git
[MNG-3714] add integration test for a command line option for toolchains
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@745944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20e8cc6236
commit
ac63225d5c
|
@ -0,0 +1,79 @@
|
|||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3714">MNG-3714</a>.
|
||||
*
|
||||
* @author Brett Porter
|
||||
* @version $Id: MavenITmng0557UserSettingsCliOptionTest.java 744504 2009-02-14 14:49:27Z brett $
|
||||
*/
|
||||
public class MavenITmng3714ToolchainsCliOptionTest
|
||||
extends AbstractMavenIntegrationTestCase
|
||||
{
|
||||
public MavenITmng3714ToolchainsCliOptionTest()
|
||||
{
|
||||
super( "[2.1.0,)" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test --toolchains CLI option
|
||||
*/
|
||||
public void testitMNG3714()
|
||||
throws Exception
|
||||
{
|
||||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3714" );
|
||||
File javaHome = new File( testDir, "javaHome" );
|
||||
javaHome.mkdirs();
|
||||
|
||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||
Properties properties = verifier.newDefaultFilterProperties();
|
||||
properties.setProperty( "@javaHome@", javaHome.getAbsolutePath() );
|
||||
|
||||
verifier.filterFile( "toolchains.xml", "toolchains.xml", "UTF-8", properties );
|
||||
|
||||
verifier.setAutoclean( false );
|
||||
verifier.deleteDirectory( "target" );
|
||||
List cliOptions = new ArrayList();
|
||||
cliOptions.add( "--toolchains toolchains.xml" );
|
||||
verifier.setCliOptions( cliOptions );
|
||||
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-toolchain:toolchain" );
|
||||
verifier.verifyErrorFreeLog();
|
||||
verifier.resetStreams();
|
||||
|
||||
verifier.assertFilePresent( "target/toolchains.properties" );
|
||||
Properties results = verifier.loadProperties( "target/toolchains.properties" );
|
||||
String tool = results.getProperty( "tool.1" );
|
||||
if ( tool.endsWith( ".exe" ) )
|
||||
{
|
||||
tool = tool.substring( 0, tool.length() - 4 );
|
||||
}
|
||||
assertEquals( new File( javaHome, "bin/javac" ).getAbsolutePath(), tool );
|
||||
}
|
||||
|
||||
}
|
|
@ -230,6 +230,12 @@ under the License.
|
|||
<version>${itPluginVersion}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-toolchain</artifactId>
|
||||
<version>${itPluginVersion}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-uses-properties</artifactId>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>Maven Integration Test :: MNG-3714</name>
|
||||
<groupId>org.apache.maven.its.mng3714</groupId>
|
||||
<artifactId>maven-it-mng3714</artifactId>
|
||||
<description>Test --toolchains CLI option</description>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-toolchain</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF8"?>
|
||||
|
||||
<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.5</version>
|
||||
<vendor>sun</vendor>
|
||||
<id>default</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>@javaHome@</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?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>
|
||||
|
||||
<parent>
|
||||
<artifactId>maven-it-plugins</artifactId>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-it-plugin-toolchain</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Maven Integration Test Plugin :: Toolchain</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-toolchain</artifactId>
|
||||
<version>2.0.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,111 @@
|
|||
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.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.toolchain.MisconfiguredToolchainException;
|
||||
import org.apache.maven.toolchain.ToolchainManagerPrivate;
|
||||
import org.apache.maven.toolchain.ToolchainPrivate;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
/**
|
||||
* @goal toolchain
|
||||
* @phase validate
|
||||
*/
|
||||
public class CoreItMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
/**
|
||||
* @component
|
||||
*/
|
||||
private ToolchainManagerPrivate toolchainManager;
|
||||
|
||||
/**
|
||||
* The path to the output file for the properties.
|
||||
*
|
||||
* @parameter expression="${toolchain.outputFile}" default-value="${project.build.directory}/toolchains.properties"
|
||||
*/
|
||||
private File outputFile;
|
||||
|
||||
/**
|
||||
* @parameter default-value="jdk"
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* @parameter default-value="javac"
|
||||
*/
|
||||
private String tool;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
ToolchainPrivate[] tcs;
|
||||
try
|
||||
{
|
||||
tcs = toolchainManager.getToolchainsForType( type );
|
||||
}
|
||||
catch ( MisconfiguredToolchainException e )
|
||||
{
|
||||
throw new MojoExecutionException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
getLog().info( "Toolchain in compiler-plugin: " + Arrays.asList( tcs ) );
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
int count = 1;
|
||||
for ( Iterator i = Arrays.asList( tcs ).iterator(); i.hasNext(); count++ )
|
||||
{
|
||||
ToolchainPrivate toolchain = (ToolchainPrivate) i.next();
|
||||
|
||||
String foundTool = toolchain.findTool( tool );
|
||||
if ( foundTool != null )
|
||||
{
|
||||
properties.setProperty( "tool." + count, foundTool );
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream out = null;
|
||||
try
|
||||
{
|
||||
outputFile.getParentFile().mkdirs();
|
||||
out = new FileOutputStream( outputFile );
|
||||
properties.store( out, "MAVEN-CORE-IT-LOG" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( e.getMessage(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( out );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ under the License.
|
|||
<module>maven-it-plugin-project-interpolation</module>
|
||||
<module>maven-it-plugin-setter</module>
|
||||
<module>maven-it-plugin-site</module>
|
||||
<module>maven-it-plugin-toolchain</module>
|
||||
<module>maven-it-plugin-touch</module>
|
||||
<module>maven-it-plugin-uses-properties</module>
|
||||
<module>maven-it-plugin-uses-wagon</module>
|
||||
|
|
Loading…
Reference in New Issue