Skip to content

Commit fa0d794

Browse files
committed
Migrate away from sbt IO in scala3doc
Fix NamedTypeArguments (again)
1 parent f510be1 commit fa0d794

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

scala3doc/build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ libraryDependencies ++= Seq(
88
"org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value,
99

1010
"com.virtuslab.dokka" % "dokka-site" % dokkaSiteVersion,
11-
"org.scala-sbt" % "io_2.13" % "1.3.4",
1211
"com.vladsch.flexmark" % "flexmark-all" % flexmarkVersion,
1312
"com.lihaoyi" % "scalatags_2.13" % scalaTagsVersion,
1413
"nl.big-o" % "liqp" % "0.6.7",

scala3doc/example-project/src/main/scala/NamedTypeArguments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package example
22

3-
import experimental.namedTypeArguments
3+
import scala.language.experimental.namedTypeArguments
44

55
/**
66
* Named Type Arguments: https://dotty.epfl.ch/docs/reference/other-new-features/named-typeargs.html

scala3doc/src/dotty/dokka/IO.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package dotty.dokka;
2+
3+
import java.io.*;
4+
import java.nio.file.*;
5+
import java.nio.file.attribute.BasicFileAttributes;
6+
import java.util.zip.*;
7+
8+
/** This code is mostly using public snippets and tries to mimic sbt-io api. */
9+
public class IO {
10+
public static void delete(File pathToBeDeleted) throws IOException {
11+
Files.walkFileTree(pathToBeDeleted.toPath(),
12+
new SimpleFileVisitor<Path>() {
13+
@Override
14+
public FileVisitResult postVisitDirectory(
15+
Path dir, IOException exc) throws IOException {
16+
Files.delete(dir);
17+
return FileVisitResult.CONTINUE;
18+
}
19+
20+
@Override
21+
public FileVisitResult visitFile(
22+
Path file, BasicFileAttributes attrs)
23+
throws IOException {
24+
Files.delete(file);
25+
return FileVisitResult.CONTINUE;
26+
}
27+
});
28+
}
29+
30+
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
31+
File destFile = new File(destinationDir, zipEntry.getName());
32+
33+
String destDirPath = destinationDir.getCanonicalPath();
34+
String destFilePath = destFile.getCanonicalPath();
35+
36+
if (!destFilePath.startsWith(destDirPath + File.separator)) {
37+
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
38+
}
39+
40+
return destFile;
41+
}
42+
43+
public static File unzip(File fileZip, File destDir) throws IOException {
44+
byte[] buffer = new byte[1024];
45+
ZipInputStream zis = null;
46+
47+
try {
48+
zis= new ZipInputStream(new FileInputStream(fileZip));
49+
ZipEntry zipEntry = zis.getNextEntry();
50+
while (zipEntry != null) {
51+
File newFile = newFile(destDir, zipEntry);
52+
FileOutputStream fos = new FileOutputStream(newFile);
53+
int len;
54+
while ((len = zis.read(buffer)) > 0) {
55+
fos.write(buffer, 0, len);
56+
}
57+
fos.close();
58+
zipEntry = zis.getNextEntry();
59+
}
60+
zis.closeEntry();
61+
} finally {
62+
if (zis != null) zis.close();
63+
}
64+
return destDir;
65+
}
66+
}

scala3doc/src/dotty/dokka/Main.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import java.util.{List => JList}
1212

1313
import scala.tasty.Reflection
1414
import scala.tasty.inspector.TastyInspector
15-
import sbt.io.IO
1615
import java.nio.file.Files
1716

1817
import org.kohsuke.args4j.{CmdLineParser, Option => COption}

0 commit comments

Comments
 (0)