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.maven.execution.MavenSession;
23  import org.apache.maven.plugin.AbstractMojo;
24  import org.apache.maven.plugin.MojoExecution;
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.project.MavenProject;
29  import org.codehaus.plexus.PlexusConstants;
30  import org.codehaus.plexus.PlexusContainer;
31  import org.codehaus.plexus.context.Context;
32  import org.codehaus.plexus.context.ContextException;
33  import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
34  
35  /**
36   * This goal displays the current platform information.
37   *
38   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
39   */
40  @Mojo( name = "display-info", threadSafe = true )
41  public class DisplayInfoMojo
42      extends AbstractMojo
43      implements Contextualizable
44  {
45  
46      /**
47       * MojoExecution needed by the ExpressionEvaluator
48       */
49      @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true )
50      protected MojoExecution mojoExecution;
51  
52      /**
53       * The MavenSession
54       */
55      @Parameter( defaultValue = "${session}", readonly = true, required = true )
56      protected MavenSession session;
57  
58      /**
59       * POM
60       */
61      @Parameter( defaultValue = "${project}", readonly = true, required = true )
62      protected MavenProject project;
63  
64      // set by the contextualize method. Only way to get the
65      // plugin's container in 2.0.x
66      protected PlexusContainer container;
67  
68      public void contextualize( Context context )
69          throws ContextException
70      {
71          container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
72      }
73  
74      /**
75       * Entry point to the mojo
76       */
77      public void execute()
78          throws MojoExecutionException
79      {
80          String mavenVersion = session.getSystemProperties().getProperty( "maven.version" );
81          String javaVersion = System.getProperty( "java.version" );
82          getLog().info( "Maven Version: " + mavenVersion );
83          getLog().info( "JDK Version: " + javaVersion + " normalized as: "
84              + RequireJavaVersion.normalizeJDKVersion( javaVersion ) );
85          RequireOS os = new RequireOS();
86          os.displayOSInfo( getLog(), true );
87      }
88  
89  }