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 collection 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 * @requiresDependencyCollection 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 Maven projects in the reactor. 55 * 56 * @parameter default-value="${reactorProjects}" 57 * @readonly 58 */ 59 private List reactorProjects; 60 61 /** 62 * Runs this mojo. 63 * 64 * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved. 65 */ 66 public void execute() 67 throws MojoExecutionException 68 { 69 try 70 { 71 for ( Object reactorProject : reactorProjects ) 72 { 73 MavenProject project = (MavenProject) reactorProject; 74 75 writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() ); 76 77 // NOTE: We can't make any assumptions about the class path but as a minimum it must not cause an 78 // exception 79 project.getTestClasspathElements(); 80 } 81 } 82 catch ( DependencyResolutionRequiredException e ) 83 { 84 throw new MojoExecutionException( "Failed to resolve dependencies", e ); 85 } 86 } 87 88 private String filter( String filename, MavenProject project ) 89 { 90 String result = filename; 91 92 if ( filename != null ) 93 { 94 result = result.replaceAll( "@artifactId@", project.getArtifactId() ); 95 } 96 97 return result; 98 } 99 100 }