use of org.eclipse.tycho.compiler.jdt.copied.LibraryInfo in project tycho by eclipse.
the class JdkLibraryInfoProvider method parseLibraryInfo.
private LibraryInfo parseLibraryInfo(String output, String javaHome) {
// JVM may add garbage before and/or after our output, strip it
String[] splitPrefixAndSuffix = output.split(Pattern.quote("####"));
if (splitPrefixAndSuffix.length < 2) {
throw new IllegalStateException("Could not parse process output: " + output);
}
output = splitPrefixAndSuffix[1];
String[] parts = output.split(Pattern.quote("|"));
if (parts.length != 4) {
throw new IllegalStateException("Could not parse process output: " + output);
}
String javaVersion = parts[0];
String[] bootclasspath = splitPath(parts[1]);
String[] extDirs = splitPath(parts[2]);
String[] endorsedDirs = splitPath(parts[3]);
// workaround for missing bootclasspath in Java 9 - see JDT bug http://eclip.se/489207
if (bootclasspath.length == 0) {
File jrtFsJar = new File(javaHome, "lib/jrt-fs.jar");
if (!jrtFsJar.isFile()) {
jrtFsJar = new File(javaHome, "jrt-fs.jar");
if (!jrtFsJar.isFile()) {
throw new IllegalStateException("jrt-fs.jar not found in " + javaHome);
}
}
bootclasspath = new String[] { jrtFsJar.getAbsolutePath() };
}
if (isRunningOnJava9orLater()) {
// JDT APT throws IllegalArgumentException for "-extdirs" CLI arg on Java 9
// TODO bug in JDT? -extdirs should only be disallowed if used with --release
// according to https://docs.oracle.com/javase/9/tools/javac.htm#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9__STANDARDOPTIONSFORJAVAC-7D3D9CC2
extDirs = new String[0];
}
return new LibraryInfo(javaVersion, bootclasspath, extDirs, endorsedDirs);
}
use of org.eclipse.tycho.compiler.jdt.copied.LibraryInfo in project tycho by eclipse.
the class JdkLibraryInfoProviderTest method testGetLibraryInfoForCurrentlyRunningJDK.
@Test
public void testGetLibraryInfoForCurrentlyRunningJDK() throws Exception {
JdkLibraryInfoProviderStub libInfoProvider = new JdkLibraryInfoProviderStub(new File("../tycho-lib-detector/target/classes/"), new SilentLog());
String javaHome = System.getProperty("java.home");
LibraryInfo libraryInfo = libInfoProvider.getLibraryInfo(javaHome);
assertEquals(System.getProperty("java.version"), libraryInfo.getVersion());
String expectedBootclasspath = getExpectedBootclasspath(javaHome);
assertEquals(expectedBootclasspath, String.join(File.pathSeparator, libraryInfo.getBootpath()));
String javaExtDirs = System.getProperty("java.ext.dirs");
if (javaExtDirs != null) {
assertEquals(javaExtDirs, String.join(File.pathSeparator, libraryInfo.getExtensionDirs()));
}
String javaEndorsedDirs = System.getProperty("java.endorsed.dirs");
if (javaExtDirs != null) {
assertEquals(javaEndorsedDirs, String.join(File.pathSeparator, libraryInfo.getEndorsedDirs()));
}
}
use of org.eclipse.tycho.compiler.jdt.copied.LibraryInfo in project tycho by eclipse.
the class JdkLibraryInfoProvider method generateLibraryInfo.
private LibraryInfo generateLibraryInfo(String javaHome) {
String executable = javaHome + File.separator + "bin" + File.separator + "java";
if (File.separatorChar == '\\') {
executable = executable + ".exe";
}
if (!new File(executable).isFile()) {
getLog().warn(executable + " not found. Fallback to scan " + javaHome + "/lib/*.jar and " + javaHome + "/lib/ext/*.jar for bootclasspath");
return new LibraryInfo("unknown", scanLibFolders(javaHome), new String[0], new String[0]);
}
CommandLine cli = new CommandLine(executable);
cli.addArguments(new String[] { "-classpath", getLibDetectorJar().getAbsolutePath(), "org.eclipse.tycho.libdetector.LibraryDetector" }, false);
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(30 * 1000L);
executor.setWatchdog(watchdog);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PumpStreamHandler handler = new PumpStreamHandler(outputStream);
executor.setStreamHandler(handler);
int exitValue = -1;
try {
exitValue = executor.execute(cli);
} catch (ExecuteException e) {
if (watchdog.killedProcess()) {
throw new RuntimeException("Timeout 30 s exceeded. Commandline " + cli.toString() + " was killed. Output: " + outputStream.toString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (exitValue == 0) {
return parseLibraryInfo(outputStream.toString(), javaHome);
} else {
throw new RuntimeException(cli.toString() + " process exit code was " + exitValue + ". Output: " + outputStream.toString());
}
}
use of org.eclipse.tycho.compiler.jdt.copied.LibraryInfo in project tycho by eclipse.
the class JdkLibraryInfoProvider method getLibraryInfo.
public LibraryInfo getLibraryInfo(String javaHome) {
LibraryInfo libInfo = libraryInfoCache.get(javaHome);
if (libInfo == null) {
libInfo = generateLibraryInfo(javaHome);
libraryInfoCache.put(javaHome, libInfo);
}
return libInfo;
}
use of org.eclipse.tycho.compiler.jdt.copied.LibraryInfo in project tycho by eclipse.
the class JdkLibraryInfoProviderTest method testGetLibraryInfoForFakeJDKWithoutJavaExecutable.
@Test
public void testGetLibraryInfoForFakeJDKWithoutJavaExecutable() throws Exception {
JdkLibraryInfoProviderStub libInfoProvider = new JdkLibraryInfoProviderStub(new File("../tycho-lib-detector/target/classes/"), new SilentLog());
LibraryInfo libInfo = libInfoProvider.getLibraryInfo(new File("src/test/resources/testJavaHome").getAbsolutePath());
assertEquals("unknown", libInfo.getVersion());
String[] bootpath = libInfo.getBootpath();
assertEquals(2, bootpath.length);
assertTrue(bootpath[0].endsWith("lib" + File.separator + "some.jar"));
assertTrue(bootpath[1].endsWith("lib" + File.separator + "ext" + File.separator + "another.jar"));
assertEquals(new String[0], libInfo.getEndorsedDirs());
assertEquals(new String[0], libInfo.getExtensionDirs());
}
Aggregations