@Test(expected = MojoFailureException.class) public void testExecute_failDir() throws Exception { final File testOutDir = new File(testOutBaseDir, "testExecute_failDir"); FileUtils.deleteDirectory(testOutDir); OpearPlanMojo mojo = newMojo(); final MavenProject project = mock(MavenProject.class); mojo.project = project; final Build build = mock(Build.class); when(project.getBuild()).thenReturn(build); final File classes = new File(testOutDir, "classes"); when(build.getOutputDirectory()).thenReturn(classes.getPath()); final MavenSession session = mock(MavenSession.class); mojo.session = session; final MavenExecutionRequest executionRequest = mock(MavenExecutionRequest.class); when(session.getRequest()).thenReturn(executionRequest); final RepositorySystem repositorySystem = mock(RepositorySystem.class); mojo.repositorySystem = repositorySystem; mojo.planFile = new File(testOutDir, "opear-plans/plan.json"); mojo.planFile.mkdirs(); mojo.execute(); }
@Override public void execute() throws MojoFailureException { planFile.getParentFile().mkdirs(); final JsonWriterFactory writerFactory = Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8); JsonWriter writer = writerFactory.createWriter(osw)) { Thread.currentThread().setContextClassLoader(createContainerClassLoader()); OakpalPlan plan = buildPlan(); writer.writeObject(plan.toJson()); } catch (IOException e) { throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
OpearPlanMojo extends AbstractCommonMojo implements MojoWithPlanParams { @Override public void execute() throws MojoFailureException { planFile.getParentFile().mkdirs(); final JsonWriterFactory writerFactory = Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8); JsonWriter writer = writerFactory.createWriter(osw)) { Thread.currentThread().setContextClassLoader(createContainerClassLoader()); OakpalPlan plan = buildPlan(); writer.writeObject(plan.toJson()); } catch (IOException e) { throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } }
OpearPlanMojo extends AbstractCommonMojo implements MojoWithPlanParams { @Override public void execute() throws MojoFailureException { planFile.getParentFile().mkdirs(); final JsonWriterFactory writerFactory = Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8); JsonWriter writer = writerFactory.createWriter(osw)) { Thread.currentThread().setContextClassLoader(createContainerClassLoader()); OakpalPlan plan = buildPlan(); writer.writeObject(plan.toJson()); } catch (IOException e) { throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }  }
OpearPlanMojo extends AbstractCommonMojo implements MojoWithPlanParams { @Override public void execute() throws MojoFailureException { planFile.getParentFile().mkdirs(); final JsonWriterFactory writerFactory = Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8); JsonWriter writer = writerFactory.createWriter(osw)) { Thread.currentThread().setContextClassLoader(createContainerClassLoader()); OakpalPlan plan = buildPlan(); writer.writeObject(plan.toJson()); } catch (IOException e) { throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }  @Override void execute(); @Override PlanBuilderParams getPlanBuilderParams(); }
OpearPlanMojo extends AbstractCommonMojo implements MojoWithPlanParams { @Override public void execute() throws MojoFailureException { planFile.getParentFile().mkdirs(); final JsonWriterFactory writerFactory = Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8); JsonWriter writer = writerFactory.createWriter(osw)) { Thread.currentThread().setContextClassLoader(createContainerClassLoader()); OakpalPlan plan = buildPlan(); writer.writeObject(plan.toJson()); } catch (IOException e) { throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }  @Override void execute(); @Override PlanBuilderParams getPlanBuilderParams();  }