Skip to content

Commit 29de0d6

Browse files
authored
Review and fix proguard contrib plugin (#4788)
Removed hardcoded `proguardVersion`. Re-enabled and overhauled tests. Manage versions used in tests from Mill build. Pull request: #4788
1 parent 52f1d7f commit 29de0d6

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

build.mill

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ object Deps {
241241
val ktfmt = ivy"com.facebook:ktfmt:0.53"
242242
val ktlint = ivy"com.pinterest.ktlint:ktlint-core:0.49.1"
243243
val palantirFormat = ivy"com.palantir.javaformat:palantir-java-format:2.51.0"
244+
val proguard = ivy"com.guardsquare:proguard-base:7.7.0"
244245
val revApi = ivy"org.revapi:revapi-standalone:0.12.0"
245246
val sbtTestInterface = ivy"com.github.sbt:junit-interface:0.13.2"
246247

@@ -258,6 +259,7 @@ object Deps {
258259
ktfmt,
259260
ktlint,
260261
palantirFormat,
262+
proguard,
261263
revApi,
262264
sbtTestInterface
263265
)
@@ -571,7 +573,8 @@ trait MillBaseTestsModule extends TestModule {
571573
s"-DTEST_ZIOTEST_VERSION=${Deps.TestDeps.zioTest.version}",
572574
s"-DTEST_ZINC_VERSION=${Deps.zinc.version}",
573575
s"-DTEST_KOTLIN_VERSION=${Deps.kotlinCompiler.version}",
574-
s"-DTEST_SBT_VERSION=${Deps.sbt.version}"
576+
s"-DTEST_SBT_VERSION=${Deps.sbt.version}",
577+
s"-DTEST_PROGUARD_VERSION=${Deps.RuntimeDeps.proguard.version}"
575578
)
576579
}
577580

contrib/proguard/src/mill/contrib/proguard/Proguard.scala

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ trait Proguard extends ScalaModule {
2121
* The version of proguard to download from Maven.
2222
* https://mvnrepository.com/artifact/com.guardsquare/proguard-base
2323
*/
24-
def proguardVersion: T[String] = Task {
25-
Task.log.error(
26-
"Using default proguard version is deprecated. Please override target proguardVersion to specify the version."
27-
)
28-
"7.2.2"
29-
}
24+
def proguardVersion: T[String]
3025

3126
/** Run the "shrink" step in the proguard pipeline. Defaults to true. */
3227
def shrink: T[Boolean] = Task { true }
@@ -114,9 +109,7 @@ trait Proguard extends ScalaModule {
114109
mainClass = "proguard.ProGuard",
115110
classPath = proguardClasspath().map(_.path).toVector,
116111
mainArgs = args,
117-
cwd = Task.dest,
118-
stdin = os.Inherit,
119-
stdout = os.Inherit
112+
cwd = Task.dest
120113
)
121114

122115
// the call above already throws an exception on a non-zero exit code,
@@ -126,12 +119,11 @@ trait Proguard extends ScalaModule {
126119

127120
/**
128121
* The location of the proguard jar files.
129-
* These are downloaded from JCenter and fed to `java -cp`
130122
*/
131123
def proguardClasspath: T[Seq[PathRef]] = Task {
132-
defaultResolver().resolveDeps(
133-
Seq(ivy"com.guardsquare:proguard-base:${proguardVersion()}")
134-
)
124+
defaultResolver().resolveDeps(Seq(
125+
ivy"com.guardsquare:proguard-base:${proguardVersion()}"
126+
))
135127
}
136128

137129
private def steps: T[Seq[String]] = Task {
@@ -161,10 +153,10 @@ trait Proguard extends ScalaModule {
161153
* These are fed as-is to the proguard command.
162154
*/
163155
def additionalOptions: T[Seq[String]] = Task {
164-
Task.log.error(
156+
Task.log.warn(
165157
"Proguard is set to not warn about message: can't find referenced method 'void invoke()' in library class java.lang.invoke.MethodHandle"
166158
)
167-
T.log.error(
159+
T.log.warn(
168160
"""Proguard is set to not warn about message: "scala.quoted.Type: can't find referenced class scala.AnyKind""""
169161
)
170162
Seq[String](
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import java.nio.file.{Files, Paths}
22

3-
object Main extends App {}
3+
object Main {
4+
def main(args: Array[String]): Unit = {
5+
Console.println("Hello " + args.mkString(" ") + "!")
6+
}
7+
}

contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@ package mill.contrib.proguard
22

33
import mill.*
44
import mill.define.{Discover, Target}
5-
import mill.util.MillModuleUtil.millProjectModule
65
import mill.scalalib.ScalaModule
7-
import mill.testkit.UnitTester
8-
import mill.testkit.TestBaseModule
6+
import mill.testkit.{TestBaseModule, UnitTester}
7+
import mill.util.Jvm
98
import os.Path
109
import utest.*
1110

1211
object ProguardTests extends TestSuite {
1312

1413
object proguard extends TestBaseModule with ScalaModule with Proguard {
15-
override def scalaVersion: T[String] = T(sys.props.getOrElse("MILL_SCALA_3_NEXT_VERSION", ???))
16-
17-
def proguardContribClasspath = Task {
18-
millProjectModule("mill-contrib-proguard", repositoriesTask())
14+
// TODO: This test works for a Scala 2.13 App, but not for a Scala 3 App, probably due to tasty files
15+
override def scalaVersion: T[String] = Task.Input {
16+
sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)
17+
}
18+
def proguardVersion = Task.Input {
19+
sys.props.getOrElse("TEST_PROGUARD_VERSION", ???)
1920
}
20-
21-
override def runClasspath: T[Seq[PathRef]] =
22-
Task { super.runClasspath() ++ proguardContribClasspath() }
2321

2422
lazy val millDiscover = Discover[this.type]
2523
}
@@ -37,11 +35,39 @@ object ProguardTests extends TestSuite {
3735
)
3836
}
3937

40-
test("should create a proguarded jar") - UnitTester(proguard, testModuleSourcesPath).scoped {
41-
_ =>
38+
test("assembly jar") - UnitTester(proguard, testModuleSourcesPath).scoped {
39+
eval =>
4240
// Not sure why this is broken in Scala 3
43-
// val Right(result) = eval.apply(proguard.proguard)
44-
// assert(os.exists(result.value.path))
41+
val Right(result) = eval.apply(proguard.assembly): @unchecked
42+
assert(os.exists(result.value.path))
43+
44+
val res = os.call(
45+
cmd = (Jvm.javaExe, "-jar", result.value.path, "world"),
46+
mergeErrIntoOut = true,
47+
check = false
48+
)
49+
assert(
50+
res.exitCode == 0,
51+
res.out.text().contains("Hello world!")
52+
)
53+
s"jar size: ${os.size(result.value.path)}"
54+
}
55+
56+
test("should create a proguarded jar") - UnitTester(proguard, testModuleSourcesPath).scoped {
57+
eval =>
58+
val Right(result) = eval.apply(proguard.proguard): @unchecked
59+
assert(os.exists(result.value.path))
60+
61+
val res = os.call(
62+
cmd = (Jvm.javaExe, "-jar", result.value.path, "proguarded", "world"),
63+
mergeErrIntoOut = true,
64+
check = false
65+
)
66+
assert(
67+
res.exitCode == 0,
68+
res.out.text().contains("Hello proguarded world!")
69+
)
70+
s"jar size: ${os.size(result.value.path)}"
4571
}
4672
}
4773
}

0 commit comments

Comments
 (0)