Skip to content

Commit d4886b0

Browse files
Address review comments
1 parent 35833c3 commit d4886b0

File tree

3 files changed

+66
-34
lines changed

3 files changed

+66
-34
lines changed

Diff for: scalalib/src/mill/scalalib/JavaModule.scala

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import mill.util.Jvm
2020

2121
import os.{Path, ProcessOutput}
2222

23+
import java.util.zip.ZipOutputStream
24+
2325
import scala.annotation.nowarn
26+
import scala.util.Using
2427

2528
/**
2629
* Core configuration required to compile a single Java compilation target
@@ -1580,12 +1583,18 @@ trait BomModule extends JavaModule {
15801583
}
15811584

15821585
def jar: T[PathRef] = Task {
1583-
(throw new Exception("A BomModule doesn't have a JAR")): PathRef
1586+
val path = T.dest / "empty.jar"
1587+
Using.resource(os.write.outputStream(path, createFolders = true)) { os =>
1588+
val zos = new ZipOutputStream(os)
1589+
zos.finish()
1590+
zos.close()
1591+
}
1592+
PathRef(path)
15841593
}
15851594
def docJar: T[PathRef] = Task {
1586-
(throw new Exception("A BomModule doesn't have a doc JAR")): PathRef
1595+
jar()
15871596
}
15881597
def sourceJar: T[PathRef] = Task {
1589-
(throw new Exception("A BomModule doesn't have a source JAR")): PathRef
1598+
jar()
15901599
}
15911600
}

Diff for: scalalib/src/mill/scalalib/PublishModule.scala

+13-5
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ trait PublishModule extends JavaModule { outer =>
243243
* @param hasJar Whether this module has a JAR or not
244244
* @return
245245
*/
246-
def ivy(hasJar: Boolean): Task[String] = Task.Anon {
246+
private def ivy(hasJar: Boolean): Task[String] = Task.Anon {
247247
val (results, bomDepMgmt) = defaultResolver().processDeps(
248248
Seq(
249249
BoundDep(
@@ -365,14 +365,22 @@ trait PublishModule extends JavaModule { outer =>
365365
case None => LocalIvyPublisher
366366
case Some(path) => new LocalIvyPublisher(path)
367367
}
368+
val extras =
369+
jarTask().toSeq.map { jar0 =>
370+
LocalIvyPublisher.jarPublishInfo(jar0)
371+
} ++
372+
sourcesJarTask().toSeq.map { sourcesJar0 =>
373+
LocalIvyPublisher.sourcesJarPublishInfo(sourcesJar0)
374+
} ++
375+
docJarTask().toSeq.map { docJar0 =>
376+
LocalIvyPublisher.docJarPublishInfo(docJar0)
377+
} ++
378+
extraPublish()
368379
publisher.publishLocal(
369-
jar = jarTask(),
370-
sourcesJar = sourcesJarTask(),
371-
docJar = docJarTask(),
372380
pom = pom().path,
373381
ivy = Right(ivy().path),
374382
artifact = artifactMetadata(),
375-
extras = extraPublish()
383+
extras = extras
376384
)
377385
}
378386
}

Diff for: scalalib/src/mill/scalalib/publish/LocalIvyPublisher.scala

+41-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package mill.scalalib.publish
22

3-
import mill.api.Ctx
3+
import mill.api.{Ctx, PathRef}
44

55
class LocalIvyPublisher(localIvyRepo: os.Path) {
66

@@ -13,26 +13,26 @@ class LocalIvyPublisher(localIvyRepo: os.Path) {
1313
ivy: os.Path,
1414
artifact: Artifact,
1515
extras: Seq[PublishInfo]
16-
)(implicit ctx: Ctx.Log): Unit =
17-
publishLocal(Some(jar), Some(sourcesJar), Some(docJar), pom, Right(ivy), artifact, extras)
16+
)(implicit ctx: Ctx.Log): Unit = {
17+
val mainArtifacts = Seq(
18+
LocalIvyPublisher.jarPublishInfo(jar),
19+
LocalIvyPublisher.sourcesJarPublishInfo(sourcesJar),
20+
LocalIvyPublisher.docJarPublishInfo(docJar)
21+
)
22+
publishLocal(pom, Right(ivy), artifact, mainArtifacts ++ extras)
23+
}
1824

1925
/**
2026
* Publishes a module locally
2127
*
22-
* @param jar The JAR of this module, if it has one
23-
* @param sourcesJar The source JAR of this module, if it has one
24-
* @param docJar The javadoc JAR of this module, if it has one
2528
* @param pom The POM of this module
2629
* @param ivy If right, the path to the ivy.xml file of this module; if left, its content as a String
2730
* @param artifact Coordinates of this module
28-
* @param extras Extra files to publish in this module
31+
* @param extras Files to publish in this module
2932
* @param ctx
3033
* @return The files created or written to when publishing locally this module
3134
*/
3235
def publishLocal(
33-
jar: Option[os.Path],
34-
sourcesJar: Option[os.Path],
35-
docJar: Option[os.Path],
3636
pom: os.Path,
3737
ivy: Either[String, os.Path],
3838
artifact: Artifact,
@@ -43,13 +43,10 @@ class LocalIvyPublisher(localIvyRepo: os.Path) {
4343
val releaseDir = localIvyRepo / artifact.group / artifact.id / artifact.version
4444

4545
val toCopy: Seq[(Either[String, os.Path], os.Path)] =
46-
jar.map(Right(_) -> releaseDir / "jars" / s"${artifact.id}.jar").toSeq ++
47-
sourcesJar.map(Right(_) -> releaseDir / "srcs" / s"${artifact.id}-sources.jar").toSeq ++
48-
docJar.map(Right(_) -> releaseDir / "docs" / s"${artifact.id}-javadoc.jar").toSeq ++
49-
Seq(
50-
Right(pom) -> releaseDir / "poms" / s"${artifact.id}.pom",
51-
ivy -> releaseDir / "ivys/ivy.xml"
52-
) ++
46+
Seq(
47+
Right(pom) -> releaseDir / "poms" / s"${artifact.id}.pom",
48+
ivy -> releaseDir / "ivys/ivy.xml"
49+
) ++
5350
extras.map { entry =>
5451
(
5552
Right(entry.file.path),
@@ -76,21 +73,39 @@ class LocalIvyPublisher(localIvyRepo: os.Path) {
7673
ivy: os.Path,
7774
artifact: Artifact,
7875
extras: Seq[PublishInfo]
79-
)(implicit ctx: Ctx.Log): Seq[os.Path] =
80-
publishLocal(
81-
Some(jar),
82-
Some(sourcesJar),
83-
Some(docJar),
84-
pom,
85-
Right(ivy),
86-
artifact,
87-
extras
76+
)(implicit ctx: Ctx.Log): Seq[os.Path] = {
77+
val mainArtifacts = Seq(
78+
LocalIvyPublisher.jarPublishInfo(jar),
79+
LocalIvyPublisher.sourcesJarPublishInfo(sourcesJar),
80+
LocalIvyPublisher.docJarPublishInfo(docJar)
8881
)
82+
publishLocal(pom, Right(ivy), artifact, mainArtifacts ++ extras)
83+
}
8984
}
9085

9186
object LocalIvyPublisher
9287
extends LocalIvyPublisher(
9388
sys.props.get("ivy.home")
9489
.map(os.Path(_))
9590
.getOrElse(os.home / ".ivy2") / "local"
91+
) {
92+
93+
private[mill] def jarPublishInfo(jar: os.Path): PublishInfo =
94+
PublishInfo(PathRef(jar), ivyType = "jar", ext = "jar", ivyConfig = "compile")
95+
private[mill] def sourcesJarPublishInfo(sourcesJar: os.Path): PublishInfo =
96+
PublishInfo(
97+
PathRef(sourcesJar),
98+
ivyType = "src",
99+
classifier = Some("sources"),
100+
ext = "jar",
101+
ivyConfig = "compile"
102+
)
103+
private[mill] def docJarPublishInfo(docJar: os.Path): PublishInfo =
104+
PublishInfo(
105+
PathRef(docJar),
106+
ivyType = "doc",
107+
classifier = Some("javadoc"),
108+
ext = "jar",
109+
ivyConfig = "compile"
96110
)
111+
}

0 commit comments

Comments
 (0)