mirror of https://github.com/sbt/sbt.git
Use java9rtexport library
This commit is contained in:
parent
7d75936b02
commit
19da0b75e9
19
build.sbt
19
build.sbt
|
|
@ -27,6 +27,8 @@ lazy val scala212Jline = "jline" % "jline" % "2.14.6"
|
|||
// use the scala-xml version used by the compiler not the latest: https://github.com/scala/scala/blob/v2.12.10/versions.properties#L22
|
||||
lazy val scala212Xml = "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6"
|
||||
lazy val sbtActual = "org.scala-sbt" % "sbt" % sbtVersionToRelease
|
||||
val java9rtexportVersion = "0.1.0"
|
||||
lazy val java9rtexport = "org.scala-sbt.rt" % "java9-rt-export" % java9rtexportVersion % Runtime
|
||||
|
||||
lazy val sbt013ExtraDeps = {
|
||||
if (sbtVersionToRelease startsWith "0.13.") Seq(scala210Jline)
|
||||
|
|
@ -207,7 +209,7 @@ val root = (project in file(".")).
|
|||
|
||||
mappings in Universal ++= {
|
||||
val launchJar = sbtLaunchJar.value
|
||||
val rtExportJar = (packageBin in Compile in java9rtexport).value
|
||||
val rtExportJar = ((exportRepoCsrDirectory in dist).value / "org/scala-sbt/rt/java9-rt-export" / java9rtexportVersion / s"java9-rt-export-${java9rtexportVersion}.jar")
|
||||
Seq(launchJar -> "bin/sbt-launch.jar", rtExportJar -> "bin/java9-rt-export.jar")
|
||||
},
|
||||
mappings in Universal ++= (Def.taskDyn {
|
||||
|
|
@ -260,18 +262,6 @@ lazy val integrationTest = (project in file("integration-test"))
|
|||
testFrameworks += new TestFramework("minitest.runner.Framework")
|
||||
)
|
||||
|
||||
lazy val java9rtexport = (project in file("java9-rt-export"))
|
||||
.settings(
|
||||
name := "java9-rt-export",
|
||||
autoScalaLibrary := false,
|
||||
crossPaths := false,
|
||||
description := "Exports the contents of the Java 9. JEP-220 runtime image to a JAR for compatibility with older tools.",
|
||||
homepage := Some(url("http://github.com/retronym/" + name.value)),
|
||||
startYear := Some(2017),
|
||||
licenses += ("Scala license", url(homepage.value.get.toString + "/blob/master/LICENSE")),
|
||||
mainClass in Compile := Some("io.github.retronym.java9rtexport.Export")
|
||||
)
|
||||
|
||||
def downloadUrlForVersion(v: String) = (v split "[^\\d]" flatMap (i => catching(classOf[Exception]) opt (i.toInt))) match {
|
||||
case Array(0, 11, 3, _*) => "http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.11.3-2/sbt-launch.jar"
|
||||
case Array(0, 11, x, _*) if x >= 3 => "http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/"+v+"/sbt-launch.jar"
|
||||
|
|
@ -357,7 +347,7 @@ lazy val dist = (project in file("dist"))
|
|||
if (sbtVersionToRelease startsWith "0.13.") scala210
|
||||
else scala212
|
||||
},
|
||||
libraryDependencies ++= Seq(sbtActual, jansi, scala212Compiler, scala212Jline, scala212Xml) ++ sbt013ExtraDeps,
|
||||
libraryDependencies ++= Seq(sbtActual, java9rtexport, jansi, scala212Compiler, scala212Jline, scala212Xml) ++ sbt013ExtraDeps,
|
||||
exportRepo := {
|
||||
val old = exportRepo.value
|
||||
sbtVersionToRelease match {
|
||||
|
|
@ -387,6 +377,7 @@ lazy val dist = (project in file("dist"))
|
|||
s"$csr fetch --cache $cache ${colonName(jansi)}".!
|
||||
s"$csr fetch --cache $cache ${colonName(scala212Compiler)}".!
|
||||
s"$csr fetch --cache $cache ${colonName(scala212Xml)}".!
|
||||
s"$csr fetch --cache $cache ${colonName(java9rtexport)}".!
|
||||
val mavenCache = cache / "https" / "repo1.maven.org" / "maven2"
|
||||
val compilerBridgeVer = IO.listFiles(mavenCache / "org" / "scala-sbt" / "compiler-bridge_2.12", DirectoryFilter).toList.headOption
|
||||
compilerBridgeVer match {
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
package io.github.retronym.java9rtexport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class Export {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if (args.length == 0) {
|
||||
System.err.println("Usage:");
|
||||
System.err.println(" java -jar java9-rt-export-*.jar $HOME/.sbt/java9-rt-ext/rt.jar");
|
||||
System.err.println(" Exports rt.jar to the specified path.");
|
||||
System.err.println("");
|
||||
System.err.println(" java -jar java9-rt-export-*.jar --rt-ext-dir");
|
||||
System.err.println(" Prints sbt global base.");
|
||||
System.exit(-1);
|
||||
}
|
||||
String destination = args[0];
|
||||
Path defaultGlobalBase = Paths.get(System.getProperty("user.home"), ".sbt", "0.13");
|
||||
String globalBase = System.getProperty("sbt.global.base", defaultGlobalBase.toString());
|
||||
if (destination.equals("--global-base")) {
|
||||
System.out.println(globalBase);
|
||||
System.exit(0);
|
||||
}
|
||||
if (destination.equals("--rt-ext-dir")) {
|
||||
String v = System.getProperty("java.vendor") + "_" + System.getProperty("java.version");
|
||||
v = v.replaceAll("\\W", "_").toLowerCase();
|
||||
/*
|
||||
* The launch script greps for output starting with "java9-rt-ext-" so changing this
|
||||
* string will require changing the grep command in sbt-launch-lib.bash.
|
||||
*/
|
||||
Path rtExtDir = Paths.get(globalBase, "java9-rt-ext-" + v);
|
||||
System.out.println(rtExtDir.toString());
|
||||
System.exit(0);
|
||||
}
|
||||
FileSystem fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
Path path = fileSystem.getPath("/modules");
|
||||
Path destPath = Paths.get(destination);
|
||||
URI uri = URI.create( "jar:" + destPath.toUri() );
|
||||
Map<String, String> env = new HashMap<>();
|
||||
env.put( "create", "true" );
|
||||
try ( FileSystem zipfs = FileSystems.newFileSystem( uri, env ) ) {
|
||||
Iterator<Path> iterator = Files.list(path).iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Path next = iterator.next();
|
||||
IO.copyDirectory(next, zipfs.getPath("/"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package io.github.retronym.java9rtexport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.*;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
|
||||
public class IO {
|
||||
public static void copyDirectory(final Path source, final Path target)
|
||||
throws IOException {
|
||||
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS),
|
||||
Integer.MAX_VALUE, new FileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir,
|
||||
BasicFileAttributes sourceBasic) throws IOException {
|
||||
|
||||
String relative = source.relativize(dir).toString();
|
||||
if (!Files.exists(target.getFileSystem().getPath(relative)))
|
||||
Files.createDirectory(target.getFileSystem().getPath(relative));
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file,
|
||||
BasicFileAttributes attrs) throws IOException {
|
||||
String relative = source.relativize(file).toString();
|
||||
Files.copy(file, target.getFileSystem().getPath(relative), COPY_ATTRIBUTES, REPLACE_EXISTING);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException {
|
||||
throw e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
|
||||
if (e != null) throw e;
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue