Coverage Report - org.apache.maven.plugin.ant.AntMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AntMojo
81%
9/11
50%
1/2
4
 
 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.execution.MavenSession;
 26  
 import org.apache.maven.plugin.AbstractMojo;
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.project.MavenProject;
 29  
 import org.apache.maven.settings.Settings;
 30  
 
 31  
 import java.io.IOException;
 32  
 import java.util.List;
 33  
 import java.util.Properties;
 34  
 
 35  
 /**
 36  
  * Generate Ant build files.
 37  
  *
 38  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 39  
  * @version $Id: AntMojo.java 831567 2009-10-31 17:14:41Z bentmann $
 40  
  * @goal ant
 41  
  * @requiresDependencyResolution test
 42  
  * @todo change this to use the artifact ant tasks instead of :get
 43  
  */
 44  3
 public class AntMojo
 45  
     extends AbstractMojo
 46  
 {
 47  
     // ----------------------------------------------------------------------
 48  
     // Mojo components
 49  
     // ----------------------------------------------------------------------
 50  
 
 51  
     /**
 52  
      * Used for resolving artifacts.
 53  
      *
 54  
      * @component
 55  
      */
 56  
     private ArtifactResolver resolver;
 57  
 
 58  
     /**
 59  
      * Factory for creating artifact objects.
 60  
      *
 61  
      * @component
 62  
      */
 63  
     private ArtifactFactory factory;
 64  
 
 65  
     // ----------------------------------------------------------------------
 66  
     // Mojo parameters
 67  
     // ----------------------------------------------------------------------
 68  
 
 69  
     /**
 70  
      * The project to create a build for.
 71  
      *
 72  
      * @parameter default-value="${project}"
 73  
      * @required
 74  
      * @readonly
 75  
      */
 76  
     private MavenProject project;
 77  
 
 78  
     /**
 79  
      * The local repository where the artifacts are located.
 80  
      *
 81  
      * @parameter default-value="${localRepository}"
 82  
      * @required
 83  
      * @readonly
 84  
      */
 85  
     private ArtifactRepository localRepository;
 86  
 
 87  
     /**
 88  
      * The remote repositories where artifacts are located.
 89  
      *
 90  
      * @parameter default-value="${project.remoteArtifactRepositories}"
 91  
      * @readonly
 92  
      */
 93  
     private List remoteRepositories;
 94  
 
 95  
     /**
 96  
      * The current user system settings for use in Maven.
 97  
      *
 98  
      * @parameter default-value="${settings}"
 99  
      * @required
 100  
      * @readonly
 101  
      */
 102  
     private Settings settings;
 103  
 
 104  
     /**
 105  
      * Whether or not to overwrite the <code>build.xml</code> file.
 106  
      *
 107  
      * @parameter expression="${overwrite}" default-value="false"
 108  
      */
 109  
     private boolean overwrite;
 110  
 
 111  
     /**
 112  
      * The current Maven session.
 113  
      * 
 114  
      * @parameter default-value="${session}"
 115  
      * @readonly
 116  
      */
 117  
     private MavenSession session;
 118  
 
 119  
     /** {@inheritDoc} */
 120  
     public void execute()
 121  
         throws MojoExecutionException
 122  
     {
 123  3
         ArtifactResolverWrapper artifactResolverWrapper = ArtifactResolverWrapper.getInstance( resolver, factory,
 124  
                                                                                        localRepository,
 125  
                                                                                        remoteRepositories );
 126  
 
 127  3
         Properties executionProperties = ( session != null ) ? session.getExecutionProperties() : null;
 128  
 
 129  3
         AntBuildWriter antBuildWriter =
 130  
             new AntBuildWriter( project, artifactResolverWrapper, settings, overwrite, executionProperties );
 131  
 
 132  
         try
 133  
         {
 134  3
             antBuildWriter.writeBuildXmls();
 135  3
             antBuildWriter.writeBuildProperties();
 136  
         }
 137  0
         catch ( IOException e )
 138  
         {
 139  0
             throw new MojoExecutionException( "Error building Ant script: " + e.getMessage(), e );
 140  3
         }
 141  
 
 142  3
         getLog().info(
 143  
                        "Wrote Ant project for " + project.getArtifactId() + " to "
 144  
                            + project.getBasedir().getAbsolutePath() );
 145  3
     }
 146  
 }