private Running() throws Exception { Box.Nullable<BundleContext> context = Box.Nullable.ofNull(); Main main = new Main() { @SuppressFBWarnings(value = "DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED", justification = "splashHandler is a thread rather than a runnable. Almost definitely a small bug, " + "but there's a lot of small bugs in the copy-pasted launcher code. It's battle-tested, FWIW.") @Override protected void invokeFramework(String[] passThruArgs, URL[] bootPath) throws Exception { context.set(EclipseStarter.startup(passThruArgs, splashHandler)); } }; main.basicRun(eclipseIni.getLinesAsArray()); this.bundleContext = Objects.requireNonNull(context.get()); }
/** Runs the display loop until the given future has returned. */ public static <T> T loopUntilGet(CompletionStage<T> future) { Box.Nullable<T> result = Box.Nullable.ofNull(); Box.Nullable<Throwable> error = Box.Nullable.ofNull(); Rx.subscribe(future, Rx.onValueOnFailure(result::set, error::set)); CompletableFuture<?> actualFuture = future.toCompletableFuture(); loopUntil(display -> actualFuture.isDone()); if (error.get() != null) { throw Errors.asRuntime(error.get()); } else { return result.get(); } }
private void runWithCleanStack(Throwing.Runnable runnable) throws Throwable { Box.Nullable<Throwable> testError = Box.Nullable.ofNull(); Thread thread = new Thread() { @Override public void run() { try { runnable.run(); } catch (Throwable e) { testError.set(e); } } }; thread.start(); thread.join(); if (testError.get() != null) { throw testError.get(); } }
Box.Nullable<String> boxValueNullableFast = Box.Nullable.ofNull(); Box.Nullable<String> boxFromMethodsNullable = Box.Nullable.from(boxValueNullable::get, boxValueNullable::set);
/** Calls javaExec() in a way which is friendly with windows classpath limitations. */ public static ExecResult javaExec(Project project, Action<JavaExecSpec> spec) throws IOException { if (OS.getNative().isWindows()) { Box.Nullable<File> classpathJarBox = Box.Nullable.ofNull(); ExecResult execResult = project.javaexec(execSpec -> { // handle the user spec.execute(execSpec); // create a jar which embeds the classpath File classpathJar = toJarWithClasspath(execSpec.getClasspath()); classpathJar.deleteOnExit(); // set the classpath to be just that one jar execSpec.setClasspath(project.files(classpathJar)); // save the jar so it can be deleted later classpathJarBox.set(classpathJar); }); // delete the jar after the task has finished Errors.suppress().run(() -> FileMisc.forceDelete(classpathJarBox.get())); return execResult; } else { return project.javaexec(spec); } }
@Test public void testLeft() { Either<TimeUnit, String> left = Either.createLeft(TimeUnit.DAYS); Assert.assertTrue(left.isLeft()); Assert.assertFalse(left.isRight()); Assert.assertEquals(TimeUnit.DAYS, left.getLeft()); Assert.assertEquals(Optional.of(TimeUnit.DAYS), left.asOptionalLeft()); Assert.assertEquals(Optional.empty(), left.asOptionalRight()); try { left.getRight(); Assert.fail(); } catch (Unhandled e) {} Assert.assertEquals("DAYS", left.fold(TimeUnit::toString, Function.identity())); Box.Nullable<TimeUnit> leftSide = Box.Nullable.ofNull(); Box.Nullable<String> rightSide = Box.Nullable.ofNull(); left.acceptBoth(leftSide, rightSide, TimeUnit.HOURS, "wahoo"); Assert.assertEquals(TimeUnit.DAYS, leftSide.get()); Assert.assertEquals("wahoo", rightSide.get()); }
@Test public void testRight() { Either<TimeUnit, String> right = Either.createRight("word"); Assert.assertTrue(right.isRight()); Assert.assertFalse(right.isLeft()); Assert.assertEquals("word", right.getRight()); Assert.assertEquals(Optional.of("word"), right.asOptionalRight()); Assert.assertEquals(Optional.empty(), right.asOptionalLeft()); try { right.getLeft(); Assert.fail(); } catch (Unhandled e) {} Assert.assertEquals("word", right.fold(TimeUnit::toString, Function.identity())); Box.Nullable<TimeUnit> leftSide = Box.Nullable.ofNull(); Box.Nullable<String> rightSide = Box.Nullable.ofNull(); right.acceptBoth(leftSide, rightSide, TimeUnit.HOURS, "wahoo"); Assert.assertEquals(TimeUnit.HOURS, leftSide.get()); Assert.assertEquals("word", rightSide.get()); }
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()); } }