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.repository.ArtifactRepository; 23 import org.apache.maven.plugin.MojoExecutionException; 24 import org.apache.maven.project.MavenProject; 25 26 import java.io.File; 27 import java.util.Properties; 28 29 /** 30 * Builds the local POMs. 31 * 32 * @author Benjamin Bentmann 33 * @goal local-pom 34 */ 35 public class BuildLocalPomMojo 36 extends AbstractPomMojo 37 { 38 39 /** 40 * The properties file to dump the POM info to. 41 * 42 * @parameter default-value="target/pom.properties" 43 */ 44 private File propertiesFile; 45 46 /** 47 * The local repository. 48 * 49 * @parameter default-value="${localRepository}" 50 * @readonly 51 * @required 52 */ 53 private ArtifactRepository localRepository; 54 55 /** 56 * The POM files to build. 57 * 58 * @parameter 59 */ 60 private File[] files; 61 62 /** 63 * Runs this mojo. 64 * 65 * @throws MojoExecutionException If the artifact file has not been set. 66 */ 67 public void execute() 68 throws MojoExecutionException 69 { 70 Properties props = new Properties(); 71 72 getLog().info( "[MAVEN-CORE-IT-LOG] Building local POMs" ); 73 74 if ( files != null ) 75 { 76 for ( File file : files ) 77 { 78 getLog().info( "[MAVEN-CORE-IT-LOG] Building " + file ); 79 80 try 81 { 82 MavenProject project = builder.build( file, localRepository, null ); 83 84 dump( props, file.getName() + ".", project ); 85 } 86 catch ( Exception e ) 87 { 88 getLog().warn( "Failed to build local POM for " + file, e ); 89 } 90 } 91 } 92 93 store( props, propertiesFile ); 94 } 95 96 }