1
- import sbt .*
2
- import sbt .Keys .*
1
+ import sbt ._
2
+ import sbt .Keys ._
3
3
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 ._
8
8
import java .security .MessageDigest
9
9
import java .nio .file .Files
10
10
import java .nio .file .StandardOpenOption .{CREATE , WRITE }
@@ -33,10 +33,7 @@ object SbtModulePatcher extends AutoPlugin {
33
33
val jarFiles =
34
34
classpath.map(_.data).filter(_.getName.endsWith(" .jar" ))
35
35
36
- log.info(" Test if it runs" )
37
-
38
36
jarFiles.foreach { jarFile =>
39
- log.info(s " Checking file ${jarFile.getName}" )
40
37
if (! isModule(jarFile, log)) {
41
38
modifyJar(jarFile, log)
42
39
updateChecksums(jarFile, log)
@@ -57,17 +54,19 @@ object SbtModulePatcher extends AutoPlugin {
57
54
)
58
55
59
56
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" )) {
61
59
return true
62
60
}
61
+ log.debug(s " Analyzing file ${jarFile.getName}... " )
63
62
64
63
val jar = new JarFile (jarFile)
65
64
val entries = jar.entries().asScala
66
65
67
66
// Check if module-info.class exists
68
67
if (entries.exists(_.getName == " module-info.class" )) {
69
68
jar.close()
70
- log.info (
69
+ log.debug (
71
70
s " JAR file ${jarFile.getName} is already a module (module-info.class found) " )
72
71
return true
73
72
}
@@ -91,6 +90,8 @@ object SbtModulePatcher extends AutoPlugin {
91
90
return true
92
91
}
93
92
93
+ log.debug(" File ${jarFile.getName} is not module-friendly, so patching is needed." )
94
+
94
95
jar.close()
95
96
false
96
97
}
@@ -112,8 +113,13 @@ object SbtModulePatcher extends AutoPlugin {
112
113
} else {
113
114
new Manifest ()
114
115
}
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
+ }
115
121
val moduleName = jarFile.getName
116
- .substring(0 , jarFile.getName.indexOf( " _2.12 " ) )
122
+ .substring(0 , idx )
117
123
.replaceAll(" -" , " ." )
118
124
.replaceAll(" _" , " ." )
119
125
val attrs = manifestOut.getMainAttributes
0 commit comments