1 | |
package org.apache.maven.plugins.help; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.util.Date; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.Properties; |
26 | |
|
27 | |
import org.apache.maven.plugin.MojoExecutionException; |
28 | |
import org.codehaus.plexus.util.StringUtils; |
29 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class SystemMojo |
41 | |
extends AbstractHelpMojo |
42 | |
{ |
43 | |
|
44 | |
private static final int REPEAT = 25; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public void execute() |
52 | |
throws MojoExecutionException |
53 | |
{ |
54 | 0 | StringBuffer message = new StringBuffer(); |
55 | |
|
56 | 0 | message.append( '\n' ); |
57 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
58 | 0 | message.append( StringUtils.repeat( "=", REPEAT ) ); |
59 | 0 | message.append( " Platform Properties Details " ); |
60 | 0 | message.append( StringUtils.repeat( "=", REPEAT ) ).append( '\n' ); |
61 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
62 | 0 | message.append( '\n' ); |
63 | |
|
64 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
65 | 0 | message.append( "System Properties" ).append( '\n' ); |
66 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
67 | |
|
68 | 0 | Properties systemProperties = System.getProperties(); |
69 | 0 | for ( Iterator it = systemProperties.keySet().iterator(); it.hasNext(); ) |
70 | |
{ |
71 | 0 | String key = it.next().toString(); |
72 | 0 | message.append( "\n" ); |
73 | 0 | message.append( key ).append( "=" ).append( systemProperties.get( key ) ); |
74 | 0 | } |
75 | |
|
76 | 0 | message.append( '\n' ).append( '\n' ); |
77 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
78 | 0 | message.append( "Environment Variables" ).append( '\n' ); |
79 | 0 | message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( '\n' ); |
80 | |
try |
81 | |
{ |
82 | 0 | Properties envVars = CommandLineUtils.getSystemEnvVars(); |
83 | 0 | for ( Iterator it2 = envVars.keySet().iterator(); it2.hasNext(); ) |
84 | |
{ |
85 | 0 | String key = it2.next().toString(); |
86 | 0 | message.append( "\n" ); |
87 | 0 | message.append( key ).append( "=" ).append( envVars.get( key ) ); |
88 | 0 | } |
89 | |
} |
90 | 0 | catch ( IOException e ) |
91 | |
{ |
92 | 0 | if ( getLog().isWarnEnabled() ) |
93 | |
{ |
94 | 0 | getLog().warn( "IOException: " + e.getMessage() ); |
95 | |
} |
96 | 0 | } |
97 | |
|
98 | 0 | message.append( "\n" ); |
99 | |
|
100 | 0 | if ( output != null ) |
101 | |
{ |
102 | 0 | StringBuffer sb = new StringBuffer(); |
103 | 0 | sb.append( "Created by: " + getClass().getName() ).append( "\n" ); |
104 | 0 | sb.append( "Created on: " + new Date() ).append( "\n" ).append( "\n" ); |
105 | 0 | sb.append( message.toString() ); |
106 | |
|
107 | |
try |
108 | |
{ |
109 | 0 | writeFile( output, sb ); |
110 | |
} |
111 | 0 | catch ( IOException e ) |
112 | |
{ |
113 | 0 | throw new MojoExecutionException( "Cannot write system report to output: " + output, e ); |
114 | 0 | } |
115 | |
|
116 | 0 | if ( getLog().isInfoEnabled() ) |
117 | |
{ |
118 | 0 | getLog().info( "System report written to: " + output ); |
119 | |
} |
120 | 0 | } |
121 | |
else |
122 | |
{ |
123 | 0 | if ( getLog().isInfoEnabled() ) |
124 | |
{ |
125 | 0 | getLog().info( message ); |
126 | |
} |
127 | |
} |
128 | 0 | } |
129 | |
} |