@Test(expected = WorkItemHandlerRuntimeException.class) public void testCleanInstallSimpleProjectWithInvalidParams() { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); MavenEmbedderWorkItemHandler handler = new MavenEmbedderWorkItemHandler(); handler.executeWorkItem(workItem, manager); assertNotNull(manager.getResults()); assertEquals(0, manager.getResults().size()); }
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String goals = (String) workItem.getParameter("Goals"); String commandLineOptions = (String) workItem.getParameter("CLOptions"); String workDir = (String) workItem.getParameter("WorkDirectory"); String projectRoot = (String) workItem.getParameter("ProjectRoot"); String modeStr = (String) workItem.getParameter("Mode"); MavenEmbedderUtils.MavenEmbedderMode mode = MavenEmbedderUtils.MavenEmbedderMode.valueOf(modeStr == null ? "SYNC" : modeStr.toUpperCase()); logger.debug("About to execute maven {} with options {} with working directory {}", goals, commandLineOptions, workDir); switch (mode) { case SYNC: Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); workItemManager.completeWorkItem(workItem.getId(), results); break; case ASYNC: long workItemId = workItem.getId(); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId() == null ? "" : ((WorkItemImpl) workItem).getDeploymentId(); long processInstanceId = workItem.getProcessInstanceId(); new Thread(new Runnable() { public void run() { try { Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId); if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results); manager.disposeRuntimeEngine(engine); } else { logger.error("Unable to complete workitem: runtime manager not found."); throw new RuntimeException("Unable to complete workitem: runtime manager not found."); } } catch (Exception e) { logger.error("Unable to execute maven commands asynchronously", e); throw new RuntimeException("Unable to execute maven commands asynchronously", e); } } }).start(); break; default: break; } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }
MavenEmbedderWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String goals = (String) workItem.getParameter("Goals"); String commandLineOptions = (String) workItem.getParameter("CLOptions"); String workDir = (String) workItem.getParameter("WorkDirectory"); String projectRoot = (String) workItem.getParameter("ProjectRoot"); String modeStr = (String) workItem.getParameter("Mode"); MavenEmbedderUtils.MavenEmbedderMode mode = MavenEmbedderUtils.MavenEmbedderMode.valueOf(modeStr == null ? "SYNC" : modeStr.toUpperCase()); logger.debug("About to execute maven {} with options {} with working directory {}", goals, commandLineOptions, workDir); switch (mode) { case SYNC: Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); workItemManager.completeWorkItem(workItem.getId(), results); break; case ASYNC: long workItemId = workItem.getId(); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId() == null ? "" : ((WorkItemImpl) workItem).getDeploymentId(); long processInstanceId = workItem.getProcessInstanceId(); new Thread(new Runnable() { public void run() { try { Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId); if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results); manager.disposeRuntimeEngine(engine); } else { logger.error("Unable to complete workitem: runtime manager not found."); throw new RuntimeException("Unable to complete workitem: runtime manager not found."); } } catch (Exception e) { logger.error("Unable to execute maven commands asynchronously", e); throw new RuntimeException("Unable to execute maven commands asynchronously", e); } } }).start(); break; default: break; } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } } }
MavenEmbedderWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String goals = (String) workItem.getParameter("Goals"); String commandLineOptions = (String) workItem.getParameter("CLOptions"); String workDir = (String) workItem.getParameter("WorkDirectory"); String projectRoot = (String) workItem.getParameter("ProjectRoot"); String modeStr = (String) workItem.getParameter("Mode"); MavenEmbedderUtils.MavenEmbedderMode mode = MavenEmbedderUtils.MavenEmbedderMode.valueOf(modeStr == null ? "SYNC" : modeStr.toUpperCase()); logger.debug("About to execute maven {} with options {} with working directory {}", goals, commandLineOptions, workDir); switch (mode) { case SYNC: Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); workItemManager.completeWorkItem(workItem.getId(), results); break; case ASYNC: long workItemId = workItem.getId(); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId() == null ? "" : ((WorkItemImpl) workItem).getDeploymentId(); long processInstanceId = workItem.getProcessInstanceId(); new Thread(new Runnable() { public void run() { try { Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId); if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results); manager.disposeRuntimeEngine(engine); } else { logger.error("Unable to complete workitem: runtime manager not found."); throw new RuntimeException("Unable to complete workitem: runtime manager not found."); } } catch (Exception e) { logger.error("Unable to execute maven commands asynchronously", e); throw new RuntimeException("Unable to execute maven commands asynchronously", e); } } }).start(); break; default: break; } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }  }
MavenEmbedderWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String goals = (String) workItem.getParameter("Goals"); String commandLineOptions = (String) workItem.getParameter("CLOptions"); String workDir = (String) workItem.getParameter("WorkDirectory"); String projectRoot = (String) workItem.getParameter("ProjectRoot"); String modeStr = (String) workItem.getParameter("Mode"); MavenEmbedderUtils.MavenEmbedderMode mode = MavenEmbedderUtils.MavenEmbedderMode.valueOf(modeStr == null ? "SYNC" : modeStr.toUpperCase()); logger.debug("About to execute maven {} with options {} with working directory {}", goals, commandLineOptions, workDir); switch (mode) { case SYNC: Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); workItemManager.completeWorkItem(workItem.getId(), results); break; case ASYNC: long workItemId = workItem.getId(); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId() == null ? "" : ((WorkItemImpl) workItem).getDeploymentId(); long processInstanceId = workItem.getProcessInstanceId(); new Thread(new Runnable() { public void run() { try { Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId); if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results); manager.disposeRuntimeEngine(engine); } else { logger.error("Unable to complete workitem: runtime manager not found."); throw new RuntimeException("Unable to complete workitem: runtime manager not found."); } } catch (Exception e) { logger.error("Unable to execute maven commands asynchronously", e); throw new RuntimeException("Unable to execute maven commands asynchronously", e); } } }).start(); break; default: break; } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }  void executeWorkItem(WorkItem workItem,
                                WorkItemManager workItemManager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager); }
MavenEmbedderWorkItemHandler extends AbstractLogOrThrowWorkItemHandler { public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String goals = (String) workItem.getParameter("Goals"); String commandLineOptions = (String) workItem.getParameter("CLOptions"); String workDir = (String) workItem.getParameter("WorkDirectory"); String projectRoot = (String) workItem.getParameter("ProjectRoot"); String modeStr = (String) workItem.getParameter("Mode"); MavenEmbedderUtils.MavenEmbedderMode mode = MavenEmbedderUtils.MavenEmbedderMode.valueOf(modeStr == null ? "SYNC" : modeStr.toUpperCase()); logger.debug("About to execute maven {} with options {} with working directory {}", goals, commandLineOptions, workDir); switch (mode) { case SYNC: Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); workItemManager.completeWorkItem(workItem.getId(), results); break; case ASYNC: long workItemId = workItem.getId(); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId() == null ? "" : ((WorkItemImpl) workItem).getDeploymentId(); long processInstanceId = workItem.getProcessInstanceId(); new Thread(new Runnable() { public void run() { try { Map<String, Object> results = MavenEmbedderUtils.executeMavenGoals(new KieMavenCli(projectRoot), RESULTS_VALUES, projectRoot, commandLineOptions, goals, workDir); RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId); if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results); manager.disposeRuntimeEngine(engine); } else { logger.error("Unable to complete workitem: runtime manager not found."); throw new RuntimeException("Unable to complete workitem: runtime manager not found."); } } catch (Exception e) { logger.error("Unable to execute maven commands asynchronously", e); throw new RuntimeException("Unable to execute maven commands asynchronously", e); } } }).start(); break; default: break; } } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }  void executeWorkItem(WorkItem workItem,
                                WorkItemManager workItemManager); void abortWorkItem(WorkItem workItem,
                              WorkItemManager manager);  }