From c47ad966d6db236101d04f854e293122d2e3d058 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 7 May 2024 16:36:00 +0200 Subject: [PATCH 1/5] Remove deprecated syntax in build.sbt. Add Scala 3.3 to cross scala versions --- build.sbt | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/build.sbt b/build.sbt index eed9818..3d502b6 100644 --- a/build.sbt +++ b/build.sbt @@ -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")), @@ -17,17 +15,18 @@ val commonSettings: Seq[Setting[_]] = Seq( Some("scm:git:git@github.com: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/" @@ -37,7 +36,7 @@ lazy val root: Project = project.in(file(".")). Some("releases" at nexus + "service/local/staging/deploy/maven2") }, pomExtra := ( - + sjrd Sébastien Doeraene @@ -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" ) From e8b3f0f93842f3215ca7858d21867c496271afba Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 7 May 2024 16:36:33 +0200 Subject: [PATCH 2/5] Update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 2f7896d..70a100b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ target/ +**/.bsp +**/.metals +**/.idea +**/.vscode From a14d5db0fd175ff6df9004f6c667342a98f72609 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 7 May 2024 16:37:08 +0200 Subject: [PATCH 3/5] Migrate syntax to allow for cross compilation using Scala 3 --- src/main/scala/java/util/logging/Formatter.scala | 4 ++-- src/main/scala/java/util/logging/Handler.scala | 2 +- src/main/scala/java/util/logging/Level.scala | 8 ++++---- src/main/scala/java/util/logging/Logger.scala | 14 +++++++------- .../scala/java/util/logging/SimpleFormatter.scala | 10 +++++----- .../scala/java/util/logging/StreamHandler.scala | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/scala/java/util/logging/Formatter.scala b/src/main/scala/java/util/logging/Formatter.scala index 138ff6c..ea19eb2 100644 --- a/src/main/scala/java/util/logging/Formatter.scala +++ b/src/main/scala/java/util/logging/Formatter.scala @@ -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 diff --git a/src/main/scala/java/util/logging/Handler.scala b/src/main/scala/java/util/logging/Handler.scala index 34b7cd1..0c3db08 100644 --- a/src/main/scala/java/util/logging/Handler.scala +++ b/src/main/scala/java/util/logging/Handler.scala @@ -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)) } } diff --git a/src/main/scala/java/util/logging/Level.scala b/src/main/scala/java/util/logging/Level.scala index d1815a4..12d222f 100644 --- a/src/main/scala/java/util/logging/Level.scala +++ b/src/main/scala/java/util/logging/Level.scala @@ -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") diff --git a/src/main/scala/java/util/logging/Logger.scala b/src/main/scala/java/util/logging/Logger.scala index 6f39960..49a22b1 100644 --- a/src/main/scala/java/util/logging/Logger.scala +++ b/src/main/scala/java/util/logging/Logger.scala @@ -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) } } @@ -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) } } diff --git a/src/main/scala/java/util/logging/SimpleFormatter.scala b/src/main/scala/java/util/logging/SimpleFormatter.scala index 50ed5ba..ab96dcb 100644 --- a/src/main/scala/java/util/logging/SimpleFormatter.scala +++ b/src/main/scala/java/util/logging/SimpleFormatter.scala @@ -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()) } } diff --git a/src/main/scala/java/util/logging/StreamHandler.scala b/src/main/scala/java/util/logging/StreamHandler.scala index 60a1002..ae6803b 100644 --- a/src/main/scala/java/util/logging/StreamHandler.scala +++ b/src/main/scala/java/util/logging/StreamHandler.scala @@ -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 From aae3821c385227853964084906219ef4963069e9 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 7 May 2024 16:49:16 +0200 Subject: [PATCH 4/5] Setup publishing artifacts via CI --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++-------- project/build.sbt | 1 + 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd9e593..ede59b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,8 @@ name: CI on: push: + tags: + - '*' branches: - main pull_request: @@ -8,22 +10,43 @@ on: - 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@v3 + - 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 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@v3 + - 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" diff --git a/project/build.sbt b/project/build.sbt index 6e94f73..70b47e6 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -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") From a006121c89b1e0fd75220b3ef34a791956247db3 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 7 May 2024 17:02:34 +0200 Subject: [PATCH 5/5] Use checkout@v4 instead of deprecated v3 Node.js 16 version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ede59b7..532a7dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: matrix: scalaversion: ["2.12.19", "2.13.14", "3.3.3"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: coursier/cache-action@v6 - uses: coursier/setup-action@v1 with: @@ -34,7 +34,7 @@ jobs: if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') needs: [build] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: coursier/cache-action@v6 - uses: coursier/setup-action@v1 with: