Skip to content

Commit

Permalink
use a BasicComponentConfigurator instead of asking plexus to inject o…
Browse files Browse the repository at this point in the history
…ne because it injects the wrong kind when debug trace is off
  • Loading branch information
mikesamuel committed Mar 10, 2016
1 parent 7b90554 commit 7cab8d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Expand Up @@ -56,15 +56,20 @@ void configure(
+ " from " + key, ex);
}

// TODO: is this right.
// TODO: Is this right?
// Newer versions have a MavenProject.getClassRealm() says
// """
// Warning: This is an internal utility method that is only public for
// technical reasons, it is not part of the public API. In particular,
// this method can be changed or deleted without prior notice and must
// not be used by plugins.
// """
// so trying to get it directly seems dodgy.
ClassRealm realm = null;
ClassLoader cl = configurable.getClass().getClassLoader();
if (cl instanceof ClassRealm) {
realm = (ClassRealm) cl;
}

try {
configurator.configureComponent(configurable, configuration, realm);
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
Expand Down Expand Up @@ -98,8 +99,18 @@ public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
treeBuilder = (DependencyTreeBuilder)
helper.getComponent(DependencyTreeBuilder.class);
configurator = (ComponentConfigurator) helper.getComponent(
ComponentConfigurator.class);
if (false) {
// This seems "the right way" since plexus is supposed to inject
// dependencies, but when run without -X to turn on debugging,
// we get a MapOrientedComponentConfigurator which cannot configure
// this object.
// http://stackoverflow.com/questions/35919157/using-xmlplexusconfiguration-to-import-more-configuration-for-a-bean-style-maven
// explains the symptoms.
configurator = (ComponentConfigurator) helper.getComponent(
ComponentConfigurator.class);
} else {
configurator = new BasicComponentConfigurator();
}
} catch (ComponentLookupException ex) {
throw new EnforcerRuleException(
"Failed to locate component: " + ex.getLocalizedMessage(), ex);
Expand Down
Expand Up @@ -144,12 +144,7 @@ public final void testImports() throws Exception {
verifyTestProject(
"test-imports-project",
Result.FAIL,
// HACK: If this is QUIET, then the test fails with an exception
// claiming the configurator is a MapOrientedConfigurator which
// expects a MapOrientedComponent to configure.
// See http://stackoverflow.com/questions/35919157
// /importing-more-maven-configuration-from-xml-files
Debug.VERBOSE,
Debug.QUIET,

"BUILD FAILURE",

Expand Down

0 comments on commit 7cab8d8

Please sign in to comment.