Hi Brett,
Author: brett
Date: Tue Mar 17 02:28:26 2009
New Revision: 755086
URL: http://svn.apache.org/viewvc?rev=755086&view=rev
Log:
[MNG-4091] Validate the plugin descriptors and improve error reporting when
mismatched with artifact
Modified:
maven/components/branches/maven-2.1.0-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.0-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=755086&r1=755085&r2=755086&view=diff
==============================================================================
---
maven/components/branches/maven-2.1.0-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
(original)
+++
maven/components/branches/maven-2.1.0-RC/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
Tue Mar 17 02:28:26 2009
@@ -296,10 +298,26 @@
try
{
- child = container.createChildContainer(
PluginUtils.constructVersionedKey( plugin ).intern(),
+ MavenPluginValidator validator = new MavenPluginValidator(
pluginArtifact );
+
+ String key = PluginUtils.constructVersionedKey( plugin ).intern();
+ child = container.createChildContainer( key,
Collections.singletonList(
pluginArtifact.getFile() ),
Collections.EMPTY_MAP,
- Collections.singletonList(
pluginCollector ) );
+ Arrays.asList( new
ComponentDiscoveryListener[] { validator, pluginCollector } ) );
+
+ if ( validator.hasErrors() )
+ {
+ String msg = "Plugin '" + key + "' has an invalid descriptor:";
+ int count = 1;
+ for ( Iterator i = validator.getErrors().iterator();
i.hasNext(); )
+ {
+ msg += "\n" + count + ") " + i.next();
+ count++;
+ }
+ throw new PluginManagerException( msg );
+ }
+
For the sake of reduced heap consumption, how about unregistering the
validator right after createChildContainer() returns such that the
validator can be garbage collected?
Imagine a plugin A which depends on another plugin artifact B, like
people would do when extending mojos (see also MNG-3217). When
ensurePluginContainerIsComplete() is called, the plugin descriptor from
artifact B will be discovered and will cause the validator to create
error strings. Furtheremore, those error strings will be created n
times, where n is the total number of plugin dependencies, each
triggering an invocation of MavenPluginValidator.componentDiscovered().
Having said this, we might as well consider unregistering the plugin
collector from the plugin container in a future Maven version. We're
only interested in the descriptor from the plugin main artifact so
spontaneously I don't see a reason to still have the collector around
when the plugin container is populated with the plugin dependencies.
Benjamin
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]