Skip to content

Commit c22c8fe

Browse files
authored
[MJAVADOC-769] fix for transitive filename based modules (#227)
When a project depends on an artifact with a manifest entry for Automatic-Module-Name which in turn depends on an artifact that uses the filename to determine the module name, it will move the former onto the module path and patch the latter into the main artifact. However, now the direct dependency on the module path can no longer access the classes that have been patched only into the main module and javadoc generation fails. As the JDK only differentiates between modules with a module descriptor and "everything else" (modules with an automatic module entry in the manifest and modules with file name based names), the javadoc plugin should do the same. This patch changes the treatment of dependencies with an Automatic-Module-Name to match dependencies that use a filename based module name. The plugin now patches all of those dependencies into the main module and the build succeeds. Includes an integration test.
1 parent dd350ed commit c22c8fe

File tree

6 files changed

+382
-2
lines changed

6 files changed

+382
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals= clean package
19+
invoker.java.version = 9+

src/it/projects/MJAVADOC-769/pom.xml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed under the Apache License, Version 2.0 (the "License");
4+
~ you may not use this file except in compliance with the License.
5+
~ You may obtain a copy of the License at
6+
~
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~
9+
~ Unless required by applicable law or agreed to in writing, software
10+
~ distributed under the License is distributed on an "AS IS" BASIS,
11+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
~ See the License for the specific language governing permissions and
13+
~ limitations under the License.
14+
-->
15+
<project xmlns="http://maven.apache.org/POM/4.0.0"
16+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
20+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
21+
<artifactId>mjavadoc769</artifactId>
22+
<version>1.0-SNAPSHOT</version>
23+
<packaging>jar</packaging>
24+
25+
<url>https://issues.apache.org/jira/browse/MJAVADOC-769</url>
26+
27+
<properties>
28+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
<maven.compiler.source>9</maven.compiler.source>
30+
<maven.compiler.target>9</maven.compiler.target>
31+
<moduleName>mavenbugs.mjavadoc769</moduleName>
32+
</properties>
33+
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.junit</groupId>
38+
<artifactId>junit-bom</artifactId>
39+
<version>5.10.0</version>
40+
<type>pom</type>
41+
<scope>import</scope>
42+
</dependency>
43+
</dependencies>
44+
</dependencyManagement>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>com.google.inject</groupId>
49+
<artifactId>guice</artifactId>
50+
<version>5.1.0</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.google.guava</groupId>
55+
<artifactId>guava</artifactId>
56+
<version>31.1-jre</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>jakarta.inject</groupId>
61+
<artifactId>jakarta.inject-api</artifactId>
62+
<version>2.0.1.MR</version>
63+
<scope>provided</scope>
64+
<optional>true</optional>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>javax.inject</groupId>
69+
<artifactId>javax.inject</artifactId>
70+
<version>1</version>
71+
<scope>provided</scope>
72+
<optional>true</optional>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.junit.jupiter</groupId>
77+
<artifactId>junit-jupiter-api</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.junit.jupiter</groupId>
83+
<artifactId>junit-jupiter-params</artifactId>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
87+
88+
<build>
89+
<pluginManagement>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-javadoc-plugin</artifactId>
94+
<version>@project.version@</version>
95+
<configuration>
96+
<outputDirectory>${project.build.directory}/apidocs
97+
</outputDirectory>
98+
<release>11</release>
99+
<nodeprecated>false</nodeprecated>
100+
<author>false</author>
101+
<nohelp>true</nohelp>
102+
</configuration>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-jar-plugin</artifactId>
107+
<version>3.3.0</version>
108+
<executions>
109+
<execution>
110+
<id>default-jar</id>
111+
<!-- add module name to main artifact -->
112+
<configuration>
113+
<archive>
114+
<manifestEntries
115+
combine.children="append">
116+
<Automatic-Module-Name>
117+
${moduleName}
118+
</Automatic-Module-Name>
119+
</manifestEntries>
120+
</archive>
121+
</configuration>
122+
</execution>
123+
<execution>
124+
<id>test-jar</id>
125+
<!-- add module name to test artifact -->
126+
<configuration>
127+
<archive>
128+
<manifestEntries
129+
combine.children="append">
130+
<Automatic-Module-Name>
131+
${moduleName}.tests
132+
</Automatic-Module-Name>
133+
</manifestEntries>
134+
</archive>
135+
</configuration>
136+
</execution>
137+
</executions>
138+
</plugin>
139+
</plugins>
140+
</pluginManagement>
141+
<plugins>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-javadoc-plugin</artifactId>
145+
<executions>
146+
<execution>
147+
<id>javadoc-jar</id>
148+
<phase>package</phase>
149+
<goals>
150+
<goal>jar</goal>
151+
</goals>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-jar-plugin</artifactId>
158+
<executions>
159+
<execution>
160+
<id>test-jar</id>
161+
<phase>package</phase>
162+
<goals>
163+
<goal>test-jar</goal>
164+
</goals>
165+
</execution>
166+
</executions>
167+
</plugin>
168+
</plugins>
169+
</build>
170+
</project>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package mavenbugs.mjavadoc769;
2+
3+
/*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.lang.annotation.Annotation;
18+
19+
import com.google.inject.Inject;
20+
import com.google.inject.Injector;
21+
import com.google.inject.Key;
22+
import com.google.inject.Provider;
23+
import com.google.inject.Scope;
24+
import com.google.inject.TypeLiteral;
25+
import com.google.inject.binder.LinkedBindingBuilder;
26+
import com.google.inject.binder.ScopedBindingBuilder;
27+
28+
import static com.google.common.base.Preconditions.checkNotNull;
29+
import static com.google.common.base.Preconditions.checkState;
30+
31+
/**
32+
* Import binding builder.
33+
*/
34+
public final class InternalImportBindingBuilder<T> implements ScopedBindingBuilder {
35+
36+
private final Key<T> concreteType;
37+
private final ScopedBindingBuilder binder;
38+
private final InternalBindingProvider<T> provider;
39+
40+
public InternalImportBindingBuilder(LinkedBindingBuilder<T> binder, Key<T> concreteType) {
41+
checkNotNull(binder, "binder is null");
42+
43+
this.concreteType = checkNotNull(concreteType, "concreteType is null");
44+
45+
this.provider = new InternalBindingProvider<>(concreteType);
46+
this.binder = binder.toProvider(provider);
47+
}
48+
49+
/**
50+
* Bind a different type as the given binding. This allows binding e.g. implementations to interface types.
51+
*/
52+
public ScopedBindingBuilder to(Class<? extends T> clazz) {
53+
checkNotNull(clazz, "clazz is null");
54+
55+
this.provider.setKey(concreteType.ofType(clazz));
56+
57+
return this;
58+
}
59+
60+
/**
61+
* Bind a different type as the given binding. This allows binding e.g. implementations to interface types.
62+
*/
63+
public ScopedBindingBuilder to(TypeLiteral<? extends T> type) {
64+
checkNotNull(type, "type is null");
65+
66+
this.provider.setKey(concreteType.ofType(type));
67+
68+
return this;
69+
}
70+
71+
@Override
72+
public void in(Class<? extends Annotation> scopeAnnotation) {
73+
checkNotNull(scopeAnnotation, "scopeAnnotation is null");
74+
this.binder.in(scopeAnnotation);
75+
}
76+
77+
@Override
78+
public void in(Scope scope) {
79+
checkNotNull(scope, "scope is null");
80+
this.binder.in(scope);
81+
}
82+
83+
@Override
84+
public void asEagerSingleton() {
85+
this.binder.asEagerSingleton();
86+
}
87+
88+
static final class InternalBindingProvider<T> implements Provider<T> {
89+
90+
private Key<? extends T> key;
91+
private Injector injector;
92+
93+
InternalBindingProvider(Key<? extends T> key) {
94+
this.key = checkNotNull(key, "key is null");
95+
}
96+
97+
InternalBindingProvider<T> setKey(Key<? extends T> key) {
98+
this.key = checkNotNull(key, "key is null");
99+
return this;
100+
}
101+
102+
@Inject
103+
void setInjector(final Injector injector) {
104+
checkNotNull(injector, "injector is null");
105+
checkState(this.injector == null, "setInjector() called multiple times!");
106+
107+
this.injector = injector;
108+
}
109+
110+
@Override
111+
public T get() {
112+
checkState(this.injector != null, "calling get() before setInjector()!");
113+
return injector.getInstance(key);
114+
}
115+
}
116+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package mavenbugs.mjavadoc769;
15+
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.Target;
18+
19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.METHOD;
21+
import static java.lang.annotation.ElementType.PARAMETER;
22+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
23+
24+
@Retention(RUNTIME)
25+
@Target({FIELD, PARAMETER, METHOD})
26+
@javax.inject.Qualifier
27+
@jakarta.inject.Qualifier
28+
public @interface Right {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package mavenbugs.mjavadoc769;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
19+
import java.lang.annotation.Annotation;
20+
import java.lang.reflect.Method;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
public class RightTest {
25+
26+
@Test
27+
public void testFoo() throws Exception {
28+
Method method = Foo.class.getMethod("foo");
29+
Annotation annotation = method.getAnnotation(Right.class);
30+
assertNotNull(annotation);
31+
}
32+
33+
@Test
34+
public void testRight() throws Exception {
35+
Annotation[] annotations = Right.class.getAnnotations();
36+
assertEquals(4, annotations.length);
37+
38+
assertEquals(javax.inject.Qualifier.class, Right.class.getAnnotation(javax.inject.Qualifier.class).annotationType());
39+
assertEquals(jakarta.inject.Qualifier.class, Right.class.getAnnotation(jakarta.inject.Qualifier.class).annotationType());
40+
}
41+
42+
43+
public static class Foo {
44+
@Right
45+
public void foo() {
46+
}
47+
}
48+
}

src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,8 +4571,7 @@ private void addJavadocOptions(
45714571
ModuleNameSource depModuleNameSource = locationManager
45724572
.resolvePath(ResolvePathRequest.ofFile(file))
45734573
.getModuleNameSource();
4574-
if (ModuleNameSource.MODULEDESCRIPTOR.equals(depModuleNameSource)
4575-
|| ModuleNameSource.MANIFEST.equals(depModuleNameSource)) {
4574+
if (ModuleNameSource.MODULEDESCRIPTOR.equals(depModuleNameSource)) {
45764575
modulePathElements.add(file);
45774576
} else {
45784577
patchModules.get(mainModuleName).add(file.toPath());

0 commit comments

Comments
 (0)