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   * @version $Id: DisplayInfoMojo.java 1799997 2017-06-26 21:26:08Z gboue $
40   */
41  @Mojo( name = "display-info", threadSafe = true )
42  public class DisplayInfoMojo
43      extends AbstractMojo
44      implements Contextualizable
45  {
46  
47      /**
48       * MojoExecution needed by the ExpressionEvaluator
49       */
50      @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true )
51      protected MojoExecution mojoExecution;
52  
53      /**
54       * The MavenSession
55       */
56      @Parameter( defaultValue = "${session}", readonly = true, required = true )
57      protected MavenSession session;
58  
59      /**
60       * POM
61       */
62      @Parameter( defaultValue = "${project}", readonly = true, required = true )
63      protected MavenProject project;
64  
65      // set by the contextualize method. Only way to get the
66      // plugin's container in 2.0.x
67      protected PlexusContainer container;
68  
69      public void contextualize( Context context )
70          throws ContextException
71      {
72          container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
73      }
74  
75      /**
76       * Entry point to the mojo
77       */
78      public void execute()
79          throws MojoExecutionException
80      {
81          String mavenVersion = session.getSystemProperties().getProperty( "maven.version" );
82          String javaVersion = System.getProperty( "java.version" );
83          getLog().info( "Maven Version: " + mavenVersion );
84          getLog().info( "JDK Version: " + javaVersion + " normalized as: "
85              + RequireJavaVersion.normalizeJDKVersion( javaVersion ) );
86          RequireOS os = new RequireOS();
87          os.displayOSInfo( getLog(), true );
88      }
89  
90  }