1 package org.apache.maven.plugin.dependency; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.Set; 23 24 import org.apache.maven.artifact.Artifact; 25 import org.apache.maven.plugin.AbstractMojo; 26 import org.apache.maven.plugin.MojoExecutionException; 27 import org.apache.maven.project.MavenProject; 28 29 /** 30 * Goal that sets a property pointing to the artifact file for each project dependency. 31 * For each dependency (direct and transitive) a project property will be set which follows the 32 * form groupId:artifactId:type:[classifier] and contains the path to the resolved artifact. 33 * 34 * @goal properties 35 * @requiresDependencyResolution test 36 * @phase initialize 37 * @author Paul Gier 38 * @version $Id: PropertiesMojo.java 1081021 2011-03-13 00:17:39Z hboutemy $ 39 * @since 2.2 40 */ 41 public class PropertiesMojo 42 extends AbstractMojo 43 { 44 45 /** 46 * The current Maven project 47 * 48 * @parameter expression="${project}" 49 * @readonly 50 */ 51 protected MavenProject project; 52 53 /** 54 * Main entry into mojo. Gets the list of dependencies and iterates through setting a property for each artifact. 55 * 56 * @throws MojoExecutionException with a message if an error occurs. 57 */ 58 public void execute() 59 throws MojoExecutionException 60 { 61 Set<Artifact> artifacts = getProject().getArtifacts(); 62 63 for ( Artifact artifact : artifacts ) 64 { 65 project.getProperties().setProperty( artifact.getDependencyConflictId(), 66 artifact.getFile().getAbsolutePath() ); 67 } 68 } 69 70 public MavenProject getProject() 71 { 72 return project; 73 } 74 75 }