Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CopyPomMojo |
|
| 5.0;5 |
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.project.MavenProject; | |
25 | ||
26 | import java.io.File; | |
27 | import java.io.FileInputStream; | |
28 | import java.io.FileOutputStream; | |
29 | import java.io.IOException; | |
30 | ||
31 | /** | |
32 | * @goal copy-pom | |
33 | * | |
34 | * @phase generate-sources | |
35 | * | |
36 | * @description Mojo which makes a copy of the POM using MavenProject.getFile() to locate the file. | |
37 | */ | |
38 | 0 | public class CopyPomMojo |
39 | extends AbstractMojo | |
40 | { | |
41 | /** | |
42 | * @parameter default-value="${project.file}" | |
43 | */ | |
44 | private File pomFile; | |
45 | ||
46 | /** | |
47 | * @parameter default-value="${project.build.directory}/pom-copy.xml" | |
48 | * @required | |
49 | */ | |
50 | private String outputFile; | |
51 | ||
52 | public void execute() | |
53 | throws MojoExecutionException | |
54 | { | |
55 | try | |
56 | { | |
57 | 0 | File dest = new File( outputFile ); |
58 | 0 | File dir = dest.getParentFile(); |
59 | ||
60 | 0 | if ( !dir.exists() ) |
61 | { | |
62 | 0 | dir.mkdirs(); |
63 | } | |
64 | ||
65 | 0 | getLog().info( "Copying POM to file: " + dest.getAbsolutePath() ); |
66 | ||
67 | 0 | FileInputStream in = new FileInputStream( pomFile ); |
68 | 0 | FileOutputStream out = new FileOutputStream( dest ); |
69 | ||
70 | 0 | int read = -1; |
71 | 0 | byte[] buf = new byte[4096]; |
72 | 0 | while( ( read = in.read( buf ) ) > -1 ) |
73 | { | |
74 | 0 | out.write( buf, 0, read ); |
75 | } | |
76 | ||
77 | 0 | in.close(); |
78 | 0 | out.close(); |
79 | } | |
80 | 0 | catch ( IOException e ) |
81 | { | |
82 | 0 | throw new MojoExecutionException( "Error copying POM", e ); |
83 | 0 | } |
84 | 0 | } |
85 | } |