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

Move to Java 17 and higher #173

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/angular-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "21"
node-version: 21
- name: Install dependencies
run: npm ci
- name: Build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-

- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'zulu'

- name: Build with Maven
Expand Down
26 changes: 11 additions & 15 deletions frank-doc-doclet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.ibissource</groupId>
<artifactId>frank-doc-parent</artifactId>
<version>2.0-SNAPSHOT</version>
<version>3.0-SNAPSHOT</version>
</parent>

<artifactId>frank-doc-doclet</artifactId>
Expand All @@ -15,7 +15,7 @@
<description>Doclet for the Frank!Doc</description>

<properties>
<log4j2.version>2.20.0</log4j2.version>
<log4j2.version>2.22.1</log4j2.version>
<argLine /> <!-- add empty default argLine so Surefire won't fail when JaCoCo isn't present -->
</properties>

Expand Down Expand Up @@ -94,7 +94,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.5</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
Expand All @@ -106,20 +106,18 @@
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.javadoc/jdk.javadoc.internal.tool=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.1</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
Expand All @@ -138,7 +136,7 @@
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -169,16 +167,14 @@
<arg>--add-exports</arg>
<arg>jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>jdk.javadoc/jdk.javadoc.internal.tool=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
Expand All @@ -192,7 +188,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -206,7 +202,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.6.3</version>
<configuration>
<doclint>none</doclint>
<useStandardDocletOptions>true</useStandardDocletOptions>
Expand Down Expand Up @@ -260,7 +256,7 @@
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
<version>1.1.4</version>
</dependency>

<dependency>
Expand All @@ -282,7 +278,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version>
<version>3.5.0</version>
</plugin>
</plugins>
</reporting>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Doclet {
FrankElementFilters.getExcludeFilter(), FrankElementFilters.getExcludeFiltersForSuperclass());

model = FrankDocModel.populate(options.getDigesterRulesUrl(), options.getRootClass(), repository);
log.info("Found classes: {}", repository.size());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.info("Found classes: {}", repository.size());
log.info("Found classes: {}", repository::size);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I do that, I get the warning: 'org.apache.logging.log4j.util.Supplier' is deprecated, so I'll leave it for now.

File outputBaseDir = new File(options.getOutputDirectory());
outputBaseDir.mkdirs();
xsdStrictFile = new File(outputBaseDir, options.getXsdStrictPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void printOptions() {

public static SourceVersion SourceVersion() {
log.trace("Method SourceVersion() called");
return SourceVersion.RELEASE_11;
return SourceVersion.RELEASE_17;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ List<FrankAttribute> createAttributes(FrankClass clazz, FrankElement attributeOw
return result;
}

private void setAttributeFeatures(FrankAttribute attribute, FrankMethod method, FrankClassRepository classRepository) throws FrankDocException {
private void setAttributeFeatures(FrankAttribute attribute, FrankMethod method, FrankClassRepository classRepository) {
Reference featureReference = new Reference(classRepository);
attribute.setDocumented(
(Description.getInstance().valueOf(method) != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

public class ConfigChildSetterDescriptorTest {
private FrankDocModel instance;
private static final String PACKAGE = "org.frankframework.frankdoc.testtarget.technical.override."; // Doesn't matter which package we choose. This test doesn't depend on a package.

@Before
public void setUp() throws SAXException, IOException {
// No need to set include and exclude filters of the FrankClassRepository, because
// we are not asking for the implementations of an interface.
instance = new FrankDocModel(TestUtil.getFrankClassRepositoryDoclet(), null);
instance = new FrankDocModel(TestUtil.getFrankClassRepositoryDoclet(PACKAGE), null);
instance.createConfigChildDescriptorsFrom(TestUtil.resourceAsURL("doc/fake-digester-rules.xml"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private Map<String, FrankAttribute> getReflectInvestigatedFrankAttributes() thro
private Map<String, FrankAttribute> getAttributesOfClass(final String className) throws FrankDocException {
attributeOwner = instance.findOrCreateFrankElement(className);
final List<FrankAttribute> attributes = instance.createAttributes(classRepository.findClass(className), attributeOwner, classRepository);
return attributes.stream().collect(Collectors.toMap(att -> att.getName(), att -> att));
return attributes.stream().collect(Collectors.toMap(FrankAttribute::getName, att -> att));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,54 @@
package org.frankframework.frankdoc.testdoclet;

import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.source.util.DocTrees;
import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.internal.tool.AccessKind;
import jdk.javadoc.internal.tool.JavadocTool;
import jdk.javadoc.internal.tool.Messager;
import jdk.javadoc.internal.tool.ToolOption;
import jdk.javadoc.doclet.Reporter;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;

import javax.tools.StandardLocation;
import java.io.File;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import static java.nio.charset.StandardCharsets.UTF_8;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

@Log4j2
@Getter
public class EasyDoclet {
final private File sourceDirectory;
final private String[] packageNames;
final private DocletEnvironment docletEnvironment;

private static final AccessKind ACCESS_KIND = AccessKind.PUBLIC;

public EasyDoclet(File sourceDirectory, String[] packageNames) {
this.sourceDirectory = sourceDirectory;
this.packageNames = packageNames;

String sourcePath = getSourceDirectory().getAbsolutePath();

if (getSourceDirectory().exists()) {
log.info("Using source path: [{}]", sourcePath);
// compOpts.put("-sourcepath", getSourceDirectory().getAbsolutePath());
} else {
log.error("Ignoring non-existing source path, check your source directory argument. Used: [{}]", sourcePath);
}

try {
docletEnvironment = createDocletEnv(sourcePath, List.of(packageNames));
} catch (Exception e) {
log.error(e);
throw new RuntimeException(e);
}
public class EasyDoclet implements Doclet {
@Getter
private static DocTrees docTrees;
@Getter
private static Set<? extends Element> includedElements;
@Getter @Setter
private static String[] packages;

@Override
public void init(Locale locale, Reporter reporter) {
log.debug("EasyDoclet.init start");
}

private static DocletEnvironment createDocletEnv(String sourcePath, Collection<String> packageNames) throws Exception {

// Create a context to hold settings for Javadoc.
Context context = new Context();

// Pre-register a messager for the context. Not needed for Java 17!
Messager.preRegister(context, EasyDoclet.class.getName());

// Set source path option for Javadoc.
try (JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8)) {

fileManager.setLocation(StandardLocation.SOURCE_PATH, List.of(new File(sourcePath)));

// JavadocLog.preRegister(context, "javadoc"); // Java 17

// Create an instance of Javadoc.
JavadocTool javadocTool = JavadocTool.make0(context);
@Override
public String getName() {
return "EasyDoclet";
}

// Set up javadoc tool options. Not needed for Java 17!
// ToolOption options = new ToolOption(context, log, null); // Java 17 ??
Map<ToolOption, Object> options = new EnumMap<>(ToolOption.class);
options.put(ToolOption.SHOW_PACKAGES, ACCESS_KIND);
options.put(ToolOption.SHOW_TYPES, ACCESS_KIND);
options.put(ToolOption.SHOW_MEMBERS, ACCESS_KIND);
options.put(ToolOption.SHOW_MODULE_CONTENTS, ACCESS_KIND);
options.put(ToolOption.SUBPACKAGES, packageNames);
@Override
public Set<? extends Option> getSupportedOptions() {
return new HashSet<>();
}

// Invoke Javadoc and ask it for a DocletEnvironment containing the specified packages.
return javadocTool.getEnvironment(
options, // options
List.of(), // java names
List.of()); // java files
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.RELEASE_11;
jkosternl marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean run(DocletEnvironment environment) {
log.debug("EasyDoclet.run start");
docTrees = environment.getDocTrees();
includedElements = environment.getIncludedElements();
log.debug("EasyDoclet.run: includedElements size = {}", includedElements.size());
jkosternl marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.Set;

import static org.junit.Assert.assertEquals;

public class EasyDocletTest {

@Test
public void test() throws Exception {
for (Element element : TestUtil.getTypeElements(null, "org.frankframework.frankdoc.testtarget.doclet")) {
Set<? extends Element> typeElements = TestUtil.getIncludedElements("org.frankframework.frankdoc.testtarget.doclet");
assertEquals(50, typeElements.size());

for (Element element : typeElements) {
if (element instanceof TypeElement) {
System.out.println(((TypeElement) element).getQualifiedName().toString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.frankframework.frankdoc.wrapper;

import org.frankframework.frankdoc.testdoclet.EasyDoclet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -59,9 +58,8 @@ public static Collection<Object[]> data() {

@Test
public void test() throws FrankDocException {
EasyDoclet easyDoclet = TestUtil.getEasyDoclet(BOTH_PACKAGES);
Set<? extends Element> classDocs = TestUtil.getTypeElements(easyDoclet, BOTH_PACKAGES);
FrankClassRepository repository = new FrankClassRepository(TestUtil.getDocTrees(easyDoclet), classDocs, new HashSet<>(includes), new HashSet<>(excludes), new HashSet<>());
Set<? extends Element> classDocs = TestUtil.getIncludedElements(BOTH_PACKAGES);
FrankClassRepository repository = new FrankClassRepository(TestUtil.getDocTrees(), classDocs, new HashSet<>(includes), new HashSet<>(excludes), new HashSet<>());
FrankClass clazz = repository.findClass(FIRST_PACKAGE + "MyInterface");
List<FrankClass> implementations = clazz.getInterfaceImplementations();
List<String> actualSimpleNames = implementations.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.frankframework.frankdoc.wrapper;

import org.frankframework.frankdoc.testdoclet.EasyDoclet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -57,10 +56,9 @@ public static Collection<Object[]> data() {

@Before
public void setUp() throws FrankDocException {
Set<? extends Element> classDocs = TestUtil.getIncludedElements(CHILD_PACKAGE, PARENT_PACKAGE);
List<String> packages = Arrays.asList(CHILD_PACKAGE, PARENT_PACKAGE);
EasyDoclet easyDoclet = TestUtil.getEasyDoclet(CHILD_PACKAGE, PARENT_PACKAGE);
Set<? extends Element> classDocs = TestUtil.getTypeElements(easyDoclet, null);
FrankClassRepository repository = new FrankClassRepository(TestUtil.getDocTrees(easyDoclet), classDocs, new HashSet<>(packages), new HashSet<>(), new HashSet<>(Collections.singletonList(superclassFilter)));
FrankClassRepository repository = new FrankClassRepository(TestUtil.getDocTrees(), classDocs, new HashSet<>(packages), new HashSet<>(), new HashSet<>(Collections.singletonList(superclassFilter)));
childClass = repository.findClass(CHILD_PACKAGE + CHILD_CLASS);
assertNotNull(childClass);
}
Expand Down
Loading
Loading