1 package org.apache.maven.plugins.enforcer;
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.lang.SystemUtils;
23 import org.apache.maven.execution.MavenSession;
24 import org.apache.maven.execution.RuntimeInformation;
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecution;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugins.annotations.Component;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.project.MavenProject;
32 import org.apache.maven.project.path.PathTranslator;
33 import org.codehaus.plexus.PlexusConstants;
34 import org.codehaus.plexus.PlexusContainer;
35 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
36 import org.codehaus.plexus.context.Context;
37 import org.codehaus.plexus.context.ContextException;
38 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
39
40
41
42
43
44
45
46 @Mojo( name = "display-info", threadSafe = true )
47 public class DisplayInfoMojo
48 extends AbstractMojo
49 implements Contextualizable
50 {
51
52
53
54
55 @Component( role = PathTranslator.class )
56 protected PathTranslator translator;
57
58
59
60
61 @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true )
62 protected MojoExecution mojoExecution;
63
64
65
66
67 @Parameter( defaultValue = "${session}", readonly = true, required = true )
68 protected MavenSession session;
69
70
71
72
73 @Parameter( defaultValue = "${project}", readonly = true, required = true )
74 protected MavenProject project;
75
76
77
78 protected PlexusContainer container;
79
80 public void contextualize ( Context context )
81 throws ContextException
82 {
83 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
84 }
85
86
87
88
89 public void execute ()
90 throws MojoExecutionException
91 {
92 try
93 {
94 EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project,
95 mojoExecution );
96 DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, getLog(),
97 container );
98 RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );
99 getLog().info( "Maven Version: " + rti.getApplicationVersion() );
100 getLog().info( "JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: "
101 + RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ) );
102 RequireOS os = new RequireOS();
103 os.displayOSInfo( getLog(), true );
104 }
105 catch ( ComponentLookupException e )
106 {
107 getLog().warn( "Unable to Lookup component: " + e.getLocalizedMessage() );
108 }
109 }
110
111 }