[MNG-4167] Adding integration test for plugins that produce derivatives of the POM in cases where the POM contains expressions in artifact-coordinate elements.

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@776755 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2009-05-20 16:26:49 +00:00
parent 8cfd30e543
commit 4e150340e0
3 changed files with 191 additions and 0 deletions

View File

@ -0,0 +1,81 @@
/*
* 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.it;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4167">MNG-4167</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 MavenITmng4167PluginAndCoordXFormPOMTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng4167PluginAndCoordXFormPOMTest()
throws InvalidVersionSpecificationException
{
super( "(2.1.0,)" ); // only test in 2.0.9+
}
public void testIt ()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4167" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
verifier.deleteArtifact( "org.apache.maven.its.mng4167", "mng-4167", "1", "pom" );
String specVersion = System.getProperty( "java.specification.version" );
verifier.deleteArtifact( "org.apache.maven.its.mng4167", "mng-4167", "1-" + specVersion, "pom" );
verifier.setCliOptions( Collections.singletonList( "-X" ) );
verifier.executeGoal( "install" );
List originalPomLines = verifier.loadFile( new File( testDir, "pom.xml" ), false );
List derivedPomLines = verifier.loadFile( new File( testDir, "target/pom-copy.xml" ), false );
assertFalse( derivedPomLines.equals( originalPomLines ) );
File repoPomPath = new File( verifier.getArtifactPath( "org.apache.maven.its.mng4167", "mng-4167", "1-" + specVersion, "pom" ) );
List repoPomLines = verifier.loadFile( repoPomPath, false );
assertEquals( repoPomLines, derivedPomLines );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
}

View File

@ -0,0 +1,25 @@
<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.mng4167</groupId>
<artifactId>mng-4167</artifactId>
<packaging>pom</packaging>
<version>1-${java.specification.version}</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>copy-pom</id>
<goals>
<goal>copy-pom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,85 @@
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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @goal copy-pom
*
* @phase generate-sources
*
* @description Mojo which makes a copy of the POM using MavenProject.getFile() to locate the file.
*/
public class CopyPomMojo
extends AbstractMojo
{
/**
* @parameter default-value="${project.file}"
*/
private File pomFile;
/**
* @parameter default-value="${project.build.directory}/pom-copy.xml"
* @required
*/
private String outputFile;
public void execute()
throws MojoExecutionException
{
try
{
File dest = new File( outputFile );
File dir = dest.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
getLog().info( "Copying POM to file: " + dest.getAbsolutePath() );
FileInputStream in = new FileInputStream( pomFile );
FileOutputStream out = new FileOutputStream( dest );
int read = -1;
byte[] buf = new byte[4096];
while( ( read = in.read( buf ) ) > -1 )
{
out.write( buf, 0, read );
}
in.close();
out.close();
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error copying POM", e );
}
}
}