Skip to content

Prepare for release #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +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.12.19", "2.13.14"]
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: "[email protected]"
- uses: coursier/cache-action@v5
- name: Scalastyle
run: sbt "++${{ matrix.scalaversion }}" root/scalastyle testSuiteJVM/scalastyle testSuiteJVM/test:scalastyle testSuiteNative/scalastyle testSuiteNative/test:scalastyle
jvm: adopt:8
- name: Test JVM
run: sbt "++${{ matrix.scalaversion }}" testSuiteJVM/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
51 changes: 24 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import sbtcrossproject.crossProject

crossScalaVersions in ThisBuild := Seq("2.12.19", "2.13.14")
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.0-SNAPSHOT",
organization := "org.scala-native",
scalacOptions ++= Seq("-deprecation", "-feature"),

scalacOptions ++= Seq("-deprecation", "-feature", "-release:8"),
homepage := Some(url("http://scala-native.org/")),
licenses += ("BSD New",
url("https://github.com/scala-native/scala-native-java-logging/blob/main/LICENSE")),
Expand All @@ -17,17 +15,18 @@ val commonSettings: Seq[Setting[_]] = Seq(
Some("scm:git:[email protected]:scala-native/scala-native-java-logging.git")))
)

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

mappings in (Compile, packageBin) ~= {
_.filter(!_._2.endsWith(".class"))
Compile / packageBin / mappings ~= {
_.filterNot { case (_, path) =>
Seq(".class", ".tasty").exists(path.endsWith)
}
},
exportJars := true,

publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand All @@ -37,7 +36,7 @@ lazy val root: Project = project.in(file(".")).
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
pomExtra := (
<developers>
<developers>
<developer>
<id>sjrd</id>
<name>Sébastien Doeraene</name>
Expand All @@ -58,19 +57,17 @@ lazy val root: Project = project.in(file(".")).
pomIncludeRepository := { _ => false }
)

lazy val testSuite = crossProject(NativePlatform, JVMPlatform).
nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin)).
settings(commonSettings: _*).
settings(
testOptions +=
Tests.Argument(TestFramework("com.novocode.junit.JUnitFramework"), "-v", "-a")
).
nativeSettings(
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(
)
.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"
)
1 change: 1 addition & 0 deletions project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ 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")
4 changes: 2 additions & 2 deletions src/main/scala/java/util/logging/Formatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ 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 Native
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/java/util/logging/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
8 changes: 4 additions & 4 deletions src/main/scala/java/util/logging/Level.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/java/util/logging/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/java/util/logging/SimpleFormatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class SimpleFormatter extends Formatter {
val fmt =
System.getProperty("java.util.logging.SimpleFormatter.format", defaultFmt)

String.format(fmt, new Date(record.getMillis),
Option(record.getSourceClassName).getOrElse(""),
Option(record.getLoggerName).getOrElse(""),
record.getLevel,
String.format(fmt, new Date(record.getMillis()),
Option(record.getSourceClassName()).getOrElse(""),
Option(record.getLoggerName()).getOrElse(""),
record.getLevel(),
formatMessage(record),
record.getThrown)
record.getThrown())
}
}
4 changes: 2 additions & 2 deletions src/main/scala/java/util/logging/StreamHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class StreamHandler(private[this] var out: OutputStream,
private[this] var headWritten: Boolean = false

private def encodingOrDefault: Charset =
if (getEncoding == null) Charset.defaultCharset()
else Charset.forName(getEncoding)
if (getEncoding() == null) Charset.defaultCharset()
else Charset.forName(getEncoding())

protected def setOutputStream(out: OutputStream): Unit = {
// Required by javadocs
Expand Down