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