Skip to content

Commit

Permalink
Updated Mill build setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Mar 16, 2023
1 parent 4debd2a commit ce2a32d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.4
0.11.0-M6
109 changes: 29 additions & 80 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
// build.sc for mill
import java.io.File
import $ivy.`de.tototec::de.tobiasroeser.mill.osgi::0.4.0-34-8cac07`

import mill._
import mill.scalalib._
import mill.scalalib.publish._
import $ivy.`de.tototec::de.tobiasroeser.mill.osgi_mill0.9:0.3.2`
import coursier.Repository
import de.tobiasroeser.mill.osgi._
import mill.define.{Target, Task}
import mill.modules.Jvm
import os.Path

object Deps {
val asciiDoclet = ivy"org.asciidoctor:asciidoclet:1.5.4"
val testng = ivy"org.testng:testng:6.11"
val junit = ivy"junit:junit:4.12"
val jupiter = ivy"org.junit.jupiter:junit-jupiter:5.9.2"
val jupiterLauncher = ivy"org.junit.platform:junit-platform-launcher:1.7.0"
val slf4j = ivy"org.slf4j:slf4j-api:1.7.25"
val logbackClassic = ivy"ch.qos.logback:logback-classic:1.2.3"
val java17Signature = ivy"org.codehaus.mojo.signature:java17:1.0"
val millTestng = ivy"com.lihaoyi:mill-contrib-testng_2.13:${sys.props("MILL_VERSION")}"
}

// TODO cross compile with retrolambda
object lambdatest extends MavenModule with PublishModule with OsgiBundleModule {

override def osgiBuildMode: OsgiBundleModule.BuildMode = OsgiBundleModule.BuildMode.CalculateManifest

override def millSourcePath: Path = super.millSourcePath / os.up

override def publishVersion = "0.6.3-SNAPSHOT"
override def publishVersion = "0.8.1-SNAPSHOT"
override def versionScheme: Target[Option[VersionScheme]] = Some(VersionScheme.EarlySemVer)

override def artifactName = "de.tobiasroeser.lambdatest"
val namespace = "de.tobiasroeser.lambdatest"
override def artifactName = namespace
override def bundleSymbolicName = artifactName

def pomSettings = PomSettings(
Expand All @@ -46,86 +46,35 @@ object lambdatest extends MavenModule with PublishModule with OsgiBundleModule {
versionControl = VersionControl.github("lefou", "LambdaTest")
)

def ivyDeps = Agg(
override def compileIvyDeps = Agg(
Deps.testng,
Deps.junit,
Deps.jupiter,
Deps.slf4j
)

object test extends Tests {
override def testFrameworks = Seq("mill.testng.TestNGFramework")
override def ivyDeps = T{ Agg(
Deps.millTestng,
Deps.logbackClassic
)}
}

object retro extends Cross[RetroCross]("7", "6")
class RetroCross(version: String) extends RetrolambdaModule {
override def bytecodeVersion: T[String] = version
def baseModule: JavaModule = lambdatest
override def retrolambdaVersion = T{ "2.5.7" }
}

}

trait RetrolambdaWorker {
def retrolambda(inputDir: Path, outputDir: Path, classpath: Seq[Path], bytecodeVersion: String)
}

trait RetrolambdaModule extends CoursierModule {
def bytecodeVersion: T[String]
def baseModule: JavaModule
def compile: T[PathRef] = T{
val dest = T.dest
retrolambdaWorker().retrolambda(
inputDir = baseModule.compile().classes.path,
outputDir = dest,
classpath = baseModule.compileClasspath().iterator.to(Seq).map(_.path),
bytecodeVersion = bytecodeVersion()
override def osgiHeaders: T[OsgiHeaders] = super.osgiHeaders().copy(
`Export-Package` = Seq(
s"${namespace}",
s"${namespace}.generic",
s"${namespace}.junit",
s"${namespace}.junit5",
s"${namespace}.testng",
s"${namespace}.proxy",
),
`Import-Package` = Seq(
"*;resolution:=optional"
)
PathRef(dest)
}

override def repositoriesTask: Task[Seq[Repository]] = T.task { baseModule.repositoriesTask() }

def localClasspath: Target[Seq[PathRef]] = T{
baseModule.resources() ++ Agg(compile())
}
)

def jar: T[PathRef] = T{
Jvm.createJar(
localClasspath().map(_.path).filter(os.exists),
baseModule.manifest()
object test extends Tests with TestModule.TestNg {
override def ivyDeps = super.ivyDeps() ++ Agg(
Deps.testng,
Deps.junit,
Deps.jupiter,
Deps.jupiterLauncher,
Deps.logbackClassic
)
}
def manifest: Target[Jvm.JarManifest] = T { baseModule.manifest() }

def retrolambdaVersion: T[String]
def retrolambdaIvyDeps: T[Agg[Dep]] = T{ Agg(ivy"net.orfjackal.retrolambda:retrolambda:${retrolambdaVersion()}".exclude("*" -> "*")) }
def retrolambdaClasspath: T[Seq[PathRef]] = T{
resolveDeps(retrolambdaIvyDeps)().iterator.to(Seq)
}
def retrolambdaWorker = T.worker {
// val cl = new URLClassLoader(retrolambdaClasspath().map(_.path.toNIO.toUri().toURL()));
// val clazz = cl.loadClass("net.orfjackal.retrolambda.Main")
// val mainMethod = clazz.getMethod("main", Seq(classOf[Array[String]]): _*)
new RetrolambdaWorker {
override def retrolambda(inputDir: Path, outputDir: Path, classpath: Seq[Path], bytecodeVersion: String): Unit = {
// mainMethod.invoke(null, Seq(args): _*)
Jvm.runSubprocess(
mainClass = "net.orfjackal.retrolambda.Main",
classPath = retrolambdaClasspath().map(_.path),
jvmArgs = Seq(
s"-Dretrolambda.inputDir=${inputDir.toIO.getPath()}",
s"-Dretrolambda.outputDir=${outputDir.toIO.getPath()}",
s"-Dretrolambda.classpath=${(Seq(inputDir) ++ classpath).map(_.toIO.getPath).mkString(File.pathSeparator)}",
s"-Dretrolambda.bytecodeVersion=${bytecodeVersion}",
s"-javaagent:${retrolambdaClasspath().head.path.toIO.getPath()}"
),
workingDir = outputDir
)
}
}
}
}
}

0 comments on commit ce2a32d

Please sign in to comment.