From 3796ddabcd16a66994fab8a1129e5ab3e8ec1881 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 19 Aug 2010 22:21:52 +0000 Subject: [PATCH] o Refactored IT plugin git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@987333 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/resources/bootstrap/group-3/pom.xml | 6 ++ .../src/test/resources/mng-4450/pom.xml | 4 +- .../src/test/resources/mng-4729/pom.xml | 4 +- .../maven-it-plugin-project/pom.xml | 66 ++++++++++++++ .../maven/plugin/coreit/AbstractPomMojo.java | 86 +++++++++++++++++++ .../plugin/coreit/BuildRemotePomMojo.java} | 54 ++---------- its/core-it-support/core-it-plugins/pom.xml | 1 + 7 files changed, 169 insertions(+), 52 deletions(-) create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-project/pom.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java rename its/core-it-support/core-it-plugins/{maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java => maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java} (67%) diff --git a/its/core-it-suite/src/test/resources/bootstrap/group-3/pom.xml b/its/core-it-suite/src/test/resources/bootstrap/group-3/pom.xml index 15c48366a4..0e27527126 100644 --- a/its/core-it-suite/src/test/resources/bootstrap/group-3/pom.xml +++ b/its/core-it-suite/src/test/resources/bootstrap/group-3/pom.xml @@ -202,6 +202,12 @@ under the License. ${itPluginVersion} runtime + + org.apache.maven.its.plugins + maven-it-plugin-project + ${itPluginVersion} + runtime + org.apache.maven.its.plugins maven-it-plugin-project-interpolation diff --git a/its/core-it-suite/src/test/resources/mng-4450/pom.xml b/its/core-it-suite/src/test/resources/mng-4450/pom.xml index b4a1148d52..500679e030 100644 --- a/its/core-it-suite/src/test/resources/mng-4450/pom.xml +++ b/its/core-it-suite/src/test/resources/mng-4450/pom.xml @@ -36,14 +36,14 @@ under the License. org.apache.maven.its.plugins - maven-it-plugin-artifact + maven-it-plugin-project 2.1-SNAPSHOT test validate - build-pom + remote-pom diff --git a/its/core-it-suite/src/test/resources/mng-4729/pom.xml b/its/core-it-suite/src/test/resources/mng-4729/pom.xml index 31ec402ba9..bcc4b09215 100644 --- a/its/core-it-suite/src/test/resources/mng-4729/pom.xml +++ b/its/core-it-suite/src/test/resources/mng-4729/pom.xml @@ -37,14 +37,14 @@ under the License. org.apache.maven.its.plugins - maven-it-plugin-artifact + maven-it-plugin-project 2.1-SNAPSHOT test validate - build-pom + remote-pom diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-project/pom.xml b/its/core-it-support/core-it-plugins/maven-it-plugin-project/pom.xml new file mode 100644 index 0000000000..3ebea97662 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-project/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + + + maven-it-plugins + org.apache.maven.its.plugins + 2.1-SNAPSHOT + + + maven-it-plugin-project + maven-plugin + + Maven Integration Test Plugin :: Project + + A test plugin that can build Maven project instances from local/remote POMs. + + 2010 + + + true + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-project + 2.0 + + + org.apache.maven + maven-model + 2.0 + + + org.apache.maven + maven-artifact + 2.0 + + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java new file mode 100644 index 0000000000..558b89d7ac --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/AbstractPomMojo.java @@ -0,0 +1,86 @@ +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 org.apache.maven.project.MavenProjectBuilder; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * @author Benjamin Bentmann + */ +public abstract class AbstractPomMojo + extends AbstractMojo +{ + + /** + * The project builder. + * + * @component + */ + protected MavenProjectBuilder builder; + + protected void dump( Properties props, String key, MavenProject project ) + { + props.setProperty( key + "project.id", project.getId() ); + if ( project.getName() != null ) + { + props.setProperty( key + "project.name", project.getName() ); + } + if ( project.getDescription() != null ) + { + props.setProperty( key + "project.description", project.getDescription() ); + } + if ( project.getArtifact() != null ) + { + props.setProperty( key + "artifact.id", project.getArtifact().getId() ); + } + } + + protected void store( Properties props, File file ) + throws MojoExecutionException + { + try + { + file.getParentFile().mkdirs(); + + FileOutputStream os = new FileOutputStream( file ); + try + { + props.store( os, "[MAVEN-CORE-IT-LOG]" ); + } + finally + { + os.close(); + } + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Failed to dump POMs: " + e.getMessage(), e ); + } + } + +} diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java similarity index 67% rename from its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java rename to its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java index b19a9fd58c..926d865d3e 100644 --- a/its/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-project/src/main/java/org/apache/maven/plugin/coreit/BuildRemotePomMojo.java @@ -23,28 +23,23 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Dependency; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import java.util.List; import java.util.Properties; /** * Builds the remote POMs of user-specified artifacts. This mimics in part the Maven Remote Resources Plugin. * - * @goal build-pom + * @goal remote-pom * * @author Benjamin Bentmann * @version $Id$ */ -public class BuildPomMojo - extends AbstractMojo +public class BuildRemotePomMojo + extends AbstractPomMojo { /** @@ -72,13 +67,6 @@ public class BuildPomMojo */ private List remoteRepositories; - /** - * The artifact resolver. - * - * @component - */ - private MavenProjectBuilder builder; - /** * The artifact factory. * @@ -99,7 +87,7 @@ public class BuildPomMojo * @throws MojoFailureException If the artifact file has not been set. */ public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException { Properties props = new Properties(); @@ -122,20 +110,7 @@ public class BuildPomMojo { MavenProject project = builder.buildFromRepository( artifact, remoteRepositories, localRepository ); - String key = artifact.getId() + "."; - props.setProperty( key + "project.id", project.getId() ); - if ( project.getName() != null ) - { - props.setProperty( key + "project.name", project.getName() ); - } - if ( project.getDescription() != null ) - { - props.setProperty( key + "project.description", project.getDescription() ); - } - if ( project.getArtifact() != null ) - { - props.setProperty( key + "artifact.id", project.getArtifact().getId() ); - } + dump( props, artifact.getId() + ".", project ); } catch ( Exception e ) { @@ -144,24 +119,7 @@ public class BuildPomMojo } } - try - { - propertiesFile.getParentFile().mkdirs(); - - FileOutputStream os = new FileOutputStream( propertiesFile ); - try - { - props.store( os, "[MAVEN-CORE-IT-LOG]" ); - } - finally - { - os.close(); - } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Failed to dump POMs: " + e.getMessage(), e ); - } + store( props, propertiesFile ); } } diff --git a/its/core-it-support/core-it-plugins/pom.xml b/its/core-it-support/core-it-plugins/pom.xml index 1298ad4114..7e569d1206 100644 --- a/its/core-it-support/core-it-plugins/pom.xml +++ b/its/core-it-support/core-it-plugins/pom.xml @@ -55,6 +55,7 @@ under the License. maven-it-plugin-packaging maven-it-plugin-parameter-implementation maven-it-plugin-plugin-dependency + maven-it-plugin-project maven-it-plugin-project-interpolation maven-it-plugin-setter maven-it-plugin-singleton-component