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.DependencyResolutionRequiredException;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.project.MavenProject;
25
26 import java.util.List;
27
28 /**
29 * Combines dependency resolution with aggregation. The path parameters of this mojo support the token
30 * <code>@artifactId@</code> to dynamically adjust the output file for each project in the reactor whose
31 * dependencies are dumped.
32 *
33 * @author Benjamin Bentmann
34 *
35 * @goal aggregate-test
36 * @requiresDependencyResolution test
37 * @aggregator true
38 */
39 public class AggregateTestMojo
40 extends AbstractDependencyMojo
41 {
42
43 /**
44 * The path to the output file for the project artifacts, relative to the project base directory. Each line of this
45 * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
46 * disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
47 * do not contribute to the class path.
48 *
49 * @parameter property="depres.projectArtifacts"
50 */
51 private String projectArtifacts;
52
53 /**
54 * The path to the output file for the test class path, relative to the project base directory. Each line of
55 * this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
56 * will not be written to disk.
57 *
58 * @parameter property="depres.testClassPath"
59 */
60 private String testClassPath;
61
62 /**
63 * The path to the properties file for the checksums of the test class path elements, relative to the project base
64 * directory. The (trimmed) path to a JAR is used as the property key, the property value is the SHA-1 hash of the
65 * JAR. If not specified, the class path checksums will not be calculated.
66 *
67 * @parameter property="depres.testClassPathChecksums"
68 */
69 private String testClassPathChecksums;
70
71 /**
72 * The Maven projects in the reactor.
73 *
74 * @parameter default-value="${reactorProjects}"
75 * @readonly
76 */
77 private List reactorProjects;
78
79 /**
80 * Runs this mojo.
81 *
82 * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
83 */
84 public void execute()
85 throws MojoExecutionException
86 {
87 try
88 {
89 for ( Object reactorProject : reactorProjects )
90 {
91 MavenProject project = (MavenProject) reactorProject;
92
93 writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() );
94 writeClassPath( filter( testClassPath, project ), project.getTestClasspathElements() );
95 writeClassPathChecksums( filter( testClassPathChecksums, project ),
96 project.getTestClasspathElements() );
97 }
98 }
99 catch ( DependencyResolutionRequiredException e )
100 {
101 throw new MojoExecutionException( "Failed to resolve dependencies", e );
102 }
103 }
104
105 private String filter( String filename, MavenProject project )
106 {
107 String result = filename;
108
109 if ( filename != null )
110 {
111 result = result.replaceAll( "@artifactId@", project.getArtifactId() );
112 }
113
114 return result;
115 }
116
117 }