Author: pgier Date: Mon Dec 13 17:22:53 2010 New Revision: 1045239 URL: http://svn.apache.org/viewvc?rev=1045239&view=rev Log: [MDEP-296] Add new goal to set properties containing the file paths of dependency artifacts.
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/ maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties (with props) maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml (with props) maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh (with props) maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java (with props) maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java (with props) maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/ maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml (with props) Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt Added: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties Mon Dec 13 17:22:53 2010 @@ -0,0 +1 @@ +invoker.goals = initialize Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml Mon Dec 13 17:22:53 2010 @@ -0,0 +1,88 @@ +<?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> + + <groupId>org.apache.maven.its.dependency</groupId> + <artifactId>test</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Test</name> + <description> + Test dependency:properties + </description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>test-1</id> + <goals> + <goal>properties</goal> + </goals> + <phase>initialize</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>properties-maven-plugin</artifactId> + <version>1.0-alpha-2</version> + <executions> + <execution> + <id>test-1</id> + <goals> + <goal>write-project-properties</goal> + </goals> + <phase>initialize</phase> + <configuration> + <outputFile>${project.build.directory}/project.properties</outputFile> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.9</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.1</version> + </dependency> + </dependencies> + +</project> Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh Mon Dec 13 17:22:53 2010 @@ -0,0 +1,28 @@ +import java.io.*; + +File projectProperties = new File( basedir, "target/project.properties" ); + +Properties props = new Properties(); +props.load( new FileInputStream( projectProperties ) ); + +String junitJarPath = props.getProperty( "junit:junit:jar" ); +if ( junitJarPath == null ) +{ + throw new Exception( "junit:junit:jar is null" ); +} +if ( ! (new File( junitJarPath )).isFile() ) +{ + throw new Exception( "junit jar is not a file: " + junitJarPath ); +} + +String mavenArtifactPath = props.getProperty( "org.apache.maven:maven-artifact:jar" ); +if ( mavenArtifactPath == null ) +{ + throw new Exception( "org.apache.maven:maven-artifact:jar is null" ); +} +if ( ! (new File( mavenArtifactPath )).isFile() ) +{ + throw new Exception( "maven-artifact jar is not a file: " + mavenArtifactPath ); +} + +return true; Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/it/dependency-properties/validate.bsh ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java Mon Dec 13 17:22:53 2010 @@ -0,0 +1,77 @@ +package org.apache.maven.plugin.dependency; + +/* + * 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.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +/** + * Goal that sets a property pointing to the artifact file for each project dependency. + * For each dependency (direct and transitive) a project property will be set which follows the + * form groupId:artifactId:type:[classifier] and contains the path to the resolved artifact. + * + * @goal properties + * @requiresDependencyResolution test + * @phase initialize + * @author Paul Gier + * @version $Id$ + * @since 2.2 + */ +public class PropertiesMojo + extends AbstractMojo +{ + + /** + * The current Maven project + * + * @parameter expression="${project}" + * @readonly + */ + protected MavenProject project; + + /** + * Main entry into mojo. Gets the list of dependencies and iterates through setting a property for each artifact. + * + * @throws MojoExecutionException with a message if an error occurs. + */ + public void execute() + throws MojoExecutionException + { + Set artifacts = getProject().getArtifacts(); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + project.getProperties().setProperty( artifact.getDependencyConflictId(), + artifact.getFile().getAbsolutePath() ); + } + } + + public MavenProject getProject() + { + return project; + } + +} Propchange: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt?rev=1045239&r1=1045238&r2=1045239&view=diff ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt (original) +++ maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt Mon Dec 13 17:22:53 2010 @@ -68,6 +68,9 @@ Maven Dependency Plugin *{{{./list-mojo.html}dependency:list}} alias for resolve that lists the dependencies for this project. + *{{{./properties-mojo.html}dependency:properties}} set a property for each project dependency containing the + to the artifact on the file system. + *{{{./purge-local-repository-mojo.html}dependency:purge-local-repository}} tells Maven to clear all dependency-artifact files out of the local repository, and optionally re-resolve them. Added: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java Mon Dec 13 17:22:53 2010 @@ -0,0 +1,76 @@ +package org.apache.maven.plugin.dependency; + +/* + * 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.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; + +public class TestPropertiesMojo + extends AbstractDependencyMojoTestCase +{ + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "markers", true ); + } + + /** + * tests the proper discovery and configuration of the mojo + * + * @throws Exception + */ + public void testSetProperties() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/properties-test/plugin-config.xml" ); + PropertiesMojo mojo = (PropertiesMojo) lookupMojo( "properties", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + + // this.assertNull( project.getProperties().getProperty( "org.apacha ) ) + mojo.execute(); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + + Artifact artifact = (Artifact) i.next(); + File artifactFile = artifact.getFile(); + assertNotNull( artifact.getDependencyConflictId() ); + assertTrue( artifactFile.isFile() ); + + } + + } + +} \ No newline at end of file Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestPropertiesMojo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml?rev=1045239&view=auto ============================================================================== --- maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml (added) +++ maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml Mon Dec 13 17:22:53 2010 @@ -0,0 +1,43 @@ +<!-- + * 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> + <build> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.9</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.1</version> + </dependency> + </dependencies> +</project> \ No newline at end of file Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml ------------------------------------------------------------------------------ svn:executable = * Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/properties-test/plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision