001package org.apache.maven.plugins.enforcer; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.lang.SystemUtils; 023import org.apache.maven.execution.MavenSession; 024import org.apache.maven.execution.RuntimeInformation; 025import org.apache.maven.plugin.AbstractMojo; 026import org.apache.maven.plugin.MojoExecutionException; 027import org.apache.maven.plugins.annotations.Component; 028import org.apache.maven.plugins.annotations.Mojo; 029import org.apache.maven.project.MavenProject; 030import org.apache.maven.project.path.PathTranslator; 031import org.codehaus.plexus.PlexusConstants; 032import org.codehaus.plexus.PlexusContainer; 033import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 034import org.codehaus.plexus.context.Context; 035import org.codehaus.plexus.context.ContextException; 036import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; 037 038/** 039 * This goal displays the current platform information. 040 * 041 * @author <a href="mailto:brianf@apache.org">Brian Fox</a> 042 * @version $Id: DisplayInfoMojo.java 1411846 2012-11-20 20:29:54Z hboutemy $ 043 */ 044@Mojo( name = "display-info", threadSafe = true ) 045public class DisplayInfoMojo 046 extends AbstractMojo 047 implements Contextualizable 048{ 049 050 /** 051 * Path Translator needed by the ExpressionEvaluator 052 */ 053 @Component( role = PathTranslator.class ) 054 protected PathTranslator translator; 055 056 /** 057 * The MavenSession 058 */ 059 @Component 060 protected MavenSession session; 061 062 /** 063 * POM 064 */ 065 @Component 066 protected MavenProject project; 067 068 // set by the contextualize method. Only way to get the 069 // plugin's container in 2.0.x 070 protected PlexusContainer container; 071 072 public void contextualize ( Context context ) 073 throws ContextException 074 { 075 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); 076 } 077 078 /** 079 * Entry point to the mojo 080 */ 081 public void execute () 082 throws MojoExecutionException 083 { 084 try 085 { 086 EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project ); 087 DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, getLog(), 088 container ); 089 RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); 090 getLog().info( "Maven Version: " + rti.getApplicationVersion() ); 091 getLog().info( "JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: " 092 + RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ) ); 093 RequireOS os = new RequireOS(); 094 os.displayOSInfo( getLog(), true ); 095 } 096 catch ( ComponentLookupException e ) 097 { 098 getLog().warn( "Unable to Lookup component: " + e.getLocalizedMessage() ); 099 } 100 } 101 102}