Skip to content

Commit

Permalink
Merge pull request #1 from sideeffffect/scala-native-port
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect authored May 6, 2024
2 parents b166a05 + 0ed8a39 commit 3eb0b1c
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 71 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@ jobs:
strategy:
fail-fast: false
matrix:
scalaversion: ["2.11.12", "2.12.10", "2.13.1"]
scalajsversion: ["1.x", "0.6.x"]
include:
- scalaversion: "2.10.7"
scalajsversion: "0.6.x"
env:
SCALAJS_VERSION: "${{ matrix.scalajsversion == '0.6.x' && '0.6.31' || '' }}"
scalaversion: ["2.12.19", "2.13.14"]
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
with:
java-version: "[email protected]"
- uses: coursier/cache-action@v5
- name: Scalastyle
run: sbt "++${{ matrix.scalaversion }}" root/scalastyle testSuiteJVM/scalastyle testSuiteJVM/test:scalastyle testSuiteJS/scalastyle testSuiteJS/test:scalastyle
run: sbt "++${{ matrix.scalaversion }}" root/scalastyle testSuiteJVM/scalastyle testSuiteJVM/test:scalastyle testSuiteNative/scalastyle testSuiteNative/test:scalastyle
- name: Test JVM
run: sbt "++${{ matrix.scalaversion }}" testSuiteJVM/test
- name: Test JS
run: sbt "++${{ matrix.scalaversion }}" testSuiteJS/test
- name: Test JS fullOpt
run: sbt "++${{ matrix.scalaversion }}" 'set scalaJSStage in Global := FullOptStage' testSuiteJS/test
- name: Test Native
run: sbt "++${{ matrix.scalaversion }}" testSuiteNative/test
- name: Test publish
run: sbt "++${{ matrix.scalaversion }}" publishLocal
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Contributing guidelines

See the [contributing guidelines of Scala.js core](https://github.com/scala-js/scala-js/blob/main/CONTRIBUTING.md).
See the [contributing guidelines of Scala Native core](https://github.com/scala-native/scala-native/blob/main/CONTRIBUTING.md).
The same guidelines apply to this repository.

## Very important notice

`scalajs-java-logging` contains a reimplementation of part of the JDK in Scala.js itself.
`scala-native-java-logging` contains a reimplementation of part of the JDK in Scala Native itself.

***To contribute to this code, it is strictly forbidden to even look at the
source code of the Oracle JDK or OpenJDK!***
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# scalajs-java-logging
# scala-native-java-logging

[![CI](https://github.com/scala-js/scala-js-java-logging/actions/workflows/ci.yml/badge.svg)](https://github.com/scala-js/scala-js-java-logging/actions/workflows/ci.yml)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org/)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.0.0.svg)](https://www.scala-js.org)
[![CI](https://github.com/scala-native/scala-native-java-logging/actions/workflows/ci.yml/badge.svg)](https://github.com/scala-native/scala-native-java-logging/actions/workflows/ci.yml)

`scalajs-java-logging` is a BSD-licensed reimplementation of the `java.logging` API for Scala.js.
It enables this API in Scala.js projects.
`scala-native-java-logging` is a BSD-licensed reimplementation of the `java.logging` API for Scala Native.
It enables this API in Scala Native projects.

Ported from https://github.com/scala-js/scala-js-java-logging.

## Usage

Simply add the following line to your sbt settings:

```scala
libraryDependencies += "org.scala-js" %%% "scalajs-java-logging" % "1.0.0"
libraryDependencies += "org.scala-native" %%% "scala-native-java-logging" % "1.0.0"
```

If you have a `crossProject`, the setting must be used only in the JS part:

```scala
lazy val myCross = crossProject.
...
jsSettings.(
libraryDependencies += "org.scala-js" %%% "scalajs-java-logging" % "1.0.0"
nativeSettings.(
libraryDependencies += "org.scala-native" %%% "scala-native-java-logging" % "1.0.0"
)
```

Expand All @@ -36,7 +36,7 @@ classes and methods!

## License

`scalajs-java-logging` is distributed under the
`scala-native-java-logging` is distributed under the
[BSD 3-Clause license](./LICENSE.txt).

## Contributing
Expand Down
36 changes: 15 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import sbtcrossproject.crossProject

crossScalaVersions in ThisBuild := {
val allVersions = Seq("2.12.10", "2.11.12", "2.10.7", "2.13.1")
if (scalaJSVersion.startsWith("0.6."))
allVersions
else
allVersions.filter(!_.startsWith("2.10."))
}
crossScalaVersions in ThisBuild := Seq("2.12.19", "2.13.14")
scalaVersion in ThisBuild := (crossScalaVersions in ThisBuild).value.head

val commonSettings: Seq[Setting[_]] = Seq(
version := "1.0.1-SNAPSHOT",
organization := "org.scala-js",
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),
organization := "org.scala-native",
scalacOptions ++= Seq("-deprecation", "-feature"),

homepage := Some(url("http://scala-js.org/")),
homepage := Some(url("http://scala-native.org/")),
licenses += ("BSD New",
url("https://github.com/scala-js/scala-js-java-logging/blob/main/LICENSE")),
url("https://github.com/scala-native/scala-native-java-logging/blob/main/LICENSE")),
scmInfo := Some(ScmInfo(
url("https://github.com/scala-js/scala-js-java-logging"),
"scm:git:[email protected]:scala-js/scala-js-java-logging.git",
Some("scm:git:[email protected]:scala-js/scala-js-java-logging.git")))
url("https://github.com/scala-native/scala-native-java-logging"),
"scm:git:[email protected]:scala-native/scala-native-java-logging.git",
Some("scm:git:[email protected]:scala-native/scala-native-java-logging.git")))
)

lazy val root: Project = project.in(file(".")).
enablePlugins(ScalaJSPlugin).
enablePlugins(ScalaNativePlugin).
settings(commonSettings).
settings(
name := "scalajs-java-logging",
name := "scala-native-java-logging",

mappings in (Compile, packageBin) ~= {
_.filter(!_._2.endsWith(".class"))
Expand Down Expand Up @@ -64,17 +58,17 @@ lazy val root: Project = project.in(file(".")).
pomIncludeRepository := { _ => false }
)

lazy val testSuite = crossProject(JSPlatform, JVMPlatform).
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
lazy val testSuite = crossProject(NativePlatform, JVMPlatform).
nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin)).
settings(commonSettings: _*).
settings(
testOptions +=
Tests.Argument(TestFramework("com.novocode.junit.JUnitFramework"), "-v", "-a")
).
jsSettings(
name := "java.logging testSuite on JS"
nativeSettings(
name := "java.logging testSuite on Native"
).
jsConfigure(_.dependsOn(root)).
nativeConfigure(_.dependsOn(root)).
jvmSettings(
name := "java.logging testSuite on JVM",
libraryDependencies +=
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.3
sbt.version=1.10.0
7 changes: 2 additions & 5 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).filter(_ != "").getOrElse("1.0.0")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.1")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.1")

addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
2 changes: 1 addition & 1 deletion scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<scalastyle>
<name>Scalastyle configuration for Scala.js</name>
<name>Scalastyle configuration for Scala Native</name>

<check level="error" enabled="true" class="org.scalastyle.file.FileTabChecker"/>
<check level="error" enabled="true" class="org.scalastyle.file.WhitespaceEndOfLineChecker"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/java/util/logging/Formatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class Formatter protected () {
val params = record.getParameters

if (params != null && params.length > 0) {
// The Java spec uses java.text formatting not available in Scala.js
// The Java spec uses java.text formatting not available in Scala Native
// Instead we'll do simple text replacement, very imperative
var msgAccumulator = new StringBuilder()
var inParam = false
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/java/util/logging/Level.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Level protected (private[this] val name: String,

def getName(): String = name

// Not implemented, no locale in Scala.js
// Not implemented, no locale in Scala Native
//def getLocalizedName():String

override def toString(): String = name
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/java/util/logging/LogRecord.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class LogRecord(private[this] var level: Level, private[this] var msg: String) {
def setLoggerName(loggerName: String): Unit =
this.loggerName = loggerName

// Not implemented, no locale in Scala.js
// Not implemented, no locale in Scala Native
//def getResourceBundle():ResourceBundle = ???

// Not implemented, no locale in Scala.js
// Not implemented, no locale in Scala Native
//def setResourceBundle(bundle: ResourceBundle):Unit = ???

// Message is not localizable, return null
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/java/util/logging/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ object Logger {
loggers.getOrElseUpdate(name, newLogger(name))
}

// Not implemented, no resource bundle in scala.js
// Not implemented, no resource bundle in Scala Native
//def getLogger(name: String, resourceBundle: String): Logger

def getAnonymousLogger(): Logger = {
// No references to anonymous loggers are kept
newLogger(null)
}

// Not implemented, no resource bundle in scala.js
// Not implemented, no resource bundle in Scala Native
//def getAnonymousLogger(resourceBundle: String):Logger
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.utils
package org.scalanative.testsuite.utils

object Platform {
/** Returns `true` if and only if the code is executing on a JVM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
** /____/\___/_/ |_/____/_/ | |__/ /____/ **
** |/____/ **
\* */
package org.scalajs.testsuite.utils
package org.scalanative.testsuite.utils

import scala.scalajs.runtime
import scala.scalanative.runtime

object Platform {
/** Returns `true` if and only if the code is executing on a JVM.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.util.logging._

import org.junit.Test
import org.junit.Assert._

import org.scalajs.testsuite.utils.Platform
import org.scalajs.testsuite.utils.AssertThrows._
import org.scalanative.testsuite.utils.Platform
import org.scalanative.testsuite.utils.AssertThrows._

class HandlerTest {
class TestHandler extends Handler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.util.logging.Level

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.util.logging.{Level, LogRecord}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.util.logging._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.util.logging.{Level, LogRecord, SimpleFormatter}

import org.junit.{Before, Test}
import org.junit.Assert._

import org.scalajs.testsuite.utils.Platform
import org.scalanative.testsuite.utils.Platform

class SimpleFormatterTest {
@Before def clearProperties():Unit = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.javalib.util.logging
package org.scalanative.testsuite.javalib.util.logging

import java.io.ByteArrayOutputStream
import java.util.logging._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalajs.testsuite.utils
package org.scalanative.testsuite.utils

object AssertThrows {
/** Backport implementation of Assert.assertThrows to be used until JUnit 4.13 is
Expand Down

0 comments on commit 3eb0b1c

Please sign in to comment.