Skip to content

Commit 6872a58

Browse files
Updates to support 2.13. CI build.
1 parent 548a6e5 commit 6872a58

File tree

6 files changed

+77
-15
lines changed

6 files changed

+77
-15
lines changed

.github/workflows/ci.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
paths:
5+
- .github/workflows/ci.yaml
6+
- .sbtopts
7+
- build.sbt
8+
- .scalafmt.conf
9+
- project/**
10+
- src/**
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}
18+
19+
jobs:
20+
code-check:
21+
runs-on: self-hosted
22+
container:
23+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
24+
steps:
25+
- uses: actions/checkout@v4
26+
- run: sbt headerCheckAll
27+
test:
28+
runs-on: self-hosted
29+
container:
30+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
31+
steps:
32+
- uses: actions/checkout@v4
33+
- run: sbt clean test

.github/workflows/publish.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
7+
env:
8+
GITHUB_TOKEN: ${{ secrets.WRITE_PACKAGES }}
9+
10+
jobs:
11+
publish:
12+
runs-on: self-hosted
13+
container:
14+
image: sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.2_13_1.9.9_2.12.19
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- name: sbt publish
20+
run: |
21+
git config --global --add safe.directory $GITHUB_WORKSPACE
22+
sbt clean publish

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ It will patch the JAR name in the JAR file itself, so that the automatic module
2020

2121
## Usage
2222

23-
This plugin currently supports only Scala 2.12.
23+
This plugin currently supports only Scala 2.12 and 2.13.
2424

2525
Add the plugin to your `project/plugins.sbt` file:
2626

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ organizationName := "RAW Labs SA"
1010

1111
organizationHomepage := Some(url("https://www.raw-labs.com/"))
1212

13-
version := "0.0.1"
14-
1513
scalaVersion := "2.12.18"
1614

1715
publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true)
16+
17+
publishTo := Some("GitHub raw-labs Apache Maven Packages" at "https://maven.pkg.github.com/raw-labs/sbt-module-patcher")

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")

src/main/scala/SbtModulePatcher.scala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import sbt.*
2-
import sbt.Keys.*
1+
import sbt._
2+
import sbt.Keys._
33

4-
import java.io.*
5-
import java.nio.file.*
6-
import java.util.jar.*
7-
import scala.collection.JavaConverters.*
4+
import java.io._
5+
import java.nio.file._
6+
import java.util.jar._
7+
import scala.collection.JavaConverters._
88
import java.security.MessageDigest
99
import java.nio.file.Files
1010
import java.nio.file.StandardOpenOption.{CREATE, WRITE}
@@ -33,10 +33,7 @@ object SbtModulePatcher extends AutoPlugin {
3333
val jarFiles =
3434
classpath.map(_.data).filter(_.getName.endsWith(".jar"))
3535

36-
log.info("Test if it runs")
37-
3836
jarFiles.foreach { jarFile =>
39-
log.info(s"Checking file ${jarFile.getName}")
4037
if (!isModule(jarFile, log)) {
4138
modifyJar(jarFile, log)
4239
updateChecksums(jarFile, log)
@@ -57,17 +54,19 @@ object SbtModulePatcher extends AutoPlugin {
5754
)
5855

5956
private def isModule(jarFile: File, log: Logger): Boolean = {
60-
if (!jarFile.getName.contains("_2.12")) {
57+
// Support both Scala 2.12 and 2.13
58+
if (!jarFile.getName.contains("_2.12") && !jarFile.getName.contains("_2.13")) {
6159
return true
6260
}
61+
log.debug(s"Analyzing file ${jarFile.getName}...")
6362

6463
val jar = new JarFile(jarFile)
6564
val entries = jar.entries().asScala
6665

6766
// Check if module-info.class exists
6867
if (entries.exists(_.getName == "module-info.class")) {
6968
jar.close()
70-
log.info(
69+
log.debug(
7170
s"JAR file ${jarFile.getName} is already a module (module-info.class found)")
7271
return true
7372
}
@@ -91,6 +90,8 @@ object SbtModulePatcher extends AutoPlugin {
9190
return true
9291
}
9392

93+
log.debug("File ${jarFile.getName} is not module-friendly, so patching is needed.")
94+
9495
jar.close()
9596
false
9697
}
@@ -112,8 +113,13 @@ object SbtModulePatcher extends AutoPlugin {
112113
} else {
113114
new Manifest()
114115
}
116+
// Support both 2.12 or 2.13
117+
var idx = jarFile.getName.indexOf("_2.12")
118+
if (idx == -1) {
119+
idx = jarFile.getName.indexOf("_2.13")
120+
}
115121
val moduleName = jarFile.getName
116-
.substring(0, jarFile.getName.indexOf("_2.12"))
122+
.substring(0, idx)
117123
.replaceAll("-", ".")
118124
.replaceAll("_", ".")
119125
val attrs = manifestOut.getMainAttributes

0 commit comments

Comments
 (0)