summaryrefslogtreecommitdiff
path: root/scalalib/src/mill/scalalib/publish/LocalPublisher.scala
blob: a8a703fcf33e37a4a165e17cf83077e6506810b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package mill.scalalib.publish

import ammonite.ops._

object LocalPublisher {

  private val root: Path = home / ".ivy2" / "local"

  def publish(jar: Path,
              sourcesJar: Path,
              docJar: Path,
              pom: Path,
              ivy: Path,
              artifact: Artifact): Unit = {
    val releaseDir = root / artifact.group / artifact.id / artifact.version
    writeFiles(
      jar -> releaseDir / "jars" / s"${artifact.id}.jar",
      sourcesJar -> releaseDir / "srcs" / s"${artifact.id}-sources.jar",
      docJar -> releaseDir / "docs" / s"${artifact.id}-javadoc.jar",
      pom -> releaseDir / "poms" / s"${artifact.id}.pom",
      ivy -> releaseDir / "ivys" / "ivy.xml"
    )
  }

  private def writeFiles(fromTo: (Path, Path)*): Unit = {
    fromTo.foreach {
      case (from, to) =>
        mkdir(to / up)
        cp.over(from, to)
    }
  }

}