From 10a192dfc23097561098edcba73318e73a59c4cc Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Sun, 16 Dec 2007 01:28:17 +0000 Subject: [PATCH] fixing error reporting for when pom file is missing, and adding deprecated-mojo and deprecated-mojo-param warnings. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@604538 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/CoreDebuggingAspect.aj | 17 ++++++ .../maven/errors/CoreReporterDebugAspect.aj | 11 +--- .../errors/LifecycleErrorReporterAspect.aj | 13 +++-- .../java/org/apache/maven/DefaultMaven.java | 13 +---- .../errors/DefaultCoreErrorReporter.java | 6 ++- .../maven/plugin/DefaultPluginManager.java | 53 +++++++++++++++++++ .../aspect/ProjectReporterDebugAspect.aj | 4 +- 7 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj diff --git a/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj b/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj new file mode 100644 index 0000000000..8abe33070d --- /dev/null +++ b/maven-core/src/main/aspect/org/apache/maven/CoreDebuggingAspect.aj @@ -0,0 +1,17 @@ +package org.apache.maven; + +import org.apache.maven.execution.MavenExecutionRequest; + +import java.util.List; + +public aspect CoreDebuggingAspect +{ + +// after( MavenExecutionRequest request ) returning( List projects ): +// call( List DefaultMaven.getProjects( MavenExecutionRequest ) ) +// && args( request ) +// { +// System.out.println( "Got projects-list of size " + ( projects == null ? "null" : "" + projects.size() ) + ":\n\n" + projects ); +// } + +} diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/CoreReporterDebugAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/CoreReporterDebugAspect.aj index d8a8321c63..a90a55f9f1 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/CoreReporterDebugAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/CoreReporterDebugAspect.aj @@ -13,16 +13,7 @@ public privileged aspect CoreReporterDebugAspect // && target( reporter ) // { // SourceLocation location = thisJoinPoint.getSourceLocation(); -// System.out.println( "Registering: " + key.getClass().getName() + "@" + key.hashCode() + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter instance hashcode is: " + reporter.hashCode() ); -// } -// -// after() returning( Throwable key ): -// execution( Throwable CoreErrorReporter+.findReportedException( Throwable ) ) -// { -// if ( key != null ) -// { -// System.out.println( "Found reported exception: " + key.getClass().getName() + "@" + key.hashCode() ); -// } +// System.out.println( "Registering: " + key + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter is: " + reporter ); // } } diff --git a/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj b/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj index 87f0a0d494..3d6412148c 100644 --- a/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj +++ b/maven-core/src/main/aspect/org/apache/maven/errors/LifecycleErrorReporterAspect.aj @@ -42,6 +42,10 @@ public privileged aspect LifecycleErrorReporterAspect execution( void PluginManager+.executeMojo( MavenProject, .. ) ) && args( project, .. ); + private pointcut within_pm_executeMojo( MavenProject project ): + withincode( void PluginManager+.executeMojo( MavenProject, .. ) ) + && args( project, .. ); + before( MojoBinding binding, MavenProject project, LifecycleExecutionException err ): cflow( le_executeGoalAndHandleFailures( binding ) ) && execution( LifecycleExecutionException.new( String, MavenProject ) ) @@ -68,14 +72,15 @@ public privileged aspect LifecycleErrorReporterAspect getReporter().reportMojoExecutionException( binding, project, cause ); } - before( MojoBinding binding, MavenProject project, PluginExecutionException cause ): + PluginExecutionException around( MojoBinding binding, MavenProject project ): cflow( le_executeGoalAndHandleFailures( binding ) ) && cflow( pm_executeMojo( project ) ) - && !handler( MojoExecutionException ) - && execution( PluginExecutionException.new( .., String ) ) - && this( cause ) + && call( PluginExecutionException.new( .., String ) ) { + PluginExecutionException cause = proceed( binding, project ); getReporter().reportInvalidPluginExecutionEnvironment( binding, project, cause ); + + return cause; } before( MojoBinding binding, MavenProject project, ComponentLookupException cause ): diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index b445c0a570..b56fdfe23c 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -281,18 +281,7 @@ public class DefaultMaven { List projects = new ArrayList( files.size() ); - if ( files.isEmpty() ) - { - try - { - projects.add( projectBuilder.buildStandaloneSuperProject( globalProfileManager ) ); - } - catch ( ProjectBuildingException e ) - { - throw new MavenExecutionException( "Failed to build super-project instance.", e ); - } - } - else + if ( !files.isEmpty() ) { for ( Iterator iterator = files.iterator(); iterator.hasNext(); ) { diff --git a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java index 98502e03c3..fe71d77db9 100644 --- a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java +++ b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java @@ -358,10 +358,14 @@ public class DefaultCoreErrorReporter writer.write( NEWLINE ); writer.write( "The following plugin cannot function in the current build environment:" ); + writer.write( NEWLINE ); writeMojoBinding( binding, writer ); - writer.write( "Referenced from project:" ); + + writer.write( "While building project:" ); + writer.write( NEWLINE ); writeProjectCoordinate( project, writer ); + writer.write( NEWLINE ); writer.write( "Reason: " ); writer.write( cause.getMessage() ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 8966a420fa..f7cd55d5b9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -528,6 +528,11 @@ public class DefaultPluginManager + " requires online mode for execution. Maven is currently offline." ); } + if ( mojoDescriptor.getDeprecated() != null ) + { + getLogger().warn( "Mojo: " + mojoDescriptor.getGoal() + " is deprecated.\n" + mojoDescriptor.getDeprecated() ); + } + if ( mojoDescriptor.isDependencyResolutionRequired() != null ) { Collection projects; @@ -805,6 +810,8 @@ public class DefaultPluginManager mergedConfiguration, mojoDescriptor ); + checkDeprecatedParameters( mojoDescriptor, extractedMojoConfiguration ); + checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator ); populatePluginFields( mojo, mojoDescriptor, extractedMojoConfiguration, expressionEvaluator ); @@ -812,6 +819,52 @@ public class DefaultPluginManager return mojo; } + private void checkDeprecatedParameters( MojoDescriptor mojoDescriptor, + PlexusConfiguration extractedMojoConfiguration ) + { + if ( ( extractedMojoConfiguration == null ) || ( extractedMojoConfiguration.getChildCount() < 1 ) ) + { + return; + } + + List parameters = mojoDescriptor.getParameters(); + if ( ( parameters != null ) && !parameters.isEmpty() ) + { + for ( Iterator it = parameters.iterator(); it.hasNext(); ) + { + Parameter param = (Parameter) it.next(); + + if ( param.getDeprecated() != null ) + { + boolean warnOfDeprecation = false; + if ( extractedMojoConfiguration.getChild( param.getName() ) != null ) + { + warnOfDeprecation = true; + } + else if ( ( param.getAlias() != null ) && ( extractedMojoConfiguration.getChild( param.getAlias() ) != null ) ) + { + warnOfDeprecation = true; + } + + if ( warnOfDeprecation ) + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "In mojo: " ).append( mojoDescriptor.getGoal() ).append( ", parameter: " ).append( param.getName() ); + + if ( param.getAlias() != null ) + { + buffer.append( " (alias: " ).append( param.getAlias() ).append( ")" ); + } + + buffer.append( " is deprecated:" ).append( "\n\n" ).append( param.getDeprecated() ).append( "\n" ); + + getLogger().warn( buffer.toString() ); + } + } + } + } + } + private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor, MavenProject project, MavenSession session ) diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj index d49ab6c8a1..36d6f00e1f 100644 --- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj +++ b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj @@ -13,7 +13,7 @@ public privileged aspect ProjectReporterDebugAspect // && target( reporter ) // { // SourceLocation location = thisJoinPoint.getSourceLocation(); -// System.out.println( "Registering: " + key.getClass().getName() + "@" + key.hashCode() + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter is: " + reporter + "\n\nMessage:\n\n" + message ); +// System.out.println( "Registering: " + key + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter is: " + reporter + "\n\nMessage:\n\n" + message ); // } // // before(): @@ -27,7 +27,7 @@ public privileged aspect ProjectReporterDebugAspect // { // if ( key != null ) // { -// System.out.println( "Found reported exception: " + key.getClass().getName() + "@" + key.hashCode() ); +// System.out.println( "Found reported exception: " + key ); // } // }