From 670cfe3240e796cb80d2475646ce5a79c10d636b Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 10 Nov 2022 15:01:09 +0100 Subject: [PATCH 1/2] Update Scala CLI to 0.1.17 --- scala-cli | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/scala-cli b/scala-cli index 5300e33..5591a68 100755 --- a/scala-cli +++ b/scala-cli @@ -1,5 +1,51 @@ #!/usr/bin/env bash -set -e -SC_EXEC="$(cs get "https://github.com/scala-cli/no-crc32-zip-input-stream/releases/download/scala-cli-launcher/scala-cli-x86_64-pc-linux-v2.gz" --archive)" -chmod +x "$SC_EXEC" -exec "$SC_EXEC" "$@" + +# This is the launcher script of Scala CLI (https://github.com/VirtusLab/scala-cli). +# This script downloads and runs the Scala CLI version set by SCALA_CLI_VERSION below. +# +# Download the latest version of this script at https://github.com/VirtusLab/scala-cli/raw/main/scala-cli.sh + +set -eu + +SCALA_CLI_VERSION="0.1.17" + +GH_ORG="VirtusLab" +GH_NAME="scala-cli" + +if [ "$SCALA_CLI_VERSION" == "nightly" ]; then + TAG="nightly" +else + TAG="v$SCALA_CLI_VERSION" +fi + +if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then + SCALA_CLI_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scala-cli-x86_64-pc-linux.gz" + CACHE_BASE="$HOME/.cache/coursier/v1" +elif [ "$(uname)" == "Darwin" ]; then + SCALA_CLI_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scala-cli-x86_64-apple-darwin.gz" + CACHE_BASE="$HOME/Library/Caches/Coursier/v1" +else + echo "This standalone scala-cli launcher is supported only in Linux and macOS. If you are using Windows, please use the dedicated launcher scala-cli.bat" + exit 1 +fi + +CACHE_DEST="$CACHE_BASE/$(echo "$SCALA_CLI_URL" | sed 's@://@/@')" +SCALA_CLI_BIN_PATH=${CACHE_DEST%.gz} + +if [ ! -f "$CACHE_DEST" ]; then + mkdir -p "$(dirname "$CACHE_DEST")" + TMP_DEST="$CACHE_DEST.tmp-setup" + echo "Downloading $SCALA_CLI_URL" + curl -fLo "$TMP_DEST" "$SCALA_CLI_URL" + mv "$TMP_DEST" "$CACHE_DEST" +fi + +if [ ! -f "$SCALA_CLI_BIN_PATH" ]; then + gunzip -k "$CACHE_DEST" +fi + +if [ ! -x "$SCALA_CLI_BIN_PATH" ]; then + chmod +x "$SCALA_CLI_BIN_PATH" +fi + +exec "$SCALA_CLI_BIN_PATH" "$@" From c00f5ef09ad82318951ccbbbe09ee638ba069fca Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 10 Nov 2022 15:04:07 +0100 Subject: [PATCH 2/2] Use Java 8 --- .github/workflows/ci.yml | 4 ---- src/config.java | 2 ++ .../zip/CustomZipInputStreamTests.scala | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61e6f37..2b1c8be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,6 @@ jobs: fetch-depth: 0 - uses: coursier/cache-action@v6.4 - uses: coursier/setup-action@v1.3.0 - with: - jvm: temurin:17 - name: Test run: ./scala-cli test . --cross --require-tests @@ -31,8 +29,6 @@ jobs: fetch-depth: 0 - uses: coursier/cache-action@v6.4 - uses: coursier/setup-action@v1.3.0 - with: - jvm: temurin:17 - name: Release run: ./scala-cli publish . --cross env: diff --git a/src/config.java b/src/config.java index 4f813ef..b201d3c 100644 --- a/src/config.java +++ b/src/config.java @@ -1,3 +1,5 @@ +//> using jvm "8" + //> using publish.organization "io.github.alexarchambault.scala-cli.tmp" //> using publish.moduleName "zip-input-stream" //> using publish.computeVersion "git:tag" diff --git a/src/test/io/github/scala_cli/zip/CustomZipInputStreamTests.scala b/src/test/io/github/scala_cli/zip/CustomZipInputStreamTests.scala index 5322672..b690255 100644 --- a/src/test/io/github/scala_cli/zip/CustomZipInputStreamTests.scala +++ b/src/test/io/github/scala_cli/zip/CustomZipInputStreamTests.scala @@ -7,12 +7,24 @@ package io.github.scala_cli.zip import coursierapi._ import utest._ -import java.io.{FileInputStream, InputStream} +import java.io.{ByteArrayOutputStream, FileInputStream, InputStream} import java.util.zip.ZipEntry import scala.collection.mutable object CustomZipInputStreamTests extends TestSuite { + private def readAllBytes(is: InputStream): Array[Byte] = { + val baos = new ByteArrayOutputStream + val buf = Array.ofDim[Byte](16 * 1024) + var read = 0 + while ({ + read = is.read(buf) + read >= 0 + }) + if (read > 0) + baos.write(buf, 0, read) + baos.toByteArray + } val tests = Tests { test("simple test") { @@ -30,7 +42,7 @@ object CustomZipInputStreamTests extends TestSuite { ent = zis.getNextEntry() ent != null }) { - val b = zis.readAllBytes() + val b = readAllBytes(zis) entries += ent.getName -> b.length } }