1 | |
package org.apache.maven.cli; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.cli.CommandLine; |
23 | |
import org.apache.commons.cli.ParseException; |
24 | |
import org.apache.maven.Maven; |
25 | |
import org.apache.maven.SettingsConfigurationException; |
26 | |
import org.apache.maven.artifact.manager.WagonManager; |
27 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
28 | |
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
29 | |
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; |
30 | |
import org.apache.maven.artifact.repository.DefaultArtifactRepository; |
31 | |
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; |
32 | |
import org.apache.maven.execution.DefaultMavenExecutionRequest; |
33 | |
import org.apache.maven.execution.MavenExecutionRequest; |
34 | |
import org.apache.maven.execution.ReactorManager; |
35 | |
import org.apache.maven.monitor.event.DefaultEventDispatcher; |
36 | |
import org.apache.maven.monitor.event.DefaultEventMonitor; |
37 | |
import org.apache.maven.monitor.event.EventDispatcher; |
38 | |
import org.apache.maven.plugin.Mojo; |
39 | |
import org.apache.maven.profiles.DefaultProfileManager; |
40 | |
import org.apache.maven.profiles.ProfileManager; |
41 | |
import org.apache.maven.reactor.MavenExecutionException; |
42 | |
import org.apache.maven.settings.MavenSettingsBuilder; |
43 | |
import org.apache.maven.settings.RuntimeInfo; |
44 | |
import org.apache.maven.settings.Settings; |
45 | |
import org.codehaus.classworlds.ClassWorld; |
46 | |
import org.codehaus.plexus.PlexusContainerException; |
47 | |
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; |
48 | |
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; |
49 | |
import org.codehaus.plexus.embed.Embedder; |
50 | |
import org.codehaus.plexus.logging.Logger; |
51 | |
import org.codehaus.plexus.logging.LoggerManager; |
52 | |
import org.codehaus.plexus.util.IOUtil; |
53 | |
import org.codehaus.plexus.util.Os; |
54 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
55 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
56 | |
|
57 | |
import java.io.File; |
58 | |
import java.io.IOException; |
59 | |
import java.io.InputStream; |
60 | |
import java.text.SimpleDateFormat; |
61 | |
import java.util.Date; |
62 | |
import java.util.Iterator; |
63 | |
import java.util.Locale; |
64 | |
import java.util.Properties; |
65 | |
import java.util.StringTokenizer; |
66 | |
import java.util.Map.Entry; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 0 | public class MavenCli |
74 | |
{ |
75 | |
|
76 | 0 | public static final String OS_NAME = Os.OS_NAME; |
77 | |
|
78 | |
|
79 | 0 | public static final String OS_ARCH = Os.OS_ARCH; |
80 | |
|
81 | |
|
82 | 0 | public static final String OS_VERSION = Os.OS_VERSION; |
83 | |
|
84 | |
private static Embedder embedder; |
85 | |
|
86 | |
public static void main( String[] args ) |
87 | |
{ |
88 | 0 | ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); |
89 | |
|
90 | 0 | int result = main( args, classWorld ); |
91 | |
|
92 | 0 | System.exit( result ); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public static int main( String[] args, ClassWorld classWorld ) |
99 | |
{ |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | 0 | CLIManager cliManager = new CLIManager(); |
105 | |
|
106 | |
CommandLine commandLine; |
107 | |
try |
108 | |
{ |
109 | 0 | commandLine = cliManager.parse( args ); |
110 | |
} |
111 | 0 | catch ( ParseException e ) |
112 | |
{ |
113 | 0 | System.err.println( "Unable to parse command line options: " + e.getMessage() ); |
114 | 0 | cliManager.displayHelp(); |
115 | 0 | return 1; |
116 | 0 | } |
117 | |
|
118 | 0 | boolean debug = commandLine.hasOption( CLIManager.DEBUG ); |
119 | |
|
120 | 0 | boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS ); |
121 | |
|
122 | 0 | if ( showErrors ) |
123 | |
{ |
124 | 0 | System.out.println( "+ Error stacktraces are turned on." ); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | 0 | if ( commandLine.hasOption( CLIManager.HELP ) ) |
132 | |
{ |
133 | 0 | cliManager.displayHelp(); |
134 | 0 | return 0; |
135 | |
} |
136 | |
|
137 | 0 | if ( commandLine.hasOption( CLIManager.VERSION ) ) |
138 | |
{ |
139 | 0 | showVersion(); |
140 | |
|
141 | 0 | return 0; |
142 | |
} |
143 | 0 | else if ( debug ) |
144 | |
{ |
145 | 0 | showVersion(); |
146 | |
} |
147 | |
|
148 | 0 | EventDispatcher eventDispatcher = new DefaultEventDispatcher(); |
149 | |
|
150 | |
|
151 | |
|
152 | 0 | String mavenHome = System.getProperty( "maven.home" ); |
153 | 0 | if ( mavenHome != null ) |
154 | |
{ |
155 | 0 | System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() ); |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | 0 | embedder = new Embedder(); |
164 | |
|
165 | |
try |
166 | |
{ |
167 | 0 | embedder.start( classWorld ); |
168 | |
} |
169 | 0 | catch ( PlexusContainerException e ) |
170 | |
{ |
171 | 0 | showFatalError( "Unable to start the embedded plexus container", e, showErrors ); |
172 | |
|
173 | 0 | return 1; |
174 | 0 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | 0 | Properties executionProperties = new Properties(); |
182 | 0 | Properties userProperties = new Properties(); |
183 | 0 | populateProperties( commandLine, executionProperties, userProperties ); |
184 | |
|
185 | |
Settings settings; |
186 | |
|
187 | |
try |
188 | |
{ |
189 | 0 | settings = buildSettings( commandLine ); |
190 | |
} |
191 | 0 | catch ( SettingsConfigurationException e ) |
192 | |
{ |
193 | 0 | showError( "Error reading settings.xml: " + e.getMessage(), e, showErrors ); |
194 | |
|
195 | 0 | return 1; |
196 | |
} |
197 | 0 | catch ( ComponentLookupException e ) |
198 | |
{ |
199 | 0 | showFatalError( "Unable to read settings.xml", e, showErrors ); |
200 | |
|
201 | 0 | return 1; |
202 | 0 | } |
203 | |
|
204 | 0 | Maven maven = null; |
205 | |
|
206 | 0 | MavenExecutionRequest request = null; |
207 | |
|
208 | 0 | LoggerManager loggerManager = null; |
209 | |
|
210 | |
try |
211 | |
{ |
212 | |
|
213 | 0 | loggerManager = (LoggerManager) embedder.lookup( LoggerManager.ROLE ); |
214 | |
|
215 | 0 | if ( debug ) |
216 | |
{ |
217 | 0 | loggerManager.setThreshold( Logger.LEVEL_DEBUG ); |
218 | |
} |
219 | 0 | else if ( commandLine.hasOption( CLIManager.QUIET ) ) |
220 | |
{ |
221 | |
|
222 | |
|
223 | 0 | loggerManager.setThreshold( Logger.LEVEL_ERROR ); |
224 | |
|
225 | |
} |
226 | |
|
227 | 0 | ProfileManager profileManager = new DefaultProfileManager( embedder.getContainer(), executionProperties ); |
228 | |
|
229 | 0 | if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) ) |
230 | |
{ |
231 | 0 | String [] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES ); |
232 | |
|
233 | 0 | if ( profileOptionValues != null ) |
234 | |
{ |
235 | 0 | for ( int i=0; i < profileOptionValues.length; ++i ) |
236 | |
{ |
237 | 0 | StringTokenizer profileTokens = new StringTokenizer( profileOptionValues[i], "," ); |
238 | |
|
239 | 0 | while ( profileTokens.hasMoreTokens() ) |
240 | |
{ |
241 | 0 | String profileAction = profileTokens.nextToken().trim(); |
242 | |
|
243 | 0 | if ( profileAction.startsWith( "-" ) || profileAction.startsWith( "!" ) ) |
244 | |
{ |
245 | 0 | profileManager.explicitlyDeactivate( profileAction.substring( 1 ) ); |
246 | |
} |
247 | 0 | else if ( profileAction.startsWith( "+" ) ) |
248 | |
{ |
249 | 0 | profileManager.explicitlyActivate( profileAction.substring( 1 ) ); |
250 | |
} |
251 | |
else |
252 | |
{ |
253 | 0 | profileManager.explicitlyActivate( profileAction ); |
254 | |
} |
255 | 0 | } |
256 | |
} |
257 | |
} |
258 | |
} |
259 | |
|
260 | 0 | request = createRequest( commandLine, settings, eventDispatcher, loggerManager, profileManager, |
261 | |
executionProperties, userProperties, showErrors ); |
262 | |
|
263 | 0 | setProjectFileOptions( commandLine, request ); |
264 | |
|
265 | 0 | maven = createMavenInstance( settings.isInteractiveMode() ); |
266 | |
} |
267 | 0 | catch ( ComponentLookupException e ) |
268 | |
{ |
269 | 0 | showFatalError( "Unable to configure the Maven application", e, showErrors ); |
270 | |
|
271 | 0 | return 1; |
272 | |
} |
273 | |
finally |
274 | |
{ |
275 | 0 | if ( loggerManager != null ) |
276 | |
{ |
277 | |
try |
278 | |
{ |
279 | 0 | embedder.release( loggerManager ); |
280 | |
} |
281 | 0 | catch ( ComponentLifecycleException e ) |
282 | |
{ |
283 | 0 | showFatalError( "Error releasing logging manager", e, showErrors ); |
284 | 0 | } |
285 | |
} |
286 | |
} |
287 | |
|
288 | |
try |
289 | |
{ |
290 | 0 | maven.execute( request ); |
291 | |
} |
292 | 0 | catch ( MavenExecutionException e ) |
293 | |
{ |
294 | 0 | return 1; |
295 | 0 | } |
296 | |
|
297 | 0 | return 0; |
298 | |
} |
299 | |
|
300 | |
private static Settings buildSettings( CommandLine commandLine ) |
301 | |
throws ComponentLookupException, SettingsConfigurationException |
302 | |
{ |
303 | 0 | String userSettingsPath = null; |
304 | |
|
305 | 0 | if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) ) |
306 | |
{ |
307 | 0 | userSettingsPath = commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ); |
308 | |
} |
309 | |
|
310 | 0 | Settings settings = null; |
311 | |
|
312 | 0 | MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE ); |
313 | |
|
314 | |
try |
315 | |
{ |
316 | 0 | if ( userSettingsPath != null ) |
317 | |
{ |
318 | 0 | File userSettingsFile = new File( userSettingsPath ); |
319 | |
|
320 | 0 | if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() ) |
321 | |
{ |
322 | 0 | settings = settingsBuilder.buildSettings( userSettingsFile ); |
323 | |
} |
324 | |
else |
325 | |
{ |
326 | 0 | System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath + |
327 | |
" is invalid. Using default path." ); |
328 | |
} |
329 | |
} |
330 | |
|
331 | 0 | if ( settings == null ) |
332 | |
{ |
333 | 0 | settings = settingsBuilder.buildSettings(); |
334 | |
} |
335 | |
} |
336 | 0 | catch ( IOException e ) |
337 | |
{ |
338 | 0 | throw new SettingsConfigurationException( "Error reading settings file", e ); |
339 | |
} |
340 | 0 | catch ( XmlPullParserException e ) |
341 | |
{ |
342 | 0 | throw new SettingsConfigurationException( e.getMessage(), e.getDetail(), e.getLineNumber(), |
343 | |
e.getColumnNumber() ); |
344 | 0 | } |
345 | |
|
346 | |
|
347 | |
|
348 | 0 | if ( commandLine.hasOption( CLIManager.BATCH_MODE ) ) |
349 | |
{ |
350 | 0 | settings.setInteractiveMode( false ); |
351 | |
} |
352 | |
|
353 | 0 | if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_REGISTRY ) ) |
354 | |
{ |
355 | 0 | settings.setUsePluginRegistry( false ); |
356 | |
} |
357 | |
|
358 | |
|
359 | |
|
360 | 0 | settings.setRuntimeInfo( createRuntimeInfo( commandLine, settings ) ); |
361 | |
|
362 | 0 | return settings; |
363 | |
} |
364 | |
|
365 | |
private static RuntimeInfo createRuntimeInfo( CommandLine commandLine, Settings settings ) |
366 | |
{ |
367 | 0 | RuntimeInfo runtimeInfo = new RuntimeInfo( settings ); |
368 | |
|
369 | 0 | if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) || |
370 | |
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) ) |
371 | |
{ |
372 | 0 | runtimeInfo.setPluginUpdateOverride( Boolean.TRUE ); |
373 | |
} |
374 | 0 | else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) ) |
375 | |
{ |
376 | 0 | runtimeInfo.setPluginUpdateOverride( Boolean.FALSE ); |
377 | |
} |
378 | |
|
379 | 0 | return runtimeInfo; |
380 | |
} |
381 | |
|
382 | |
|
383 | |
private static void showFatalError( String message, Exception e, boolean show ) |
384 | |
{ |
385 | 0 | System.err.println( "FATAL ERROR: " + message ); |
386 | 0 | if ( show ) |
387 | |
{ |
388 | 0 | System.err.println( "Error stacktrace:" ); |
389 | |
|
390 | 0 | e.printStackTrace(); |
391 | |
} |
392 | |
else |
393 | |
{ |
394 | 0 | System.err.println( "For more information, run with the -e flag" ); |
395 | |
} |
396 | 0 | } |
397 | |
|
398 | |
private static void showError( String message, Exception e, boolean show ) |
399 | |
{ |
400 | 0 | System.err.println( message ); |
401 | 0 | if ( show ) |
402 | |
{ |
403 | 0 | System.err.println( "Error stacktrace:" ); |
404 | |
|
405 | 0 | e.printStackTrace(); |
406 | |
} |
407 | 0 | } |
408 | |
|
409 | |
private static MavenExecutionRequest createRequest( CommandLine commandLine, Settings settings, |
410 | |
EventDispatcher eventDispatcher, LoggerManager loggerManager, |
411 | |
ProfileManager profileManager, Properties executionProperties, |
412 | |
Properties userProperties, boolean showErrors ) |
413 | |
throws ComponentLookupException |
414 | |
{ |
415 | |
MavenExecutionRequest request; |
416 | |
|
417 | 0 | ArtifactRepository localRepository = createLocalRepository( embedder, settings, commandLine ); |
418 | |
|
419 | 0 | File userDir = new File( System.getProperty( "user.dir" ) ); |
420 | |
|
421 | 0 | request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher, |
422 | |
commandLine.getArgList(), userDir.getPath(), profileManager, |
423 | |
executionProperties, userProperties, showErrors ); |
424 | |
|
425 | |
|
426 | 0 | Logger logger = loggerManager.getLoggerForComponent( Mojo.ROLE ); |
427 | |
|
428 | 0 | if ( logger != null ) |
429 | |
{ |
430 | 0 | request.addEventMonitor( new DefaultEventMonitor( logger ) ); |
431 | |
} |
432 | |
|
433 | 0 | if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) ) |
434 | |
{ |
435 | 0 | request.setRecursive( false ); |
436 | |
} |
437 | |
|
438 | 0 | if ( commandLine.hasOption( CLIManager.FAIL_FAST ) ) |
439 | |
{ |
440 | 0 | request.setFailureBehavior( ReactorManager.FAIL_FAST ); |
441 | |
} |
442 | 0 | else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) ) |
443 | |
{ |
444 | 0 | request.setFailureBehavior( ReactorManager.FAIL_AT_END ); |
445 | |
} |
446 | 0 | else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) ) |
447 | |
{ |
448 | 0 | request.setFailureBehavior( ReactorManager.FAIL_NEVER ); |
449 | |
} |
450 | |
|
451 | 0 | return request; |
452 | |
} |
453 | |
|
454 | |
private static void setProjectFileOptions( CommandLine commandLine, MavenExecutionRequest request ) |
455 | |
{ |
456 | 0 | if ( commandLine.hasOption( CLIManager.REACTOR ) ) |
457 | |
{ |
458 | 0 | request.setReactorActive( true ); |
459 | |
} |
460 | 0 | else if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) ) |
461 | |
{ |
462 | 0 | request.setPomFile( commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE ) ); |
463 | |
} |
464 | 0 | } |
465 | |
|
466 | |
private static Maven createMavenInstance( boolean interactive ) |
467 | |
throws ComponentLookupException |
468 | |
{ |
469 | |
|
470 | 0 | WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE ); |
471 | 0 | if ( interactive ) |
472 | |
{ |
473 | 0 | wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() ); |
474 | |
} |
475 | |
else |
476 | |
{ |
477 | 0 | wagonManager.setDownloadMonitor( new BatchModeDownloadMonitor() ); |
478 | |
} |
479 | |
|
480 | 0 | wagonManager.setInteractive( interactive ); |
481 | |
|
482 | 0 | return (Maven) embedder.lookup( Maven.ROLE ); |
483 | |
} |
484 | |
|
485 | |
private static ArtifactRepository createLocalRepository( Embedder embedder, Settings settings, |
486 | |
CommandLine commandLine ) |
487 | |
throws ComponentLookupException |
488 | |
{ |
489 | |
|
490 | |
|
491 | 0 | ArtifactRepositoryLayout repositoryLayout = |
492 | |
(ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "default" ); |
493 | |
|
494 | 0 | ArtifactRepositoryFactory artifactRepositoryFactory = |
495 | |
(ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE ); |
496 | |
|
497 | 0 | String url = settings.getLocalRepository(); |
498 | |
|
499 | 0 | if ( !url.startsWith( "file:" ) ) |
500 | |
{ |
501 | 0 | url = "file://" + url; |
502 | |
} |
503 | |
|
504 | 0 | ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout ); |
505 | |
|
506 | 0 | boolean snapshotPolicySet = false; |
507 | |
|
508 | 0 | if ( commandLine.hasOption( CLIManager.OFFLINE ) ) |
509 | |
{ |
510 | 0 | settings.setOffline( true ); |
511 | |
|
512 | 0 | snapshotPolicySet = true; |
513 | |
} |
514 | |
|
515 | 0 | if ( !snapshotPolicySet && commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) ) |
516 | |
{ |
517 | 0 | artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); |
518 | |
} |
519 | |
|
520 | 0 | if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) ) |
521 | |
{ |
522 | 0 | System.out.println( "+ Enabling strict checksum verification on all artifact downloads." ); |
523 | |
|
524 | 0 | artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); |
525 | |
} |
526 | 0 | else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) ) |
527 | |
{ |
528 | 0 | System.out.println( "+ Disabling strict checksum verification on all artifact downloads." ); |
529 | |
|
530 | 0 | artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); |
531 | |
} |
532 | |
|
533 | 0 | return localRepository; |
534 | |
} |
535 | |
|
536 | |
static Properties getBuildProperties() |
537 | |
{ |
538 | 0 | Properties properties = new Properties(); |
539 | 0 | InputStream resourceAsStream = null; |
540 | |
try |
541 | |
{ |
542 | 0 | resourceAsStream = MavenCli.class.getClassLoader().getResourceAsStream( "org/apache/maven/messages/build.properties" ); |
543 | |
|
544 | 0 | if ( resourceAsStream != null ) |
545 | |
{ |
546 | 0 | properties.load( resourceAsStream ); |
547 | |
} |
548 | |
} |
549 | 0 | catch ( IOException e ) |
550 | |
{ |
551 | 0 | System.err.println( "Unable determine version from JAR file: " + e.getMessage() ); |
552 | |
} |
553 | |
finally |
554 | |
{ |
555 | 0 | IOUtil.close( resourceAsStream ); |
556 | 0 | } |
557 | |
|
558 | 0 | return properties; |
559 | |
} |
560 | |
|
561 | |
private static void showVersion() |
562 | |
{ |
563 | 0 | Properties properties = getBuildProperties(); |
564 | |
|
565 | 0 | String timestamp = reduce( properties.getProperty( "timestamp" ) ); |
566 | 0 | String version = reduce( properties.getProperty( "version" ) ); |
567 | 0 | String rev = reduce( properties.getProperty( "buildNumber" ) ); |
568 | |
|
569 | 0 | String msg = "Apache Maven "; |
570 | 0 | msg += ( version != null ? version : "<version unknown>" ); |
571 | 0 | if ( rev != null || timestamp != null ) |
572 | |
{ |
573 | 0 | msg += " ("; |
574 | 0 | msg += ( rev != null ? "r" + rev : "" ); |
575 | 0 | if ( timestamp != null ) |
576 | |
{ |
577 | 0 | SimpleDateFormat fmt = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ" ); |
578 | 0 | String ts = fmt.format( new Date( Long.valueOf( timestamp ).longValue() ) ); |
579 | 0 | msg += ( rev != null ? "; " : "" ) + ts; |
580 | |
} |
581 | 0 | msg += ")"; |
582 | |
} |
583 | |
|
584 | 0 | System.out.println( msg ); |
585 | |
|
586 | 0 | System.out.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) ); |
587 | |
|
588 | 0 | System.out.println( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) ); |
589 | |
|
590 | 0 | System.out.println( "Default locale: " + Locale.getDefault() + ", platform encoding: " |
591 | |
+ System.getProperty( "file.encoding", "<unknown encoding>" ) ); |
592 | |
|
593 | 0 | System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + |
594 | |
"\" arch: \"" + Os.OS_ARCH + "\" Family: \"" + Os.OS_FAMILY + "\"" ); |
595 | 0 | } |
596 | |
|
597 | |
private static String reduce( String s ) |
598 | |
{ |
599 | 0 | return ( s != null ? ( s.startsWith( "${" ) && s.endsWith( "}" ) ? null : s ) : null ); |
600 | |
} |
601 | |
|
602 | |
|
603 | |
|
604 | |
|
605 | |
|
606 | |
static void populateProperties( CommandLine commandLine, Properties executionProperties, Properties userProperties ) |
607 | |
{ |
608 | |
|
609 | |
|
610 | |
try |
611 | |
{ |
612 | 0 | Properties envVars = CommandLineUtils.getSystemEnvVars(); |
613 | 0 | Iterator i = envVars.entrySet().iterator(); |
614 | 0 | while ( i.hasNext() ) |
615 | |
{ |
616 | 0 | Entry e = (Entry) i.next(); |
617 | 0 | executionProperties.setProperty( "env." + e.getKey().toString(), e.getValue().toString() ); |
618 | 0 | } |
619 | |
} |
620 | 0 | catch ( IOException e ) |
621 | |
{ |
622 | 0 | System.err.println( "Error getting environment vars for profile activation: " + e ); |
623 | 0 | } |
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | 0 | if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) ) |
632 | |
{ |
633 | 0 | String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ); |
634 | |
|
635 | 0 | if ( defStrs != null ) |
636 | |
{ |
637 | 0 | for ( int i = 0; i < defStrs.length; ++i ) |
638 | |
{ |
639 | 0 | setCliProperty( defStrs[i], userProperties ); |
640 | |
} |
641 | |
} |
642 | |
|
643 | 0 | executionProperties.putAll( userProperties ); |
644 | |
} |
645 | |
|
646 | 0 | executionProperties.putAll( System.getProperties() ); |
647 | 0 | } |
648 | |
|
649 | |
private static void setCliProperty( String property, Properties requestProperties ) |
650 | |
{ |
651 | |
String name; |
652 | |
|
653 | |
String value; |
654 | |
|
655 | 0 | int i = property.indexOf( "=" ); |
656 | |
|
657 | 0 | if ( i <= 0 ) |
658 | |
{ |
659 | 0 | name = property.trim(); |
660 | |
|
661 | 0 | value = "true"; |
662 | |
} |
663 | |
else |
664 | |
{ |
665 | 0 | name = property.substring( 0, i ).trim(); |
666 | |
|
667 | 0 | value = property.substring( i + 1 ).trim(); |
668 | |
} |
669 | |
|
670 | 0 | requestProperties.setProperty( name, value ); |
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | 0 | System.setProperty( name, value ); |
678 | 0 | } |
679 | |
} |