This repository has been archived by the owner on Apr 25, 2021. It is now read-only.
Merged
add JDK 9 support #143
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f77c154
add JDK 9 support
eed3si9n e8670ba
Change to Windows lineending
eed3si9n 1b9f618
Implement JDK 9 support for Windows
eed3si9n dfc3312
oraclejdk8
eed3si9n 605a17d
move JDK9 logic within copyRt
eed3si9n 39d8504
--rt-ext-dir returns a dir specific to JDK 9 ver
eed3si9n File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
java9-rt-export/src/main/java/io/github/retronym/java9rtexport/Copy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 Copy { | ||
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; | ||
} | ||
}); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
java9-rt-export/src/main/java/io/github/retronym/java9rtexport/Export.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 --global-base"); | ||
System.err.println(" Prints sbt global base."); | ||
System.exit(-1); | ||
} | ||
String destination = args[0]; | ||
if (destination.equals("--global-base")) { | ||
Path defaultGlobalBase = Paths.get(System.getProperty("user.home"), ".sbt", "0.13"); | ||
String globalBase = System.getProperty("sbt.global.base", defaultGlobalBase.toString()); | ||
System.out.println(globalBase); | ||
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(); | ||
Copy.copyDirectory(next, zipfs.getPath("/")); | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,10 @@ acquire_sbt_jar () { | |
fi | ||
} | ||
|
||
rt_export_file () { | ||
echo "${sbt_bin_dir}/java9-rt-export.jar" | ||
} | ||
|
||
execRunner () { | ||
# print the arguments one to a line, quoting any containing spaces | ||
[[ $verbose || $debug ]] && echo "# Executing command line:" && { | ||
|
@@ -147,8 +151,16 @@ process_args () { | |
process_my_args "${myargs[@]}" | ||
} | ||
|
||
java_version=$("$java_cmd" -Xmx512M -version 2>&1 | sed 's/.*version "\([0-9]*\)\.\([0-9]*\)\..*"/\1.\2/; 1q') | ||
## parses 1.7, 1.8, 9, etc out of java version "1.8.0_91" | ||
java_version=$("$java_cmd" -Xmx512M -version 2>&1 | sed 's/.*version "\([0-9]*\)\(\.[0-9]*\)\{0,1\}\(.*\)*"/\1\2/; 1q') | ||
vlog "[process_args] java_version = '$java_version'" | ||
rtexport=$(rt_export_file) | ||
sbt_global_dir=$("$java_cmd" ${JAVA_OPTS} ${SBT_OPTS:-$default_sbt_opts} ${java_args[@]} \ | ||
-jar "$rtexport" --global-base) | ||
java9_ext=$(echo "$sbt_global_dir/java9-rt-ext") | ||
java9_rt=$(echo "$java9_ext/rt.jar") | ||
vlog "[process_args] sbt_global_dir = '$sbt_global_dir'" | ||
vlog "[process_args] java9_rt = '$java9_rt'" | ||
} | ||
|
||
# Detect that we have java installed. | ||
|
@@ -174,6 +186,21 @@ checkJava() { | |
fi | ||
} | ||
|
||
copyRt() { | ||
if [[ "$java_version" > "8" ]] && [[ ! -f "$java9_rt" ]]; then | ||
echo Copying runtime jar. | ||
execRunner "$java_cmd" \ | ||
${JAVA_OPTS} \ | ||
${SBT_OPTS:-$default_sbt_opts} \ | ||
${java_args[@]} \ | ||
-jar "$rtexport" \ | ||
"${java9_rt}" | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will copy rt.jar only once. However, jdk 9 might be updated over time. People may select different versions for debugging reasons, or may flip from OpenJDK to Oracle's JDK, to IBM's JVM. That may cause unexpected behavior or crashes. Probably rt.jar should be copied on each startup; alternatively, the full version string could be dumped to a text file and matched upon startup, so that if it differs the rt.jar file is extracted again. |
||
if [[ "$java_version" > "8" ]]; then | ||
addJava "-Dscala.ext.dirs=${java9_ext}" | ||
fi | ||
} | ||
|
||
|
||
run() { | ||
# no jar? download it. | ||
|
@@ -191,6 +218,9 @@ run() { | |
# TODO - java check should be configurable... | ||
checkJava "1.6" | ||
|
||
# Java 9 support | ||
copyRt | ||
|
||
#If we're in cygwin, we should use the windows config, and terminal hacks | ||
if [[ "$CYGWIN_FLAG" == "true" ]]; then | ||
stty -icanon min 1 -echo > /dev/null 2>&1 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to move this out to copyRt so I can use this script from Java 1.6 and 1.7.