Skip to content

Commit

Permalink
Merge pull request #6 from alexarchambault/java-8
Browse files Browse the repository at this point in the history
Use Java 8
  • Loading branch information
alexarchambault authored Nov 10, 2022
2 parents 0127041 + c00f5ef commit 27a845e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
fetch-depth: 0
- uses: coursier/[email protected]
- uses: coursier/[email protected]
with:
jvm: temurin:17
- name: Test
run: ./scala-cli test . --cross --require-tests

Expand All @@ -31,8 +29,6 @@ jobs:
fetch-depth: 0
- uses: coursier/[email protected]
- uses: coursier/[email protected]
with:
jvm: temurin:17
- name: Release
run: ./scala-cli publish . --cross
env:
Expand Down
54 changes: 50 additions & 4 deletions scala-cli
Original file line number Diff line number Diff line change
@@ -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" "$@"
2 changes: 2 additions & 0 deletions src/config.java
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 14 additions & 2 deletions src/test/io/github/scala_cli/zip/CustomZipInputStreamTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") {

Expand All @@ -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
}
}
Expand Down

0 comments on commit 27a845e

Please sign in to comment.