diff options
author | 2018-05-16 09:38:45 -0700 | |
---|---|---|
committer | 2018-05-16 09:39:50 -0700 | |
commit | 6236c178845cb83cb017c054cbe222e5b17de47e (patch) | |
tree | d74e648eecb9a5cea88b306ab03666a1cce0dfd8 /src/main/java/com/google/devtools/build | |
parent | 83ebe8c8773eb8def96b0c5aa1517ee9b1625144 (diff) |
Fix embedded JDK LICENSE handling for JDK 9
PiperOrigin-RevId: 196840344
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java index 7ad512acb6..a7ca2c68ae 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java @@ -13,7 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.runtime.commands; -import com.google.common.io.Files; +import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeCommandResult; @@ -22,11 +22,15 @@ import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.util.ResourceFileLoader; import com.google.devtools.build.lib.util.io.OutErr; -import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; -import java.util.TreeSet; +import java.io.UncheckedIOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; /** A command that prints an embedded license text. */ @Command( @@ -38,15 +42,8 @@ import java.util.TreeSet; ) public class LicenseCommand implements BlazeCommand { - private static final TreeSet<String> JAVA_LICENSE_FILES = - new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - - static { - JAVA_LICENSE_FILES.add("ASSEMBLY_EXCEPTION"); - JAVA_LICENSE_FILES.add("DISCLAIMER"); - JAVA_LICENSE_FILES.add("LICENSE"); - JAVA_LICENSE_FILES.add("THIRD_PARTY_README"); - } + private static final ImmutableSet<String> JAVA_LICENSE_FILES = + ImmutableSet.of("ASSEMBLY_EXCEPTION", "DISCLAIMER", "LICENSE", "THIRD_PARTY_README"); public static boolean isSupported() { return ResourceFileLoader.resourceExists(LicenseCommand.class, "LICENSE"); @@ -67,16 +64,24 @@ public class LicenseCommand implements BlazeCommand { } Path bundledJdk = - env.getDirectories().getEmbeddedBinariesRoot().getRelative("embedded_tools/jdk"); - if (bundledJdk.exists()) { + env.getDirectories() + .getEmbeddedBinariesRoot() + .getRelative("embedded_tools/jdk") + .getPathFile() + .toPath(); + if (Files.exists(bundledJdk)) { outErr.printOutLn( "This binary comes with a bundled JDK, which contains the following license files:\n"); printJavaLicenseFiles(outErr, bundledJdk); } Path bundledJre = - env.getDirectories().getEmbeddedBinariesRoot().getRelative("embedded_tools/jre"); - if (bundledJre.exists()) { + env.getDirectories() + .getEmbeddedBinariesRoot() + .getRelative("embedded_tools/jre") + .getPathFile() + .toPath(); + if (Files.exists(bundledJre)) { outErr.printOutLn( "This binary comes with a bundled JRE, which contains the following license files:\n"); printJavaLicenseFiles(outErr, bundledJre); @@ -87,15 +92,22 @@ public class LicenseCommand implements BlazeCommand { private static void printJavaLicenseFiles(OutErr outErr, Path bundledJdkOrJre) { try { - for (Path path : bundledJdkOrJre.getDirectoryEntries()) { - if (JAVA_LICENSE_FILES.contains(path.getBaseName().toLowerCase())) { - outErr.printOutLn(path.getPathString() + ":\n"); - Files.copy(path.getPathFile(), outErr.getOutputStream()); - outErr.printOutLn("\n"); - } - } + Files.walkFileTree( + bundledJdkOrJre, + new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) + throws IOException { + if (JAVA_LICENSE_FILES.contains(path.getFileName().toString())) { + outErr.printOutLn(path + ":\n"); + Files.copy(path, outErr.getOutputStream()); + outErr.printOutLn("\n"); + } + return super.visitFile(path, basicFileAttributes); + } + }); } catch (IOException e) { - throw new IllegalStateException( + throw new UncheckedIOException( "I/O error while trying to print license file of bundled JDK or JRE: " + e.getMessage(), e); } |