in maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java [110:152]
public void beforeEach(ExtensionContext context) throws Exception {
Field field = PlexusExtension.class.getDeclaredField("basedir");
field.setAccessible(true);
field.set(null, getBasedir());
field = PlexusExtension.class.getDeclaredField("context");
field.setAccessible(true);
field.set(this, context);
getContainer().addComponent(getContainer(), PlexusContainer.class.getName());
((DefaultPlexusContainer) getContainer()).addPlexusInjector(Collections.emptyList(), binder -> {
binder.install(ProviderMethodsModule.forObject(context.getRequiredTestInstance()));
binder.requestInjection(context.getRequiredTestInstance());
binder.bind(Log.class).toInstance(new DefaultLog(LoggerFactory.getLogger("anonymous")));
});
Map<Object, Object> map = getContainer().getContext().getContextData();
ClassLoader classLoader = context.getRequiredTestClass().getClassLoader();
try (InputStream is = Objects.requireNonNull(
classLoader.getResourceAsStream(getPluginDescriptorLocation()),
"Unable to find plugin descriptor: " + getPluginDescriptorLocation());
Reader reader = new BufferedReader(new XmlStreamReader(is));
InterpolationFilterReader interpolationReader = new InterpolationFilterReader(reader, map, "${", "}")) {
PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationReader);
// Artifact artifact =
// lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(),
// pluginDescriptor.getArtifactId(),
// pluginDescriptor.getVersion(), ".jar" );
//
// artifact.setFile( getPluginArtifactFile() );
// pluginDescriptor.setPluginArtifact( artifact );
// pluginDescriptor.setArtifacts( Collections.singletonList( artifact ) );
context.getStore(ExtensionContext.Namespace.GLOBAL).put(PluginDescriptor.class, pluginDescriptor);
for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) {
getContainer().addComponentDescriptor(desc);
}
}
}