1 package org.apache.maven.plugin.ant; 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.factory.ArtifactFactory; 23 import org.apache.maven.artifact.repository.ArtifactRepository; 24 import org.apache.maven.artifact.resolver.ArtifactResolver; 25 import org.apache.maven.plugin.AbstractMojo; 26 import org.apache.maven.plugin.MojoExecutionException; 27 import org.apache.maven.project.MavenProject; 28 import org.apache.maven.settings.Settings; 29 30 import java.io.IOException; 31 import java.util.List; 32 33 /** 34 * Generate Ant build files. 35 * 36 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 37 * @version $Id: AntMojo.java 639646 2008-03-21 13:58:11Z bentmann $ 38 * @goal ant 39 * @requiresDependencyResolution test 40 * @todo change this to use the artifact ant tasks instead of :get 41 */ 42 public class AntMojo 43 extends AbstractMojo 44 { 45 /** 46 * The project to create a build for. 47 * 48 * @parameter expression="${project}" 49 * @required 50 */ 51 private MavenProject project; 52 53 /** 54 * Used for resolving artifacts. 55 * 56 * @component 57 */ 58 private ArtifactResolver resolver; 59 60 /** 61 * Factory for creating artifact objects. 62 * 63 * @component 64 */ 65 private ArtifactFactory factory; 66 67 /** 68 * The local repository where the artifacts are located. 69 * 70 * @parameter expression="${localRepository}" 71 * @required 72 */ 73 private ArtifactRepository localRepository; 74 75 /** 76 * The remote repositories where artifacts are located. 77 * 78 * @parameter expression="${project.remoteArtifactRepositories}" 79 */ 80 private List remoteRepositories; 81 82 /** 83 * The current user system settings for use in Maven. 84 * 85 * @parameter expression="${settings}" 86 * @required 87 * @readonly 88 */ 89 private Settings settings; 90 91 /** 92 * Whether or not to overwrite the <code>build.xml</code> file. 93 * 94 * @parameter expression="${overwrite}" default-value="false" 95 */ 96 private boolean overwrite; 97 98 /** 99 * @see org.apache.maven.plugin.Mojo#execute() 100 */ 101 public void execute() 102 throws MojoExecutionException 103 { 104 ArtifactResolverWrapper artifactResolverWrapper = ArtifactResolverWrapper.getInstance( resolver, factory, 105 localRepository, 106 remoteRepositories ); 107 108 AntBuildWriter antBuildWriter = new AntBuildWriter( project, artifactResolverWrapper, settings, overwrite ); 109 110 try 111 { 112 antBuildWriter.writeBuildXmls(); 113 antBuildWriter.writeBuildProperties(); 114 } 115 catch ( IOException e ) 116 { 117 throw new MojoExecutionException( "Error building Ant script: " + e.getMessage(), e ); 118 } 119 120 getLog().info( 121 "Wrote Ant project for " + project.getArtifactId() + " to " 122 + project.getBasedir().getAbsolutePath() ); 123 } 124 }