Skip to content

Commit

Permalink
Added a parameter -latest-lts to get the latest avaialble lts for a g…
Browse files Browse the repository at this point in the history
…iven distro
  • Loading branch information
HanSolo committed Apr 6, 2022
1 parent 9a46d0c commit 0a0cded
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ discocli -d zulu -v 17.0.2 -os macos -lc libc -arc x64 -at tar.gz -pt jdk -fx
discocli -d zulu -v 17.0.2 -os macos -lc libc -arc x64 -at tar.gz -pt jdk
```

If you just want to download the latest available LTS release of a given distro
````shell
Get the latest available LTS release of Zulu for your machine:

discocli -d zulu -latest-lts

````

<br>

#### Build native image with GraalVM:
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/eu/hansolo/discocli/DiscoCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public class DiscoCLI implements Callable<Integer> {

@Option(names = { "-latest" }, description = "Latest available for given version number") boolean latest;

@Option(names = { "-latest-lts" }, description = "Latest available LTS release") boolean lts;

private int downloadPkg(final String url, final String filename, final long size) {
final Path path = Paths.get(filename);
if (Files.exists(path)) { return 2; }
Expand Down Expand Up @@ -179,6 +181,7 @@ private int downloadPkg(final String url, final String filename, final long size
.append("[").append(yellow).append(" -ea").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -fx").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -latest").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -latest-lts").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -i").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -f").append(end).append("]").append(" ")
.append("[").append(yellow).append(" -fd").append(end).append("=<fd>]")
Expand All @@ -192,6 +195,7 @@ private int downloadPkg(final String url, final String filename, final long size
.append(yellow).append(" -fx, --javafx").append(end).append(" Bundled with JavaFX").append("\n")
.append(yellow).append(" -i, --info").append(end).append(" Info about parameters").append("\n")
.append(yellow).append(" -latest").append(end).append(" Latest available for given version number").append("\n")
.append(yellow).append(" -latest-lts").append(end).append(" Latest available LTS release").append("\n")
.append(yellow).append(" -lc, --libc-type").append(end).append("=<lc> Lib C type (libc, glibc, c_std_lib, musl)").append("\n")
.append(yellow).append(" -os, --operating-system").append(end).append("=<os> Operating system (e.g. windows, linux, macos)").append("\n")
.append(yellow).append(" -p, --path").append(end).append("=<pt> The path where the JDK pkg should be saved to (e.g. /User/hansolo").append("\n")
Expand Down Expand Up @@ -427,6 +431,10 @@ private int downloadPkg(final String url, final String filename, final long size
}
}

if (lts && (null != versionNumber || latest || ea)) {
System.out.println(Ansi.AUTO.string("@|red \n -latest-lts only works without a given version number, latest or ea |@ \n"));
return 1;
}
if (null == versionNumber && latest) {
System.out.println(Ansi.AUTO.string("@|red \n -latest only works with a given version number (e.g. -v 17 -latest) |@ \n"));
return 1;
Expand All @@ -449,7 +457,8 @@ private int downloadPkg(final String url, final String filename, final long size
final String architectureParam = Architecture.NONE == architecture ? "" : "&architecture=" + architecture.getApiString();
final String archiveTypeParam = ArchiveType.NONE == archiveType ? "" : "&archive_type=" + archiveType.getApiString();
final String packageTypeParam = PackageType.NONE == packageType ? "" : "&package_type=" + packageType.getApiString();
final String latestParam = find ? (majorVersionOnly ? "&latest=all_of_version" : "") : ((null == versionNumber || latest) ? "&latest=available" : "");
final String latestParam = find ? (majorVersionOnly ? "&latest=all_of_version" : "") : ((null == versionNumber || latest) ? lts ? "" : "&latest=available" : "");
final String latestLtsParam = lts ? "&latest=available&version_by_definition=latest_lts" : "";
final String javafxBundledParam = fx ? "&javafx_bundled=true" : "";
final String releaseStatusParam = ea ? "&release_status=ea&release_status=ga" : "&release_status=ga";
final String directlyDownloadableParam = "&directlyDownloadable=true";
Expand All @@ -462,13 +471,16 @@ private int downloadPkg(final String url, final String filename, final long size
.append(architectureParam)
.append(versionParam)
.append(latestParam)
.append(latestLtsParam)
.append(archiveTypeParam)
.append(javafxBundledParam)
.append(packageTypeParam)
.append(directlyDownloadableParam)
.append(releaseStatusParam)
.toString();

System.out.println(request);

HttpResponse<String> response = Helper.get(request);
if (null == response) {
System.out.println(Ansi.AUTO.string(Constants.DEFAULT_ERROR_MSG));
Expand Down

0 comments on commit 0a0cded

Please sign in to comment.