protected String getContents(Predicate<String> subpathsToInclude) throws IOException { TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow()); List<File> files = TreeStream.depthFirst(treeDef, rootFolder()) .filter(File::isFile) .collect(Collectors.toList()); ListIterator<File> iterator = files.listIterator(files.size()); int rootLength = rootFolder().getAbsolutePath().length() + 1; return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> { while (iterator.hasPrevious()) { File file = iterator.previous(); String subPath = file.getAbsolutePath().substring(rootLength); if (subpathsToInclude.test(subPath)) { printer.println("### " + subPath + " ###"); printer.println(read(subPath)); } } })); }
@Override public void runAllTasks(Project project) { project.getTasks().stream() .filter(task -> task instanceof SpotlessTask) .map(task -> (SpotlessTask) task) .forEach(task -> Errors.rethrow().run(() -> { IncrementalTaskInputs inputs = Mocks.mockIncrementalTaskInputs(task.getTarget()); task.setCheck(); task.performAction(inputs); })); }
@Override public void runAllTasks(Project project) { project.getTasks().stream() .filter(task -> task instanceof SpotlessTask) .map(task -> (SpotlessTask) task) .forEach(task -> Errors.rethrow().run(() -> { IncrementalTaskInputs inputs = Mocks.mockIncrementalTaskInputs(task.getTarget()); task.setApply(); task.performAction(inputs); })); }
Errors.rethrow().run(() -> { byte[] manifest = getManifestContent(jarTask, extension).getBytes(StandardCharsets.UTF_8);
Errors.rethrow().run(() -> {
@Test public void testWiresCrossed() { DurianPlugins.resetForTesting(); Errors.resetForTesting(); DurianPlugins.register(Errors.Plugins.Log.class, new TestHandler("Log")); DurianPlugins.register(Errors.Plugins.Dialog.class, new TestHandler("Dialog")); try { Errors.suppress().run(ErrorsTest::throwException); try { Errors.rethrow().run(ErrorsTest::throwException); } catch (RuntimeException e) { // it should pass the RuntimeException unphased Assert.assertNull(e.getCause()); } try { Errors.log().run(ErrorsTest::throwException); } catch (RuntimeException e) { Assert.assertEquals("Log", e.getMessage()); } try { Errors.dialog().run(ErrorsTest::throwException); } catch (RuntimeException e) { Assert.assertEquals("Dialog", e.getMessage()); } } finally { DurianPlugins.resetForTesting(); Errors.resetForTesting(); } }
private void testCharset(Charset charset) { // get the bytes for this string byte[] bytes = TEST_UTF.getBytes(charset); // write the complicated UTF string one byte at a time to an OutputStream String byteByByteOutputStream = StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { OutputStream output = printer.toOutputStream(charset); for (byte b : bytes) { output.write(b); } }); }); Assert.assertEquals(TEST_UTF, byteByByteOutputStream); // write the complicated UTF string one byte at a time to a PrintStream String byteByBytePrintStream = StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { OutputStream output = printer.toPrintStream(charset); for (byte b : bytes) { output.write(b); } }); }); Assert.assertEquals(TEST_UTF, byteByBytePrintStream); }
protected String getContents(Predicate<String> subpathsToInclude) throws IOException { TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow()); List<File> files = TreeStream.depthFirst(treeDef, folder.getRoot()) .filter(file -> file.isFile()) .collect(Collectors.toList()); ListIterator<File> iterator = files.listIterator(files.size()); int rootLength = folder.getRoot().getAbsolutePath().length() + 1; return StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { while (iterator.hasPrevious()) { File file = iterator.previous(); String subPath = file.getAbsolutePath().substring(rootLength); if (subpathsToInclude.test(subPath)) { printer.println("### " + subPath + " ###"); printer.println(read(subPath)); } } }); }); }
private void copyVersionsOfPlugin(PluginCatalog catalog, String plugin) { if (!catalog.isSupportedPlatform(plugin)) { return; } Set<Version> versions = catalog.getVersionsFor(plugin); for (Version version : versions) { File source = catalog.getFile(plugin, version); File dest = new File(destination, source.getName()); Errors.rethrow().run(() -> { if (source.isFile()) { FileUtils.copyFile(source, dest); } else { FileUtils.copyDirectory(source, dest); } }); } } }
/** Returns true if the given directory exists, and waits up to 500ms for the directory to exist. */ public static boolean dirExists(File dir) { long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < MS_RETRY) { File refreshed = Errors.rethrow().get(dir::getCanonicalFile); if (refreshed.exists() && refreshed.isDirectory()) { return true; } else { Errors.rethrow().run(() -> Thread.sleep(1)); } } return false; }
/** Initializes overrides based on project properties named "goomph_override_whatever" */ public static void initFromProject(Project project) { for (Field field : GoomphCacheLocations.class.getFields()) { Object value = project.getProperties().get("goomph_" + field.getName()); if (value != null) { Errors.rethrow().run(() -> field.set(null, value)); } } }
/** Returns the workspace directory appropriate for the given name and file. */ public File workspaceDir(String name, File ideDir) { return ownerToWorkspace.computeIfAbsent(ideDir, owner -> { File workspace = new File(root, name + "-" + owner.getAbsolutePath().hashCode()); FileMisc.mkdirs(workspace); Errors.rethrow().run(() -> { FileMisc.writeToken(root, workspace.getName() + OWNER_PATH, ideDir.getAbsolutePath()); }); return workspace; }); }
@Override protected void applyOnce(Project project) { extension = project.getExtensions().create(AsMavenExtension.NAME, AsMavenExtension.class, project); project.afterEvaluate(proj -> { // reload Errors.rethrow().run(extension::run); // set maven repo project.getRepositories().maven(maven -> { maven.setUrl(extension.mavenDir(proj)); }); }); }
/** Provisions using the given version of the full Eclipse PDE. */ public void runP2UsingPDE(String version) { runP2Using(directorApp -> Errors.rethrow().run(() -> { directorApp.runUsing(PdeInstallation.from(EclipseRelease.official(version))); })); }
public OomphIdeExtension(Project project) throws IOException { this.project = Objects.requireNonNull(project); this.workspaceRegistry = WorkspaceRegistry.instance(); this.name = project.getRootProject().getName(); this.description = this.name; this.perspective = Perspectives.RESOURCES; this.runP2Using = app -> Errors.rethrow().run(() -> app.runUsingBootstrapper(project)); }
private void writerTestCase(String expected, Throwing.Consumer<Writer> underTest) { Assert.assertEquals(expected, StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { underTest.accept(printer.toWriter()); }); })); }
@Test public void testToOutputStream() { Assert.assertEquals(TEST_STR, StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { printer.toOutputStream(StandardCharsets.UTF_8).write(TEST_STR.getBytes(StandardCharsets.UTF_8)); }); })); }
@Test public void testToPrintStream() { Assert.assertEquals(TEST_STR, StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { printer.toPrintStream().print(TEST_STR); }); })); }
void pauseForFilesystem() { Errors.rethrow().run(() -> Thread.sleep(FILESYSTEM_RESOLUTION_MS)); }