@@ -23,7 +23,7 @@ object Deps {
2323 val acyclic = ivy"com.lihaoyi:::acyclic:0.3.18"
2424 val jna = ivy"net.java.dev.jna:jna:5.15.0"
2525 val geny = ivy"com.lihaoyi::geny::1.1.1"
26- val compress = ivy"org.apache.ant:ant:1.10.15"
26+ // val compress = ivy"org.apache.ant:ant:1.10.15"
2727 val sourcecode = ivy"com.lihaoyi::sourcecode::0.4.2"
2828 val utest = ivy"com.lihaoyi::utest::0.8.4"
2929 val expecty = ivy"com.eed3si9n.expecty::expecty::0.16.0"
@@ -113,7 +113,8 @@ trait OsLibModule
113113}
114114
115115trait OsModule extends OsLibModule { outer =>
116- def ivyDeps = Agg(Deps.geny, Deps.compress)
116+ def ivyDeps = Agg(Deps.geny)
117+ // def ivyDeps = Agg(Deps.geny, Deps.compress)
117118 override def compileIvyDeps = T {
118119 val scalaReflectOpt = Option.when(!ZincWorkerUtil.isDottyOrScala3(scalaVersion()))(
119120 Deps.scalaReflect(scalaVersion())
@@ -139,6 +140,38 @@ trait OsModule extends OsLibModule { outer =>
139140
140141 def scalaDocOptions = super.scalaDocOptions() ++ conditionalScalaDocOptions()
141142
143+ def apacheAntZipSources: T[PathRef] = Task(persistent = true) {
144+ if (!_root_.os.exists(Task.dest / "src")) {
145+ _root_.os.remove.all(Task.dest / "unzipped")
146+ _root_.os.unzip.stream(
147+ requests.get.stream("https://repo1.maven.org/maven2/org/apache/ant/ant/1.10.15/ant-1.10.15-sources.jar"),
148+ Task.dest / "unzipped"
149+ )
150+ _root_.os.makeDir.all(Task.dest / "src/os")
151+
152+ val classes = _root_.os.walk.stream(Task.dest / "unzipped" / "org/apache/tools/zip")
153+ .map(_.baseName)
154+ val classRegex = classes.mkString("|")
155+ val prefix = "_Apache"
156+
157+ // Add "_Apache" prefix to all classes
158+ // Move from "package org.apache.tools.zip" to "package os"
159+ // Make all classes package private (private [os])
160+ _root_.os.walk.stream(Task.dest / "unzipped" / "org/apache/tools/zip")
161+ .filter(_.ext == "java")
162+ .foreach { p =>
163+ val content = _root_.os.read(p)
164+ .replaceAll(s"(?<![_a-zA-Z\\.])(${classRegex})(?![_a-zA-Z0-9])", prefix + "$1")
165+ .replaceAll(s"(?<=org.apache.tools.zip.)($classRegex)(?![_a-zA-Z0-9])", prefix + "$1")
166+ .replaceAll("org.apache.tools.zip", "os")
167+ .replaceAll("^public ", "")
168+ _root_.os.write(Task.dest / "src/os" / s"$prefix${p.last}", content)
169+ }
170+ }
171+
172+ PathRef(Task.dest / "src")
173+ }
174+
142175 def generatedSources = T {
143176 val conversions = for (i <- Range.inclusive(2, 22)) yield {
144177 val ts = Range.inclusive(1, i).map(n => s"T$n").mkString(", ")
@@ -162,7 +195,7 @@ trait OsModule extends OsLibModule { outer =>
162195 |""".stripMargin,
163196 createFolders = true
164197 )
165- Seq(PathRef(T.dest))
198+ Seq(PathRef(T.dest), apacheAntZipSources() )
166199 }
167200}
168201
0 commit comments