From 4d92a71cffb1530bc502393efb60987c0f1737b7 Mon Sep 17 00:00:00 2001 From: Ethan McCue Date: Fri, 5 Jan 2024 15:01:51 -0500 Subject: [PATCH] ... --- JRESOLVE_RELEASED_VERSION | 1 + JRESOLVE_VERSION | 1 + Justfile | 8 +- install | 176 ++++++++++++++++++ pom.xml | 4 +- .../java/dev/mccue/resolve/cli/CliMain.java | 10 +- src/main/java/module-info.java | 2 +- 7 files changed, 189 insertions(+), 13 deletions(-) create mode 100644 JRESOLVE_RELEASED_VERSION create mode 100644 JRESOLVE_VERSION create mode 100644 install diff --git a/JRESOLVE_RELEASED_VERSION b/JRESOLVE_RELEASED_VERSION new file mode 100644 index 0000000..6812f81 --- /dev/null +++ b/JRESOLVE_RELEASED_VERSION @@ -0,0 +1 @@ +0.0.3 \ No newline at end of file diff --git a/JRESOLVE_VERSION b/JRESOLVE_VERSION new file mode 100644 index 0000000..6812f81 --- /dev/null +++ b/JRESOLVE_VERSION @@ -0,0 +1 @@ +0.0.3 \ No newline at end of file diff --git a/Justfile b/Justfile index 28a5bba..5c20617 100644 --- a/Justfile +++ b/Justfile @@ -7,7 +7,7 @@ make_reflect_config: ./mvnw -Ppicocli-codegen dependency:copy-dependencies ./mvnw package java \ - --class-path target/jresolve-cli-0.0.2.jar:target/dependency/json-0.2.4.jar:target/dependency/picocli-4.7.5.jar:target/dependency/picocli-codegen-4.7.5.jar:target/dependency/purl-0.0.1.jar:target/dependency/resolve-0.0.4.jar \ + --class-path target/jresolve-cli-0.0.3.jar:target/dependency/json-0.3.1.jar:target/dependency/picocli-4.7.5.jar:target/dependency/picocli-codegen-4.7.5.jar:target/dependency/purl-0.0.1.jar:target/dependency/resolve-0.0.4.jar \ picocli.codegen.aot.graalvm.ReflectionConfigGenerator \ dev.mccue.resolve.cli.CliMain > reflect.json @@ -17,9 +17,9 @@ exe static='': ./mvnw dependency:copy-dependencies ./mvnw package native-image \ - --module-path target/dependency/json-0.2.4.jar:target/dependency/picocli-4.7.5.jar:target/dependency/purl-0.0.1.jar:target/dependency/resolve-0.0.4.jar \ + --module-path target/dependency/json-0.3.1.jar:target/dependency/picocli-4.7.5.jar:target/dependency/purl-0.0.1.jar:target/dependency/resolve-0.0.4.jar \ -H:+UnlockExperimentalVMOptions -H:ReflectionConfigurationFiles=reflect.json -H:+ReportUnsupportedElementsAtRuntime \ - -jar target/jresolve-cli-0.0.2.jar \ + -jar target/jresolve-cli-0.0.3.jar \ {{static}} jresolve exe_windows: @@ -27,4 +27,4 @@ exe_windows: ./mvnw compile ./mvnw dependency:copy-dependencies ./mvnw package - native-image.cmd --module-path "target\dependency\json-0.2.4.jar;target\dependency\picocli-4.7.5.jar;target\dependency\purl-0.0.1.jar;target\dependency\resolve-0.0.4.jar" -H:+UnlockExperimentalVMOptions -H:ReflectionConfigurationFiles=reflect.json -H:+ReportUnsupportedElementsAtRuntime -jar "target\jresolve-cli-0.0.2.jar" jresolve \ No newline at end of file + native-image.cmd --module-path "target\dependency\json-0.3.1.jar;target\dependency\picocli-4.7.5.jar;target\dependency\purl-0.0.1.jar;target\dependency\resolve-0.0.4.jar" -H:+UnlockExperimentalVMOptions -H:ReflectionConfigurationFiles=reflect.json -H:+ReportUnsupportedElementsAtRuntime -jar "target\jresolve-cli-0.0.3.jar" jresolve \ No newline at end of file diff --git a/install b/install new file mode 100644 index 0000000..71be0d8 --- /dev/null +++ b/install @@ -0,0 +1,176 @@ +#!/usr/bin/env bash + +set -euo pipefail + +version="" +checksum="" +static_binary="false" +default_install_dir="/usr/local/bin" +install_dir="$default_install_dir" +download_dir="" +dev_build="" + +print_help() { + echo "Installs latest (or specific) version of jresolve. Installation directory defaults to /usr/local/bin." + echo -e + echo "Usage:" + echo "install [--dir ] [--download-dir ] [--version ] [--checksum ] [--static]" + echo -e + echo "Defaults:" + echo " * Installation directory: ${default_install_dir}" + echo " * Download directory: temporary" + if [[ -z "$checksum" ]]; then + echo " * Checksum: no" + else + echo " * Checksum: ${checksum}" + fi + echo " * Static binary: ${static_binary}" + echo " * Version: " + exit 1 +} + +while [[ $# -gt 0 ]] +do + key="$1" + case "$key" in + --dir) + install_dir="$2" + shift + shift + ;; + --download-dir) + download_dir="$2" + shift + shift + ;; + --version) + version="$2" + shift + shift + ;; + --checksum) + checksum="$2" + shift + shift + ;; + --static) + static_binary="true" + shift + ;; + --dev-build) + dev_build="true" + shift + ;; + *) # unknown option + print_help + shift + ;; + esac +done + +if [[ -z "$download_dir" ]]; then + download_dir="$(mktemp -d)" + trap 'rm -rf "$download_dir"' EXIT +fi + +if [[ "$checksum" != "" ]] && [[ "$version" == "" ]]; then + >&2 echo "Options --checksum and --version should be provided together!" + exit 1 +fi + +if [[ "$version" == "" ]]; then + if [[ "$dev_build" == "true" ]]; then + version="$(curl -sL https://raw.githubusercontent.com/bowbahdoe/jresolve/master/resources/JRESOLVE_VERSION)" + else + version="$(curl -sL https://raw.githubusercontent.com/bowbahdoe/jresolve/master/resources/JRESOLVE_RELEASED_VERSION)" + fi +fi + +case "$(uname -s)" in + Linux*) platform=linux;; + Darwin*) platform=macos;; +esac + +# Ugly ugly conversion of version to a comparable number +IFS='.' read -ra VER <<< "${version//-SNAPSHOT/}" +vernum=$(printf "%03d%03d%03d" "${VER[0]}" "${VER[1]}" "${VER[2]}") + +case "$(uname -m)" in + aarch64) arch=aarch64 + if [[ "$platform" == "linux" ]]; then + static_binary="true" + fi + ;; + arm64) arch="aarch64" + ;; + *) arch=amd64 + # always use static image on linux + if [[ "$platform" == "linux" ]]; then + static_binary="true" + fi + ;; +esac + +ext="tar.gz" +util="$(which tar) -zxf" + +case "$platform-$static_binary" in + linux-true) filename="jresolve-$version-$platform-$arch-static."$ext + ;; + *-true) >&2 echo "Static binaries are only available in Linux platform! Using the non-static one..." + filename="jresolve-$version-$platform-$arch."$ext + ;; + *) filename="jresolve-$version-$platform-$arch."$ext + ;; +esac + +if [[ "$version" == *-SNAPSHOT ]] +then + repo="jresolve-dev-builds" +else + repo="jresolve" +fi + +download_url="https://github.com/jresolve/$repo/releases/download/v$version/$filename" + +# macOS only have shasum available by default +# Some Linux distros (RHEL-like) only have sha256sum available by default (others have both) +if command -v sha256sum >/dev/null; then + sha256sum_cmd="sha256sum" +elif command -v shasum >/dev/null; then + sha256sum_cmd="shasum -a 256" +else + >&2 echo "Either 'sha256sum' or 'shasum' needs to be on PATH for '--checksum' flag!" + >&2 echo "Exiting..." + exit 1 +fi + +# Running this part in a subshell so when it finishes we go back to the previous directory +mkdir -p "$download_dir" && ( + cd "$download_dir" + echo -e "Downloading $download_url to $download_dir" + + curl -o "$filename" -sL "$download_url" + if [[ -n "$checksum" ]]; then + if ! echo "$checksum *$filename" | $sha256sum_cmd --check --status; then + >&2 echo "Failed checksum on $filename" + >&2 echo "Got: $(shasum -a 256 "$filename" | cut -d' ' -f1)" + >&2 echo "Expected: $checksum" + exit 1 + fi + fi + $util "$filename" + rm -f "$filename" +) + +if [[ "$download_dir" != "$install_dir" ]] +then + mkdir -p "$install_dir" + if [ -f "$install_dir/jresolve" ]; then + echo "Moving $install_dir/jresolve to $install_dir/jresolve.old" + mv -f "$install_dir/jresolve" "$install_dir/jresolve.old" + fi + mv -f "$download_dir/jresolve" "$install_dir/bb" +fi + +echo "Successfully installed jresolve in $install_dir" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1865e25..93d3090 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.mccue jresolve-cli - 0.0.2 + 0.0.3 21 @@ -56,7 +56,7 @@ dev.mccue json - 0.2.4 + 0.3.1 dev.mccue diff --git a/src/main/java/dev/mccue/resolve/cli/CliMain.java b/src/main/java/dev/mccue/resolve/cli/CliMain.java index 5125f9a..3917206 100644 --- a/src/main/java/dev/mccue/resolve/cli/CliMain.java +++ b/src/main/java/dev/mccue/resolve/cli/CliMain.java @@ -15,18 +15,19 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.UncheckedIOException; -import java.net.*; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.URISyntaxException; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.*; import java.util.concurrent.Callable; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; @@ -416,9 +417,6 @@ public CliMain() { this(new PrintWriter(System.out), new PrintWriter(System.err)); } - - // this example implements Callable, so parsing, error handling and handling user - // requests for usage help or version help can be done with one line of code. public static void main(String... args) { int exitCode = new CommandLine(new CliMain()) .execute(args); diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index a4b2056..d546ee3 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -2,7 +2,7 @@ import java.util.spi.ToolProvider; -module dev.mccue.resolve.cli{ +module dev.mccue.resolve.cli { requires dev.mccue.resolve; requires dev.mccue.json; requires dev.mccue.purl;