Skip to content

Commit

Permalink
extract renderTrait helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Jan 22, 2025
1 parent c136f18 commit ce4a916
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 61 deletions.
6 changes: 5 additions & 1 deletion main/init/buildgen/src/mill/main/buildgen/BuildGenUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object BuildGenUtil {
|
|${renderCompileModuleDeps(scopedDeps.testCompileModuleDeps)}
|
|${renderResources(Nil)}
|${renderResources(testResources)}
|}""".stripMargin
}

Expand Down Expand Up @@ -104,6 +104,10 @@ object BuildGenUtil {
|
|${renderPublishProperties(Nil)}
|
|${renderResources(resources)}
|
|${renderPublishProperties(publishProperties)}
|
|$testModuleTypedef""".stripMargin

}
Expand Down
5 changes: 4 additions & 1 deletion main/init/buildgen/src/mill/main/buildgen/ir.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ case class IrBuild(
pomSettings: IrPom,
publishVersion: String,
packaging: String,
pomParentArtifact: String
pomParentArtifact: String,
resources: Seq[os.SubPath],
testResources: Seq[os.SubPath],
publishProperties: Seq[(String, String)]
)

case class IrScopedDeps(
Expand Down
39 changes: 18 additions & 21 deletions main/init/gradle/src/mill/main/gradle/BuildGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,28 @@ object BuildGen {

val scopedDeps = extractScopedDeps(project, packages, cfg)

val inner = {
val javacOptions = {
val inner = IrBuild(
scopedDeps,
cfg.shared.testModule,
hasTest,
dirs,
repos = getRepositories(project).diff(baseRepos),
javacOptions = {
val options = getJavacOptions(project).diff(baseJavacOptions)
if (options == baseJavacOptions) Seq.empty else options
}
val repos = getRepositories(project).diff(baseRepos)
val pomSettings = if (baseNoPom) extractPomSettings(project) else null
val publishVersion = {
},
project.name(),
pomSettings = if (baseNoPom) extractPomSettings(project) else null,
publishVersion = {
val version = getPublishVersion(project)
if (version == basePublishVersion) null else version
}
IrBuild(
scopedDeps,
cfg.shared.testModule,
hasTest,
dirs,
repos,
javacOptions,
project.name(),
pomSettings,
publishVersion,
packaging = null,
pomParentArtifact = null
)
}
},
packaging = null,
pomParentArtifact = null,
resources = Nil,
testResources = Nil,
publishProperties = Nil
)

build.copy(value =
BuildObject(
Expand Down
64 changes: 26 additions & 38 deletions main/init/maven/src/mill/main/maven/BuildGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,47 +118,35 @@ object BuildGen {

val supertypes =
Seq("RootModule") ++
(cfg.shared.baseModule match {
case None => moduleSupertypes
case Some(v) => Seq(v)
})
cfg.shared.baseModule.fold(moduleSupertypes)(Seq(_))

val scopedDeps = extractScopedDeps(model, packages, cfg)

val inner = {
val options = Plugins.MavenCompilerPlugin.javacOptions(model)
val javacOptions = if (options == baseJavacOptions) Seq.empty else options

val pomSettings = if (baseNoPom) extractPomSettings(model) else null
val resources = model.getBuild.getResources.iterator().asScala
.map(_.getDirectory)
.map(os.Path(_).subRelativeTo(millSourcePath))
.filterNot(_ == mavenMainResourceDir)
val version = model.getVersion
val publishVersion = if (version == basePublishVersion) null else version

val publishProperties = getPublishProperties(model, cfg).diff(basePublishProperties)
val pomParentArtifact = mkPomParent(model.getParent)

val testResources = model.getBuild.getTestResources.iterator().asScala
.map(_.getDirectory)
.map(os.Path(_).subRelativeTo(millSourcePath))
.filterNot(_ == mavenTestResourceDir)

IrBuild(
scopedDeps,
cfg.shared.testModule,
hasTest,
dirs,
repos = Nil,
javacOptions,
artifactId,
pomSettings,
publishVersion,
packaging,
pomParentArtifact
)
}
val options = Plugins.MavenCompilerPlugin.javacOptions(model)

def processResources(input: java.util.List[org.apache.maven.model.Resource]) = input
.asScala
.map(_.getDirectory)
.map(os.Path(_).subRelativeTo(millSourcePath))
.filterNot(_ == mavenTestResourceDir)
.toSeq

val inner = IrBuild(
scopedDeps,
cfg.shared.testModule,
hasTest,
dirs,
repos = Nil,
javacOptions = if (options == baseJavacOptions) Seq.empty else options,
artifactId,
pomSettings = if (baseNoPom) extractPomSettings(model) else null,
publishVersion = if (model.getVersion == basePublishVersion) null else model.getVersion,
packaging,
pomParentArtifact = mkPomParent(model.getParent),
resources = processResources(model.getBuild.getResources),
testResources = processResources(model.getBuild.getTestResources),
publishProperties = getPublishProperties(model, cfg).diff(basePublishProperties)
)

build.copy(value =
BuildObject(
Expand Down

0 comments on commit ce4a916

Please sign in to comment.