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 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.project.MavenProject;
26
27 import java.io.File;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.OutputStreamWriter;
31
32
33
34
35
36
37
38
39
40
41 public class ResourcesMojo
42 extends AbstractMojo
43 {
44
45
46
47
48
49
50
51
52 private MavenProject project;
53
54
55
56
57
58
59 private String pathname = "target/resources-resources.txt";
60
61
62
63
64
65
66
67 private String message;
68
69
70
71
72
73
74
75 public void execute()
76 throws MojoExecutionException, MojoFailureException
77 {
78 getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + pathname );
79
80 if ( pathname == null || pathname.length() <= 0 )
81 {
82 throw new MojoFailureException( "Path name for output file has not been specified" );
83 }
84
85 File outputFile = new File( pathname );
86 if ( !outputFile.isAbsolute() )
87 {
88 outputFile = new File( project.getBasedir(), pathname ).getAbsoluteFile();
89 }
90
91 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile );
92
93 try
94 {
95 outputFile.getParentFile().mkdirs();
96
97 if ( message != null && message.length() > 0 )
98 {
99 getLog().info( "[MAVEN-CORE-IT-LOG] " + message );
100
101 OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( outputFile, true ), "UTF-8" );
102 try
103 {
104 writer.write( message );
105 writer.write( "\n" );
106 }
107 finally
108 {
109 writer.close();
110 }
111 }
112 else
113 {
114 outputFile.createNewFile();
115 }
116 }
117 catch ( IOException e )
118 {
119 throw new MojoExecutionException( "Output file could not be created: " + pathname, e );
120 }
121
122 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + outputFile );
123 }
124
125 }