void pauseForFilesystem() { Errors.rethrow().run(() -> Thread.sleep(FILESYSTEM_RESOLUTION_MS)); }
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); })); }
private void taskRanAgainst(String task, String... ranAgainst) throws IOException { pauseForFilesystem(); String console = StringPrinter.buildString(Errors.rethrow().wrap(printer -> { boolean expectFailure = task.equals("spotlessCheck") && !isClean(); if (expectFailure) { gradleRunner().withArguments(task).forwardStdOutput(printer.toWriter()).buildAndFail(); } else { gradleRunner().withArguments(task).forwardStdOutput(printer.toWriter()).build(); } })); SortedSet<String> added = new TreeSet<>(); for (String line : console.split("\n")) { String trimmed = line.trim(); if (trimmed.startsWith("<") && trimmed.endsWith(">")) { added.add(trimmed.substring(1, trimmed.length() - 1)); } } Assert.assertEquals(concat(Arrays.asList(ranAgainst)), concat(added)); }
/** 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; }
/** Creates a PrintStream of the given charset, which passes its content to this StringPrinter. */ public PrintStream toPrintStream(Charset charset) { return Errors.rethrow().get(() -> { return new PrintStream(toOutputStream(charset), true, charset.name()); }); }
/** 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)); } } }
/** * Creates a `PrintStream` of the given charset, which passes its content to this `StringPrinter`. * * Note that `PrintStream.println` uses the system newline, while `StringPrinter.println` always uses `\n`. */ public PrintStream toPrintStream(Charset charset) { return Errors.rethrow().get(() -> { return new PrintStream(toOutputStream(charset), true, charset.name()); }); }
/** Returns the content of template.build.properties as a String. */ static String rawFile() { return Errors.rethrow().get(() -> { URL url = PdeBuildProperties.class.getResource("template.build.properties"); System.out.println("url=" + url); byte[] content = Resources.toByteArray(url); return new String(content, StandardCharsets.UTF_8); }); }
/** Creates a PrintStream of the given charset, which passes its content to this StringPrinter. */ public PrintStream toPrintStream(Charset charset) { return Errors.rethrow().get(() -> { return new PrintStream(toOutputStream(charset), true, charset.name()); }); }
/** 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; }); }
/** Loads an instance of the colors. */ public static XkcdColors load() { URL url = XkcdColors.class.getResource("/xkcd_colors.txt"); return Errors.rethrow().get(() -> new XkcdColors(url)); }
@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)); }); }); }
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 static Map<String, String> parseFromFile(File artifactsJar) throws IOException { Box.Nullable<Map<String, String>> value = Box.Nullable.ofNull(); ZipMisc.read(artifactsJar, "artifacts.xml", input -> { value.set(Errors.rethrow().get(() -> parse(input))); }); return Objects.requireNonNull(value.get()); } }
/** 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))); })); }
@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); }); })); }
private void writerTestCase(String expected, Throwing.Consumer<Writer> underTest) { Assert.assertEquals(expected, StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> { underTest.accept(printer.toWriter()); }); })); }