Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJAVADOC-769] fix for transitive filename based modules #227

Merged
merged 1 commit into from Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/it/projects/MJAVADOC-769/invoker.properties
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals= clean package
invoker.java.version = 9+
170 changes: 170 additions & 0 deletions src/it/projects/MJAVADOC-769/pom.xml
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.javadoc.it</groupId>
<artifactId>mjavadoc769</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<url>https://issues.apache.org/jira/browse/MJAVADOC-769</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<moduleName>mavenbugs.mjavadoc769</moduleName>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.1.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>

<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1.MR</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<outputDirectory>${project.build.directory}/apidocs
</outputDirectory>
<release>11</release>
<nodeprecated>false</nodeprecated>
<author>false</author>
<nohelp>true</nohelp>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
<!-- add module name to main artifact -->
<configuration>
<archive>
<manifestEntries
combine.children="append">
<Automatic-Module-Name>
${moduleName}
</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</execution>
<execution>
<id>test-jar</id>
<!-- add module name to test artifact -->
<configuration>
<archive>
<manifestEntries
combine.children="append">
<Automatic-Module-Name>
${moduleName}.tests
</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We build test-jar with tests classes - but java doc is executed only for main java code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is irrelevant. The tests are only executed to illustrate why the scopes in the pom make sense. The dependency scopes in the pom is what exhibits the problem that this patch fixes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider to use goals:

  • javadoc-no-fork and test-javadoc-no-fork

we not need jars with javadocs

</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
Comment on lines +155 to +167
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This execution should be before javadoc - it can have impact on test

</plugins>
</build>
</project>
@@ -0,0 +1,116 @@
package mavenbugs.mjavadoc769;

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.lang.annotation.Annotation;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.Scope;
import com.google.inject.TypeLiteral;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.binder.ScopedBindingBuilder;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

/**
* Import binding builder.
*/
public final class InternalImportBindingBuilder<T> implements ScopedBindingBuilder {
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved

private final Key<T> concreteType;
private final ScopedBindingBuilder binder;
private final InternalBindingProvider<T> provider;

public InternalImportBindingBuilder(LinkedBindingBuilder<T> binder, Key<T> concreteType) {
checkNotNull(binder, "binder is null");

this.concreteType = checkNotNull(concreteType, "concreteType is null");

this.provider = new InternalBindingProvider<>(concreteType);
this.binder = binder.toProvider(provider);
}

/**
* Bind a different type as the given binding. This allows binding e.g. implementations to interface types.
*/
public ScopedBindingBuilder to(Class<? extends T> clazz) {
checkNotNull(clazz, "clazz is null");

this.provider.setKey(concreteType.ofType(clazz));

return this;
}

/**
* Bind a different type as the given binding. This allows binding e.g. implementations to interface types.
*/
public ScopedBindingBuilder to(TypeLiteral<? extends T> type) {
checkNotNull(type, "type is null");

this.provider.setKey(concreteType.ofType(type));

return this;
}

@Override
public void in(Class<? extends Annotation> scopeAnnotation) {
checkNotNull(scopeAnnotation, "scopeAnnotation is null");
this.binder.in(scopeAnnotation);
}

@Override
public void in(Scope scope) {
checkNotNull(scope, "scope is null");
this.binder.in(scope);
}

@Override
public void asEagerSingleton() {
this.binder.asEagerSingleton();
}

static final class InternalBindingProvider<T> implements Provider<T> {

private Key<? extends T> key;
private Injector injector;

InternalBindingProvider(Key<? extends T> key) {
this.key = checkNotNull(key, "key is null");
}

InternalBindingProvider<T> setKey(Key<? extends T> key) {
this.key = checkNotNull(key, "key is null");
return this;
}

@Inject
void setInjector(final Injector injector) {
checkNotNull(injector, "injector is null");
checkState(this.injector == null, "setInjector() called multiple times!");

this.injector = injector;
}

@Override
public T get() {
checkState(this.injector != null, "calling get() before setInjector()!");
return injector.getInstance(key);
}
}
}
@@ -0,0 +1,28 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mavenbugs.mjavadoc769;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
@Target({FIELD, PARAMETER, METHOD})
@javax.inject.Qualifier
@jakarta.inject.Qualifier
public @interface Right {}
@@ -0,0 +1,48 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mavenbugs.mjavadoc769;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.junit.jupiter.api.Test;

public class RightTest {

@Test
public void testFoo() throws Exception {
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
Method method = Foo.class.getMethod("foo");
Annotation annotation = method.getAnnotation(Right.class);
assertNotNull(annotation);
}

@Test
public void testRight() throws Exception {
Annotation[] annotations = Right.class.getAnnotations();
assertEquals(4, annotations.length);

assertEquals(javax.inject.Qualifier.class, Right.class.getAnnotation(javax.inject.Qualifier.class).annotationType());
assertEquals(jakarta.inject.Qualifier.class, Right.class.getAnnotation(jakarta.inject.Qualifier.class).annotationType());
}


public static class Foo {
@Right
public void foo() {
}
}
}
Expand Up @@ -4554,8 +4554,7 @@ private void addJavadocOptions(
ModuleNameSource depModuleNameSource = locationManager
.resolvePath(ResolvePathRequest.ofFile(file))
.getModuleNameSource();
if (ModuleNameSource.MODULEDESCRIPTOR.equals(depModuleNameSource)
|| ModuleNameSource.MANIFEST.equals(depModuleNameSource)) {
if (ModuleNameSource.MODULEDESCRIPTOR.equals(depModuleNameSource)) {
modulePathElements.add(file);
} else {
patchModules.get(mainModuleName).add(file.toPath());
Expand Down