2021-12-08 08:50:21 +00:00
|
|
|
//JAVA 11+
|
2023-05-24 18:16:06 +00:00
|
|
|
|
2021-03-29 08:57:32 +00:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
2021-03-27 19:23:46 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.file.Files;
|
2021-03-29 09:07:32 +00:00
|
|
|
import java.nio.file.Path;
|
2023-05-24 18:16:06 +00:00
|
|
|
|
|
|
|
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
|
|
|
import static java.nio.file.StandardOpenOption.CREATE;
|
|
|
|
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
|
|
|
import static java.nio.file.StandardOpenOption.WRITE;
|
2021-03-27 19:23:46 +00:00
|
|
|
|
2021-04-06 14:47:34 +00:00
|
|
|
class get_jreleaser {
|
2021-04-06 16:47:36 +00:00
|
|
|
public static void main(String... args) throws Exception {
|
|
|
|
// default version
|
|
|
|
var version = "latest";
|
|
|
|
|
|
|
|
if (args.length > 1) {
|
|
|
|
System.err.println("Usage: java get_jreleaser.java [VERSION]");
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// grab the version if specified
|
|
|
|
if (args.length == 1) {
|
|
|
|
version = args[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// check
|
|
|
|
if (null == version || version.isEmpty()) {
|
|
|
|
System.out.printf("❌ Version '%s' is invalid%n", version);
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
2023-05-24 18:16:06 +00:00
|
|
|
var versionFile = Path.of("JRELEASER_VERSION");
|
|
|
|
|
|
|
|
var cachedVersion = "";
|
|
|
|
if (Files.exists(versionFile)) {
|
|
|
|
try {
|
|
|
|
cachedVersion = Files.readString(versionFile).trim();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.printf("☠️ JReleaser %s could not be resolved%n", version);
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 16:47:36 +00:00
|
|
|
// resolve latest to a tagged release
|
|
|
|
if ("latest".equalsIgnoreCase(version)) {
|
|
|
|
var url = "https://jreleaser.org/releases/latest/download/VERSION";
|
|
|
|
|
|
|
|
try (var stream = new URL(url).openStream()) {
|
|
|
|
System.out.printf("✅ Located version marker%n");
|
2023-05-24 18:16:06 +00:00
|
|
|
Files.copy(stream, versionFile, REPLACE_EXISTING);
|
|
|
|
version = new String(Files.readAllBytes(versionFile)).trim();
|
2021-04-06 16:47:36 +00:00
|
|
|
System.out.printf("✅ JReleaser latest resolves to %s%n", version);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
System.out.printf("❌ JReleaser %s not found%n", version);
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.printf("☠️ JReleaser %s could not be downloaded/copied%n", version);
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
2023-05-24 18:16:06 +00:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Files.writeString(versionFile, version, CREATE, TRUNCATE_EXISTING, WRITE);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.printf("☠️ JReleaser %s could not be resolved%n", version);
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var jreleaserJar = Path.of("jreleaser-cli.jar");
|
|
|
|
if (version.equals(cachedVersion) && Files.exists(jreleaserJar)) {
|
|
|
|
// assume jreleaserJar has the expected version for now
|
|
|
|
System.out.printf("✅ JReleaser %s already downloaded%n", version);
|
|
|
|
System.exit(0);
|
2021-04-06 16:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup the actual download
|
2021-04-11 13:46:41 +00:00
|
|
|
var tag = !"early-access".equals(version) ? "v" + version : version;
|
|
|
|
var url = "https://github.com/jreleaser/jreleaser/releases/download/" + tag + "/jreleaser-tool-provider-" + version + ".jar";
|
2021-03-29 08:57:32 +00:00
|
|
|
|
2021-04-06 16:47:36 +00:00
|
|
|
try (var stream = new URL(url).openStream()) {
|
|
|
|
System.out.printf("✅ Located JReleaser %s%n", version);
|
|
|
|
System.out.printf("⬇️ Downloading %s%n", url);
|
2023-05-24 18:16:06 +00:00
|
|
|
var size = Files.copy(stream, jreleaserJar, REPLACE_EXISTING);
|
|
|
|
System.out.printf("%s << copied %d bytes%n", jreleaserJar, size);
|
2021-04-06 16:47:36 +00:00
|
|
|
System.out.printf("✅ JReleaser installed successfully%n");
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
System.out.printf("❌ JReleaser %s not found%n", version);
|
|
|
|
System.exit(1);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.printf("☠️ JReleaser %s could not be downloaded/copied%n", version);
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
2021-03-27 19:23:46 +00:00
|
|
|
}
|
|
|
|
}
|