You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2025/10/27 16:45:34 UTC
(maven-plugin-testing) branch maven-plugin-testing-3.x updated: Support classpath in Basedir
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-plugin-testing-3.x
in repository https://gitbox.apache.org/repos/asf/maven-plugin-testing.git
The following commit(s) were added to refs/heads/maven-plugin-testing-3.x by this push:
new 77de9fa Support classpath in Basedir
77de9fa is described below
commit 77de9fadbc8a3352626fefca1622fdd8abbc95ed
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Oct 25 16:31:41 2025 +0200
Support classpath in Basedir
Allow to provide classpath in Basedir instead of path to project
---
.../org/apache/maven/api/plugin/testing/MojoExtension.java | 5 +++++
.../org/apache/maven/plugin/testing/ParametersMojoTest.java | 8 ++++++++
.../src/test/projects/basedir-set-by-annotation/pom.xml | 9 ---------
.../projects/basedir-set-by-annotation-classpath}/pom.xml | 11 +----------
4 files changed, 14 insertions(+), 19 deletions(-)
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 2697dcb..3c0f03c 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
@@ -179,6 +179,11 @@ public class MojoExtension extends PlexusExtension implements ParameterResolver
.map(Basedir::value)
.orElseGet(PlexusExtension::getBasedir);
+ URL resource = context.getRequiredTestClass().getResource(basedir);
+ if (resource != null) {
+ basedir = Paths.get(resource.toURI()).toString();
+ }
+
setTestBasedir(basedir, context);
PlexusContainer plexusContainer = getContainer(context);
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
index 4b6baed..01c286d 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
@@ -116,4 +116,12 @@ public class ParametersMojoTest {
assertEquals("i-have-a-basedir-set-by-annotation", mojo.getPlain());
assertDoesNotThrow(mojo::execute);
}
+
+ @Test
+ @Basedir("/projects/basedir-set-by-annotation-classpath")
+ @InjectMojo(goal = "parameters", pom = POM_DOT_XML_FILE)
+ void basedirInjectedWithBasedirFromClasspathAnnotation(ParametersMojo mojo) {
+ assertEquals("i-have-a-basedir-set-by-annotation-classpath", mojo.getPlain());
+ assertDoesNotThrow(mojo::execute);
+ }
}
diff --git a/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml b/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml
index 82cb188..dc5af5c 100644
--- a/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml
+++ b/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml
@@ -33,15 +33,6 @@ under the License.
<groupId>test</groupId>
<artifactId>test-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
- <executions>
- <execution>
- <id>test</id>
- <goals>
- <goal>test</goal>
- </goals>
- <phase>compile</phase>
- </execution>
- </executions>
<configuration>
<plain>i-have-a-basedir-set-by-annotation</plain>
</configuration>
diff --git a/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml b/maven-plugin-testing-harness/src/test/resources/projects/basedir-set-by-annotation-classpath/pom.xml
similarity index 81%
copy from maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml
copy to maven-plugin-testing-harness/src/test/resources/projects/basedir-set-by-annotation-classpath/pom.xml
index 82cb188..0fd819e 100644
--- a/maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml
+++ b/maven-plugin-testing-harness/src/test/resources/projects/basedir-set-by-annotation-classpath/pom.xml
@@ -33,17 +33,8 @@ under the License.
<groupId>test</groupId>
<artifactId>test-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
- <executions>
- <execution>
- <id>test</id>
- <goals>
- <goal>test</goal>
- </goals>
- <phase>compile</phase>
- </execution>
- </executions>
<configuration>
- <plain>i-have-a-basedir-set-by-annotation</plain>
+ <plain>i-have-a-basedir-set-by-annotation-classpath</plain>
</configuration>
</plugin>
</plugins>