Skip to content

Commit 6dfce8f

Browse files
Support classpath in Basedir
Allow to provide classpath in Basedir instead of path to project
1 parent 9db988a commit 6dfce8f

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public void beforeEach(ExtensionContext context) throws Exception {
146146
.map(Basedir::value)
147147
.orElseGet(PlexusExtension::getBasedir);
148148

149+
URL resource = context.getRequiredTestClass().getResource(basedir);
150+
if (resource != null) {
151+
basedir = resource.getPath();
152+
}
153+
149154
setTestBasedir(basedir, context);
150155

151156
PlexusContainer plexusContainer = getContainer(context);

maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,12 @@ void basedirInjectedWithBasedirAnnotation(ParametersMojo mojo) {
116116
assertEquals("i-have-a-basedir-set-by-annotation", mojo.getPlain());
117117
assertDoesNotThrow(mojo::execute);
118118
}
119+
120+
@Test
121+
@Basedir("/projects/basedir-set-by-annotation-classpath")
122+
@InjectMojo(goal = "parameters", pom = POM_DOT_XML_FILE)
123+
void basedirInjectedWithBasedirFromClasspathAnnotation(ParametersMojo mojo) {
124+
assertEquals("i-have-a-basedir-set-by-annotation-classpath", mojo.getPlain());
125+
assertDoesNotThrow(mojo::execute);
126+
}
119127
}

maven-plugin-testing-harness/src/test/projects/basedir-set-by-annotation/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ under the License.
3333
<groupId>test</groupId>
3434
<artifactId>test-plugin</artifactId>
3535
<version>0.0.1-SNAPSHOT</version>
36-
<executions>
37-
<execution>
38-
<id>test</id>
39-
<goals>
40-
<goal>test</goal>
41-
</goals>
42-
<phase>compile</phase>
43-
</execution>
44-
</executions>
4536
<configuration>
4637
<plain>i-have-a-basedir-set-by-annotation</plain>
4738
</configuration>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project>
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>test</groupId>
26+
<artifactId>test-test</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
<packaging>jar</packaging>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>test</groupId>
34+
<artifactId>test-plugin</artifactId>
35+
<version>0.0.1-SNAPSHOT</version>
36+
<configuration>
37+
<plain>i-have-a-basedir-set-by-annotation-classpath</plain>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
</project>

0 commit comments

Comments
 (0)