Skip to content

Commit

Permalink
Add new enums to force the arch and the os options
Browse files Browse the repository at this point in the history
FMT 1.4.3

Some fixes here and there

Update docs/readme
  • Loading branch information
FlowArg committed May 25, 2024
1 parent ece93b9 commit 0915b7c
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 31 deletions.
26 changes: 17 additions & 9 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
```
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/fr/flowarg/azuljavadownloader/AzulJavaArch.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public List<String> 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 + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
* }
* </pre>
* @see <a href="https://docs.azul.com/core/zulu-openjdk/install/metadata-api">Azul Zulu's Metadata API</a>
* @see <a href="https://docs.azul.com/core/install/metadata-api">Azul Zulu's Metadata API</a>
*/
public class AzulJavaDownloader
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/fr/flowarg/azuljavadownloader/AzulJavaOS.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public String getType()
return this.type;
}

@Override
public String toString()
{
return this.type;
}
}
31 changes: 18 additions & 13 deletions src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
Expand All @@ -48,20 +47,26 @@ 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;
}

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
);
}
}

0 comments on commit 0915b7c

Please sign in to comment.