Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PropertiesMojo |
|
| 1.5;1.5 |
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 org.apache.maven.artifact.Artifact; | |
23 | import org.apache.maven.plugin.AbstractMojo; | |
24 | import org.apache.maven.plugin.MojoExecutionException; | |
25 | import org.apache.maven.plugins.annotations.Component; | |
26 | import org.apache.maven.plugins.annotations.LifecyclePhase; | |
27 | import org.apache.maven.plugins.annotations.Mojo; | |
28 | import org.apache.maven.plugins.annotations.ResolutionScope; | |
29 | import org.apache.maven.project.MavenProject; | |
30 | ||
31 | import java.util.Set; | |
32 | ||
33 | /** | |
34 | * Goal that sets a property pointing to the artifact file for each project dependency. | |
35 | * For each dependency (direct and transitive) a project property will be set which follows the | |
36 | * <code>groupId:artifactId:type:[classifier]</code> form and contains the path to the resolved artifact. | |
37 | * | |
38 | * @author Paul Gier | |
39 | * @version $Id: PropertiesMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $ | |
40 | * @since 2.2 | |
41 | */ | |
42 | @Mojo( name = "properties", requiresDependencyResolution = ResolutionScope.TEST, | |
43 | defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true ) | |
44 | 1 | public class PropertiesMojo |
45 | extends AbstractMojo | |
46 | { | |
47 | ||
48 | /** | |
49 | * The current Maven project | |
50 | */ | |
51 | @Component | |
52 | protected MavenProject project; | |
53 | ||
54 | /** | |
55 | * Main entry into mojo. Gets the list of dependencies and iterates through setting a property for each artifact. | |
56 | * | |
57 | * @throws MojoExecutionException with a message if an error occurs. | |
58 | */ | |
59 | public void execute() | |
60 | throws MojoExecutionException | |
61 | { | |
62 | 1 | @SuppressWarnings( "unchecked" ) Set<Artifact> artifacts = getProject().getArtifacts(); |
63 | ||
64 | 1 | for ( Artifact artifact : artifacts ) |
65 | { | |
66 | 7 | project.getProperties().setProperty( artifact.getDependencyConflictId(), |
67 | artifact.getFile().getAbsolutePath() ); | |
68 | } | |
69 | 1 | } |
70 | ||
71 | public MavenProject getProject() | |
72 | { | |
73 | 3 | return project; |
74 | } | |
75 | ||
76 | } |