diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index ec152b5336fa..60206de54f9a 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -30,8 +30,11 @@ object Bench { val iterations = if (intArgs.length > 1) intArgs(1).toInt else 20 val forks = if (intArgs.length > 2) intArgs(2).toInt else 1 + + import File.{ separator => sep } + val args2 = args1.map { arg => - if ((arg.endsWith(".scala") || arg.endsWith(".java")) && arg.head != '/') "../" + arg + if ((arg.endsWith(".scala") || arg.endsWith(".java")) && !(new File(arg)).isAbsolute) ".." + sep + arg else arg } storeCompileOptions(args2) @@ -61,9 +64,10 @@ object Bench { val libs = if (args.contains("-with-compiler")) compiler_libs else standard_libs var argsNorm = args.filter(_ != "-with-compiler") + import File.{ pathSeparator => sep } var cpIndex = argsNorm.indexOf("-classpath") if (cpIndex == -1) cpIndex = argsNorm.indexOf("-cp") - if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + java.io.File.pathSeparator + libs + if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + sep + libs else argsNorm = argsNorm :+ "-classpath" :+ libs val file = new File(COMPILE_OPTS_FILE) diff --git a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala index a761d746efdd..73702947a991 100644 --- a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala @@ -174,7 +174,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No if (inPackage == "") Nil else { packageToModuleBases.getOrElse(inPackage, Nil).flatMap(x => - Files.list(x.resolve(inPackage.replace('.', '/'))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x => + Files.list(x.resolve(FileUtils.dirPath(inPackage))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x => ClassFileEntryImpl(new PlainFile(new dotty.tools.io.File(x)))).toVector } } @@ -193,7 +193,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No else { val inPackage = packageOf(className) packageToModuleBases.getOrElse(inPackage, Nil).iterator.flatMap{x => - val file = x.resolve(className.replace('.', '/') + ".class") + val file = x.resolve(FileUtils.dirPath(className) + ".class") if (Files.exists(file)) new PlainFile(new dotty.tools.io.File(file)) :: Nil else Nil }.take(1).toList.headOption } @@ -207,7 +207,7 @@ case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[ClassFile def findClassFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) - val classFile = new JFile(s"$dir/$relativePath.class") + val classFile = new JFile(dir, relativePath + ".class") if (classFile.exists) { val wrappedClassFile = new dotty.tools.io.File(classFile.toPath) val abstractClassFile = new PlainFile(wrappedClassFile) @@ -232,7 +232,7 @@ case class DirectorySourcePath(dir: JFile) extends JFileDirectoryLookup[SourceFi private def findSourceFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) val sourceFile = Stream("scala", "java") - .map(ext => new JFile(s"$dir/$relativePath.$ext")) + .map(ext => new JFile(dir, relativePath + "." + ext)) .collectFirst { case file if file.exists() => file } sourceFile.map { file => diff --git a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala index 684fc7a58239..a8628be6db3c 100644 --- a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala +++ b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala @@ -43,7 +43,7 @@ object FileUtils { else throw new FatalError("Unexpected source file ending: " + fileName) } - def dirPath(forPackage: String): String = forPackage.replace('.', '/') + def dirPath(forPackage: String): String = forPackage.replace('.', JFile.separatorChar) def endsClass(fileName: String): Boolean = fileName.length > 6 && fileName.substring(fileName.length - 6) == ".class" diff --git a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala index 1579e70afc55..ae285f80790b 100644 --- a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala @@ -24,7 +24,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi protected def emptyFiles: Array[AbstractFile] = Array.empty protected def getSubDir(packageDirName: String): Option[AbstractFile] = - Option(lookupPath(dir)(packageDirName.split('/'), directory = true)) + Option(lookupPath(dir)(packageDirName.split(java.io.File.separator), directory = true)) protected def listChildren(dir: AbstractFile, filter: Option[AbstractFile => Boolean] = None): Array[F] = filter match { case Some(f) => dir.iterator.filter(f).toArray case _ => dir.toArray @@ -41,7 +41,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi def findClassFile(className: String): Option[AbstractFile] = { val relativePath = FileUtils.dirPath(className) + ".class" - Option(lookupPath(dir)(relativePath split '/', directory = false)) + Option(lookupPath(dir)(relativePath.split(java.io.File.separator), directory = false)) } private[dotty] def classes(inPackage: String): Seq[ClassFileEntry] = files(inPackage) diff --git a/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala b/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala index 256956fdb54b..42226e9a3b8f 100644 --- a/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala +++ b/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala @@ -66,7 +66,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends ClassPa } private def findDirEntry(pkg: String): Option[archive.DirEntry] = { - val dirName = s"${FileUtils.dirPath(pkg)}/" + val dirName = pkg.replace('.', '/') + "/" archive.allDirs.get(dirName) } diff --git a/compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala b/compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala index 6fd80cbe50e2..2e54866459be 100644 --- a/compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala +++ b/compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala @@ -17,7 +17,8 @@ object ConsumeTasty { } val currentClasspath = QuoteDriver.currentClasspath - val args = "-from-tasty" +: "-classpath" +: s"$classpath:$currentClasspath" +: classes + import java.io.File.{ pathSeparator => sep } + val args = "-from-tasty" +: "-classpath" +: s"$classpath$sep$currentClasspath" +: classes (new Consume).process(args.toArray) } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index faf48ae9e966..827e9d424bb2 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -96,7 +96,8 @@ object QuoteDriver { case cl: URLClassLoader => // Loads the classes loaded by this class loader // When executing `run` or `test` in sbt the classpath is not in the property java.class.path - val newClasspath = cl.getURLs.map(_.getFile()) + import java.nio.file.Paths + val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString) newClasspath.mkString("", java.io.File.pathSeparator, if (classpath0 == "") "" else java.io.File.pathSeparator + classpath0) case _ => classpath0 } diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala index 523f9ebe94ce..1e656ee4f37d 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala @@ -8,6 +8,7 @@ import java.io.{ File => JFile, OutputStreamWriter, BufferedWriter, ByteArrayInp import java.util.{ List => JList, Arrays } import java.nio.file.Path import java.nio.charset.StandardCharsets +import java.io.File.{ separator => sep } import com.vladsch.flexmark.parser.ParserEmulationProfile import com.vladsch.flexmark.parser.Parser @@ -166,9 +167,9 @@ case class Site( private def defaultParams(pageLocation: JFile, additionalDepth: Int = 0): DefaultParams = { val pathFromRoot = stripRoot(pageLocation) val baseUrl: String = { - val rootLen = root.getAbsolutePath.split('/').length - val assetLen = pageLocation.getAbsolutePath.split('/').length - "../" * (assetLen - rootLen - 1 + additionalDepth) + "." + val rootLen = root.toPath.toAbsolutePath.normalize.getNameCount + val assetLen = pageLocation.toPath.toAbsolutePath.normalize.getNameCount + "../" * (assetLen - rootLen + additionalDepth) + "." } DefaultParams( @@ -197,16 +198,16 @@ case class Site( // Suffix is index.html for packages and therefore the additional depth // is increased by 1 val (suffix, offset) = - if (e.kind == "package") ("/index.html", -1) + if (e.kind == "package") (sep + "index.html", -1) else (".html", 0) val path = if (scala.util.Properties.isWin) e.path.map(_.replace("<", "_").replace(">", "_")) - else + else e.path - val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/" + path.mkString("/") + suffix)) + val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + path.mkString(sep) + suffix)) val params = defaultParams(target.toFile, -1).withPosts(blogInfo).withEntity(Some(e)).toMap - val page = new HtmlPage("_layouts/api-page.html", layouts("api-page").content, params, includes) + val page = new HtmlPage("_layouts" + sep + "api-page.html", layouts("api-page").content, params, includes) render(page).foreach { rendered => val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)) @@ -223,9 +224,9 @@ case class Site( } // generate search page: - val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/search.html")) + val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + "search.html")) val searchPageParams = defaultParams(target.toFile, -1).withPosts(blogInfo).toMap - val searchPage = new HtmlPage("_layouts/search.html", layouts("search").content, searchPageParams, includes) + val searchPage = new HtmlPage("_layouts" + sep + "search.html", layouts("search").content, searchPageParams, includes) render(searchPage).foreach { rendered => Files.copy( new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)), diff --git a/project/Build.scala b/project/Build.scala index d616430f56fc..e77c731cd370 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -628,8 +628,7 @@ object Build { val dottyLib = jars("dotty-library") def run(args: List[String]): Unit = { - val sep = File.pathSeparator - val fullArgs = insertClasspathInArgs(args, s".$sep$dottyLib$sep$scalaLib") + val fullArgs = insertClasspathInArgs(args, List(".", dottyLib, scalaLib).mkString(File.pathSeparator)) runProcess("java" :: fullArgs, wait = true) } @@ -645,7 +644,7 @@ object Build { val asm = findLib(attList, "scala-asm") val dottyCompiler = jars("dotty-compiler") val dottyInterfaces = jars("dotty-interfaces") - run(insertClasspathInArgs(args1, s"$dottyCompiler:$dottyInterfaces:$asm")) + run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm).mkString(File.pathSeparator))) } else run(args) }, @@ -1092,8 +1091,8 @@ object Build { Developer( id = "liufengyun", name = "Liu Fengyun", - email = "liufengyun@chaos-lab.com", - url = url("http://chaos-lab.com") + email = "liu@fengy.me", + url = url("https://fengy.me") ), Developer( id = "nicolasstucki",