From e6861a921d01143551c74e8f76589cfd158f4fa4 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Fri, 15 Mar 2024 17:58:21 +0000 Subject: [PATCH] Include :tools:fake-javadoc-sdk if there is no tools.jar and the Java version is < 9 or >= 16. --- settings.gradle | 46 +++++++++++++++++++++++++++++++++++++ tools/fake-javadoc-sdk/build.gradle | 8 +++---- tools/markdown-javadoc/build.gradle | 29 ++++++----------------- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/settings.gradle b/settings.gradle index 5260cd3b6c..8edc31bfb3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -100,6 +100,41 @@ if (JavaVersion.current() >= JavaVersion.VERSION_HIGHER || } } +// On Java 8 we have tools.jar for JavaDoc +FileCollection toolsJar = files(Paths.get("${System.properties['java.home']}") + .getParent().resolve("lib").resolve("tools.jar")) +if (!Files.exists(toolsJar.singleFile.toPath())) { + // If on Java 9 or higher the module must be pulled in, but it does not + // exist since Java 17 + if (JavaVersion.current() >= JavaVersion.VERSION_1_9 && + JavaVersion.current() < JavaVersion.VERSION_16) { + // Windows/Linux + toolsJar = files(Paths.get("${System.properties['java.home']}") + .getParent().resolve("jmods").resolve("jdk.javadoc.jmod")) + + // Mac OS + if (!Files.exists(toolsJar.singleFile.toPath())) { + toolsJar = files(Paths.get("${System.properties['java.home']}") + .resolve("jmods").resolve("jdk.javadoc.jmod")) + } + } +} + +// What should we do for this? +def squirreljmeFakeJavaDocSdk = + !Files.exists(toolsJar.singleFile.toPath()) +if (squirreljmeFakeJavaDocSdk) { + // Use fake API for building + gradle.beforeProject({proj -> + proj.ext.squirreljmeFakeJavaDocSdk = true + }) +} else { + // Use the real tools Jar for this + gradle.beforeProject({proj -> + proj.ext.squirreljmeToolsJar = toolsJar + }) +} + // Modules and available platforms include "modules" include "emulators" @@ -130,6 +165,17 @@ file(rootProject.projectDir.toPath().resolve("emulators")) file(rootProject.projectDir.toPath().resolve("tools")) .eachDir( { subdir -> + // We may or may not want to include this accordingly + if ("fake-javadoc-sdk".equals(subdir.name)) { + if (squirreljmeFakeJavaDocSdk) { + logger.lifecycle("Including Fake JavaDoc SDK!") + } else { + logger.lifecycle("Not including Fake JavaDoc SDK, becuase " + + "${toolsJar.getFiles()} exists...") + return + } + } + if (subdir.toPath().resolve("build.gradle").toFile().exists()) { include "tools:" + subdir.name diff --git a/tools/fake-javadoc-sdk/build.gradle b/tools/fake-javadoc-sdk/build.gradle index bed0591579..970003aab4 100644 --- a/tools/fake-javadoc-sdk/build.gradle +++ b/tools/fake-javadoc-sdk/build.gradle @@ -2,8 +2,8 @@ plugins { id "java-library" } -description = "Fake JavaDoc API" +// Java 8 Only +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 -build { - onlyIf { false } -} +description = "Fake JavaDoc API" diff --git a/tools/markdown-javadoc/build.gradle b/tools/markdown-javadoc/build.gradle index 641a90995f..184bd71bcb 100644 --- a/tools/markdown-javadoc/build.gradle +++ b/tools/markdown-javadoc/build.gradle @@ -10,7 +10,7 @@ plugins { apply plugin: "com.github.johnrengelman.shadow" -// Say this is a Java 8 project +// Java 8 Only sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -21,30 +21,15 @@ shadowJar { dependsOn jar } -// On Java 8 we have tools.jar for this -FileCollection toolsJar = files(Paths.get("${System.properties['java.home']}") - .getParent().resolve("lib").resolve("tools.jar")) -if (!Files.exists(toolsJar.singleFile.toPath())) { - // If on Java 9 or higher the module must be pulled in - if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { - // Windows/Linux - toolsJar = files(Paths.get("${System.properties['java.home']}") - .getParent().resolve("jmods").resolve("jdk.javadoc.jmod")) - - // Mac OS - if (!Files.exists(toolsJar.singleFile.toPath())) { - toolsJar = files(Paths.get("${System.properties['java.home']}") - .resolve("jmods").resolve("jdk.javadoc.jmod")) - } - } -} - dependencies { // Depend directly on tools.jar so it is brought in, or the module - if (Files.exists(toolsJar.singleFile.toPath())) { - implementation files(toolsJar) + if (rootProject.hasProperty("squirreljmeFakeJavaDocSdk") && + rootProject.squirreljmeFakeJavaDocSdk) { + implementation project(":tools:fake-javadoc-sdk") } else { - implementation project(":tools:fake-javadoc-api") + logger.lifecycle("Tools 1 ${rootProject.squirreljmeToolsJar.getFiles()}") + logger.lifecycle("Tools 2 ${rootProject.ext.squirreljmeToolsJar.getFiles()}") + implementation files(rootProject.ext.squirreljmeToolsJar) } implementation project(":modules:io-file") -- 2.11.4.GIT