Skip to content

Commit 0915b7c

Browse files
committed
Add new enums to force the arch and the os options
FMT 1.4.3 Some fixes here and there Update docs/readme
1 parent ece93b9 commit 0915b7c

File tree

8 files changed

+148
-31
lines changed

8 files changed

+148
-31
lines changed

README.MD

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ This library is used to download the Azul Java binaries from the Azul CDN.
55
#### Example :
66

77
```java
8-
final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println);
9-
final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded.
10-
final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "windows", "x64", true)); // jdk 17 with javafx for Windows 64 bits
11-
final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas);
12-
System.out.println(javaHomeWindows.toAbsolutePath()); // The path to the Java home directory
13-
14-
final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "linux", "x64", true)); // jdk 17 with javafx for linux 64 bits
15-
final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas);
16-
System.out.println(javaHomeLinux.toAbsolutePath()); // The path to the Java home directory
8+
import fr.flowarg.azuljavadownloader.*;
9+
10+
class Test
11+
{
12+
public static void test()
13+
{
14+
final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println);
15+
final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded.
16+
final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.WINDOWS, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for windows 64 bits
17+
final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas);
18+
System.out.println(javaHomeWindows.toAbsolutePath());
19+
20+
final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.LINUX, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for linux 64 bits
21+
final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas);
22+
System.out.println(javaHomeLinux.toAbsolutePath());
23+
}
24+
}
1725
```

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation 'org.jetbrains:annotations:24.0.1'
17-
implementation 'fr.flowarg:flowmultitools:1.4.1'
16+
implementation 'org.jetbrains:annotations:24.1.0'
17+
implementation 'fr.flowarg:flowmultitools:1.4.3'
1818
implementation 'com.google.code.gson:gson:2.10.1'
1919
}
2020

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package fr.flowarg.azuljavadownloader;
2+
3+
public enum AzulJavaArch
4+
{
5+
/** x86 64bit and x86 32bit */
6+
X86("x86"),
7+
/** x86 64bit same as {@link #AMD64} */
8+
X64("x64"),
9+
/** x86 64bit same as {@link #X64} */
10+
AMD64("amd64"),
11+
/** x86 32bit */
12+
I686("i686"),
13+
/** arm 64bit and arm 32bit */
14+
ARM("arm"),
15+
/** arm 64bit */
16+
AARCH64("aarch64"),
17+
/** arm 32bit */
18+
AARCH32("aarch32"),
19+
20+
// mostly unused
21+
/** arm 32bit soft float */
22+
AARCH32SF("aarch32sf"),
23+
/** arm 32bit hard float */
24+
AARCH32HF("aarch32hf"),
25+
/** ppc 64bit and ppc 32bit */
26+
PPC("ppc"),
27+
/** ppc 64bit */
28+
PPC64("ppc64"),
29+
/** ppc 32bit */
30+
PPC32("ppc32"),
31+
/** ppc 32bit hard float */
32+
PPC32HF("ppc32hf"),
33+
/** ppc 32bit spe */
34+
PPC32SPE("ppc32spe"),
35+
/** sparcv9 64bit and sparcv9 32bit */
36+
SPARCV9("sparcv9"),
37+
/** sparcv9 32bit */
38+
SPARCV9_32("sparcv9-32"),
39+
/** sparcv9 64bit */
40+
SPARCV9_64("sparcv9-64")
41+
;
42+
43+
private final String arch;
44+
45+
AzulJavaArch(String arch)
46+
{
47+
this.arch = arch;
48+
}
49+
50+
public String getArch()
51+
{
52+
return this.arch;
53+
}
54+
55+
@Override
56+
public String toString()
57+
{
58+
return this.arch;
59+
}
60+
}

src/main/java/fr/flowarg/azuljavadownloader/AzulJavaBuildInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ public List<String> getDistroVersion()
145145
@Override
146146
public String toString()
147147
{
148-
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 + '}';
148+
return "AzulJavaBuildInfo{" + "packageUUID='" + this.packageUUID + '\'' + ", name='" + this.name + '\'' +
149+
", md5Hash='" + this.md5Hash + '\'' + ", sha256Hash='" + this.sha256Hash + '\'' + ", buildDate='" +
150+
this.buildDate + '\'' + ", lastModified='" + this.lastModified + '\'' + ", downloadUrl='" +
151+
this.downloadUrl + '\'' + ", product='" + this.product + '\'' + ", javaVersion=" + this.javaVersion +
152+
", javaPackageType='" + this.javaPackageType + '\'' + ", javafxBundled=" + this.javafxBundled +
153+
", javaPackageFeatures=" + this.javaPackageFeatures + ", os='" + this.os + '\'' + ", archiveType='" +
154+
this.archiveType + '\'' + ", size=" + this.size + ", latest=" + this.latest + ", distroVersion=" + this.distroVersion + '}';
149155
}
150156
}

src/main/java/fr/flowarg/azuljavadownloader/AzulJavaDownloader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
* // Example :
3232
* final AzulJavaDownloader downloader = new AzulJavaDownloader(System.out::println);
3333
* final Path javas = Paths.get("javas"); // The directory where the Java versions will be downloaded.
34-
* final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "windows", "x64", true)); // jdk 17 with javafx for windows 64 bits
34+
* final AzulJavaBuildInfo buildInfoWindows = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.WINDOWS, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for windows 64 bits
3535
* final Path javaHomeWindows = downloader.downloadAndInstall(buildInfoWindows, javas);
3636
* System.out.println(javaHomeWindows.toAbsolutePath());
3737
*
38-
* final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, "linux", "x64", true)); // jdk 17 with javafx for linux 64 bits
38+
* final AzulJavaBuildInfo buildInfoLinux = downloader.getBuildInfo(new RequestedJavaInfo("17", AzulJavaType.JDK, AzulJavaOS.LINUX, AzulJavaArch.X64).setJavaFxBundled(true)); // jdk 17 with javafx for linux 64 bits
3939
* final Path javaHomeLinux = downloader.downloadAndInstall(buildInfoLinux, javas);
4040
* System.out.println(javaHomeLinux.toAbsolutePath());
4141
* }
4242
* </pre>
43-
* @see <a href="https://docs.azul.com/core/zulu-openjdk/install/metadata-api">Azul Zulu's Metadata API</a>
43+
* @see <a href="https://docs.azul.com/core/install/metadata-api">Azul Zulu's Metadata API</a>
4444
*/
4545
public class AzulJavaDownloader
4646
{
@@ -127,7 +127,7 @@ else if(buildInfo.getArchiveType().equalsIgnoreCase("tar.gz"))
127127
if (this.callback != null)
128128
this.callback.onStep(Callback.Step.DONE);
129129

130-
return extractedPath;
130+
return extractedPath.toAbsolutePath();
131131
}
132132

133133
// Internal methods
@@ -182,10 +182,10 @@ private static void smartDecompressTarArchive(final Path tarGzFile, final Path d
182182
{
183183
int count;
184184
final byte[] data = new byte[4096];
185-
try(final OutputStream dest = Files.newOutputStream(path))
185+
try(final OutputStream output = Files.newOutputStream(path))
186186
{
187187
while((count = tarIn.read(data, 0, 4096)) != -1)
188-
dest.write(data, 0, count);
188+
output.write(data, 0, count);
189189
}
190190
}
191191
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fr.flowarg.azuljavadownloader;
2+
3+
public enum AzulJavaOS
4+
{
5+
MACOS("macos"),
6+
LINUX("linux"),
7+
WINDOWS("windows"),
8+
9+
// mostly unused
10+
SOLARIS("solaris"),
11+
AIX("aix"),
12+
QNX("qnx"),
13+
LINUX_MUSL("linux-musl"),
14+
LINUX_GLIBC("linux-glibc");
15+
16+
private final String os;
17+
18+
AzulJavaOS(String os)
19+
{
20+
this.os = os;
21+
}
22+
23+
public String getOs()
24+
{
25+
return this.os;
26+
}
27+
28+
@Override
29+
public String toString()
30+
{
31+
return this.os;
32+
}
33+
}

src/main/java/fr/flowarg/azuljavadownloader/AzulJavaType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ public String getType()
1717
return this.type;
1818
}
1919

20+
@Override
21+
public String toString()
22+
{
23+
return this.type;
24+
}
2025
}

src/main/java/fr/flowarg/azuljavadownloader/RequestedJavaInfo.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ public class RequestedJavaInfo
44
{
55
private final String javaVersion;
66
private final AzulJavaType javaType;
7-
private final String os;
8-
private final String arch;
9-
private final boolean javafxBundled;
7+
private final AzulJavaOS os;
8+
private final AzulJavaArch arch;
109

1110
// optionals
12-
private String binaryType;
11+
private boolean javafxBundled;
12+
private String archiveType;
1313

14-
public RequestedJavaInfo(String javaVersion, AzulJavaType javaType, String os, String arch, boolean javafxBundled)
14+
public RequestedJavaInfo(String javaVersion, AzulJavaType javaType, AzulJavaOS os, AzulJavaArch arch)
1515
{
1616
this.javaVersion = javaVersion;
1717
this.javaType = javaType;
1818
this.os = os;
1919
this.arch = arch;
20-
this.javafxBundled = javafxBundled;
21-
this.binaryType = this.os.equalsIgnoreCase("windows") ? "zip" : "tar.gz";
20+
this.archiveType = this.os == AzulJavaOS.WINDOWS ? "zip" : "tar.gz";
2221
}
2322

2423
public String getJavaVersion()
@@ -31,12 +30,12 @@ public AzulJavaType getJavaType()
3130
return this.javaType;
3231
}
3332

34-
public String getOs()
33+
public AzulJavaOS getOs()
3534
{
3635
return this.os;
3736
}
3837

39-
public String getArch()
38+
public AzulJavaArch getArch()
4039
{
4140
return this.arch;
4241
}
@@ -48,20 +47,26 @@ public boolean isJavafxBundled()
4847

4948
public String getBinaryType()
5049
{
51-
return this.binaryType;
50+
return this.archiveType;
51+
}
52+
53+
public RequestedJavaInfo setJavaFxBundled(boolean javafxBundled)
54+
{
55+
this.javafxBundled = javafxBundled;
56+
return this;
5257
}
5358

54-
public RequestedJavaInfo setBinaryType(String binaryType)
59+
public RequestedJavaInfo setArchiveType(String archiveType)
5560
{
56-
this.binaryType = binaryType;
61+
this.archiveType = archiveType;
5762
return this;
5863
}
5964

6065
public String buildParams(String apiEndpointPackages)
6166
{
6267
return apiEndpointPackages + String.format(
6368
"?java_version=%s&os=%s&arch=%s&java_package_type=%s&javafx_bundled=%s&latest=true&archive_type=%s&page=1&page_size=100",
64-
this.javaVersion, this.os, this.arch, this.javaType.getType(), this.javafxBundled, this.binaryType
69+
this.javaVersion, this.os.toString(), this.arch.toString(), this.javaType.toString(), this.javafxBundled, this.archiveType
6570
);
6671
}
6772
}

0 commit comments

Comments
 (0)