@@ -681,42 +681,96 @@ object Build {
681681 " https://repo1.maven.org/maven2/com/lihaoyi/fansi_3/0.5.1/fansi_3-0.5.1-sources.jar" ,
682682 " https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_3/0.4.3-M5/sourcecode_3-0.4.3-M5-sources.jar" ,
683683 )
684- val sourceManagedPath = os. Path ((Compile / sourceManaged).value / " downloaded" )
685- os.remove.all(sourceManagedPath)
686- os.makeDir.all(sourceManagedPath )
687- for (download <- downloads) {
688- os.unzip.stream(requests.get.stream(download), dest = sourceManagedPath)
684+ val dest = ((Compile / sourceManaged).value / " downloaded" ).toPath
685+ if ( Files .exists(dest)) {
686+ Files .walk(dest )
687+ .sorted(java.util. Comparator .reverseOrder()) // delete children before parents
688+ .forEach(p => Files .delete(p));
689689 }
690- for {
691- file <- os.walk(sourceManagedPath)
692- if file.ext == " scala"
693- if file.last != " CollectionName.scala"
694- } yield {
695- val text = os.read(file)
696- os.write.over(
697- file,
698- " package dotty.shaded\n " +
699- text
700- .replace(" import scala" , " import _root_.scala" )
701- .replace(" scala.collection." , " _root_.scala.collection." )
702- .replace(" _root_.pprint" , " _root_.dotty.shaded.pprint" )
703- .replace(" _root_.fansi" , " _root_.dotty.shaded.fansi" )
704- .replace(" def apply(c: Char): Trie[T]" , " def apply(c: Char): Trie[T] | Null" )
705- .replace(" var head: Iterator[T] = null" , " var head: Iterator[T] | Null = null" )
706- .replace(" if (head != null && head.hasNext) true" , " if (head != null && head.nn.hasNext) true" )
707- .replace(" head.next()" , " head.nn.next()" )
708- .replace(
709- " _root_.scala.collection.internal.pprint.CollectionName.get(i)" ,
710- " import scala.reflect.Selectable.reflectiveSelectable\n " +
711- " i.asInstanceOf[{def collectionClassName: String}].collectionClassName"
712- )
713- .replace(" abstract class Walker" , " @scala.annotation.nowarn abstract class Walker" )
714- .replace(" object TPrintLowPri" , " @scala.annotation.nowarn object TPrintLowPri" )
715- // .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
716- // .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
717- )
718- file.toIO
690+ Files .createDirectories(dest)
691+
692+ for (url <- downloads) {
693+ import java .io ._
694+ import java .net .{HttpURLConnection , URL }
695+ import java .nio .file ._
696+ import java .nio .file .attribute .FileTime
697+ import java .util .zip .{ZipEntry , ZipInputStream }
698+
699+
700+
701+
702+ val conn = new URL (url).openConnection().asInstanceOf [HttpURLConnection ]
703+ conn.setInstanceFollowRedirects(true )
704+ conn.setConnectTimeout(15000 )
705+ conn.setReadTimeout(60000 )
706+ conn.setRequestMethod(" GET" )
707+
708+ var in : InputStream = null
709+ var zis : ZipInputStream = null
710+ try {
711+ in = new BufferedInputStream (conn.getInputStream)
712+ zis = new ZipInputStream (in)
713+
714+ var entry : ZipEntry = zis.getNextEntry
715+ val buffer = new Array [Byte ](8192 )
716+
717+ while (entry != null ) {
718+ val target = dest.resolve(entry.getName).normalize()
719+ if (entry.isDirectory) Files .createDirectories(target)
720+ else {
721+ Files .createDirectories(target.getParent)
722+ var out : OutputStream = null
723+ try {
724+ out = new BufferedOutputStream (Files .newOutputStream(target, StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING ))
725+ var n = zis.read(buffer)
726+ while (n != - 1 ) {
727+ out.write(buffer, 0 , n)
728+ n = zis.read(buffer)
729+ }
730+ } finally if (out != null ) out.close()
731+ }
732+
733+ zis.closeEntry()
734+ entry = zis.getNextEntry
735+ }
736+ } finally {
737+ if (zis != null ) zis.close()
738+ if (in != null ) in.close()
739+ conn.disconnect()
740+ }
719741 }
742+
743+ import collection .JavaConverters ._
744+ Files .walk(dest)
745+ .filter(p => p.toString().endsWith(" .scala" ))
746+ .filter(p => ! p.getFileName().toString().equals(" CollectionName.scala" ))
747+ .map[java.io.File ] { (file : java.nio.file.Path ) =>
748+ val text = Files .readString(file)
749+ Files .write(
750+ file,
751+ (" package dotty.shaded\n " +
752+ text
753+ .replace(" import scala" , " import _root_.scala" )
754+ .replace(" scala.collection." , " _root_.scala.collection." )
755+ .replace(" _root_.pprint" , " _root_.dotty.shaded.pprint" )
756+ .replace(" _root_.fansi" , " _root_.dotty.shaded.fansi" )
757+ .replace(" def apply(c: Char): Trie[T]" , " def apply(c: Char): Trie[T] | Null" )
758+ .replace(" var head: Iterator[T] = null" , " var head: Iterator[T] | Null = null" )
759+ .replace(" if (head != null && head.hasNext) true" , " if (head != null && head.nn.hasNext) true" )
760+ .replace(" head.next()" , " head.nn.next()" )
761+ .replace(
762+ " _root_.scala.collection.internal.pprint.CollectionName.get(i)" ,
763+ " import scala.reflect.Selectable.reflectiveSelectable\n " +
764+ " i.asInstanceOf[{def collectionClassName: String}].collectionClassName"
765+ )
766+ .replace(" abstract class Walker" , " @scala.annotation.nowarn abstract class Walker" )
767+ .replace(" object TPrintLowPri" , " @scala.annotation.nowarn object TPrintLowPri" )).getBytes
768+ )
769+ file.toFile
770+
771+ }
772+ .collect(java.util.stream.Collectors .toList()).asScala.toSeq
773+
720774 }.taskValue
721775 // Settings shared between scala3-compiler and scala3-compiler-bootstrapped
722776 lazy val commonDottyCompilerSettings = Seq (
0 commit comments