protected JpsSdk<JpsDummyElement> addJdk(final String name, final String path) { String homePath = System.getProperty("java.home"); String versionString = System.getProperty("java.version"); JpsTypedLibrary<JpsSdk<JpsDummyElement>> jdk = myModel.getGlobal().addSdk(name, homePath, versionString, JpsJavaSdkType.INSTANCE); jdk.addRoot(JpsPathUtil.pathToUrl(path), JpsOrderRootType.COMPILED); return jdk.getProperties(); }
protected static void change(String filePath, final @Nullable String newContent) { try { File file = new File(FileUtil.toSystemDependentName(filePath)); assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists()); if (newContent != null) { FileUtil.writeToFile(file, newContent); } long oldTimestamp = FileSystemUtil.lastModified(file); long time = System.currentTimeMillis(); setLastModified(file, time); if (FileSystemUtil.lastModified(file) <= oldTimestamp) { setLastModified(file, time + 1); long newTimeStamp = FileSystemUtil.lastModified(file); if (newTimeStamp <= oldTimestamp) { // Mac OS and some versions of Linux truncates timestamp to nearest second setLastModified(file, time + 1000); newTimeStamp = FileSystemUtil.lastModified(file); assertTrue( "Failed to change timestamp for " + file.getAbsolutePath(), newTimeStamp > oldTimestamp); } sleepUntil(newTimeStamp); } } catch (IOException e) { throw new RuntimeException(e); } }
protected static void sleepUntil(long time) { // we need this to ensure that the file won't be treated as changed by user during compilation // and therefore marked for recompilation long delta; while ((delta = time - System.currentTimeMillis()) > 0) { try { //noinspection BusyWait Thread.sleep(delta); } catch (InterruptedException ignored) { } } }