Skip to content

Commit 21334e0

Browse files
committed
partial
1 parent ce19a26 commit 21334e0

File tree

2 files changed

+82
-60
lines changed

2 files changed

+82
-60
lines changed

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

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ object HelloGroovyTests extends TestSuite {
1717
lazy val millDiscover = Discover[this.type]
1818

1919
// needed for a special test where only the tests are written in Groovy while appcode remains Java
20-
object `mixed-compile` extends JavaModule with MavenModule {
20+
object `groovy-tests` extends JavaMavenModuleWithGroovyTests {
2121

22-
object `test` extends TestGroovyMavenModule with TestModule.Junit5 {
22+
object `test` extends GroovyMavenTests with TestModule.Junit5 {
2323

2424
override def moduleDeps: Seq[JavaModule] = Seq(
25-
HelloGroovy.`mixed-compile`, // TODO improve: TestOnly does not inherit outer deps
25+
HelloGroovy.`groovy-tests`,
2626
)
2727

2828
override def groovyVersion = groovy4Version
@@ -37,6 +37,7 @@ object HelloGroovyTests extends TestSuite {
3737

3838
object `joint-compile` extends GroovyModule {
3939
override def groovyVersion: T[String] = groovy4Version
40+
override def mainClass = Some("jointcompile.JavaMain")
4041
}
4142

4243
trait Test extends GroovyModule {
@@ -92,52 +93,53 @@ object HelloGroovyTests extends TestSuite {
9293
def tests: Tests = Tests {
9394

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

@@ -153,23 +155,33 @@ object HelloGroovyTests extends TestSuite {
153155
val Right(_) = eval.apply(mixed.test.testForked()): @unchecked
154156
}
155157
}
156-
157-
test("compile & run Spock test") {
158+
//
159+
// test("compile & run Spock test") {
160+
// testEval().scoped { eval =>
161+
//
162+
// val Right(result1) = eval.apply(m.spock.compile): @unchecked
163+
// assert(
164+
// os.walk(result1.value.classes.path).exists(_.last == "SpockTest.class")
165+
// )
166+
//
167+
// val Right(discovered) = eval.apply(m.spock.discoveredTestClasses): @unchecked
168+
// assert(discovered.value == Seq("hello.spock.SpockTest"))
169+
//
170+
// val Right(_) = eval.apply(m.spock.testForked()): @unchecked
171+
// }
172+
// }
173+
174+
test("compile joint (groovy <-> java cycle) & run test") {
158175
testEval().scoped { eval =>
176+
val Right(result) = eval.apply(joint.compile): @unchecked
159177

160-
val Right(result1) = eval.apply(m.spock.compile): @unchecked
161178
assert(
162-
os.walk(result1.value.classes.path).exists(_.last == "SpockTest.class")
179+
os.walk(result.value.classes.path).exists(_.last == "JavaPrinter.class")
163180
)
164181

165-
val Right(discovered) = eval.apply(m.spock.discoveredTestClasses): @unchecked
166-
assert(discovered.value == Seq("hello.spock.SpockTest"))
167-
168-
val Right(_) = eval.apply(m.spock.testForked()): @unchecked
182+
val Right(_) = eval.apply(joint.run()): @unchecked
169183
}
170184
}
171185

172-
173-
174186
}
175187
}

libs/groovylib/worker/src/mill/groovylib/worker/impl/GroovyWorkerImpl.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import mill.api.TaskCtx
66
import mill.javalib.api.CompilationResult
77
import mill.groovylib.worker.api.GroovyWorker
88
import org.codehaus.groovy.control.{CompilationUnit, CompilerConfiguration, Phases}
9+
import org.codehaus.groovy.tools.javac.JavaStubCompilationUnit
910

1011
import scala.jdk.CollectionConverters.*
1112
import scala.util.Try
@@ -16,6 +17,7 @@ class GroovyWorkerImpl extends GroovyWorker {
1617
sourceFiles: Seq[os.Path],
1718
classpath: Seq[os.Path],
1819
outputDir: os.Path
20+
// TODO Function Stubs to JavaClasspath (neu)
1921
)(implicit
2022
ctx: TaskCtx
2123
): Result[CompilationResult] = {
@@ -25,21 +27,29 @@ class GroovyWorkerImpl extends GroovyWorker {
2527
config.setClasspathList(classpath.map(_.toIO.getAbsolutePath).asJava)
2628
// TODO
2729
// config.setDisabledGlobalASTTransformations()
28-
// config.setJointCompilationOptions()
30+
config.setJointCompilationOptions(Map(
31+
"stubDir" -> outputDir.toIO,
32+
"keepStubs" -> true
33+
).asJava)
2934
// config.setSourceEncoding()
3035

3136
// we need to set the classloader for groovy to use the worker classloader
3237
val parentCl: ClassLoader = this.getClass.getClassLoader
3338
// config in the GroovyClassLoader is needed when the CL itself is compiling classes
3439
val gcl = new GroovyClassLoader(parentCl, config)
3540
// config for actual compilation
41+
val stubs = JavaStubCompilationUnit(config, gcl)
3642
val unit = new CompilationUnit(config, null, gcl)
3743

3844
sourceFiles.foreach { sourceFile =>
45+
if(sourceFile.ext == "java"){
46+
stubs.addSource(sourceFile.toIO)
47+
}
3948
unit.addSource(sourceFile.toIO)
4049
}
4150

4251
Try {
52+
stubs.compile(Phases.OUTPUT)
4353
unit.compile(Phases.OUTPUT)
4454
CompilationResult(outputDir, mill.api.PathRef(outputDir))
4555
}.fold(

0 commit comments

Comments
 (0)