Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CompileMojo |
|
| 7.0;7 |
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.plugin.AbstractMojo; | |
23 | import org.apache.maven.plugin.MojoExecutionException; | |
24 | import org.apache.maven.plugin.MojoFailureException; | |
25 | import org.apache.maven.project.MavenProject; | |
26 | ||
27 | import java.io.File; | |
28 | import java.io.IOException; | |
29 | ||
30 | /** | |
31 | * Creates a text file in the project base directory. | |
32 | * | |
33 | * @goal compile | |
34 | * @phase compile | |
35 | * | |
36 | * @author Benjamin Bentmann | |
37 | * @version $Id: CompileMojo.java 697428 2008-09-20 22:40:52Z bentmann $ | |
38 | */ | |
39 | 0 | public class CompileMojo |
40 | extends AbstractMojo | |
41 | { | |
42 | ||
43 | /** | |
44 | * The current Maven project. | |
45 | * | |
46 | * @parameter default-value="${project}" | |
47 | * @required | |
48 | * @readonly | |
49 | */ | |
50 | private MavenProject project; | |
51 | ||
52 | /** | |
53 | * The path to the output file, relative to the project base directory directory. | |
54 | * | |
55 | * @parameter | |
56 | */ | |
57 | 0 | private String pathname = "target/compiler-compile.txt"; |
58 | ||
59 | /** | |
60 | * Runs this mojo. | |
61 | * | |
62 | * @throws MojoExecutionException If the output file could not be created. | |
63 | * @throws MojoFailureException If the output file has not been set. | |
64 | */ | |
65 | public void execute() | |
66 | throws MojoExecutionException, MojoFailureException | |
67 | { | |
68 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + pathname ); |
69 | ||
70 | 0 | if ( pathname == null || pathname.length() <= 0 ) |
71 | { | |
72 | 0 | throw new MojoFailureException( "Path name for output file has not been specified" ); |
73 | } | |
74 | ||
75 | 0 | File outputFile = new File( pathname ); |
76 | 0 | if ( !outputFile.isAbsolute() ) |
77 | { | |
78 | 0 | outputFile = new File( project.getBasedir(), pathname ).getAbsoluteFile(); |
79 | } | |
80 | ||
81 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile ); |
82 | ||
83 | try | |
84 | { | |
85 | 0 | outputFile.getParentFile().mkdirs(); |
86 | 0 | outputFile.createNewFile(); |
87 | } | |
88 | 0 | catch ( IOException e ) |
89 | { | |
90 | 0 | throw new MojoExecutionException( "Output file could not be created: " + pathname, e ); |
91 | 0 | } |
92 | ||
93 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + outputFile ); |
94 | 0 | } |
95 | ||
96 | } |