-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19785. mvn site fails in JDK17 #8182
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
Merged
+274
−355
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa2f27e
[WIP] HADOOP-19785. mvn site fails in JDK17
aajisaka 04b2940
Switch to default doclet
aajisaka cf1acb5
Fix javadoc errors
aajisaka 519a926
Update link to Java API docs
aajisaka d7bbac8
Additional javadoc error fix after rebasing
aajisaka d5e55d5
Add HadoopDocEnvImpl class to avoid cast error
aajisaka 26535b3
Refactor code to reduce Java reflections
aajisaka 82309df
Add missing license header
aajisaka bfeaec4
Fix default stability level
aajisaka 2ecadb2
Fix mvn javadoc:javadoc and checkstyle:checkstyle
aajisaka 2c87dd5
Downgrade maven-javadoc-plugin < 3.10.0 to fix the output path
aajisaka fa3894c
Remove jdk17+ profile and set --release flag in maven-compiler-plugin
aajisaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...op-annotations/src/main/java/org/apache/hadoop/classification/tools/HadoopDocEnvImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.hadoop.classification.tools; | ||
|
|
||
| import com.sun.source.util.DocTrees; | ||
| import jdk.javadoc.doclet.DocletEnvironment; | ||
| import jdk.javadoc.internal.tool.DocEnvImpl; | ||
| import jdk.javadoc.internal.tool.ToolEnvironment; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.classification.InterfaceStability; | ||
|
|
||
| import javax.lang.model.SourceVersion; | ||
| import javax.lang.model.element.AnnotationMirror; | ||
| import javax.lang.model.element.Element; | ||
| import javax.lang.model.element.ElementKind; | ||
| import javax.lang.model.element.TypeElement; | ||
| import javax.lang.model.util.Elements; | ||
| import javax.lang.model.util.Types; | ||
| import javax.tools.JavaFileManager; | ||
| import javax.tools.JavaFileObject; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * This class extends Java internal DocEnvImpl to avoid cast error while | ||
| * migrating to JDK17. It filters elements based on Hadoop's InterfaceAudience | ||
| * and InterfaceStability annotations. | ||
| * This class depends on JDK internal implementation, so we might need to | ||
| * update the source code when upgrading to upper JDK versions. | ||
aajisaka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| public class HadoopDocEnvImpl extends DocEnvImpl { | ||
|
|
||
| private final DocletEnvironment delegate; | ||
| private final String stability; | ||
| private final boolean treatUnannotatedClassesAsPrivate; | ||
|
|
||
| public HadoopDocEnvImpl(DocletEnvironment original, String stability, | ||
| boolean treatUnannotatedClassesAsPrivate) { | ||
| super(extractToolEnvironment(original), null); | ||
| this.delegate = original; | ||
| this.stability = stability; | ||
| this.treatUnannotatedClassesAsPrivate = treatUnannotatedClassesAsPrivate; | ||
| } | ||
|
|
||
| // Use original ToolEnvironment to avoid NullPointerException | ||
| private static ToolEnvironment extractToolEnvironment(DocletEnvironment original) { | ||
| if (original instanceof DocEnvImpl impl) { | ||
| return impl.toolEnv; | ||
| } | ||
| throw new IllegalArgumentException( | ||
| "Expected DocEnvImpl but got: " + original.getClass().getName()); | ||
| } | ||
|
|
||
| private boolean exclude(Element el) { | ||
| boolean sawPublic = false; | ||
|
|
||
| for (AnnotationMirror am : el.getAnnotationMirrors()) { | ||
| final String qname = am.getAnnotationType().toString(); | ||
|
|
||
| if (qname.equals(InterfaceAudience.Private.class.getCanonicalName()) || qname.equals( | ||
| InterfaceAudience.LimitedPrivate.class.getCanonicalName())) { | ||
| return true; | ||
| } | ||
|
|
||
| if (stability.equals(StabilityOptions.EVOLVING_OPTION)) { | ||
| if (qname.equals(InterfaceStability.Unstable.class.getCanonicalName())) { | ||
| return true; | ||
| } | ||
| } | ||
| if (stability.equals(StabilityOptions.STABLE_OPTION)) { | ||
| if (qname.equals(InterfaceStability.Unstable.class.getCanonicalName()) || qname.equals( | ||
| InterfaceStability.Evolving.class.getCanonicalName())) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if (qname.equals(InterfaceAudience.Public.class.getCanonicalName())) { | ||
| sawPublic = true; | ||
| } | ||
| } | ||
|
|
||
| if (sawPublic) { | ||
| return false; | ||
| } | ||
|
|
||
| if (treatUnannotatedClassesAsPrivate) { | ||
| ElementKind k = el.getKind(); | ||
| if (k == ElementKind.CLASS || k == ElementKind.INTERFACE | ||
| || k == ElementKind.ANNOTATION_TYPE) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<? extends Element> getSpecifiedElements() { | ||
| Set<? extends Element> base = delegate.getSpecifiedElements(); | ||
| return base.stream().filter(e -> !exclude(e)) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<? extends Element> getIncludedElements() { | ||
| Set<? extends Element> base = delegate.getIncludedElements(); | ||
| return base.stream().filter(e -> !exclude(e)) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| @Override | ||
| public DocTrees getDocTrees() { | ||
| return delegate.getDocTrees(); | ||
| } | ||
|
|
||
| @Override | ||
| public Elements getElementUtils() { | ||
| return delegate.getElementUtils(); | ||
| } | ||
|
|
||
| @Override | ||
| public Types getTypeUtils() { | ||
| return delegate.getTypeUtils(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isIncluded(Element e) { | ||
| boolean base = delegate.isIncluded(e); | ||
| return base && !exclude(e); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSelected(Element e) { | ||
| return delegate.isSelected(e); | ||
| } | ||
|
|
||
| @Override | ||
| public JavaFileManager getJavaFileManager() { | ||
| return delegate.getJavaFileManager(); | ||
| } | ||
|
|
||
| @Override | ||
| public SourceVersion getSourceVersion() { | ||
| return delegate.getSourceVersion(); | ||
| } | ||
|
|
||
| @Override | ||
| public DocletEnvironment.ModuleMode getModuleMode() { | ||
| return delegate.getModuleMode(); | ||
| } | ||
|
|
||
| @Override | ||
| public JavaFileObject.Kind getFileKind(TypeElement type) { | ||
| return delegate.getFileKind(type); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.