Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: scala-js/scala-js-java-logging
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: scala-native/scala-native-java-logging
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 24 files changed
  • 3 contributors

Commits on May 6, 2024

  1. Scala Native port

    sideeffffect committed May 6, 2024

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    a80cba8 View commit details
  2. Remove -Xfatal-warnings

    sideeffffect committed May 6, 2024
    Copy the full SHA
    0ed8a39 View commit details
  3. Copy the full SHA
    3eb0b1c View commit details

Commits on May 7, 2024

  1. Copy the full SHA
    5067a94 View commit details
  2. Copy the full SHA
    11513a8 View commit details
  3. Update .gitignore

    WojciechMazur committed May 7, 2024
    Copy the full SHA
    8fe93df View commit details
  4. Copy the full SHA
    a351742 View commit details
  5. Copy the full SHA
    5dac8b3 View commit details
  6. Copy the full SHA
    cbca74a View commit details
  7. Set version to 1.0.0

    WojciechMazur authored May 7, 2024
    Copy the full SHA
    bad9ae5 View commit details
  8. Copy the full SHA
    638ed91 View commit details
  9. Towards 1.0.1

    WojciechMazur authored May 7, 2024
    Copy the full SHA
    a1803cf View commit details
Showing with 137 additions and 118 deletions.
  1. +33 −18 .github/workflows/ci.yml
  2. +4 −0 .gitignore
  3. +2 −2 CONTRIBUTING.md
  4. +10 −10 README.md
  5. +43 −41 build.sbt
  6. +1 −1 project/build.properties
  7. +3 −5 project/build.sbt
  8. +1 −1 scalastyle-config.xml
  9. +3 −3 src/main/scala/java/util/logging/Formatter.scala
  10. +1 −1 src/main/scala/java/util/logging/Handler.scala
  11. +5 −5 src/main/scala/java/util/logging/Level.scala
  12. +2 −2 src/main/scala/java/util/logging/LogRecord.scala
  13. +9 −9 src/main/scala/java/util/logging/Logger.scala
  14. +5 −5 src/main/scala/java/util/logging/SimpleFormatter.scala
  15. +2 −2 src/main/scala/java/util/logging/StreamHandler.scala
  16. +1 −1 testSuite/jvm/src/test/scala/org/{scalajs → scalanative}/testsuite/utils/Platform.scala
  17. +2 −2 ...rc/test/scala/org/scalajs → native/src/test/scala/org/scalanative}/testsuite/utils/Platform.scala
  18. +3 −3 ...hared/src/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/HandlerTest.scala
  19. +1 −1 .../shared/src/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/LevelTest.scala
  20. +1 −1 ...red/src/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/LogRecordTest.scala
  21. +1 −1 ...shared/src/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/LoggerTest.scala
  22. +2 −2 ...c/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/SimpleFormatterTest.scala
  23. +1 −1 ...src/test/scala/org/{scalajs → scalanative}/testsuite/javalib/util/logging/StreamHandlerTest.scala
  24. +1 −1 testSuite/shared/src/test/scala/org/{scalajs → scalanative}/testsuite/utils/AssertThrows.scala
51 changes: 33 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
name: CI
on:
push:
tags:
- '*'
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
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", "3.3.3"]
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
- uses: actions/checkout@v4
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1
with:
java-version: "adopt@1.8"
- uses: coursier/cache-action@v5
- name: Scalastyle
run: sbt "++${{ matrix.scalaversion }}" root/scalastyle testSuiteJVM/scalastyle testSuiteJVM/test:scalastyle testSuiteJS/scalastyle testSuiteJS/test:scalastyle
jvm: adopt:8
- 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

publish:
name: Publish
runs-on: ubuntu-22.04
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1
with:
jvm: adopt:8
- name: Setup PGP Key
run: |
echo -n "$PGP_SECRET" | base64 --decode | gpg --batch --import
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
- name: Publish release
env:
MAVEN_USER: "${{ secrets.SONATYPE_USER }}"
MAVEN_PASSWORD: "${{ secrets.SONATYPE_PASSWORD }}"
PGP_PASSPHRASE: "${{ secrets.PGP_PASSWORD }}"
run: sbt "clean;+root/publishSigned"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
target/
**/.bsp
**/.metals
**/.idea
**/.vscode
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!***
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/tree/b166a058c85c6e3d1d305d84cb932efdc5c920af.

## 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"
)
```

@@ -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
84 changes: 43 additions & 41 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
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."))
}
scalaVersion in ThisBuild := (crossScalaVersions in ThisBuild).value.head

ThisBuild / crossScalaVersions := Seq("2.12.19", "2.13.14", "3.3.3")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.last
val commonSettings: Seq[Setting[_]] = Seq(
version := "1.0.1-SNAPSHOT",
organization := "org.scala-js",
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),

homepage := Some(url("http://scala-js.org/")),
organization := "org.scala-native",
scalacOptions ++= Seq("-deprecation", "-feature", "-release:8"),
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:git@github.com:scala-js/scala-js-java-logging.git",
Some("scm:git:git@github.com:scala-js/scala-js-java-logging.git")))
url("https://github.com/scala-native/scala-native-java-logging"),
"scm:git:git@github.com:scala-native/scala-native-java-logging.git",
Some("scm:git:git@github.com:scala-native/scala-native-java-logging.git")))
)

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

mappings in (Compile, packageBin) ~= {
_.filter(!_._2.endsWith(".class"))
lazy val root: Project = project
.in(file("."))
.enablePlugins(ScalaNativePlugin)
.settings(commonSettings)
.settings(
name := "scala-native-java-logging",
Compile / packageBin / mappings ~= {
_.filterNot { case (_, path) =>
Seq(".class", ".tasty").exists(path.endsWith)
}
},
exportJars := true,

publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
@@ -42,8 +35,19 @@ lazy val root: Project = project.in(file(".")).
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
credentials ++= {
for {
user <- sys.env.get("MAVEN_USER")
password <- sys.env.get("MAVEN_PASSWORD")
} yield Credentials(
realm = "Sonatype Nexus Repository Manager",
host = "oss.sonatype.org",
userName = user,
passwd = password
)
}.toSeq,
pomExtra := (
<developers>
<developers>
<developer>
<id>sjrd</id>
<name>Sébastien Doeraene</name>
@@ -64,19 +68,17 @@ lazy val root: Project = project.in(file(".")).
pomIncludeRepository := { _ => false }
)

lazy val testSuite = crossProject(JSPlatform, JVMPlatform).
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
settings(commonSettings: _*).
settings(
testOptions +=
Tests.Argument(TestFramework("com.novocode.junit.JUnitFramework"), "-v", "-a")
).
jsSettings(
name := "java.logging testSuite on JS"
).
jsConfigure(_.dependsOn(root)).
jvmSettings(
lazy val testSuite = crossProject(NativePlatform, JVMPlatform)
.nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin))
.settings(commonSettings: _*)
.settings(
testOptions += Tests.Argument(TestFramework("com.novocode.junit.JUnitFramework"), "-v", "-a")
)
.nativeSettings(
name := "java.logging testSuite on Native"
)
.nativeConfigure(_.dependsOn(root))
.jvmSettings(
name := "java.logging testSuite on JVM",
libraryDependencies +=
"com.novocode" % "junit-interface" % "0.9" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.9" % "test"
)
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
8 changes: 3 additions & 5 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.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"/>
6 changes: 3 additions & 3 deletions src/main/scala/java/util/logging/Formatter.scala
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@ abstract class Formatter protected () {
def getTail(h: Handler): String = ""

def formatMessage(record: LogRecord): String = {
val msg = record.getMessage
val params = record.getParameters
val msg = record.getMessage()
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
2 changes: 1 addition & 1 deletion src/main/scala/java/util/logging/Handler.scala
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ abstract class Handler protected () {
def getLevel(): Level = level

def isLoggable(record:LogRecord): Boolean = {
level.intValue() <= record.getLevel.intValue() &&
level.intValue() <= record.getLevel().intValue() &&
(filter == null || filter.isLoggable(record))
}
}
10 changes: 5 additions & 5 deletions src/main/scala/java/util/logging/Level.scala
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@ object Level {
val FINEST: Level = new Level("FINEST", 300)
val ALL: Level = new Level("ALL", Int.MinValue)

private lazy val knownLevels = Map[String, Level](OFF.getName -> OFF,
SEVERE.getName -> SEVERE, WARNING.getName -> WARNING,
INFO.getName -> INFO, CONFIG.getName -> CONFIG, FINE.getName -> FINE,
FINER.getName -> FINER, FINEST.getName -> FINEST, ALL.getName -> ALL)
private lazy val knownLevels = Map[String, Level](OFF.getName() -> OFF,
SEVERE.getName() -> SEVERE, WARNING.getName() -> WARNING,
INFO.getName() -> INFO, CONFIG.getName() -> CONFIG, FINE.getName() -> FINE,
FINER.getName() -> FINER, FINEST.getName() -> FINEST, ALL.getName() -> ALL)

def parse(name: String): Level =
if (name == null) throw new NullPointerException("Name cannot be null")
@@ -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
4 changes: 2 additions & 2 deletions src/main/scala/java/util/logging/LogRecord.scala
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions src/main/scala/java/util/logging/Logger.scala
Original file line number Diff line number Diff line change
@@ -44,14 +44,14 @@ object Logger {
}

private def updateChildLoggerParent(newParent: Logger): Unit ={
val prefix = s"${newParent.getName}."
val prefix = s"${newParent.getName()}."
// Traverse all child loggers of the new parent
for ((name, childLogger) <- loggers if name.startsWith(prefix)) {
val currentParent = childLogger.getParent
val currentParent = childLogger.getParent()
// For example, when a new parent a.b is added:
// - if child is a.b.c.d (parent = null) => needs to be a.b.c.d (parent = a.b)
// - if child is a.b.c.e (parent = a.b.c) => no update is required.
if (currentParent == null || !currentParent.getName.startsWith(prefix)) {
if (currentParent == null || !currentParent.getName().startsWith(prefix)) {
childLogger.setParent(newParent)
}
}
@@ -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
}

@@ -100,9 +100,9 @@ class Logger(name: String, resourceBundle: String) {
private def levelR: Level = {
@tailrec
def go(logger: Logger): Level = {
if (logger.getLevel != null) logger.getLevel
else if (logger.getParent == null) null
else go(logger.getParent)
if (logger.getLevel() != null) logger.getLevel()
else if (logger.getParent() == null) null
else go(logger.getParent())
}

go(this)
@@ -128,7 +128,7 @@ class Logger(name: String, resourceBundle: String) {
}

def log(record: LogRecord): Unit = {
if (isLoggable(record.getLevel)) {
if (isLoggable(record.getLevel())) {
publish(record)
}
}
Loading