1 package org.apache.maven.plugin.coreit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29
30
31
32
33
34
35
36 public class CopyPomMojo
37 extends AbstractMojo
38 {
39
40
41
42 private File pomFile;
43
44
45
46
47
48 private String outputFile;
49
50 public void execute()
51 throws MojoExecutionException
52 {
53 try
54 {
55 File dest = new File( outputFile );
56 File dir = dest.getParentFile();
57
58 if ( !dir.exists() )
59 {
60 dir.mkdirs();
61 }
62
63 getLog().info( "Copying POM to file: " + dest.getAbsolutePath() );
64
65 FileInputStream in = new FileInputStream( pomFile );
66 FileOutputStream out = new FileOutputStream( dest );
67
68 int read = -1;
69 byte[] buf = new byte[4 * 1024];
70 while ( ( read = in.read( buf ) ) > -1 )
71 {
72 out.write( buf, 0, read );
73 }
74
75 in.close();
76 out.close();
77 }
78 catch ( IOException e )
79 {
80 throw new MojoExecutionException( "Error copying POM", e );
81 }
82 }
83 }