diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java index 3ea09b8..5d114b2 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java @@ -128,13 +128,11 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte @Override public void beforeEach(ExtensionContext context) throws Exception { - // TODO provide protected setters in PlexusExtension - Field field = PlexusExtension.class.getDeclaredField("basedir"); - field.setAccessible(true); String basedir = AnnotationSupport.findAnnotation(context.getElement().get(), Basedir.class) .map(Basedir::value) - .orElse(getBasedir()); - field.set(null, basedir); + .orElse(null); + + setTestBasedir(basedir); setContext(context); @@ -167,13 +165,6 @@ public void beforeEach(ExtensionContext context) throws Exception { } } - @Override - public void afterEach(ExtensionContext context) throws Exception { - Field field = PlexusExtension.class.getDeclaredField("basedir"); - field.setAccessible(true); - field.set(null, null); - } - /** * Default MojoExecution mock * @@ -210,7 +201,7 @@ private Mojo lookupMojo( String[] coord = mojoCoordinates(goal); Xpp3Dom pomDom; if (pom.startsWith("file:")) { - Path path = Paths.get(getBasedir()).resolve(pom.substring("file:".length())); + Path path = Paths.get(getTestBasedir()).resolve(pom.substring("file:".length())); pomDom = Xpp3DomBuilder.build(new XmlStreamReader(path.toFile())); } else if (pom.startsWith("classpath:")) { URL url = holder.getResource(pom.substring("classpath:".length())); @@ -221,7 +212,7 @@ private Mojo lookupMojo( } else if (pom.contains("")) { pomDom = Xpp3DomBuilder.build(new StringReader(pom)); } else { - Path path = Paths.get(getBasedir()).resolve(pom); + Path path = Paths.get(getTestBasedir()).resolve(pom); pomDom = Xpp3DomBuilder.build(new XmlStreamReader(path.toFile())); } Xpp3Dom pluginConfiguration = extractPluginConfiguration(coord[1], pomDom); @@ -245,7 +236,7 @@ protected String[] mojoCoordinates(String goal) throws Exception { if (goal.matches(".*:.*:.*:.*")) { return goal.split(":"); } else { - Path pluginPom = Paths.get(getBasedir(), "pom.xml"); + Path pluginPom = Paths.get(getTestBasedir(), "pom.xml"); Xpp3Dom pluginPomDom = Xpp3DomBuilder.build(new XmlStreamReader(pluginPom.toFile())); String artifactId = pluginPomDom.getChild("artifactId").getValue(); String groupId = resolveFromRootThenParent(pluginPomDom, "groupId");