Skip to content

Commit f7cd2cf

Browse files
committed
cleanup
1 parent 6d02694 commit f7cd2cf

File tree

4 files changed

+75
-54
lines changed

4 files changed

+75
-54
lines changed

libs/groovylib/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import millbuild.*
88
object `package` extends MillPublishScalaModule with BuildInfo {
99

1010
def moduleDeps = Seq(build.libs.javalib, build.libs.javalib.testrunner, api)
11-
def localTestExtraModules =
11+
def localTestExtraModules: Seq[MillJavaModule] =
1212
super.localTestExtraModules ++ Seq(worker)
1313

1414
def buildInfoPackageName = "mill.groovylib"

libs/groovylib/src/mill/groovylib/GroovyModule.scala

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import mill.api.daemon.internal.bsp.{BspBuildTarget, BspModuleApi}
1212
import mill.javalib.api.internal.{JavaCompilerOptions, JvmWorkerApi, ZincCompileJava}
1313

1414
/**
15-
* Core configuration required to compile a single Groovy module
15+
* Core configuration required to compile a single Groovy module.
16+
*
17+
* Resolves
1618
*/
1719
trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
1820

@@ -33,36 +35,31 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
3335
* All individual source files fed into the compiler.
3436
*/
3537
override def allSourceFiles: T[Seq[PathRef]] = Task {
36-
Lib.findSourceFiles(allSources(), Seq("groovy", "java")).map(PathRef(_))
38+
allGroovySourceFiles() ++ allJavaSourceFiles()
3739
}
3840

3941
/**
4042
* All individual Java source files fed into the compiler.
4143
* Subset of [[allSourceFiles]].
4244
*/
4345
private def allJavaSourceFiles: T[Seq[PathRef]] = Task {
44-
allSourceFiles().filter(_.path.ext.toLowerCase() == "java")
46+
Lib.findSourceFiles(allSources(), Seq("java")).map(PathRef(_))
4547
}
4648

4749
/**
4850
* All individual Groovy source files fed into the compiler.
4951
* Subset of [[allSourceFiles]].
5052
*/
5153
private def allGroovySourceFiles: T[Seq[PathRef]] = Task {
52-
allSourceFiles().filter(path => Seq("groovy").contains(path.path.ext.toLowerCase()))
54+
Lib.findSourceFiles(allSources(), Seq("groovy")).map(PathRef(_))
5355
}
5456

5557
/**
5658
* The dependencies of this module.
57-
* Defaults to add the groovy dependency matching the [[groovyVersion]].
59+
* Defaults to add the Groovy dependency matching the [[groovyVersion]].
5860
*/
5961
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
60-
super.mandatoryMvnDeps()
61-
++
62-
groovyCompilerMvnDeps()
63-
// Seq(
64-
// mvn"org.apache.groovy:groovy:${groovyVersion()}"
65-
// )
62+
super.mandatoryMvnDeps() ++ groovyCompilerMvnDeps()
6663
}
6764

6865
def jvmWorkerRef: ModuleRef[JvmWorkerModule] = jvmWorker
@@ -86,28 +83,11 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
8683
/**
8784
* The Ivy/Coursier dependencies resembling the Groovy compiler.
8885
*
89-
* Default is derived from [[groovyCompilerVersion]].
86+
* Default is derived from [[groovyVersion]].
9087
*/
9188
def groovyCompilerMvnDeps: T[Seq[Dep]] = Task {
9289
val gv = groovyVersion()
93-
val compilerDep = mvn"org.apache.groovy:groovy-all:$gv"
94-
Seq(compilerDep)
95-
}
96-
97-
/**
98-
* Compiler Plugin dependencies.
99-
*/
100-
def groovyCompilerPluginMvnDeps: T[Seq[Dep]] = Task { Seq.empty[Dep] }
101-
102-
/**
103-
* The resolved plugin jars
104-
*/
105-
def groovyCompilerPluginJars: T[Seq[PathRef]] = Task {
106-
val jars = defaultResolver().classpath(
107-
allMvnDeps(),
108-
resolutionParamsMapOpt = None
109-
)
110-
jars.toSeq
90+
Seq(mvn"org.apache.groovy:groovy:$gv")
11191
}
11292

11393
/**
@@ -118,9 +98,8 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
11898
}
11999

120100
/**
121-
* The actual Groovy compile task (used by [[compile]] and [[groovycHelp]]).
101+
* The actual Groovy compile task (used by [[compile]]).
122102
*/
123-
// TODO joint compilation: generate groovy-stubs -> compile java -> compile groovy -> delete stubs (or keep for debugging)
124103
protected def groovyCompileTask(): Task[CompilationResult] =
125104
Task.Anon {
126105
val ctx = Task.ctx()
@@ -140,9 +119,9 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
140119

141120
def compileJava: Result[CompilationResult] = {
142121
ctx.log.info(
143-
s"Compiling ${javaSourceFiles.size} Java sources to ${classes} ..."
122+
s"Compiling ${javaSourceFiles.size} Java sources to $classes ..."
144123
)
145-
// The compile step is lazy, but its dependencies are not!
124+
// The compiler step is lazy, but its dependencies are not!
146125
internalCompileJavaFiles(
147126
worker = jvmWorkerRef().internalWorker(),
148127
upstreamCompileOutput = updateCompileOutput,
@@ -170,14 +149,15 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
170149

171150
if(isMixed || isGroovy){
172151
ctx.log.info(
173-
s"Compiling ${groovySourceFiles.size} Groovy sources to ${classes} ..."
152+
s"Compiling ${groovySourceFiles.size} Groovy sources to $classes ..."
174153
)
175154

176155
val workerGroovyResult =
177156
GroovyWorkerManager.groovyWorker().withValue(groovyCompilerClasspath()) {
178157
_.compile(groovySourceFiles, compileCp, classes)
179158
}
180159

160+
// TODO figure out if there is a better way to do this
181161
val analysisFile = dest / "groovy.analysis.dummy" // needed for mills CompilationResult
182162
os.write(target = analysisFile, data = "", createFolders = true)
183163

@@ -236,7 +216,7 @@ trait GroovyModule extends JavaModule with GroovyModuleApi { outer =>
236216
}
237217

238218
/**
239-
* A test sub-module linked to its parent module best suited for unit-tests.
219+
* A test submodule linked to its parent module best suited for unit-tests.
240220
*/
241221
trait GroovyTests extends JavaTests with GroovyModule {
242222

libs/groovylib/test/src/mill/groovylib/HelloGroovyTests.scala

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,16 @@ object HelloGroovyTests extends TestSuite {
6262
override def mainClass = Some("hellostatic.HelloStatic")
6363
}
6464

65-
object spock extends GroovyTests with TestModule.Junit5 {
65+
object spock extends GroovyTests with TestModule.Spock {
6666
override def junitPlatformVersion = "1.13.4"
67-
def spockVersion: T[String] = "2.3-groovy-4.0"
67+
override def spockVersion = "2.3-groovy-4.0"
6868
override def groovyVersion = "4.0.28"
6969

7070
def bomMvnDeps = Seq(
7171
mvn"org.junit:junit-bom:5.13.4",
72-
mvn"org.apache.groovy:groovy-bom:${groovyVersion()}",
72+
// mvn"org.apache.groovy:groovy-bom:${groovyVersion()}",
7373
mvn"org.spockframework:spock-bom:${spockVersion()}"
7474
)
75-
76-
def mvnDeps = Seq(
77-
mvn"org.spockframework:spock-core"
78-
)
7975
}
8076
}
8177
object main extends Test {
@@ -96,6 +92,56 @@ object HelloGroovyTests extends TestSuite {
9692
def mixed = HelloGroovy.`groovy-tests`
9793
def joint = HelloGroovy.`joint-compile`
9894

95+
test("running a Groovy script") {
96+
testEval().scoped { eval =>
97+
val Right(_) = eval.apply(m.script.run()): @unchecked
98+
}
99+
}
100+
101+
test("running a Groovy script") {
102+
testEval().scoped { eval =>
103+
val Right(_) = eval.apply(m.script.run()): @unchecked
104+
}
105+
}
106+
107+
test("compile & run Groovy module") {
108+
testEval().scoped { eval =>
109+
val Right(result) = eval.apply(m.compile): @unchecked
110+
111+
assert(
112+
os.walk(result.value.classes.path).exists(_.last == "Hello.class")
113+
)
114+
115+
val Right(_) = eval.apply(m.run()): @unchecked
116+
}
117+
}
118+
119+
test("compile & run Groovy JUnit5 test") {
120+
testEval().scoped { eval =>
121+
122+
val Right(result) = eval.apply(m.test.compile): @unchecked
123+
124+
assert(
125+
os.walk(result.value.classes.path).exists(_.last == "HelloTest.class")
126+
)
127+
128+
val Right(discovered) = eval.apply(m.test.discoveredTestClasses): @unchecked
129+
assert(discovered.value == Seq("hello.tests.HelloTest"))
130+
131+
val Right(_) = eval.apply(m.test.testForked()): @unchecked
132+
}
133+
}
134+
135+
test("compile & run a statically compiled Groovy") {
136+
testEval().scoped { eval =>
137+
val Right(result) = eval.apply(m.staticcompile.compile): @unchecked
138+
assert(
139+
os.walk(result.value.classes.path).exists(_.last == "HelloStatic.class")
140+
)
141+
val Right(_) = eval.apply(m.staticcompile.run()): @unchecked
142+
}
143+
}
144+
99145

100146
test("compile & test module (only test uses Groovy)") {
101147
testEval().scoped { eval =>

libs/javalib/src/mill/javalib/TestModule.scala

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,22 @@ object TestModule {
602602

603603
/**
604604
* TestModule that uses Spock Test Framework to run tests.
605-
* You can override the [[spockTestVersion]] task or provide the Spock-dependency yourself.
605+
* You can override the [[spockVersion]] task or provide the Spock dependency yourself.
606606
*/
607607
trait Spock extends TestModule.Junit5 {
608608

609-
/** The Spock Test version to use, or the empty string, if you want to provide the Spock Test-dependency yourself. */
609+
/** The Spock Test version to use, or the empty string, if you want to provide the Spock test dependency yourself. */
610610
def spockVersion: T[String] = Task {
611611
""
612612
}
613613

614-
/** The Groovy version to use, or the empty string, if you want to provide the Groovy Test-dependency yourself. */
614+
/** The Groovy version to use, or the empty string, if you want to provide the Groovy test dependency yourself. */
615615
def groovyVersion: T[String] = Task {
616616
""
617617
}
618618

619+
// TODO currently bomMvnDeps not in JavaModuleBase so we cannot pull in the Spock-BOM
620+
619621
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
620622
super.mandatoryMvnDeps() ++
621623
Seq(spockVersion())
@@ -624,13 +626,6 @@ object TestModule {
624626
Seq(
625627
mvn"org.spockframework:spock-core:${v.trim()}"
626628
)
627-
) ++
628-
Seq(groovyVersion())
629-
.filter(!_.isBlank())
630-
.flatMap(v =>
631-
Seq(
632-
mvn"org.apache.groovy:groovy:${v.trim()}"
633-
)
634629
)
635630
}
636631
}

0 commit comments

Comments
 (0)