WebsterMojo extends AbstractMojo { void executeWebsterPlan(final @NotNull WebsterPlan.Builder builder) throws MojoFailureException { try { websterTempDirectory.mkdirs(); final File globalRepositoryHome = Files .createTempDirectory(websterTempDirectory.toPath(), "webster_repository") .toFile().getAbsoluteFile(); try { WebsterPlan plan = builder .withGlobalSegmentStore(new File(globalRepositoryHome, "segmentstore")).build(); plan.perform(); } catch (Exception e) { throw new MojoFailureException("Failed to execute Webster plan.", e); } finally { try { tempDirDeleter.tryAccept(globalRepositoryHome); } catch (Exception e) { getLog().error("Failed to delete temp global segment store: " + globalRepositoryHome.getAbsolutePath(), e); } } } catch (IOException e) { throw new MojoFailureException("Failed to create temp global segment store", e); } }  @Override final void execute(); static final String PARAM_REPOSITORY_HOME; static final String PARAM_OAK_RUN_ARGS; static final String PARAM_TMPDIR; }
@Test(expected = MojoFailureException.class) public void testExecuteWebsterPlan_tempFails() throws Exception { final File testOutDir = new File(testOutBaseDir, "testExecuteWebsterPlan_tempFails"); recursiveDeleteWithRetry(testOutDir); final File projectRoot = new File(testOutDir, "content-package"); FileUtils.copyDirectory(new File(srcDir, "content-package"), projectRoot); WebsterMojo mojo = newMojo(); final File tempDir = new File(testOutDir, "webster-tmp"); FileUtils.touch(tempDir); mojo.websterTempDirectory = tempDir; final WebsterPlan.Builder builder = new WebsterPlan.Builder(); mojo.executeWebsterPlan(builder); }
@Test(expected = MojoFailureException.class) public void testExecuteWebsterPlan_targetFails() throws Exception { final File testOutDir = new File(testOutBaseDir, "testExecuteWebsterPlan_targetFails"); recursiveDeleteWithRetry(testOutDir); final File projectRoot = new File(testOutDir, "content-package"); FileUtils.copyDirectory(new File(srcDir, "content-package"), projectRoot); final WebsterMojo mojo = newMojo(); final File tempDir = new File(testOutDir, "webster-tmp"); mojo.websterTempDirectory = tempDir; final WebsterPlan.Builder builder = new WebsterPlan.Builder(); final File segmentStore = new File(testOutDir, "segmentstore"); builder.withFixtureProvider(() -> JcrFactory.getReadWriteFixture(segmentStore)); withMockTarget(builder, session -> { throw new Exception("Whoops."); }); mojo.executeWebsterPlan(builder); }
@Test public void testExecuteWebsterPlan_cleanTempFails() throws Exception { final File testOutDir = new File(testOutBaseDir, "testExecuteWebsterPlan_cleanTempFails"); recursiveDeleteWithRetry(testOutDir); final File projectRoot = new File(testOutDir, "content-package"); FileUtils.copyDirectory(new File(srcDir, "content-package"), projectRoot); final WebsterMojo mojo = newMojo(); final File tempDir = new File(testOutDir, "webster-tmp"); mojo.websterTempDirectory = tempDir; final WebsterPlan.Builder builder = new WebsterPlan.Builder(); final File segmentStore = new File(testOutDir, "segmentstore"); builder.withFixtureProvider(() -> JcrFactory.getReadWriteFixture(segmentStore)); final CompletableFuture<File> globalHome = new CompletableFuture<>(); withMockTarget(builder, session -> { final File tmp = tempDir.listFiles()[0]; globalHome.complete(tmp); }); mojo.tempDirDeleter = dir -> { throw new IOException("OMG I can't tho. Sorry, dir: " + dir.getAbsolutePath()); }; mojo.executeWebsterPlan(builder); assertTrue("expect log indicating failure to delete global home", logFor(mojo).any(entry -> entry.message.startsWith("Failed to delete temp global"))); }