-
-
Notifications
You must be signed in to change notification settings - Fork 422
Extended mill init to support an existing Maven project
#3756
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
ab80850
Extended `mill init` to support an existing Maven project
ajaychandran 9cfa813
Renamed variable
ajaychandran 6b1d573
Added magic import to generated build.mill
ajaychandran 0e1dbe6
Added provided dependencies to compileIvyDeps
ajaychandran 6c4ad41
Extended `mill init` to support an existing Maven project
ajaychandran b60147e
Renamed variable
ajaychandran db77ae6
Added magic import to generated build.mill
ajaychandran e28b83f
Added provided dependencies to compileIvyDeps
ajaychandran 6fc9eb2
Merge remote-tracking branch 'origin/main'
ajaychandran 229e95c
Added magic import to resolve base module in package build files
ajaychandran 4b7948c
Fix test
ajaychandran 6e7061e
Refactored out code generation
ajaychandran 76e4bd5
Merge branch 'com-lihaoyi:main' into main
ajaychandran b784532
Merge branch 'com-lihaoyi:main' into main
ajaychandran d16915f
Merge branch 'com-lihaoyi:main' into main
ajaychandran 3b5d140
Merge branch 'com-lihaoyi:main' into main
ajaychandran 69273e8
Merge branch 'com-lihaoyi:main' into main
ajaychandran 3658abb
- Addressed review comments
ajaychandran 50f87b9
Renamed exception
ajaychandran 70e4614
Fixed formatting
ajaychandran 84098b7
Renamed symbolic operators
ajaychandran a71c46f
Added test case for avaje-config
ajaychandran 34ac1e0
Added location of compile errors
ajaychandran dab05d0
Separated variable declarations
ajaychandran 1d6e756
Changed implicit parameters to arguments.
ajaychandran acae1a8
Cleaned folder names
ajaychandran d5778a7
Cleaned object names
ajaychandran dd41e49
Merge branch 'com-lihaoyi:main' into main
ajaychandran 52a11a0
Replaced arrow assertions with assert
ajaychandran f092903
Format build files generated in tests
ajaychandran 50fe2ac
Removed support for build-helper-maven-plugin
ajaychandran 86501ff
Aligned inheritance scheme with existing capabilities
ajaychandran 4785683
Merge branch 'com-lihaoyi:main' into main
ajaychandran 7b15c28
Added test class for owner project and cleaned existing tests
ajaychandran b0d45da
Reordered parameters
ajaychandran 17d8e92
Improved generator algorithm
ajaychandran 0bb1824
Annotated compile tasks
ajaychandran d641e2a
Replaced System.lineSeparator()
ajaychandran 65ddee1
Renamed method and updated Scaladoc
ajaychandran 5622b78
Simplified build IR
ajaychandran 76b21c6
Added feature flag to compact build tree
ajaychandran ee93973
Updated comments for JPMS errors
ajaychandran 4df7e8d
Added documentation with example
ajaychandran e3aa816
Refactored integration tests
ajaychandran 8a229d8
Removed compile tasks for "pom" modules
ajaychandran ff40e9e
Merge branch 'com-lihaoyi:main' into main
ajaychandran 46cd3b2
Improved integration tests
ajaychandran c3bcb72
Updated documentation
ajaychandran 2ab9b05
- Fix error due to use of /* in command
ajaychandran f0b487f
Updated test golden files
ajaychandran 75e704f
Compare lines instead of content to avoid file EOL differences
ajaychandran 7018dde
Merge remote-tracking branch 'upstream/main'
ajaychandran 895ffe2
Removed default parameter value
ajaychandran a01a8d2
Suppressed test assertion to avoid CI failure
ajaychandran fe6cc7b
Cleanup
ajaychandran b0839c8
Escape single backslash to handle Windows paths
ajaychandran e8683d9
Use raw interpolator for single backslashes
ajaychandran 88cdcf6
debug
lihaoyi fbffb2a
use pprint literalize
lihaoyi 0c56337
cleanup
lihaoyi e309e9b
docs
lihaoyi 3449411
docs
lihaoyi 0d2ddc0
fixtests
lihaoyi 639c2a4
docs
lihaoyi 6010bce
docs
lihaoyi 219cef4
docs
lihaoyi ef66ca9
docs
lihaoyi 9cb7be5
.
lihaoyi 47a71fc
.
lihaoyi c08d6d0
.
lihaoyi a0a0d2c
.
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
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,221 @@ | ||
| package mill.integration | ||
|
|
||
| import mill.testkit.{IntegrationTester, UtestIntegrationTestSuite} | ||
| import utest._ | ||
|
|
||
| object MillInitMavenTests extends UtestIntegrationTestSuite { | ||
|
|
||
| private def prep[T](githubSourceZipUrl: String)(f: IntegrationTester => T): T = { | ||
| val zipFile = os.temp(requests.get(githubSourceZipUrl)) | ||
| val unzipDir = os.unzip(zipFile, os.temp.dir()) | ||
| val sourceDir = os.list(unzipDir).head | ||
|
|
||
| integrationTest { tester => | ||
| for (p <- os.list(sourceDir)) os.move.into(p, tester.workspacePath) | ||
| f(tester) | ||
| } | ||
| } | ||
|
|
||
| def tests: Tests = Tests { | ||
|
|
||
| // - Junit5 | ||
| // - maven-compiler-plugin release option | ||
| test("jansi") { | ||
| prep("https://github.com/fusesource/jansi/archive/refs/tags/jansi-2.4.1.zip") { tester => | ||
| import tester._ | ||
|
|
||
| val initRes = eval(("init", "--deps-object", "Deps")) | ||
| initRes.out.contains( | ||
| "generated 1 Mill build file(s)" | ||
| ) ==> true | ||
| initRes.isSuccess ==> true | ||
|
|
||
| val compileRes = eval("compile") | ||
| compileRes.err.contains( | ||
| "compiling 20 Java sources" | ||
| ) ==> true | ||
| compileRes.isSuccess ==> true | ||
|
|
||
| val testRes = eval("test") | ||
| testRes.out.contains( | ||
| "Test run finished: 0 failed, 1 ignored, 90 total" | ||
| ) ==> true | ||
| testRes.isSuccess ==> true | ||
|
|
||
| val publishLocalRes = eval("publishLocal") | ||
| publishLocalRes.err.contains( | ||
| "Publishing Artifact(org.fusesource.jansi,jansi,2.4.1)" | ||
| ) ==> true | ||
| publishLocalRes.isSuccess ==> true | ||
| } | ||
| } | ||
|
|
||
| // - multi-module | ||
| // - TestNg | ||
| // - maven-compiler-plugin release option | ||
| test("dotenv") { | ||
| prep("https://github.com/shyiko/dotenv/archive/refs/tags/0.1.1.zip") { tester => | ||
| import tester._ | ||
|
|
||
| val initRes = eval("init") | ||
| initRes.out.contains( | ||
| "generated 3 Mill build file(s)" | ||
| ) ==> true | ||
| initRes.isSuccess ==> true | ||
|
|
||
| val resolveRes = eval(("resolve", "_")) | ||
| Seq( | ||
| "dotenv", | ||
| "dotenv-guice" | ||
| ).forall(resolveRes.out.contains) ==> true | ||
|
|
||
| // JavaModule.JavaTests is not picking compileIvyDeps from outer module | ||
| val compileRes = eval("__.compile") | ||
| compileRes.err.contains("package com.google.inject does not exist") ==> true | ||
| compileRes.isSuccess ==> false | ||
ajaychandran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // even if compile error is fixed, TestNg version is not supported | ||
| // val testRes = eval("__.test") | ||
| // testRes.isSuccess ==> false | ||
| } | ||
| } | ||
|
|
||
| // - multi-module | ||
| // - Junit5 | ||
| // - submodule e2e directory and artifact name differ | ||
| test("fastexcel") { | ||
| prep("https://github.com/dhatim/fastexcel/archive/refs/tags/0.18.4.zip") { tester => | ||
| import tester._ | ||
|
|
||
| val initRes = eval("init") | ||
| initRes.out.contains( | ||
| "generated 4 Mill build file(s)" | ||
| ) ==> true | ||
| initRes.isSuccess ==> true | ||
|
|
||
| val resolveRes = eval(("resolve", "_")) | ||
| Seq( | ||
| "fastexcel-reader", | ||
| "fastexcel-writer", | ||
| "e2e" | ||
| ).forall(resolveRes.out.contains) ==> true | ||
|
|
||
| // not sure why this happens but pom.xml has a hack to handle JPMS | ||
| val compileRes = eval("__.compile") | ||
ajaychandran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Seq( | ||
| "module not found: org.apache.commons.compress", | ||
| "module not found: com.fasterxml.aalto", | ||
| "module not found: opczip" | ||
| ).forall(compileRes.err.contains) ==> true | ||
| compileRes.isSuccess ==> false | ||
| } | ||
| } | ||
|
|
||
| // - multi-module | ||
| // - Junit5 | ||
| // - build-helper-maven-plugin | ||
| // - maven-compiler-plugin compilerArgs options | ||
| // - submodule directory and artifact names differ | ||
| // - multi line description, property <argLine.common> | ||
| // - property <jetty.alpnAgent.path> contains quotes | ||
| test("netty") { | ||
| prep("https://github.com/netty/netty/archive/refs/tags/netty-4.1.114.Final.zip") { tester => | ||
| import tester._ | ||
|
|
||
| val initRes = eval(("init", "--publish-properties")) | ||
| // cannot resolve native dependencies defined by build extension os-maven-plugin | ||
| initRes.out.contains( | ||
| """[codec-http2] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[transport-native-epoll] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[transport-native-kqueue] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[handler] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[example] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[testsuite] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[testsuite-shading] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[transport-blockhound-tests] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |[microbench] dropping classifier ${os.detected.classifier} for dependency io.netty:netty-tcnative:2.0.66.Final | ||
| |""".stripMargin | ||
| ) ==> true | ||
| initRes.out.contains( | ||
| "generated 47 Mill build file(s)" | ||
| ) ==> true | ||
| initRes.isSuccess ==> true | ||
|
|
||
| val resolveRes = eval(("resolve", "_")) | ||
| Seq( | ||
| "all", | ||
| "dev-tools", | ||
| "common", | ||
| "buffer", | ||
| "codec", | ||
| "codec-dns", | ||
| "codec-haproxy", | ||
| "codec-http", | ||
| "codec-http2", | ||
| "codec-memcache", | ||
| "codec-mqtt", | ||
| "codec-redis", | ||
| "codec-smtp", | ||
| "codec-socks", | ||
| "codec-stomp", | ||
| "codec-xml", | ||
| "resolver", | ||
| "resolver-dns", | ||
| "resolver-dns-classes-macos", | ||
| "resolver-dns-native-macos", | ||
| "transport", | ||
| "transport-native-unix-common-tests", | ||
| "transport-native-unix-common", | ||
| "transport-classes-epoll", | ||
| "transport-native-epoll", | ||
| "transport-classes-kqueue", | ||
| "transport-native-kqueue", | ||
| "transport-rxtx", | ||
| "transport-sctp", | ||
| "transport-udt", | ||
| "handler", | ||
| "handler-proxy", | ||
| "handler-ssl-ocsp", | ||
| "example", | ||
| "testsuite", | ||
| "testsuite-autobahn", | ||
| "testsuite-http2", | ||
| "testsuite-osgi", | ||
| "testsuite-shading", | ||
| "testsuite-native", | ||
| "testsuite-native-image", | ||
| "testsuite-native-image-client", | ||
| "testsuite-native-image-client-runtime-init", | ||
| "transport-blockhound-tests", | ||
| "microbench", | ||
| "bom" | ||
| ).forall(resolveRes.out.contains) ==> true | ||
ajaychandran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // additional sources defined by build-helper-maven-plugin | ||
| val sourcesRes = eval(("show", "transport-native-epoll.sources")) | ||
| Seq( | ||
| s"$workspacePath/transport-native-epoll/src/main/java", | ||
| s"$workspacePath/transport-native-epoll/src/main/c" | ||
| ).forall(sourcesRes.out.contains) ==> true | ||
ajaychandran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // compile succeeds for submodule | ||
| val compileRes = eval("codec.compile") | ||
ajaychandran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| compileRes.err.contains( | ||
| "compiling 155 Java sources" | ||
| ) ==> true | ||
| compileRes.isSuccess ==> true | ||
|
|
||
| // test compile fails for submodule due to missing native dependency | ||
| val testRes = eval("codec.test") | ||
| testRes.err.contains( | ||
| "package io.netty.nativeimage does not exist" | ||
| ) ==> true | ||
| testRes.isSuccess ==> false | ||
|
|
||
| // publishLocal fails for submodule (due to several Javadoc errors) | ||
| val publishLocalRes = eval("codec.publishLocal") | ||
| publishLocalRes.isSuccess ==> false | ||
| } | ||
| } | ||
| } | ||
| } | ||
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,95 @@ | ||
| package mill.init | ||
|
|
||
| import coursier.LocalRepositories | ||
| import coursier.maven.MavenRepository | ||
| import mill.api.{Loose, PathRef} | ||
| import mill.define.{Discover, ExternalModule, TaskModule} | ||
| import mill.scalalib.scalafmt.ScalafmtWorkerModule | ||
| import mill.util.{Jvm, Util} | ||
| import mill.{Command, T, Task} | ||
|
|
||
| import scala.util.control.NoStackTrace | ||
|
|
||
| @mill.api.experimental | ||
| object InitMavenModule extends ExternalModule with InitMavenModule with TaskModule { | ||
|
|
||
| lazy val millDiscover: Discover = Discover[this.type] | ||
| } | ||
|
|
||
| /** | ||
| * Defines a [[InitModule.init task]] to convert a Maven build to Mill. | ||
| */ | ||
| @mill.api.experimental | ||
| trait InitMavenModule extends TaskModule { | ||
|
|
||
| def defaultCommandName(): String = "init" | ||
|
|
||
| /** | ||
| * Classpath containing [[buildGenMainClass build file generator]]. | ||
| */ | ||
| def buildGenClasspath: T[Loose.Agg[PathRef]] = T { | ||
| val repositories = Seq( | ||
| LocalRepositories.ivy2Local, | ||
| MavenRepository("https://repo1.maven.org/maven2"), | ||
| MavenRepository("https://oss.sonatype.org/content/repositories/releases") | ||
| ) | ||
| Util.millProjectModule("mill-main-maven", repositories) | ||
| } | ||
|
|
||
| /** | ||
| * Mill build file generator application entrypoint. | ||
| */ | ||
| def buildGenMainClass: T[String] = "mill.main.maven.BuildGen" | ||
|
|
||
| /** | ||
| * Scalafmt configuration file for formatting generated Mill build files. | ||
| */ | ||
| def initScalafmtConfig: T[PathRef] = T { | ||
| val config = millSourcePath / ".scalafmt.conf" | ||
| if (!os.exists(config)) { | ||
| T.log.info(s"creating Scalafmt configuration file $config ...") | ||
| os.write( | ||
| config, | ||
| s"""version = "3.8.4-RC1" | ||
| |runner.dialect = scala213 | ||
| |""".stripMargin | ||
| ) | ||
| } | ||
| PathRef(config) | ||
| } | ||
|
|
||
| /** | ||
| * Generates and formats Mill build files for an existing Maven project. | ||
| * | ||
| * @param args arguments for the [[buildGenMainClass build file generator]] | ||
| */ | ||
| def init(args: String*): Command[Unit] = Task.Command { | ||
| val root = millSourcePath | ||
|
|
||
| val mainClass = buildGenMainClass() | ||
| val classPath = buildGenClasspath().map(_.path) | ||
| val exit = Jvm.callSubprocess( | ||
| mainClass = mainClass, | ||
| classPath = classPath, | ||
| mainArgs = args, | ||
| workingDir = root | ||
| ).exitCode | ||
|
|
||
| if (exit == 0) { | ||
| val files = os.walk.stream(root, skip = (root / "out").equals) | ||
| .filter(_.ext == "mill") | ||
| .map(PathRef(_)) | ||
| .toSeq | ||
| val config = initScalafmtConfig() | ||
| T.log.info("formatting Mill build files ...") | ||
| ScalafmtWorkerModule.worker().reformat(files, config) | ||
|
|
||
| T.log.info("init completed, run \"mill resolve _\" to list available tasks") | ||
| } else { | ||
| throw InitMavenException(s"$mainClass exit($exit)") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @mill.api.experimental | ||
| case class InitMavenException(message: String) extends Exception(message) with NoStackTrace |
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.