Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AntMojo |
|
| 3.0;3 |
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 764402 2009-04-13 10:55:53Z vsiveton $ | |
38 | * @goal ant | |
39 | * @requiresDependencyResolution test | |
40 | * @todo change this to use the artifact ant tasks instead of :get | |
41 | */ | |
42 | 27 | public class AntMojo |
43 | extends AbstractMojo | |
44 | { | |
45 | // ---------------------------------------------------------------------- | |
46 | // Mojo components | |
47 | // ---------------------------------------------------------------------- | |
48 | ||
49 | /** | |
50 | * Used for resolving artifacts. | |
51 | * | |
52 | * @component | |
53 | */ | |
54 | private ArtifactResolver resolver; | |
55 | ||
56 | /** | |
57 | * Factory for creating artifact objects. | |
58 | * | |
59 | * @component | |
60 | */ | |
61 | private ArtifactFactory factory; | |
62 | ||
63 | // ---------------------------------------------------------------------- | |
64 | // Mojo parameters | |
65 | // ---------------------------------------------------------------------- | |
66 | ||
67 | /** | |
68 | * The project to create a build for. | |
69 | * | |
70 | * @parameter default-value="${project}" | |
71 | * @required | |
72 | * @readonly | |
73 | */ | |
74 | private MavenProject project; | |
75 | ||
76 | /** | |
77 | * The local repository where the artifacts are located. | |
78 | * | |
79 | * @parameter default-value="${localRepository}" | |
80 | * @required | |
81 | * @readonly | |
82 | */ | |
83 | private ArtifactRepository localRepository; | |
84 | ||
85 | /** | |
86 | * The remote repositories where artifacts are located. | |
87 | * | |
88 | * @parameter default-value="${project.remoteArtifactRepositories}" | |
89 | * @readonly | |
90 | */ | |
91 | private List remoteRepositories; | |
92 | ||
93 | /** | |
94 | * The current user system settings for use in Maven. | |
95 | * | |
96 | * @parameter default-value="${settings}" | |
97 | * @required | |
98 | * @readonly | |
99 | */ | |
100 | private Settings settings; | |
101 | ||
102 | /** | |
103 | * Whether or not to overwrite the <code>build.xml</code> file. | |
104 | * | |
105 | * @parameter expression="${overwrite}" default-value="false" | |
106 | */ | |
107 | private boolean overwrite; | |
108 | ||
109 | /** {@inheritDoc} */ | |
110 | public void execute() | |
111 | throws MojoExecutionException | |
112 | { | |
113 | 27 | ArtifactResolverWrapper artifactResolverWrapper = ArtifactResolverWrapper.getInstance( resolver, factory, |
114 | localRepository, | |
115 | remoteRepositories ); | |
116 | ||
117 | 27 | AntBuildWriter antBuildWriter = new AntBuildWriter( project, artifactResolverWrapper, settings, overwrite ); |
118 | ||
119 | try | |
120 | { | |
121 | 27 | antBuildWriter.writeBuildXmls(); |
122 | 27 | antBuildWriter.writeBuildProperties(); |
123 | } | |
124 | 0 | catch ( IOException e ) |
125 | { | |
126 | 0 | throw new MojoExecutionException( "Error building Ant script: " + e.getMessage(), e ); |
127 | 27 | } |
128 | ||
129 | 27 | getLog().info( |
130 | "Wrote Ant project for " + project.getArtifactId() + " to " | |
131 | + project.getBasedir().getAbsolutePath() ); | |
132 | 27 | } |
133 | } |