1 package org.apache.maven.plugin.cxx;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.OutputStream;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.apache.maven.plugins.annotations.Mojo;
33 import org.apache.maven.plugins.annotations.Parameter;
34
35
36
37
38
39
40 @Mojo( name = "launch" )
41 public class LaunchMojo extends AbstractLaunchMojo
42 {
43
44
45
46
47
48
49
50 @Parameter()
51 private List<String> arguments;
52
53
54 @Override
55 protected List<String> getArgsList()
56 {
57 return arguments;
58 }
59
60
61
62
63
64 @Parameter( property = "launch.args" )
65 private String commandArgs;
66
67 @Override
68 protected String getCommandArgs()
69 {
70 return commandArgs;
71 }
72
73
74
75
76
77
78
79 @Parameter( property = "launch.executable", required = true )
80 private String executable;
81
82 @Override
83 protected String getExecutable()
84 {
85 return executable;
86 }
87
88
89
90
91
92
93 @Parameter()
94 private Map environmentVariables = new HashMap();
95
96 @Override
97 protected Map getMoreEnvironmentVariables()
98 {
99 return environmentVariables;
100 }
101
102
103
104
105
106
107
108 @Parameter()
109 private List<String> successCodes;
110
111 @Override
112 protected List<String> getSuccesCode()
113 {
114 return successCodes;
115 }
116
117
118
119
120
121
122 @Parameter( property = "launch.workingdir" )
123 private File workingDir;
124
125 @Override
126 protected File getWorkingDir()
127 {
128 if ( null == workingDir )
129 {
130 workingDir = new File( basedir.getPath() );
131 }
132 return workingDir;
133 }
134
135
136
137
138
139
140
141 @Parameter()
142 private List includeOS;
143
144
145
146
147
148
149
150 @Parameter()
151 private List excludeOS;
152
153 @Override
154 protected boolean isSkip()
155 {
156 String sOsName = System.getProperty( "os.name" );
157 sOsName = sOsName.replace( " ", "" );
158 getLog().info( "os.name is \"" + sOsName + "\"" );
159 if ( null == excludeOS && null == includeOS )
160 {
161 return false;
162 }
163 else if ( null == includeOS )
164 {
165 return excludeOS.contains( sOsName );
166 }
167 else if ( null == excludeOS )
168 {
169 return !includeOS.contains( sOsName );
170 }
171 else
172 {
173 return ( excludeOS.contains( sOsName ) || !includeOS.contains( sOsName ) );
174 }
175 }
176
177
178
179
180
181
182 @Parameter( property = "launch.outputStreamOut", defaultValue = "" )
183 private File outputStreamOut;
184
185 @Override
186 protected OutputStream getOutputStreamOut()
187 {
188 String sOutputStreamOut = new String();
189 if ( null != outputStreamOut && !outputStreamOut.toString().isEmpty() )
190 {
191 if ( outputStreamOut.isAbsolute() )
192 {
193 sOutputStreamOut = outputStreamOut.getPath();
194 }
195 else
196 {
197 sOutputStreamOut = basedir.getAbsolutePath() + File.separator + outputStreamOut.getPath();
198 }
199
200 getLog().info( "Launch output location " + sOutputStreamOut );
201
202 OutputStream output = super.getOutputStreamOut();
203 File file = new File( sOutputStreamOut );
204 try
205 {
206 new File( file.getParent() ).mkdirs();
207 file.createNewFile();
208 output = new FileOutputStream( file );
209 }
210 catch ( IOException e )
211 {
212 getLog().error( "Launch report redirected to stout since " + sOutputStreamOut + " can't be opened" );
213 }
214 return output;
215 }
216 else
217 {
218 return super.getOutputStreamOut();
219 }
220 }
221
222
223
224
225
226
227 @Parameter( property = "launch.outputStreamErr", defaultValue = "" )
228 private File outputStreamErr;
229
230 @Override
231 protected OutputStream getOutputStreamErr()
232 {
233 String sOutputStreamErr = new String();
234 if ( null != outputStreamErr && !outputStreamErr.toString().isEmpty() )
235 {
236 if ( outputStreamErr.isAbsolute() )
237 {
238 sOutputStreamErr = outputStreamErr.getPath();
239 }
240 else
241 {
242 sOutputStreamErr = basedir.getAbsolutePath() + File.separator + outputStreamErr.getPath();
243 }
244
245 getLog().info( "Launch erroutput location " + sOutputStreamErr );
246
247 OutputStream output = super.getOutputStreamErr();
248 File file = new File( sOutputStreamErr );
249 try
250 {
251 new File( file.getParent() ).mkdirs();
252 file.createNewFile();
253 output = new FileOutputStream( file );
254 }
255 catch ( IOException e )
256 {
257 getLog().error( "Launch report redirected to stout since " + sOutputStreamErr + " can't be opened" );
258 }
259 return output;
260 }
261 else
262 {
263 return super.getOutputStreamErr();
264 }
265 }
266
267
268
269
270
271
272 @Parameter( property = "launch.inputStream", defaultValue = "" )
273 private File inputStream;
274
275 @Override
276 protected InputStream getInputStream()
277 {
278 String sInputStream = new String();
279 if ( null != inputStream && !inputStream.toString().isEmpty() )
280 {
281 if ( inputStream.isAbsolute() )
282 {
283 sInputStream = inputStream.getPath();
284 }
285 else
286 {
287 sInputStream = basedir.getAbsolutePath() + File.separator + inputStream.getPath();
288 }
289
290 getLog().info( "Launch input location " + sInputStream );
291
292 InputStream input = super.getInputStream();
293 File file = new File( sInputStream );
294 try
295 {
296 new File( file.getParent() ).mkdirs();
297 file.createNewFile();
298 input = new FileInputStream( file );
299 }
300 catch ( IOException e )
301 {
302 getLog().error( "Launch report redirected to stout since " + sInputStream + " can't be opened" );
303 }
304 return input;
305 }
306 else
307 {
308 return super.getInputStream();
309 }
310 }
311 }