aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-02-26 10:45:00 +0000
committerJuan J. Martinez <jjm@usebox.net>2021-07-22 19:49:48 +0100
commitb2d82bddd39d61c81ce14086809d817a1475e0b5 (patch)
tree0a0e233a2f134abd2da44eece02fc16ffd382dd7
parent2149d073ddb557ad70d2aa0a86289653530e5986 (diff)
downloadspacebeans-b2d82bddd39d61c81ce14086809d817a1475e0b5.tar.gz
spacebeans-b2d82bddd39d61c81ce14086809d817a1475e0b5.zip
Support for JDK 8 (and 11)
-rw-r--r--.github/workflows/actions.yaml8
-rw-r--r--README.md4
-rw-r--r--server/src/net/usebox/gemini/server/Server.scala8
-rw-r--r--server/test/src/ServerSpec.scala34
4 files changed, 36 insertions, 18 deletions
diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml
index acc9ac2..0a78809 100644
--- a/.github/workflows/actions.yaml
+++ b/.github/workflows/actions.yaml
@@ -4,15 +4,19 @@ on: [push]
jobs:
test:
+ strategy:
+ matrix:
+ java-version: [8, 11]
+
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: coursier/cache-action@v5
- - name: Set up JDK 11
+ - name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v1
with:
- java-version: 11
+ java-version: ${{ matrix.java-version }}
- name: Run tests
run: ./mill server.test
diff --git a/README.md b/README.md
index d0c89d5..0b85687 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Check [CHANGES](CHANGES.md) to see what's new in the latest release.
## How to run it
-Download [the `jar` distribution file](https://github.com/reidrac/spacebeans/releases/) and install Java Runtime Environment 11 (or
+Download [the `jar` distribution file](https://github.com/reidrac/spacebeans/releases/) and install Java Runtime Environment 8 (or
later; [openJRE](https://adoptopenjdk.net/) recommended).
You can run the service with:
@@ -92,7 +92,7 @@ validating the certificate, this is perfectly safe.
Requirements:
- - JDK 11
+ - JDK 8 (or later)
- [Mill](https://com-lihaoyi.github.io/mill/) for building
Run the server with `mill server.run` and the tests with `mill server.test`.
diff --git a/server/src/net/usebox/gemini/server/Server.scala b/server/src/net/usebox/gemini/server/Server.scala
index c2fcee3..ed9252d 100644
--- a/server/src/net/usebox/gemini/server/Server.scala
+++ b/server/src/net/usebox/gemini/server/Server.scala
@@ -3,8 +3,7 @@ package net.usebox.gemini.server
import java.nio.charset.Charset
import javax.net.ssl.SSLEngine
import java.net.URI
-import java.nio.file.Path
-import java.nio.file.Files
+import java.nio.file.{Path, FileSystems, Files}
import scala.util.{Try, Success => TrySuccess}
@@ -102,7 +101,10 @@ case class Server(conf: ServiceConf) {
logger.debug("redirect to normalize uri")
PermanentRedirect(req, uri.normalize().toString())
case ("gemini", host, path, Some(vhost)) =>
- val resource = Path.of(vhost.root, path).normalize()
+ val resource = FileSystems
+ .getDefault()
+ .getPath(vhost.root, path)
+ .normalize()
logger.debug(s"requesting: '$resource'")
diff --git a/server/test/src/ServerSpec.scala b/server/test/src/ServerSpec.scala
index 40a2818..d086d2d 100644
--- a/server/test/src/ServerSpec.scala
+++ b/server/test/src/ServerSpec.scala
@@ -1,6 +1,6 @@
package net.usebox.gemini.server
-import java.nio.file.Path
+import java.nio.file.FileSystems
import scala.concurrent.duration._
@@ -33,33 +33,42 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve a known MIME type" in {
Server(TestData.conf)
- .guessMimeType(Path.of("file.html"), None) shouldBe "text/html"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.html"),
+ None
+ ) shouldBe "text/html"
}
it should "resolve de default MIME type for unknown types" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("unknow"),
+ FileSystems.getDefault().getPath("unknow"),
None
) shouldBe TestData.conf.defaultMimeType
}
it should "resolve gemini MIME type" in {
Server(TestData.conf)
- .guessMimeType(Path.of("file.gmi"), None) shouldBe "text/gemini"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gmi"),
+ None
+ ) shouldBe "text/gemini"
Server(TestData.conf)
- .guessMimeType(Path.of("file.gemini"), None) shouldBe "text/gemini"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gemini"),
+ None
+ ) shouldBe "text/gemini"
}
it should "resolve gemini MIME type, including parameters" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some("param")
) shouldBe "text/gemini; param"
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gemini"),
+ FileSystems.getDefault().getPath("file.gemini"),
Some("param")
) shouldBe "text/gemini; param"
}
@@ -67,7 +76,7 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "gemini MIME type parameters are sanitized" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some(" ; param")
) shouldBe "text/gemini; param"
}
@@ -76,14 +85,17 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve a known MIME type" in {
Server(TestData.conf.copy(mimeTypes = TestData.mimeTypes))
- .guessMimeType(Path.of("file.gmi"), None) shouldBe "config"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gmi"),
+ None
+ ) shouldBe "config"
}
it should "include parameters for text/gemini MIME types" in {
Server(
TestData.conf.copy(mimeTypes = Some(Map("text/gemini" -> List(".gmi"))))
).guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some("param")
) shouldBe "text/gemini; param"
}
@@ -91,7 +103,7 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve de default MIME type for unknown types" in {
Server(TestData.conf.copy(mimeTypes = TestData.mimeTypes))
.guessMimeType(
- Path.of("unknow"),
+ FileSystems.getDefault().getPath("unknow"),
None
) shouldBe TestData.conf.defaultMimeType
}