JdkLibraryInfoProvider { public LibraryInfo getLibraryInfo(String javaHome) { LibraryInfo libInfo = libraryInfoCache.get(javaHome); if (libInfo == null) { libInfo = generateLibraryInfo(javaHome); libraryInfoCache.put(javaHome, libInfo); } return libInfo; }  LibraryInfo getLibraryInfo(String javaHome);  }
@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())); } }
@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")); assertArrayEquals(new String[0], libInfo.getEndorsedDirs()); assertArrayEquals(new String[0], libInfo.getExtensionDirs()); }