Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BuildRemotePomMojo |
|
| 4.0;4 |
1 | package org.apache.maven.plugin.coreit; | |
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.artifact.factory.ArtifactFactory; | |
24 | import org.apache.maven.artifact.repository.ArtifactRepository; | |
25 | import org.apache.maven.model.Dependency; | |
26 | import org.apache.maven.plugin.MojoExecutionException; | |
27 | import org.apache.maven.project.MavenProject; | |
28 | ||
29 | import java.io.File; | |
30 | import java.util.List; | |
31 | import java.util.Properties; | |
32 | ||
33 | /** | |
34 | * Builds the remote POMs of user-specified artifacts. This mimics in part the Maven Remote Resources Plugin. | |
35 | * | |
36 | * @goal remote-pom | |
37 | * | |
38 | * @author Benjamin Bentmann | |
39 | * @version $Id: BuildRemotePomMojo.java 992078 2010-09-02 19:46:09Z bentmann $ | |
40 | */ | |
41 | 0 | public class BuildRemotePomMojo |
42 | extends AbstractPomMojo | |
43 | { | |
44 | ||
45 | /** | |
46 | * The properties file to dump the POM info to. | |
47 | * | |
48 | * @parameter default-value="target/pom.properties" | |
49 | */ | |
50 | private File propertiesFile; | |
51 | ||
52 | /** | |
53 | * The local repository. | |
54 | * | |
55 | * @parameter default-value="${localRepository}" | |
56 | * @readonly | |
57 | * @required | |
58 | */ | |
59 | private ArtifactRepository localRepository; | |
60 | ||
61 | /** | |
62 | * The remote repositories of the current Maven project. | |
63 | * | |
64 | * @parameter default-value="${project.remoteArtifactRepositories}" | |
65 | * @readonly | |
66 | * @required | |
67 | */ | |
68 | private List remoteRepositories; | |
69 | ||
70 | /** | |
71 | * The artifact factory. | |
72 | * | |
73 | * @component | |
74 | */ | |
75 | private ArtifactFactory factory; | |
76 | ||
77 | /** | |
78 | * The dependencies to resolve. | |
79 | * | |
80 | * @parameter | |
81 | */ | |
82 | private Dependency[] dependencies; | |
83 | ||
84 | /** | |
85 | * Runs this mojo. | |
86 | * | |
87 | * @throws MojoFailureException If the artifact file has not been set. | |
88 | */ | |
89 | public void execute() | |
90 | throws MojoExecutionException | |
91 | { | |
92 | 0 | Properties props = new Properties(); |
93 | ||
94 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Building remote POMs" ); |
95 | ||
96 | 0 | if ( dependencies != null ) |
97 | { | |
98 | 0 | for ( int i = 0; i < dependencies.length; i++ ) |
99 | { | |
100 | 0 | Dependency dependency = dependencies[i]; |
101 | ||
102 | 0 | Artifact artifact = |
103 | factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), | |
104 | dependency.getVersion(), dependency.getType(), | |
105 | dependency.getClassifier() ); | |
106 | ||
107 | 0 | String id = artifact.getId(); |
108 | ||
109 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Building " + id ); |
110 | ||
111 | try | |
112 | { | |
113 | 0 | MavenProject project = builder.buildFromRepository( artifact, remoteRepositories, localRepository ); |
114 | ||
115 | 0 | dump( props, id + ".", project ); |
116 | } | |
117 | 0 | catch ( Exception e ) |
118 | { | |
119 | 0 | getLog().warn( "Failed to build remote POM for " + artifact.getId(), e ); |
120 | 0 | } |
121 | ||
122 | 0 | put( props, id + ".file", artifact.getFile() ); |
123 | 0 | put( props, id + ".version", artifact.getVersion() ); |
124 | } | |
125 | } | |
126 | ||
127 | 0 | store( props, propertiesFile ); |
128 | 0 | } |
129 | ||
130 | } |