-
-
Notifications
You must be signed in to change notification settings - Fork 423
Initial Groovy setup #5747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lostiniceland
wants to merge
45
commits into
com-lihaoyi:main
Choose a base branch
from
lostiniceland:groovylib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Initial Groovy setup #5747
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
541652c
Intial Groovy setup
lostiniceland 51d6266
adding more test cases and fixing classloader issue during groovy com…
lostiniceland 4bcb5b1
improve test-only-groovy to not rely on an existing outer module
lostiniceland 45dfd9b
3-stage compile to support Groovy <-> Java cycles
lostiniceland cacf2c7
manage BOMs in Tests
lostiniceland eb13bc6
test with cross-compile Groovy 4 & 5
lostiniceland 13c7ec9
samples
lostiniceland ea34a49
docs
lostiniceland 9a26ea3
[autofix.ci] apply automated fixes
autofix-ci[bot] b8d28f7
Groovy Compiler options for bytecode version, preview features and as…
lostiniceland 507b11b
[autofix.ci] apply automated fixes
autofix-ci[bot] e218ec2
Added example tests to CI setup
lefou 485a8c3
Rudimentarily fix webpage generation
lefou f0cc0b8
Cleanup and Testcase for targetBytecode and previewEnabled
lostiniceland 48b6020
[autofix.ci] apply automated fixes
autofix-ci[bot] 21cf8f7
minor test improvement
lostiniceland 0df8825
Mark API as experimental
lefou 2c80e4b
Fix mima setup
lefou d232684
minor review remarks
lostiniceland 7fac9ce
use Mill caching for stub folder
lostiniceland b5177ad
[autofix.ci] apply automated fixes
autofix-ci[bot] eed6b58
Revert back to experimental module
lostiniceland 00b6893
[autofix.ci] apply automated fixes
autofix-ci[bot] ca34a80
Merge branch 'main' into groovylib
lostiniceland 9bd964c
fix binary compat
lostiniceland 7ec26ce
add scripting support
lostiniceland 132d44e
Merge branch 'main' into groovylib
lostiniceland 2c38719
Fixes after merge
lostiniceland f2e817b
[autofix.ci] apply automated fixes
autofix-ci[bot] fc252cc
get rid of example-usage-comments for now
lostiniceland e00d104
[autofix.ci] apply automated fixes
autofix-ci[bot] d8b8fb0
Fix integration tests
lostiniceland 12ecb27
Merge branch 'main' into groovylib
lostiniceland fa4ca79
Merge branch 'main' into groovylib
lostiniceland 6bbef67
Update core/api/daemon/src/mill/api/daemon/internal/GroovyModuleApi.s…
lostiniceland b18f152
Update libs/groovylib/src/mill/groovylib/GroovyModule.scala
lostiniceland 3242bd4
Update libs/groovylib/src/mill/groovylib/GroovyWorkerManager.scala
lostiniceland 14f8379
Update libs/groovylib/worker/src/mill/groovylib/worker/impl/GroovyWor…
lostiniceland e9a74bc
Update libs/script/src/GroovyModule.scala
lostiniceland 650c611
Update libs/script/src/GroovyModule.scala
lostiniceland f91e58e
Update core/api/daemon/src/mill/api/daemon/internal/GroovyModuleApi.s…
lefou 887ac9a
Merge groovy testing docu to groovy intro
lostiniceland 3626125
Merge branch 'main' into groovylib
lihaoyi 42be580
Update GroovyModule.scala
lihaoyi c9c8633
Update run-tests.yml
lihaoyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
core/api/daemon/src/mill/api/daemon/internal/GroovyModuleApi.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package mill.api.daemon.internal | ||
|
|
||
| trait GroovyModuleApi extends JavaModuleApi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||
| //// SNIPPET:BUILD | ||||||||
|
|
||||||||
| package build | ||||||||
| import mill.*, groovylib.* | ||||||||
|
|
||||||||
| object foo extends GroovyModule { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| def groovyVersion = "5.0.1" | ||||||||
|
|
||||||||
| def mvnDeps = Seq( | ||||||||
| mvn"org.apache.groovy:groovy-cli-commons", // BOM already loaded by module | ||||||||
| mvn"org.apache.groovy:groovy-xml" // BOM already loaded by module | ||||||||
| ) | ||||||||
|
|
||||||||
| def mainClass = Some("foo.Foo") | ||||||||
|
|
||||||||
| object test extends GroovyTests with TestModule.Junit5 { | ||||||||
| def jupiterVersion = "5.13.4" | ||||||||
|
|
||||||||
| def mvnDeps = Seq( | ||||||||
| mvn"org.apache.groovy:groovy-test" // BOM already loaded by module | ||||||||
| ) | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // This is a basic Mill build for a single `GroovyModule`, with one | ||||||||
| // third-party dependency and a test suite using the JUnit framework. | ||||||||
| //// SNIPPET:TREE | ||||||||
| // ---- | ||||||||
| // build.mill | ||||||||
| // foo/ | ||||||||
| // src/ | ||||||||
| // foo/Foo.groovy | ||||||||
| // resources/ | ||||||||
| // ... | ||||||||
| // test/ | ||||||||
| // src/ | ||||||||
| // foo/FooTest.groovy | ||||||||
| // out/foo/ | ||||||||
| // compile.json | ||||||||
| // compile.dest/ | ||||||||
| // ... | ||||||||
| // test/ | ||||||||
| // compile.json | ||||||||
| // compile.dest/ | ||||||||
| // ... | ||||||||
| // ---- | ||||||||
| // | ||||||||
| // NOTE: The default Mill source folder layout `foo/src/` differs from that of Maven/Gradle's | ||||||||
| // `foo/src/main/groovy`. If you wish to use the Maven source folder layout, e.g. for migrating | ||||||||
| // an existing codebase, you should use | ||||||||
| // xref:#_maven_compatible_modules[Maven-Compatible Modules] | ||||||||
| // | ||||||||
| //// SNIPPET:DEPENDENCIES | ||||||||
| // | ||||||||
| // This example project uses two third-party dependencies | ||||||||
| // - Groovy-Cli-Commons for CLI argument parsing | ||||||||
| // - Groovy-Xml for HTML templating and escaping | ||||||||
| // and uses them to wrap a given input string in HTML templates with proper escaping. | ||||||||
| // | ||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package foo | ||
|
|
||
| import groovy.xml.MarkupBuilder | ||
| import groovy.cli.commons.CliBuilder | ||
|
|
||
| class Foo { | ||
| static String generateHtml(String text) { | ||
| def writer = new StringWriter() | ||
| new MarkupBuilder(writer).h1 { | ||
| mkp.yield text | ||
| } | ||
| writer.toString() | ||
| } | ||
|
|
||
| static void main(String[] args) { | ||
| def cli = new CliBuilder(usage:'help') | ||
| cli.t(longOpt:'text', args: 1, 'Passes text to the HTML generation') | ||
| def options = cli.parse(args) | ||
|
|
||
| if (!options) { | ||
| return | ||
| } | ||
|
|
||
| if (options.h) { | ||
| cli.usage() | ||
| return | ||
| } | ||
|
|
||
| String textToProcess = options.t ?: "hello from main" | ||
| println generateHtml(textToProcess) | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
example/groovylib/basic/1-simple/foo/test/src/foo/FooTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package foo | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class FooTest { | ||
| @Test | ||
| void "generate html created properly"() { | ||
| assert Foo.generateHtml("hello") == "<h1>hello</h1>" | ||
| } | ||
|
|
||
| @Test | ||
| void "generated html is properly escaped"() { | ||
| assert Foo.generateHtml("<hello>") == "<h1><hello></h1>" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //// SNIPPET:ALL | ||
| // Mill's default folder layout of `foo/src/` and `foo/test/src` differs from that | ||
| // of Maven or Gradle's `foo/src/main/groovy/` and `foo/src/test/groovy/`. If you are | ||
| // migrating an existing codebase, you can use Mill's `GroovyMavenModule` and | ||
| // `GroovyMavenTests` as shown below to preserve filesystem compatibility with an existing | ||
| // Maven or Gradle build: | ||
|
|
||
| package build | ||
| import mill.*, groovylib.* | ||
|
|
||
| object foo extends GroovyMavenModule { | ||
|
|
||
| def groovyVersion = "5.0.1" | ||
|
|
||
| object test extends GroovyMavenTests with TestModule.Junit5 {} | ||
| object integration extends GroovyMavenTests with TestModule.Junit5 {} | ||
| } | ||
|
|
||
| // `GroovyMavenModule` is a variant of `GroovyModule` | ||
| // that uses the more verbose folder layout of Maven, `sbt`, and other tools: | ||
| // | ||
| // - `foo/src/main/java` | ||
| // - `foo/src/main/groovy` | ||
| // - `foo/src/test/java` | ||
| // - `foo/src/test/groovy` | ||
| // - `foo/src/integration/java` | ||
| // - `foo/src/integration/groovy` | ||
| // | ||
| // Rather than Mill's | ||
| // | ||
| // - `foo/src` | ||
| // - `foo/test/src` | ||
| // | ||
| // This is especially useful if you are migrating from Maven to Mill (or vice | ||
| // versa), during which a particular module may be built using both Maven and | ||
| // Mill at the same time | ||
| // | ||
| // For more details on migrating from other build tools, see xref:migrating/migrating.adoc[] |
12 changes: 12 additions & 0 deletions
12
...roovylib/basic/2-compat-modules/foo/src/integration/groovy/foo/FooIntegrationTests.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package foo | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class FooIntegrationTests { | ||
| @Test | ||
| void "hello should print correct greeting"() { | ||
| // Groovy creates an implicit class for the script named after the file | ||
| def foo = new Foo() | ||
| assert foo.hello() == "Hello World, Earth" | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
example/groovylib/basic/2-compat-modules/foo/src/main/groovy/foo/Foo.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package foo | ||
|
|
||
| def run(){ | ||
| println(hello()) | ||
| } | ||
|
|
||
| def hello() { | ||
| "Hello World, ${Foo2.VALUE}" | ||
| } |
5 changes: 5 additions & 0 deletions
5
example/groovylib/basic/2-compat-modules/foo/src/main/java/foo/Foo2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package foo; | ||
|
|
||
| public class Foo2 { | ||
| public static final String VALUE = "Earth"; | ||
| } |
13 changes: 13 additions & 0 deletions
13
example/groovylib/basic/2-compat-modules/foo/src/test/groovy/foo/FooTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package foo | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class FooTest { | ||
|
|
||
| @Test | ||
| void "hello should print correct greeting"() { | ||
| // Groovy creates an implicit class for the script named after the file | ||
| def foo = new Foo() | ||
| assert foo.hello() == "Hello World, Earth" | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
example/groovylib/testing/1-test-suite/bar/src/bar/Bar.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package bar | ||
|
|
||
| def hello() { | ||
| "Hello World" | ||
| } | ||
|
|
||
| def run(){ | ||
| println new Bar().hello() | ||
| } |
29 changes: 29 additions & 0 deletions
29
example/groovylib/testing/1-test-suite/bar/test/src/bar/BarTests.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package bar | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import groovy.mock.interceptor.MockFor | ||
|
|
||
| class BarTests{ | ||
| @Test | ||
| void "hello"() { | ||
| def result = new Bar().hello() | ||
| assert result == "Hello World" | ||
| } | ||
|
|
||
| @Test | ||
| void "world"() { | ||
| def result = new Bar().hello() | ||
| assert result.endsWith("World") | ||
| } | ||
|
|
||
| @Test | ||
| void "using groovy mocks"() { | ||
| def mockBar = new MockFor(Bar) | ||
| mockBar.demand.hello { "Hello GroovyMock World" } | ||
|
|
||
| mockBar.use{ | ||
| def result = new Bar().hello() | ||
| assert result == "Hello GroovyMock World" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //// SNIPPET:BUILD1 | ||
| package build | ||
| import mill.*, groovylib.* | ||
|
|
||
| object foo extends GroovyModule { | ||
|
|
||
| def groovyVersion = "5.0.1" | ||
|
|
||
| object test extends GroovyTests with TestModule.Junit5 { | ||
| def jupiterVersion = "5.13.4" | ||
|
|
||
| def mvnDeps = Seq( | ||
| mvn"org.apache.groovy:groovy-test" // BOM already loaded by module | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| object bar extends GroovyModule { | ||
|
|
||
| def mainClass = Some("bar.Bar") | ||
|
|
||
| def groovyVersion = "5.0.1" | ||
|
|
||
| object test extends GroovyTests, TestModule.Junit5 { | ||
| def jupiterVersion = "5.13.4" | ||
|
|
||
| def mvnDeps = Seq( | ||
| mvn"org.apache.groovy:groovy-test" // BOM already loaded by module | ||
| ) | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
example/groovylib/testing/1-test-suite/foo/src/foo/Foo.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package foo | ||
|
|
||
| class Foo { | ||
| def hello() { | ||
| "Hello World" | ||
| } | ||
|
|
||
| static void main(String[] args){ | ||
| println Foo().hello() | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
example/groovylib/testing/1-test-suite/foo/test/src/foo/FooTests.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package foo | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
| import groovy.mock.interceptor.MockFor | ||
|
|
||
| class FooMoreTests{ | ||
| @Test | ||
| void "hello"() { | ||
| def result = new Foo().hello() | ||
| assert result == "Hello World" | ||
| } | ||
|
|
||
| @Test | ||
| void "world"() { | ||
| def result = new Foo().hello() | ||
| assert result.endsWith("World") | ||
| } | ||
|
|
||
| @Test | ||
| void "using groovy mocks"() { | ||
| def mockFoo = new MockFor(Foo) | ||
| mockFoo.demand.hello { "Hello GroovyMock World" } | ||
|
|
||
| mockFoo.use{ | ||
| def result = new Foo().hello() | ||
| assert result == "Hello GroovyMock World" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //// SNIPPET:BUILD2 | ||
| package build | ||
| import mill.*, groovylib.* | ||
| object qux extends GroovyModule { | ||
|
|
||
| def groovyVersion = "5.0.1" | ||
|
|
||
| object test extends GroovyTests with TestModule.Junit5 { | ||
| def mvnDeps = super.mvnDeps() ++ Seq( | ||
| mvn"org.apache.groovy:groovy-test" | ||
| ) | ||
| } | ||
| object integration extends GroovyTests with TestModule.Junit5 { | ||
| def mvnDeps = super.mvnDeps() ++ Seq( | ||
| mvn"org.apache.groovy:groovy-test" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // The integration suite is just another regular test module within the parent GroovyModule |
18 changes: 18 additions & 0 deletions
18
.../groovylib/testing/2-integration-suite/qux/integration/src/qux/QuxIntegrationTests.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package qux | ||
|
|
||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class QuxIntegrationTests { | ||
|
|
||
| @Test | ||
| void "hello"() { | ||
| def result = new Qux().hello() | ||
| assert result == "Hello World" | ||
| } | ||
|
|
||
| @Test | ||
| void "world"() { | ||
| def result = new Qux().hello() | ||
| assert result.endsWith("World") | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
example/groovylib/testing/2-integration-suite/qux/src/qux/Qux.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package qux | ||
|
|
||
| class Qux { | ||
| static void main(String[] args){ | ||
| println(hello()) | ||
| } | ||
|
|
||
| String hello(){ | ||
| "Hello World" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.