diff --git a/README.MD b/README.MD index 2aa3ec7..549c963 100644 --- a/README.MD +++ b/README.MD @@ -5,13 +5,21 @@ This library is used to download the Azul Java binaries from the Azul CDN. #### Example : ```java - final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println); - final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded. - final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "windows", "x64", true)); // jdk 17 with javafx for Windows 64 bits - final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas); - System.out.println(javaHomeWindows.toAbsolutePath()); // The path to the Java home directory - - final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "linux", "x64", true)); // jdk 17 with javafx for linux 64 bits - final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas); - System.out.println(javaHomeLinux.toAbsolutePath()); // The path to the Java home directory +import fr.flowarg.azuljavadownloader.*; + +class Test +{ + public static void test() + { + final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println); + final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded. + final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.WINDOWS, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for windows 64 bits + final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas); + System.out.println(javaHomeWindows.toAbsolutePath()); + + final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.LINUX, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for linux 64 bits + final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas); + System.out.println(javaHomeLinux.toAbsolutePath()); + } +} ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 252eb12..6ed50a3 100644 --- a/build.gradle +++ b/build.gradle @@ -13,8 +13,8 @@ repositories { } dependencies { - implementation 'org.jetbrains:annotations:24.0.1' - implementation 'fr.flowarg:flowmultitools:1.4.1' + implementation 'org.jetbrains:annotations:24.1.0' + implementation 'fr.flowarg:flowmultitools:1.4.3' implementation 'com.google.code.gson:gson:2.10.1' } diff --git a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaArch.java b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaArch.java new file mode 100644 index 0000000..b7bf90e --- /dev/null +++ b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaArch.java @@ -0,0 +1,60 @@ +package fr.flowarg.azuljavadownloader; + +public enum AzulJavaArch +{ + /** x86 64bit and x86 32bit */ + X86("x86"), + /** x86 64bit same as {@link #AMD64} */ + X64("x64"), + /** x86 64bit same as {@link #X64} */ + AMD64("amd64"), + /** x86 32bit */ + I686("i686"), + /** arm 64bit and arm 32bit */ + ARM("arm"), + /** arm 64bit */ + AARCH64("aarch64"), + /** arm 32bit */ + AARCH32("aarch32"), + + // mostly unused + /** arm 32bit soft float */ + AARCH32SF("aarch32sf"), + /** arm 32bit hard float */ + AARCH32HF("aarch32hf"), + /** ppc 64bit and ppc 32bit */ + PPC("ppc"), + /** ppc 64bit */ + PPC64("ppc64"), + /** ppc 32bit */ + PPC32("ppc32"), + /** ppc 32bit hard float */ + PPC32HF("ppc32hf"), + /** ppc 32bit spe */ + PPC32SPE("ppc32spe"), + /** sparcv9 64bit and sparcv9 32bit */ + SPARCV9("sparcv9"), + /** sparcv9 32bit */ + SPARCV9_32("sparcv9-32"), + /** sparcv9 64bit */ + SPARCV9_64("sparcv9-64") + ; + + private final String arch; + + AzulJavaArch(String arch) + { + this.arch = arch; + } + + public String getArch() + { + return this.arch; + } + + @Override + public String toString() + { + return this.arch; + } +} diff --git a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaBuildInfo.java b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaBuildInfo.java index e3a2e8d..aed88dd 100644 --- a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaBuildInfo.java +++ b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaBuildInfo.java @@ -145,6 +145,12 @@ public List getDistroVersion() @Override public String toString() { - return "AzulJavaBuildInfo{" + "packageUUID='" + packageUUID + '\'' + ", name='" + name + '\'' + ", md5Hash='" + md5Hash + '\'' + ", sha256Hash='" + sha256Hash + '\'' + ", buildDate='" + buildDate + '\'' + ", lastModified='" + lastModified + '\'' + ", downloadUrl='" + downloadUrl + '\'' + ", product='" + product + '\'' + ", javaVersion=" + javaVersion + ", javaPackageType='" + javaPackageType + '\'' + ", javafxBundled=" + javafxBundled + ", javaPackageFeatures=" + javaPackageFeatures + ", os='" + os + '\'' + ", archiveType='" + archiveType + '\'' + ", size=" + size + ", latest=" + latest + ", distroVersion=" + distroVersion + '}'; + return "AzulJavaBuildInfo{" + "packageUUID='" + this.packageUUID + '\'' + ", name='" + this.name + '\'' + + ", md5Hash='" + this.md5Hash + '\'' + ", sha256Hash='" + this.sha256Hash + '\'' + ", buildDate='" + + this.buildDate + '\'' + ", lastModified='" + this.lastModified + '\'' + ", downloadUrl='" + + this.downloadUrl + '\'' + ", product='" + this.product + '\'' + ", javaVersion=" + this.javaVersion + + ", javaPackageType='" + this.javaPackageType + '\'' + ", javafxBundled=" + this.javafxBundled + + ", javaPackageFeatures=" + this.javaPackageFeatures + ", os='" + this.os + '\'' + ", archiveType='" + + this.archiveType + '\'' + ", size=" + this.size + ", latest=" + this.latest + ", distroVersion=" + this.distroVersion + '}'; } } diff --git a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaDownloader.java b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaDownloader.java index 5b8ae70..c643d01 100644 --- a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaDownloader.java +++ b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaDownloader.java @@ -31,16 +31,16 @@ * // Example : * final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println); * final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded. - * final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "windows", "x64", true)); // jdk 17 with javafx for windows 64 bits + * final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.WINDOWS, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for windows 64 bits * final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas); * System.out.println(javaHomeWindows.toAbsolutePath()); * - * final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "linux", "x64", true)); // jdk 17 with javafx for linux 64 bits + * final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.LINUX, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for linux 64 bits * final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas); * System.out.println(javaHomeLinux.toAbsolutePath()); * } * - * @see Azul Zulu's Metadata API + * @see Azul Zulu's Metadata API */ public class AzulJavaDownloader { @@ -127,7 +127,7 @@ else if(buildInfo.getArchiveType().equalsIgnoreCase("tar.gz")) if (this.callback != null) this.callback.onStep(Callback.Step.DONE); - return extractedPath; + return extractedPath.toAbsolutePath(); } // Internal methods @@ -182,10 +182,10 @@ private static void smartDecompressTarArchive(final Path tarGzFile, final Path d { int count; final byte[] data = new byte[4096]; - try(final OutputStream dest = Files.newOutputStream(path)) + try(final OutputStream output = Files.newOutputStream(path)) { while((count = tarIn.read(data, 0, 4096)) != -1) - dest.write(data, 0, count); + output.write(data, 0, count); } } } diff --git a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaOS.java b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaOS.java new file mode 100644 index 0000000..f8c1131 --- /dev/null +++ b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaOS.java @@ -0,0 +1,33 @@ +package fr.flowarg.azuljavadownloader; + +public enum AzulJavaOS +{ + MACOS("macos"), + LINUX("linux"), + WINDOWS("windows"), + + // mostly unused + SOLARIS("solaris"), + AIX("aix"), + QNX("qnx"), + LINUX_MUSL("linux-musl"), + LINUX_GLIBC("linux-glibc"); + + private final String os; + + AzulJavaOS(String os) + { + this.os = os; + } + + public String getOs() + { + return this.os; + } + + @Override + public String toString() + { + return this.os; + } +} diff --git a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java index e3690a7..eb93390 100644 --- a/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java +++ b/src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java @@ -17,4 +17,9 @@ public String getType() return this.type; } + @Override + public String toString() + { + return this.type; + } } diff --git a/src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java b/src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java index fb7e80b..c54a3ac 100644 --- a/src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java +++ b/src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java @@ -4,21 +4,20 @@ public class RequestedJavaInfo { private final String javaVersion; private final AzulJavaType javaType; - private final String os; - private final String arch; - private final boolean javafxBundled; + private final AzulJavaOS os; + private final AzulJavaArch arch; // optionals - private String binaryType; + private boolean javafxBundled; + private String archiveType; - public RequestedJavaInfo(String javaVersion, AzulJavaType javaType, String os, String arch, boolean javafxBundled) + public RequestedJavaInfo(String javaVersion, AzulJavaType javaType, AzulJavaOS os, AzulJavaArch arch) { this.javaVersion = javaVersion; this.javaType = javaType; this.os = os; this.arch = arch; - this.javafxBundled = javafxBundled; - this.binaryType = this.os.equalsIgnoreCase("windows") ? "zip" : "tar.gz"; + this.archiveType = this.os == AzulJavaOS.WINDOWS ? "zip" : "tar.gz"; } public String getJavaVersion() @@ -31,12 +30,12 @@ public AzulJavaType getJavaType() return this.javaType; } - public String getOs() + public AzulJavaOS getOs() { return this.os; } - public String getArch() + public AzulJavaArch getArch() { return this.arch; } @@ -48,12 +47,18 @@ public boolean isJavafxBundled() public String getBinaryType() { - return this.binaryType; + return this.archiveType; + } + + public RequestedJavaInfo setJavaFxBundled(boolean javafxBundled) + { + this.javafxBundled = javafxBundled; + return this; } - public RequestedJavaInfo setBinaryType(String binaryType) + public RequestedJavaInfo setArchiveType(String archiveType) { - this.binaryType = binaryType; + this.archiveType = archiveType; return this; } @@ -61,7 +66,7 @@ public String buildParams(String apiEndpointPackages) { return apiEndpointPackages + String.format( "?java_version=%s&os=%s&arch=%s&java_package_type=%s&javafx_bundled=%s&latest=true&archive_type=%s&page=1&page_size=100", - this.javaVersion, this.os, this.arch, this.javaType.getType(), this.javafxBundled, this.binaryType + this.javaVersion, this.os.toString(), this.arch.toString(), this.javaType.toString(), this.javafxBundled, this.archiveType ); } }