View Javadoc
1   package org.apache.maven.plugins.enforcer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This goal displays the current platform information.
42   *
43   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
44   * @version $Id: DisplayInfoMojo.java 1649120 2015-01-02 21:01:18Z khmarbaise $
45   */
46  @Mojo( name = "display-info", threadSafe = true )
47  public class DisplayInfoMojo
48      extends AbstractMojo
49      implements Contextualizable
50  {
51  
52      /**
53       * Path Translator needed by the ExpressionEvaluator
54       */
55      @Component( role = PathTranslator.class )
56      protected PathTranslator translator;
57  
58      /**
59       * MojoExecution needed by the ExpressionEvaluator
60       */
61      @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true )
62      protected MojoExecution mojoExecution;
63  
64      /**
65       * The MavenSession
66       */
67      @Parameter( defaultValue = "${session}", readonly = true, required = true )
68      protected MavenSession session;
69  
70      /**
71       * POM
72       */
73      @Parameter( defaultValue = "${project}", readonly = true, required = true )
74      protected MavenProject project;
75  
76      // set by the contextualize method. Only way to get the
77      // plugin's container in 2.0.x
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       * Entry point to the mojo
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 }