Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java Fri Nov 11 17:13:13 2016 @@ -19,8 +19,6 @@ package org.apache.maven.plugins.help; * under the License. */ -import static org.apache.maven.plugins.help.HelpUtil.LS; - import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -28,47 +26,39 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.DefaultLifecycleExecutor; +import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.Lifecycle; -import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.PluginNotFoundException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; +import org.apache.maven.plugin.version.DefaultPluginVersionRequest; import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.plugin.version.PluginVersionResolver; +import org.apache.maven.plugin.version.PluginVersionResult; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.reporting.MavenReport; +import org.apache.maven.reporting.exec.MavenPluginManagerHelper; +import org.apache.maven.shared.artifact.ArtifactCoordinate; +import org.apache.maven.tools.plugin.generator.GeneratorUtils; import org.apache.maven.tools.plugin.util.PluginUtils; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.StringUtils; /** @@ -107,36 +97,36 @@ public class DescribeMojo // ---------------------------------------------------------------------- // Mojo components // ---------------------------------------------------------------------- - + /** - * Maven Artifact Factory component. - * - * @since 2.1 + * Component used to get a plugin descriptor from a given plugin. */ @Component - private ArtifactFactory artifactFactory; + private MavenPluginManagerHelper pluginManager; /** - * Maven Artifact Resolver component. - * - * @since 2.2.1 + * Component used to get a plugin by its prefix and get mojo descriptors. */ @Component - private ArtifactResolver artifactResolver; - + private MojoDescriptorCreator mojoDescriptorCreator; + /** - * The Plugin manager instance used to resolve Plugin descriptors. + * Component used to resolve the version for a plugin. */ - @Component( role = PluginManager.class ) - private PluginManager pluginManager; - + @Component + private PluginVersionResolver pluginVersionResolver; + /** - * The project builder instance used to retrieve the super-project instance - * in the event there is no current MavenProject instance. Some MavenProject - * instance has to be present to use in the plugin manager APIs. + * The Maven default built-in lifecycles. */ - @Component( role = MavenProjectBuilder.class ) - private MavenProjectBuilder projectBuilder; + @Component + private DefaultLifecycles defaultLifecycles; + + /** + * A map from each packaging to its lifecycle mapping. + */ + @Component + private Map<String, LifecycleMapping> lifecycleMappings; // ---------------------------------------------------------------------- // Mojo parameters @@ -152,30 +142,6 @@ public class DescribeMojo private MavenProject project; /** - * The current build session instance. This is used for - * plugin manager API calls. - */ - @org.apache.maven.plugins.annotations.Parameter( defaultValue = "${session}", readonly = true, required = true ) - private MavenSession session; - - /** - * The local repository ArtifactRepository instance. This is used - * for plugin manager API calls. - */ - @org.apache.maven.plugins.annotations.Parameter( defaultValue = "${localRepository}", required = true, - readonly = true ) - private ArtifactRepository localRepository; - - /** - * Remote repositories used for the project. - * - * @since 2.1 - */ - @org.apache.maven.plugins.annotations.Parameter( defaultValue = "${project.remoteArtifactRepositories}", - required = true, readonly = true ) - private List<ArtifactRepository> remoteRepositories; - - /** * The Maven Plugin to describe. This must be specified in one of three ways: * <br/> * <ol> @@ -267,18 +233,6 @@ public class DescribeMojo { validateParameters(); - if ( project == null ) - { - try - { - project = projectBuilder.buildStandaloneSuperProject( session.getProjectBuilderConfiguration() ); - } - catch ( ProjectBuildingException e ) - { - throw new MojoExecutionException( "Error while retrieving the super-project.", e ); - } - } - StringBuilder descriptionBuffer = new StringBuilder(); boolean describePlugin = true; @@ -289,21 +243,16 @@ public class DescribeMojo if ( describePlugin ) { - PluginInfo pi = new PluginInfo(); - - parsePluginLookupInfo( pi ); - + PluginInfo pi = parsePluginLookupInfo(); PluginDescriptor descriptor = lookupPluginDescriptor( pi ); - if ( StringUtils.isNotEmpty( goal ) ) { MojoDescriptor mojo = descriptor.getMojo( goal ); if ( mojo == null ) { - throw new MojoFailureException( - "The mojo '" + goal + "' does not exist in the plugin '" + pi.getPrefix() + "'" ); + throw new MojoFailureException( "The mojo '" + goal + "' does not exist in the plugin '" + + pi.getPrefix() + "'" ); } - describeMojo( mojo, descriptionBuffer ); } else @@ -325,15 +274,15 @@ public class DescribeMojo private void validateParameters() { // support legacy parameters "mojo" and "full" - if ( goal == null && session.getExecutionProperties().get( "mojo" ) != null ) + if ( goal == null && session.getUserProperties().get( "mojo" ) != null ) { - goal = session.getExecutionProperties().getProperty( "mojo" ); + goal = session.getUserProperties().getProperty( "mojo" ); } - if ( !detail && session.getExecutionProperties().get( "full" ) != null ) + if ( !detail && session.getUserProperties().get( "full" ) != null ) { - String full = session.getExecutionProperties().getProperty( "full" ); - detail = Boolean.valueOf( full ); + String full = session.getUserProperties().getProperty( "full" ); + detail = Boolean.parseBoolean( full ); } if ( detail || minimal ) @@ -362,17 +311,11 @@ public class DescribeMojo throw new MojoExecutionException( "Cannot write plugin/mojo description to output: " + output, e ); } - if ( getLog().isInfoEnabled() ) - { - getLog().info( "Wrote descriptions to: " + output ); - } + getLog().info( "Wrote descriptions to: " + output ); } else { - if ( getLog().isInfoEnabled() ) - { - getLog().info( descriptionBuffer.toString() ); - } + getLog().info( descriptionBuffer.toString() ); } } @@ -387,31 +330,25 @@ public class DescribeMojo private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) throws MojoExecutionException, MojoFailureException { - PluginDescriptor descriptor = null; - Plugin forLookup = null; - if ( StringUtils.isNotEmpty( pi.getPrefix() ) ) { - descriptor = pluginManager.getPluginDescriptorForPrefix( pi.getPrefix() ); - if ( descriptor == null ) + try + { + forLookup = mojoDescriptorCreator.findPluginForPrefix( pi.getPrefix(), session ); + } + catch ( NoPluginFoundForPrefixException e ) { - forLookup = pluginManager.getPluginDefinitionForPrefix( pi.getPrefix(), session, project ); + throw new MojoExecutionException( "Unable to find the plugin with prefix: " + pi.getPrefix(), e ); } } else if ( StringUtils.isNotEmpty( pi.getGroupId() ) && StringUtils.isNotEmpty( pi.getArtifactId() ) ) { forLookup = new Plugin(); - forLookup.setGroupId( pi.getGroupId() ); forLookup.setArtifactId( pi.getArtifactId() ); - - if ( StringUtils.isNotEmpty( pi.getVersion() ) ) - { - forLookup.setVersion( pi.getVersion() ); - } } - else + if ( forLookup == null ) { String msg = "You must specify either: both 'groupId' and 'artifactId' parameters OR a 'plugin' parameter" @@ -427,88 +364,48 @@ public class DescribeMojo throw new MojoFailureException( msg ); } - if ( descriptor == null && forLookup != null ) + if ( StringUtils.isNotEmpty( pi.getVersion() ) ) + { + forLookup.setVersion( pi.getVersion() ); + } + else { try { - descriptor = pluginManager.loadPluginDescriptor( forLookup, project, session ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS - + LS + "groupId: '" + groupId + "'" - + LS + "artifactId: '" + artifactId + "'" - + LS + "version: '" + version + "'" + LS + LS, e ); - } - catch ( PluginManagerException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS - + LS + "groupId: '" + groupId + "'" - + LS + "artifactId: '" + artifactId + "'" - + LS + "version: '" + version + "'" + LS + LS, e ); + PluginVersionResult versionResult = + pluginVersionResolver.resolve( new DefaultPluginVersionRequest( forLookup, session ) ); + forLookup.setVersion( versionResult.getVersion() ); } catch ( PluginVersionResolutionException e ) { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS - + LS + "groupId: '" + groupId + "'" - + LS + "artifactId: '" + artifactId + "'" - + LS + "version: '" + version + "'" + LS + LS, e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new MojoExecutionException( "Plugin dependency does not exist: " + e.getMessage(), e ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS - + LS + "groupId: '" + groupId + "'" - + LS + "artifactId: '" + artifactId + "'" - + LS + "version: '" + version + "'" + LS + LS, e ); - } - catch ( InvalidPluginException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS - + LS + "groupId: '" + groupId + "'" - + LS + "artifactId: '" + artifactId + "'" - + LS + "version: '" + version + "'" + LS + LS, e ); - } - catch ( PluginNotFoundException e ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Unable to find plugin", e ); - } - throw new MojoFailureException( "Plugin does not exist: " + e.getMessage() ); - } - catch ( PluginVersionNotFoundException e ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Unable to find plugin version", e ); - } - throw new MojoFailureException( e.getMessage() ); + throw new MojoExecutionException( "Unable to resolve the version of the plugin with prefix: " + + pi.getPrefix(), e ); } } - if ( descriptor == null ) + try { - throw new MojoFailureException( "Plugin could not be found. If you believe it is correct," - + " check your pluginGroups setting, and run with -U to update the remote configuration" ); + return pluginManager.getPluginDescriptor( forLookup, session ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:" + LS + LS + "groupId: '" + + groupId + "'" + LS + "artifactId: '" + artifactId + "'" + LS + "version: '" + version + "'" + LS + + LS, e ); } - - return descriptor; } /** * Method for parsing the plugin parameter * - * @param pi contains information about the plugin whose description is to be retrieved + * @return Plugin info containing information about the plugin whose description is to be retrieved * @throws MojoFailureException if <code>plugin<*code> parameter is not conform to * <code>groupId:artifactId[:version]</code> */ - private void parsePluginLookupInfo( PluginInfo pi ) + private PluginInfo parsePluginLookupInfo() throws MojoFailureException { + PluginInfo pi = new PluginInfo(); if ( StringUtils.isNotEmpty( plugin ) ) { if ( plugin.indexOf( ':' ) > -1 ) @@ -517,14 +414,14 @@ public class DescribeMojo switch ( pluginParts.length ) { - case ( 1 ): + case 1: pi.setPrefix( pluginParts[0] ); break; - case ( 2 ): + case 2: pi.setGroupId( pluginParts[0] ); pi.setArtifactId( pluginParts[1] ); break; - case ( 3 ): + case 3: pi.setGroupId( pluginParts[0] ); pi.setArtifactId( pluginParts[1] ); pi.setVersion( pluginParts[2] ); @@ -545,6 +442,7 @@ public class DescribeMojo pi.setArtifactId( artifactId ); pi.setVersion( version ); } + return pi; } /** @@ -564,21 +462,21 @@ public class DescribeMojo String name = pd.getName(); if ( name == null ) { - // Always null see MPLUGIN-137 - // TODO remove when maven-plugin-tools-api:2.4.4 + // Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3) + ArtifactCoordinate coordinate = toArtifactCoordinate( pd, "jar" ); + ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() ); + pbr.setRemoteRepositories( remoteRepositories ); + pbr.setProject( null ); + pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); try { - Artifact artifact = artifactFactory.createPluginArtifact( pd.getGroupId(), pd.getArtifactId(), - VersionRange.createFromVersion( - pd.getVersion() ) ); - MavenProject pluginProject = - projectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository ); - - name = pluginProject.getName(); + Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact(); + name = projectBuilder.build( artifact, pbr ).getProject().getName(); } - catch ( ProjectBuildingException e ) + catch ( Exception e ) { // oh well, we tried our best. + getLog().warn( "Unable to get the name of the plugin " + pd.getId() + ": " + e.getMessage() ); name = pd.getId(); } } @@ -590,7 +488,6 @@ public class DescribeMojo append( buffer, "Goal Prefix", pd.getGoalPrefix(), 0 ); buffer.append( LS ); - @SuppressWarnings( "unchecked" ) List<MojoDescriptor> mojos = pd.getMojos(); if ( mojos == null ) @@ -742,7 +639,6 @@ public class DescribeMojo private void describeMojoParameters( MojoDescriptor md, StringBuilder buffer ) throws MojoFailureException, MojoExecutionException { - @SuppressWarnings( "unchecked" ) List<Parameter> params = md.getParameters(); if ( params == null || params.isEmpty() ) @@ -752,15 +648,7 @@ public class DescribeMojo } params = new ArrayList<Parameter>( params ); - // TODO remove when maven-plugin-tools-api:2.4.4 is out see PluginUtils.sortMojoParameters() - Collections.sort( params, new Comparator<Parameter>() - { - /** {@inheritDoc} */ - public int compare( Parameter parameter1, Parameter parameter2 ) - { - return parameter1.getName().compareToIgnoreCase( parameter2.getName() ); - } - } ); + PluginUtils.sortMojoParameters( params ); append( buffer, "Available parameters:", 1 ); @@ -847,106 +735,96 @@ public class DescribeMojo if ( cmd.indexOf( ':' ) == -1 ) { // phase - try + Lifecycle lifecycle = defaultLifecycles.getPhaseToLifecycleMap().get( cmd ); + if ( lifecycle == null ) { - DefaultLifecycleExecutor lifecycleExecutor = - (DefaultLifecycleExecutor) session.lookup( LifecycleExecutor.ROLE ); - - Lifecycle lifecycle = (Lifecycle) lifecycleExecutor.getPhaseToLifecycleMap().get( cmd ); - if ( lifecycle == null ) - { - throw new MojoExecutionException( "The given phase '" + cmd + "' is an unknown phase." ); - } + throw new MojoExecutionException( "The given phase '" + cmd + "' is an unknown phase." ); + } - LifecycleMapping lifecycleMapping = - (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, project.getPackaging() ); - @SuppressWarnings( "unchecked" ) - List<String> phases = lifecycle.getPhases(); + Map<String, String> defaultLifecyclePhases = + lifecycleMappings.get( project.getPackaging() ).getLifecycles().get( "default" ).getPhases(); + List<String> phases = lifecycle.getPhases(); - if ( lifecycle.getDefaultPhases() == null ) + if ( lifecycle.getDefaultPhases() == null ) + { + descriptionBuffer.append( "'" ).append( cmd ); + descriptionBuffer.append( "' is a phase corresponding to this plugin:" ).append( LS ); + for ( String key : phases ) { - descriptionBuffer.append( "'" ).append( cmd ); - descriptionBuffer.append( "' is a phase corresponding to this plugin:" ).append( LS ); - for ( String key : phases ) + if ( !key.equals( cmd ) ) { - if ( !key.equals( cmd ) ) - { - continue; - } - - if ( lifecycleMapping.getPhases( "default" ).get( key ) != null ) - { - descriptionBuffer.append( lifecycleMapping.getPhases( "default" ).get( key ) ); - descriptionBuffer.append( LS ); - } + continue; } + if ( defaultLifecyclePhases.get( key ) != null ) + { + descriptionBuffer.append( defaultLifecyclePhases.get( key ) ); + descriptionBuffer.append( LS ); + } + } - descriptionBuffer.append( LS ); - descriptionBuffer.append( "It is a part of the lifecycle for the POM packaging '" ); - descriptionBuffer.append( project.getPackaging() ); - descriptionBuffer.append( "'. This lifecycle includes the following phases:" ); - descriptionBuffer.append( LS ); - for ( String key : phases ) + descriptionBuffer.append( LS ); + descriptionBuffer.append( "It is a part of the lifecycle for the POM packaging '" ); + descriptionBuffer.append( project.getPackaging() ); + descriptionBuffer.append( "'. This lifecycle includes the following phases:" ); + descriptionBuffer.append( LS ); + for ( String key : phases ) + { + descriptionBuffer.append( "* " ).append( key ).append( ": " ); + String value = defaultLifecyclePhases.get( key ); + if ( StringUtils.isNotEmpty( value ) ) { - descriptionBuffer.append( "* " ).append( key ).append( ": " ); - String value = (String) lifecycleMapping.getPhases( "default" ).get( key ); - if ( StringUtils.isNotEmpty( value ) ) + for ( StringTokenizer tok = new StringTokenizer( value, "," ); tok.hasMoreTokens(); ) { - for ( StringTokenizer tok = new StringTokenizer( value, "," ); tok.hasMoreTokens(); ) - { - descriptionBuffer.append( tok.nextToken().trim() ); + descriptionBuffer.append( tok.nextToken().trim() ); - if ( !tok.hasMoreTokens() ) - { - descriptionBuffer.append( LS ); - } - else - { - descriptionBuffer.append( ", " ); - } + if ( !tok.hasMoreTokens() ) + { + descriptionBuffer.append( LS ); + } + else + { + descriptionBuffer.append( ", " ); } - } - else - { - descriptionBuffer.append( NOT_DEFINED ).append( LS ); } } - } - else - { - descriptionBuffer.append( "'" ).append( cmd ); - descriptionBuffer.append( "' is a lifecycle with the following phases: " ); - descriptionBuffer.append( LS ); - - for ( String key : phases ) + else { - descriptionBuffer.append( "* " ).append( key ).append( ": " ); - if ( lifecycle.getDefaultPhases().get( key ) != null ) - { - descriptionBuffer.append( lifecycle.getDefaultPhases().get( key ) ).append( LS ); - } - else - { - descriptionBuffer.append( NOT_DEFINED ).append( LS ); - } + descriptionBuffer.append( NOT_DEFINED ).append( LS ); } } } - catch ( ComponentLookupException e ) - { - throw new MojoFailureException( "ComponentLookupException: " + e.getMessage() ); - } - catch ( LifecycleExecutionException e ) + else { - throw new MojoFailureException( "LifecycleExecutionException: " + e.getMessage() ); - } + descriptionBuffer.append( "'" ).append( cmd ); + descriptionBuffer.append( "' is a lifecycle with the following phases: " ); + descriptionBuffer.append( LS ); + for ( String key : phases ) + { + descriptionBuffer.append( "* " ).append( key ).append( ": " ); + if ( lifecycle.getDefaultPhases().get( key ) != null ) + { + descriptionBuffer.append( lifecycle.getDefaultPhases().get( key ) ).append( LS ); + } + else + { + descriptionBuffer.append( NOT_DEFINED ).append( LS ); + } + } + } return false; } // goals - MojoDescriptor mojoDescriptor = HelpUtil.getMojoDescriptor( cmd, session, project, cmd, true, false ); - + MojoDescriptor mojoDescriptor; + try + { + mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( cmd, session, project ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Unable to get descriptor for " + cmd, e ); + } descriptionBuffer.append( "'" ).append( cmd ).append( "' is a plugin goal (aka mojo)" ).append( "." ); descriptionBuffer.append( LS ); plugin = mojoDescriptor.getPluginDescriptor().getId(); @@ -977,6 +855,7 @@ public class DescribeMojo new Class[]{ String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE } ); m.setAccessible( true ); + @SuppressWarnings( "unchecked" ) List<String> output = (List<String>) m.invoke( HelpMojo.class, text, indent, indentSize, lineLength ); if ( output == null ) @@ -1122,15 +1001,18 @@ public class DescribeMojo */ private boolean isReportGoal( MojoDescriptor md ) { - PluginDescriptor d = md.getPluginDescriptor(); - Artifact jar = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), "", "jar" ); - Artifact pom = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), "", "pom" ); + PluginDescriptor pd = md.getPluginDescriptor(); List<URL> urls = new ArrayList<URL>(); + ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() ); + pbr.setRemoteRepositories( remoteRepositories ); + pbr.setResolveDependencies( true ); + pbr.setProject( null ); + pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); try { - artifactResolver.resolve( jar, remoteRepositories, localRepository ); - artifactResolver.resolve( pom, remoteRepositories, localRepository ); - MavenProject project = projectBuilder.buildWithDependencies( pom.getFile(), localRepository, null ); + Artifact jar = artifactResolver.resolveArtifact( pbr, toArtifactCoordinate( pd, "jar" ) ).getArtifact(); + Artifact pom = artifactResolver.resolveArtifact( pbr, toArtifactCoordinate( pd, "pom" ) ).getArtifact(); + MavenProject project = projectBuilder.build( pom.getFile(), pbr ).getProject(); urls.add( jar.getFile().toURI().toURL() ); for ( Object artifact : project.getCompileClasspathElements() ) { @@ -1142,12 +1024,25 @@ public class DescribeMojo } catch ( Exception e ) { - getLog().warn( "Couldn't identify if this goal is a report goal.", e ); + getLog().warn( "Couldn't identify if this goal is a report goal: " + e.getMessage() ); return false; } } /** + * Transforms the given plugin descriptor into an artifact coordinate. It is formed by its GAV information, along + * with the given type. + * + * @param pd Plugin descriptor. + * @param type Extension for the coordinate. + * @return Coordinate of an artifact having the same GAV as the given plugin descriptor, with the given type. + */ + private ArtifactCoordinate toArtifactCoordinate( PluginDescriptor pd, String type ) + { + return getArtifactCoordinate( pd.getGroupId(), pd.getArtifactId(), pd.getVersion(), type ); + } + + /** * Gets the effective string to use for the plugin/mojo/parameter description. * * @param description The description of the element, may be <code>null</code>. @@ -1157,7 +1052,7 @@ public class DescribeMojo { if ( StringUtils.isNotEmpty( description ) ) { - return PluginUtils.toText( description ); + return GeneratorUtils.toText( description ); } return "(no description available)"; @@ -1176,12 +1071,6 @@ public class DescribeMojo private String version; - private String mojo; - - private Plugin plugin; - - private PluginDescriptor pluginDescriptor; - /** * @return the prefix */ @@ -1246,52 +1135,5 @@ public class DescribeMojo this.version = version; } - /** - * @return the mojo - */ - public String getMojo() - { - return mojo; - } - - /** - * @param mojo the mojo to set - */ - public void setMojo( String mojo ) - { - this.mojo = mojo; - } - - /** - * @return the plugin - */ - public Plugin getPlugin() - { - return plugin; - } - - /** - * @param plugin the plugin to set - */ - public void setPlugin( Plugin plugin ) - { - this.plugin = plugin; - } - - /** - * @return the pluginDescriptor - */ - public PluginDescriptor getPluginDescriptor() - { - return pluginDescriptor; - } - - /** - * @param pluginDescriptor the pluginDescriptor to set - */ - public void setPluginDescriptor( PluginDescriptor pluginDescriptor ) - { - this.pluginDescriptor = pluginDescriptor; - } } }
Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java Fri Nov 11 17:13:13 2016 @@ -19,8 +19,6 @@ package org.apache.maven.plugins.help; * under the License. */ -import static org.apache.maven.plugins.help.HelpUtil.LS; - import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.plugin.MojoExecutionException; @@ -74,11 +72,11 @@ public class EffectivePomMojo /** * The artifact for which to display the effective POM. - * <br/> + * <br> * <b>Note</b>: Should respect the Maven format, i.e. <code>groupId:artifactId[:version]</code>. The * latest version of the artifact will be used when no version is specified. * - * @since 2.2.1 + * @since 3.0.0 */ @Parameter( property = "artifact" ) private String artifact; @@ -135,10 +133,7 @@ public class EffectivePomMojo throw new MojoExecutionException( "Cannot write effective-POM to output: " + output, e ); } - if ( getLog().isInfoEnabled() ) - { - getLog().info( "Effective-POM written to: " + output ); - } + getLog().info( "Effective-POM written to: " + output ); } else { @@ -150,10 +145,7 @@ public class EffectivePomMojo message.append( effectivePom ); message.append( LS ); - if ( getLog().isInfoEnabled() ) - { - getLog().info( message.toString() ); - } + getLog().info( message.toString() ); } } Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java Fri Nov 11 17:13:13 2016 @@ -19,7 +19,13 @@ package org.apache.maven.plugins.help; * under the License. */ -import static org.apache.maven.plugins.help.HelpUtil.LS; +import java.io.IOException; +import java.io.StringWriter; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; @@ -35,14 +41,6 @@ import org.codehaus.plexus.util.xml.Pret import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; -import java.io.IOException; -import java.io.StringWriter; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance * of the global settings into the user-level settings. @@ -114,10 +112,7 @@ public class EffectiveSettingsMojo throw new MojoExecutionException( "Cannot write effective-settings to output: " + output, e ); } - if ( getLog().isInfoEnabled() ) - { - getLog().info( "Effective-settings written to: " + output ); - } + getLog().info( "Effective-settings written to: " + output ); } else { @@ -127,10 +122,7 @@ public class EffectiveSettingsMojo message.append( effectiveSettings ); message.append( LS ); - if ( getLog().isInfoEnabled() ) - { - getLog().info( message.toString() ); - } + getLog().info( message.toString() ); } } Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java Fri Nov 11 17:13:13 2016 @@ -19,8 +19,6 @@ package org.apache.maven.plugins.help; * under the License. */ -import static org.apache.maven.plugins.help.HelpUtil.LS; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -35,11 +33,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarInputStream; import org.apache.commons.lang3.ClassUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; @@ -51,11 +45,14 @@ import org.apache.maven.plugin.descripto import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.project.path.PathTranslator; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.settings.Settings; import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; +import org.apache.maven.shared.artifact.ArtifactCoordinate; +import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.components.interactivity.InputHandler; import org.codehaus.plexus.util.IOUtil; @@ -88,20 +85,10 @@ public class EvaluateMojo private InputHandler inputHandler; /** + * Component used to get mojo descriptors. */ @Component - private PathTranslator pathTranslator; - - /** - * Artifact Resolver component. - */ - @Component - private ArtifactResolver resolver; - - /** - */ - @Component - private LoggerRetriever loggerRetriever; + private MojoDescriptorCreator mojoDescriptorCreator; // ---------------------------------------------------------------------- // Mojo parameters @@ -114,7 +101,7 @@ public class EvaluateMojo * <br/> * <b>Note</b>: Could be a relative path. * - * @since 2.2.1 + * @since 3.0.0 */ @Parameter( property = "output" ) private File output; @@ -138,19 +125,13 @@ public class EvaluateMojo * Maven project built from the given {@link #artifact}. Otherwise, the current Maven project or the super pom. */ @Parameter( defaultValue = "${project}", readonly = true, required = true ) - protected MavenProject project; + private MavenProject project; /** * The system settings for Maven. */ @Parameter( defaultValue = "${settings}", readonly = true, required = true ) - protected Settings settings; - - /** - * The current Maven session. - */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) - private MavenSession session; + private Settings settings; // ---------------------------------------------------------------------- // Instance variables @@ -238,26 +219,30 @@ public class EvaluateMojo * @return a lazy loading evaluator object. * @throws MojoExecutionException if any * @throws MojoFailureException if any reflection exceptions occur or missing components. - * @see #getMojoDescriptor(String, MavenSession, MavenProject, String, boolean, boolean) */ private PluginParameterExpressionEvaluator getEvaluator() throws MojoExecutionException, MojoFailureException { if ( evaluator == null ) { - MojoDescriptor mojoDescriptor = - HelpUtil.getMojoDescriptor( "help:evaluate", session, project, "help:evaluate", true, false ); + MojoDescriptor mojoDescriptor; + try + { + mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( "help:evaluate", session, project ); + } + catch ( Exception e ) + { + throw new MojoFailureException( "Failure while evaluating.", e ); + } MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); MavenProject currentProject = session.getCurrentProject(); - // Maven3: PluginParameterExpressionEvaluator ignores the project parameter and gets the current project - // from the session: synchronize in case another thread wants to fetch the real current project in between + // Maven 3: PluginParameterExpressionEvaluator gets the current project from the session: + // synchronize in case another thread wants to fetch the real current project in between synchronized ( session ) { session.setCurrentProject( project ); - evaluator = new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, - loggerRetriever.getLogger(), project, - session.getExecutionProperties() ); + evaluator = new PluginParameterExpressionEvaluator( session, mojoExecution ); session.setCurrentProject( currentProject ); } } @@ -486,18 +471,11 @@ public class EvaluateMojo getLog().debug( "MojoExecutionException: " + e.getMessage(), e ); } } - catch ( ArtifactResolutionException e ) + catch ( ArtifactResolverException e ) { if ( getLog().isDebugEnabled() ) { - getLog().debug( "ArtifactResolutionException: " + e.getMessage(), e ); - } - } - catch ( ArtifactNotFoundException e ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "ArtifactNotFoundException: " + e.getMessage(), e ); + getLog().debug( "ArtifactResolverException: " + e.getMessage(), e ); } } catch ( ProjectBuildingException e ) @@ -572,12 +550,10 @@ public class EvaluateMojo * @return the <code>org.apache.maven:maven-model</code> artifact jar file in the local repository. * @throws MojoExecutionException if any * @throws ProjectBuildingException if any - * @throws ArtifactResolutionException if any - * @throws ArtifactNotFoundException if any + * @throws ArtifactResolverException if any */ private File getMavenModelJarFile() - throws MojoExecutionException, ProjectBuildingException, ArtifactResolutionException, - ArtifactNotFoundException + throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException { return getArtifactFile( true ); } @@ -586,32 +562,26 @@ public class EvaluateMojo * @return the <code>org.apache.maven:maven-settings</code> artifact jar file in the local repository. * @throws MojoExecutionException if any * @throws ProjectBuildingException if any - * @throws ArtifactResolutionException if any - * @throws ArtifactNotFoundException if any + * @throws ArtifactResolverException if any */ private File getMavenSettingsJarFile() - throws MojoExecutionException, ProjectBuildingException, ArtifactResolutionException, - ArtifactNotFoundException + throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException { return getArtifactFile( false ); } /** - * - * @param isPom <code>true</code> to lookup the <code>maven-model</code> artifact jar, <code>false</code> to - * lookup the <code>maven-settings</code> artifact jar. + * @param isPom <code>true</code> to lookup the <code>maven-model</code> artifact jar, <code>false</code> to lookup + * the <code>maven-settings</code> artifact jar. * @return the <code>org.apache.maven:maven-model|maven-settings</code> artifact jar file for this current - * HelpPlugin pom. + * HelpPlugin pom. * @throws MojoExecutionException if any * @throws ProjectBuildingException if any - * @throws ArtifactResolutionException if any - * @throws ArtifactNotFoundException if any + * @throws ArtifactResolverException if any */ private File getArtifactFile( boolean isPom ) - throws MojoExecutionException, ProjectBuildingException, ArtifactResolutionException, - ArtifactNotFoundException + throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException { - @SuppressWarnings( "unchecked" ) List<Dependency> dependencies = getHelpPluginPom().getDependencies(); for ( Dependency depependency : dependencies ) { @@ -635,12 +605,12 @@ public class EvaluateMojo } } - Artifact mavenArtifact = - getArtifact( depependency.getGroupId() + ":" + depependency.getArtifactId() + ":" - + depependency.getVersion() ); - resolver.resolveAlways( mavenArtifact, remoteRepositories, localRepository ); - - return mavenArtifact.getFile(); + ArtifactCoordinate coordinate = + getArtifactCoordinate( depependency.getGroupId(), depependency.getArtifactId(), + depependency.getVersion(), "jar" ); + ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() ); + pbr.setRemoteRepositories( remoteRepositories ); + return artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact().getFile(); } throw new MojoExecutionException( "Unable to find the 'org.apache.maven:" Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/SystemMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/SystemMojo.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/SystemMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/SystemMojo.java Fri Nov 11 17:13:13 2016 @@ -19,8 +19,6 @@ package org.apache.maven.plugins.help; * under the License. */ -import static org.apache.maven.plugins.help.HelpUtil.LS; - import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; @@ -67,11 +65,10 @@ public class SystemMojo message.append( StringUtils.repeat( "=", LINE_LENGTH ) ).append( LS ); Properties systemProperties = System.getProperties(); - for ( Object o1 : systemProperties.keySet() ) + for ( String key : systemProperties.stringPropertyNames() ) { - String key = o1.toString(); message.append( LS ); - message.append( key ).append( "=" ).append( systemProperties.get( key ) ); + message.append( key ).append( "=" ).append( systemProperties.getProperty( key ) ); } message.append( LS ).append( LS ); @@ -81,19 +78,15 @@ public class SystemMojo try { Properties envVars = CommandLineUtils.getSystemEnvVars(); - for ( Object o : envVars.keySet() ) + for ( String key : envVars.stringPropertyNames() ) { - String key = o.toString(); message.append( LS ); - message.append( key ).append( "=" ).append( envVars.get( key ) ); + message.append( key ).append( "=" ).append( envVars.getProperty( key ) ); } } catch ( IOException e ) { - if ( getLog().isWarnEnabled() ) - { - getLog().warn( "IOException: " + e.getMessage() ); - } + getLog().warn( "Unable to get the environment variables: " + e.getMessage() ); } message.append( LS ); @@ -115,17 +108,11 @@ public class SystemMojo throw new MojoExecutionException( "Cannot write system report to output: " + output, e ); } - if ( getLog().isInfoEnabled() ) - { - getLog().info( "System report written to: " + output ); - } + getLog().info( "System report written to: " + output ); } else { - if ( getLog().isInfoEnabled() ) - { - getLog().info( message ); - } + getLog().info( message ); } } } Modified: maven/plugins/trunk/maven-help-plugin/src/site/apt/examples/describe-configuration.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/site/apt/examples/describe-configuration.apt?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/site/apt/examples/describe-configuration.apt (original) +++ maven/plugins/trunk/maven-help-plugin/src/site/apt/examples/describe-configuration.apt Fri Nov 11 17:13:13 2016 @@ -226,10 +226,6 @@ help:evaluate interactive mode. Deprecated. No reason given -help:expressions - Description: Displays the supported Plugin expressions used by Maven. - Deprecated. No reason given - help:help Description: Display help information on maven-help-plugin. Call Modified: maven/plugins/trunk/maven-help-plugin/src/site/apt/index.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/site/apt/index.apt.vm?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/site/apt/index.apt.vm (original) +++ maven/plugins/trunk/maven-help-plugin/src/site/apt/index.apt.vm Fri Nov 11 17:13:13 2016 @@ -36,7 +36,7 @@ ${project.name} * Goals Overview - The Help Plugin has 8 goals: + The Help Plugin has 7 goals: * {{{./active-profiles-mojo.html}help:active-profiles}} lists the profiles which are currently active for the build. @@ -53,13 +53,18 @@ ${project.name} * {{{./evaluate-mojo.html}help:evaluate}} evaluates Maven expressions given by the user in an interactive mode. - * {{{./expressions-mojo.html}help:expressions}} displays the supported Plugin expressions used by Maven. - * {{{./system-mojo.html}help:system}} displays a list of the platform details like system properties and environment variables. [] +* Major Version Upgrade to version 3.0.0 + + Please note that the goal <<<expressions>>> has been completely removed from the plugin. All the Maven expressions + that are supported as plugin parameters are available in the Javadoc of the + {{{/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html} + <<<PluginParameterExpressionEvaluator>>>}} class. + * Usage General instructions on how to use the Help Plugin can be found on the {{{./usage.html}usage page}}. Some more Modified: maven/plugins/trunk/maven-help-plugin/src/site/apt/usage.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/site/apt/usage.apt?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/site/apt/usage.apt (original) +++ maven/plugins/trunk/maven-help-plugin/src/site/apt/usage.apt Fri Nov 11 17:13:13 2016 @@ -120,36 +120,6 @@ Usage <<Note>>: you could also use the <<<output>>> parameter to redirect output to a file. -* The <<<expressions>>> Goal - - When you develop a new Maven Plugin, you could need to use some expressions given by Maven. To list them, just call - the {{{./expressions-mojo.html}expressions}} goal: - -+-----+ -# mvn help:expressions -... -[INFO] [help:expressions] -[INFO] Maven supports the following Plugin expressions: - -${project}: No description available. - -${settings}: No description available. - -${session}: No description available. - -${plugin}: No description available. - -${rootless}: No description available. - -${settings.interactiveMode}: If false, flags the system to skip prompting the -user for any information, or holding up the build waiting for any input. NOTE: -It's also possible to switch to batch (ie. non-interactive) mode using the '-B' -command-line option. -... -+-----+ - - <<Note>>: you could also use the <<<output>>> parameter to redirect output to a file. - * The <<<help:evaluate>>> Goal You could use this interactive goal to evaluate some Maven expressions. To do it, just call the @@ -173,5 +143,6 @@ null object or invalid expression The <<<artifact>>> parameter refers to ask expressions on the artifact POM. If omitted, the evaluate goal uses the current pom. - You could ask for all Maven expressions listed by <<<help:expressions>>> goal, i.e. $\{project\}, $\{project.licenses\}, - $\{settings\}, $\{settings.profiles\}. + You could ask for all Maven expressions listed in the Javadoc of the + {{{/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html} + <<<PluginParameterExpressionEvaluator>>>}} class. Added: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java?rev=1769319&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java (added) +++ maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java Fri Nov 11 17:13:13 2016 @@ -0,0 +1,133 @@ +package org.apache.maven.plugins.help; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.IOUtil; + +/** + * Test class for the active-profiles mojo of the Help Plugin. + */ +public class ActiveProfilesMojoTest + extends AbstractMojoTestCase +{ + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + } + + /** + * Tests that profiles activated in the settings are resolved. + * + * @throws Exception in case of errors. + */ + public void testActiveProfilesFromSettings() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/active-profiles/plugin-config.xml" ); + + ActiveProfilesMojo mojo = (ActiveProfilesMojo) lookupMojo( "active-profiles", testPom ); + + MavenProject project = mock( MavenProject.class ); + when( project.getInjectedProfileIds() ).thenReturn( getProfiles( Arrays.asList( "from-settings" ), + Collections.<String>emptyList() ) ); + + setUpMojo( mojo, Arrays.asList( project ), "from-settings.txt" ); + + mojo.execute(); + + String file = readFile( "from-settings.txt" ); + assertTrue( file.contains( "from-settings (source: external)" ) ); + } + + /** + * Tests that profiles activated in the POM are resolved. + * + * @throws Exception in case of errors. + */ + public void testActiveProfilesFromPom() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/active-profiles/plugin-config.xml" ); + + ActiveProfilesMojo mojo = (ActiveProfilesMojo) lookupMojo( "active-profiles", testPom ); + + MavenProject project = mock( MavenProject.class ); + when( project.getInjectedProfileIds() ).thenReturn( getProfiles( Collections.<String>emptyList(), + Arrays.asList( "from-pom" ) ) ); + + setUpMojo( mojo, Arrays.asList( project ), "from-pom.txt" ); + + mojo.execute(); + + String file = readFile( "from-pom.txt" ); + assertTrue( file.contains( "from-pom (source: org.apache.maven.test:test:1.0)" ) ); + } + + private Map<String, List<String>> getProfiles( List<String> externals, List<String> pom ) + { + Map<String, List<String>> profiles = new HashMap<String, List<String>>(); + profiles.put( "external", externals ); // from settings + profiles.put( "org.apache.maven.test:test:1.0", pom ); // from POM + profiles.put( "", Collections.<String>emptyList() ); // from super POM + return profiles; + } + + private void setUpMojo( ActiveProfilesMojo mojo, List<MavenProject> projects, String output ) + throws IllegalAccessException + { + setVariableValueToObject( mojo, "projects", projects ); + setVariableValueToObject( mojo, "output", + new File( getBasedir(), "target/test-classes/unit/active-profiles/" + output ) ); + } + + private String readFile( String path ) + throws FileNotFoundException, IOException + { + FileInputStream fis = null; + try + { + fis = new FileInputStream( new File( getBasedir(), "target/test-classes/unit/active-profiles/" + path ) ); + return IOUtil.toString( fis ); + } + finally + { + IOUtil.close( fis ); + } + } + +} Propchange: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java?rev=1769319&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java (added) +++ maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java Fri Nov 11 17:13:13 2016 @@ -0,0 +1,194 @@ +package org.apache.maven.plugins.help; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.model.Profile; +import org.apache.maven.monitor.logging.DefaultLog; +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.LoggerManager; +import org.codehaus.plexus.util.IOUtil; + +/** + * Test class for the all-profiles mojo of the Help Plugin. + */ +public class AllProfilesMojoTest + extends AbstractMojoTestCase +{ + + private InterceptingLog interceptingLogger; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + interceptingLogger = + new InterceptingLog( getContainer().lookup( LoggerManager.class ).getLoggerForComponent( Mojo.ROLE ) ); + } + + /** + * Tests the case when no profiles are present for the projects. + * + * @throws Exception in case of errors. + */ + public void testNoProfiles() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml" ); + + AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo( "all-profiles", testPom ); + + setUpMojo( mojo, Arrays.<MavenProject>asList( new MavenProjectStub() ), + Collections.<org.apache.maven.settings.Profile>emptyList(), "empty.txt" ); + + mojo.execute(); + + assertTrue( interceptingLogger.warnLogs.contains( "No profiles detected!" ) ); + } + + /** + * Tests the case when profiles are present in the POM and in a parent POM. + * + * @throws Exception in case of errors. + */ + public void testProfileFromPom() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml" ); + + AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo( "all-profiles", testPom ); + + MavenProjectStub project = new MavenProjectStub(); + project.getModel().setProfiles( Arrays.asList( newPomProfile( "pro-1", "pom" ), newPomProfile( "pro-2", "pom" ) ) ); + project.setParent( new MavenProjectStub() ); + project.getParent().getModel().setProfiles( Arrays.asList( newPomProfile( "pro-3", "pom" ) ) ); + project.setActiveProfiles( Arrays.asList( newPomProfile( "pro-1", "pom" ) ) ); + + setUpMojo( mojo, Arrays.<MavenProject>asList( project ), + Collections.<org.apache.maven.settings.Profile>emptyList(), "profiles-from-pom.txt" ); + + mojo.execute(); + + String file = readFile( "profiles-from-pom.txt" ); + assertTrue( file.contains( "Profile Id: pro-1 (Active: true , Source: pom)" ) ); + assertTrue( file.contains( "Profile Id: pro-2 (Active: false , Source: pom)" ) ); + assertTrue( file.contains( "Profile Id: pro-3 (Active: false , Source: pom)" ) ); + } + + /** + * Tests the case when profiles are present in the settings. + * + * @throws Exception in case of errors. + */ + public void testProfileFromSettings() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml" ); + + AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo( "all-profiles", testPom ); + + MavenProject project = new MavenProjectStub(); + project.setActiveProfiles( Arrays.asList( newPomProfile( "settings-1", "settings.xml" ) ) ); + + List<org.apache.maven.settings.Profile> settingsProfiles = new ArrayList<org.apache.maven.settings.Profile>(); + settingsProfiles.add( newSettingsProfile( "settings-1" ) ); + settingsProfiles.add( newSettingsProfile( "settings-2" ) ); + setUpMojo( mojo, Arrays.<MavenProject>asList( project ), settingsProfiles, "profiles-from-settings.txt" ); + + mojo.execute(); + + String file = readFile( "profiles-from-settings.txt" ); + assertTrue( file.contains( "Profile Id: settings-1 (Active: true , Source: settings.xml)" ) ); + assertTrue( file.contains( "Profile Id: settings-2 (Active: false , Source: settings.xml)" ) ); + } + + private Profile newPomProfile( String id, String source ) + { + Profile profile = new Profile(); + profile.setId( id ); + profile.setSource( source ); + return profile; + } + + private org.apache.maven.settings.Profile newSettingsProfile( String id ) + { + org.apache.maven.settings.Profile profile = new org.apache.maven.settings.Profile(); + profile.setId( id ); + return profile; + } + + private void setUpMojo( AllProfilesMojo mojo, List<MavenProject> projects, + List<org.apache.maven.settings.Profile> settingsProfiles, String output ) + throws IllegalAccessException + { + setVariableValueToObject( mojo, "projects", projects ); + setVariableValueToObject( mojo, "settingsProfiles", settingsProfiles ); + setVariableValueToObject( mojo, "output", + new File( getBasedir(), "target/test-classes/unit/active-profiles/" + output ) ); + setVariableValueToObject( mojo, "log", interceptingLogger ); + } + + private String readFile( String path ) + throws FileNotFoundException, IOException + { + FileInputStream fis = null; + try + { + fis = new FileInputStream( new File( getBasedir(), "target/test-classes/unit/active-profiles/" + path ) ); + return IOUtil.toString( fis ); + } + finally + { + IOUtil.close( fis ); + } + } + + private static final class InterceptingLog + extends DefaultLog + { + List<String> warnLogs = new ArrayList<String>(); + + public InterceptingLog( Logger logger ) + { + super( logger ); + } + + @Override + public void warn( CharSequence content ) + { + super.warn( content ); + warnLogs.add( content.toString() ); + } + } + +} Propchange: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java Fri Nov 11 17:13:13 2016 @@ -19,13 +19,29 @@ package org.apache.maven.plugins.help; * under the License. */ +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; +import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.version.PluginVersionRequest; +import org.apache.maven.plugin.version.PluginVersionResolver; +import org.apache.maven.plugin.version.PluginVersionResult; +import org.apache.maven.plugins.help.DescribeMojo.PluginInfo; +import org.apache.maven.reporting.exec.MavenPluginManagerHelper; +import org.mockito.ArgumentCaptor; import junit.framework.Assert; import junit.framework.TestCase; import junitx.util.PrivateAccessor; - /** * @author <a href="mailto:vincent.sive...@gmail.com">Vincent Siveton</a> * @version $Id$ @@ -112,5 +128,235 @@ public class DescribeMojoTest } } + + public void testParsePluginInfoGAV() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PrivateAccessor.setField( mojo, "groupId", "org.test" ); + PrivateAccessor.setField( mojo, "artifactId", "test" ); + PrivateAccessor.setField( mojo, "version", "1.0" ); + PluginInfo pi = (PluginInfo) PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + assertEquals( pi.getGroupId(), "org.test" ); + assertEquals( pi.getArtifactId(), "test" ); + assertEquals( pi.getVersion(), "1.0" ); + assertNull( pi.getPrefix() ); + } + + public void testParsePluginInfoPluginPrefix() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PrivateAccessor.setField( mojo, "plugin", "help" ); + PluginInfo pi = (PluginInfo) PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + assertNull( pi.getGroupId() ); + assertNull( pi.getArtifactId() ); + assertNull( pi.getVersion() ); + assertEquals( "help", pi.getPrefix() ); + + PrivateAccessor.setField( mojo, "plugin", "help2:::" ); + pi = (PluginInfo) PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + assertEquals( "help2", pi.getPrefix() ); + } + + public void testParsePluginInfoPluginGA() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PrivateAccessor.setField( mojo, "plugin", "org.test:test" ); + PluginInfo pi = (PluginInfo) PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + assertEquals( "org.test", pi.getGroupId() ); + assertEquals( "test", pi.getArtifactId() ); + assertNull( pi.getVersion() ); + assertNull( pi.getPrefix() ); + } + + public void testParsePluginInfoPluginGAV() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PrivateAccessor.setField( mojo, "plugin", "org.test:test:1.0" ); + PluginInfo pi = (PluginInfo) PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + assertEquals( "org.test", pi.getGroupId() ); + assertEquals( "test", pi.getArtifactId() ); + assertEquals( "1.0", pi.getVersion() ); + assertNull( pi.getPrefix() ); + } + + public void testParsePluginInfoPluginIncorrect() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PrivateAccessor.setField( mojo, "plugin", "org.test:test:1.0:invalid" ); + try + { + PrivateAccessor.invoke( mojo, "parsePluginLookupInfo", null, null ); + fail(); + } + catch ( Exception e ) + { + // expected + } + } + + public void testLookupPluginDescriptorPrefixWithVersion() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + + PluginInfo pi = new PluginInfo(); + pi.setPrefix( "help" ); + pi.setVersion( "1.0" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( "org.test" ); + plugin.setArtifactId( "test" ); + + PluginDescriptor pd = new PluginDescriptor(); + + MojoDescriptorCreator mojoDescriptorCreator = mock( MojoDescriptorCreator.class ); + PluginVersionResolver pluginVersionResolver = mock( PluginVersionResolver.class ); + MavenPluginManagerHelper pluginManager = mock( MavenPluginManagerHelper.class ); + MavenSession session = mock( MavenSession.class ); + PrivateAccessor.setField( mojo, "mojoDescriptorCreator", mojoDescriptorCreator ); + PrivateAccessor.setField( mojo, "pluginVersionResolver", pluginVersionResolver ); + PrivateAccessor.setField( mojo, "pluginManager", pluginManager ); + PrivateAccessor.setField( mojo, "session", session ); + when( mojoDescriptorCreator.findPluginForPrefix( "help", session ) ).thenReturn( plugin ); + when( pluginManager.getPluginDescriptor( any( Plugin.class ), eq( session ) ) ).thenReturn( pd ); + + PluginDescriptor returned = + (PluginDescriptor) PrivateAccessor.invoke( mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, + new Object[] { pi } ); + assertEquals( pd, returned ); + + verify( mojoDescriptorCreator ).findPluginForPrefix( "help", session ); + verify( pluginVersionResolver, never() ).resolve( any( PluginVersionRequest.class ) ); + ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass( Plugin.class ); + verify( pluginManager ).getPluginDescriptor( argument.capture(), eq( session ) ); + Plugin capturedPlugin = argument.getValue(); + assertEquals( "org.test", capturedPlugin.getGroupId() ); + assertEquals( "test", capturedPlugin.getArtifactId() ); + assertEquals( "1.0", capturedPlugin.getVersion() ); + } + + public void testLookupPluginDescriptorPrefixWithoutVersion() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + + PluginInfo pi = new PluginInfo(); + pi.setPrefix( "help" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( "org.test" ); + plugin.setArtifactId( "test" ); + + PluginDescriptor pd = new PluginDescriptor(); + + MojoDescriptorCreator mojoDescriptorCreator = mock( MojoDescriptorCreator.class ); + PluginVersionResolver pluginVersionResolver = mock( PluginVersionResolver.class ); + MavenPluginManagerHelper pluginManager = mock( MavenPluginManagerHelper.class ); + PluginVersionResult versionResult = mock( PluginVersionResult.class ); + MavenSession session = mock( MavenSession.class ); + PrivateAccessor.setField( mojo, "mojoDescriptorCreator", mojoDescriptorCreator ); + PrivateAccessor.setField( mojo, "pluginVersionResolver", pluginVersionResolver ); + PrivateAccessor.setField( mojo, "pluginManager", pluginManager ); + PrivateAccessor.setField( mojo, "session", session ); + when( mojoDescriptorCreator.findPluginForPrefix( "help", session ) ).thenReturn( plugin ); + when( pluginVersionResolver.resolve( any( PluginVersionRequest.class ) ) ).thenReturn( versionResult ); + when( versionResult.getVersion() ).thenReturn( "1.0" ); + when( pluginManager.getPluginDescriptor( any( Plugin.class ), eq( session ) ) ).thenReturn( pd ); + + PluginDescriptor returned = + (PluginDescriptor) PrivateAccessor.invoke( mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, + new Object[] { pi } ); + assertEquals( pd, returned ); + + verify( mojoDescriptorCreator ).findPluginForPrefix( "help", session ); + ArgumentCaptor<PluginVersionRequest> versionArgument = ArgumentCaptor.forClass( PluginVersionRequest.class ); + verify( pluginVersionResolver ).resolve( versionArgument.capture() ); + assertEquals( "org.test", versionArgument.getValue().getGroupId() ); + assertEquals( "test", versionArgument.getValue().getArtifactId() ); + ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass( Plugin.class ); + verify( pluginManager ).getPluginDescriptor( argument.capture(), eq( session ) ); + Plugin capturedPlugin = argument.getValue(); + assertEquals( "org.test", capturedPlugin.getGroupId() ); + assertEquals( "test", capturedPlugin.getArtifactId() ); + assertEquals( "1.0", capturedPlugin.getVersion() ); + } + + public void testLookupPluginDescriptorGAV() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + + PluginInfo pi = new PluginInfo(); + pi.setGroupId( "org.test" ); + pi.setArtifactId( "test" ); + pi.setVersion( "1.0" ); + + PluginDescriptor pd = new PluginDescriptor(); + + MojoDescriptorCreator mojoDescriptorCreator = mock( MojoDescriptorCreator.class ); + PluginVersionResolver pluginVersionResolver = mock( PluginVersionResolver.class ); + MavenPluginManagerHelper pluginManager = mock( MavenPluginManagerHelper.class ); + MavenSession session = mock( MavenSession.class ); + PrivateAccessor.setField( mojo, "mojoDescriptorCreator", mojoDescriptorCreator ); + PrivateAccessor.setField( mojo, "pluginVersionResolver", pluginVersionResolver ); + PrivateAccessor.setField( mojo, "pluginManager", pluginManager ); + PrivateAccessor.setField( mojo, "session", session ); + when( pluginManager.getPluginDescriptor( any( Plugin.class ), eq( session ) ) ).thenReturn( pd ); + + PluginDescriptor returned = + (PluginDescriptor) PrivateAccessor.invoke( mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, + new Object[] { pi } ); + assertEquals( pd, returned ); + + verify( mojoDescriptorCreator, never() ).findPluginForPrefix( any( String.class ), any( MavenSession.class ) ); + verify( pluginVersionResolver, never() ).resolve( any( PluginVersionRequest.class ) ); + ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass( Plugin.class ); + verify( pluginManager ).getPluginDescriptor( argument.capture(), eq( session ) ); + Plugin capturedPlugin = argument.getValue(); + assertEquals( "org.test", capturedPlugin.getGroupId() ); + assertEquals( "test", capturedPlugin.getArtifactId() ); + assertEquals( "1.0", capturedPlugin.getVersion() ); + } + + public void testLookupPluginDescriptorGMissingA() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PluginInfo pi = new PluginInfo(); + pi.setGroupId( "org.test" ); + try + { + PrivateAccessor.invoke( mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, + new Object[] { pi } ); + fail(); + } + catch ( Exception e ) + { + assertTrue( e.getMessage().startsWith( "You must specify either" ) ); + } + } + + public void testLookupPluginDescriptorAMissingG() + throws Throwable + { + DescribeMojo mojo = new DescribeMojo(); + PluginInfo pi = new PluginInfo(); + pi.setArtifactId( "test" ); + try + { + PrivateAccessor.invoke( mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, + new Object[] { pi } ); + fail(); + } + catch ( Exception e ) + { + assertTrue( e.getMessage().startsWith( "You must specify either" ) ); + } + } } Modified: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java?rev=1769319&r1=1769318&r2=1769319&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java Fri Nov 11 17:13:13 2016 @@ -38,6 +38,7 @@ import org.apache.maven.settings.Setting import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.components.interactivity.InputHandler; import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.LoggerManager; /** * Test class for the evaluate mojo of the Help Plugin. @@ -53,7 +54,8 @@ public class EvaluateMojoTest throws Exception { super.setUp(); - interceptingLogger = new InterceptingLog( getContainer().getLoggerManager().getLoggerForComponent( Mojo.ROLE ) ); + interceptingLogger = + new InterceptingLog( getContainer().lookup( LoggerManager.class ).getLoggerForComponent( Mojo.ROLE ) ); } /** Added: maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml?rev=1769319&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml (added) +++ maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml Fri Nov 11 17:13:13 2016 @@ -0,0 +1,37 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.its.help</groupId> + <artifactId>active-profiles</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <url>http://maven.apache.org</url> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-help-plugin</artifactId> + <configuration> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/test/resources/unit/active-profiles/plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision