List of usage examples for org.apache.maven.project ProjectBuildingException getProjectId
public String getProjectId()
From source file:org.codehaus.mojo.pomtools.console.screens.AbstractModelScreen.java
License:Apache License
public ConsoleEventDispatcher getDefaultEventManager(boolean includeDefaultListener) { final ConsoleScreen thisScreen = this; final ConsoleEventDispatcher ced = new ConsoleEventDispatcher(); // Save listener ced.add(new MatchingListener(new String[] { "save", "s" }, "Save any modified poms.", "s[ave]") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { doSave(event);// w w w .ja va 2 s.c o m } }); // Revert listener ced.add(new MatchingListener(new String[] { "revert" }, "Revert all projects to unmodified state.") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { if (isModified()) { ConsoleEventClosure yesClosure = new ConsoleEventClosure() { public void execute(ConsoleEvent event) throws ConsoleExecutionException { doRevert(event); event.setReturnToFirstScreen(); } }; event.setNextScreen(new ConfirmYesNoScreen("Are you sure you want to revert your changes?", yesClosure, null)); } else { event.addConsoleMessage("Nothing is modified so there are no changes to revert."); } } }); // Validate Model Listener ced.add(new MatchingListener(new String[] { "validate", "val" }, "Validate the model for the current project.", "val[idate]") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { try { ProjectValidationResult result = PomToolsPluginContext.getInstance().getActiveProject() .validateModel(); event.setNextScreen(new ModelValidationScreen(Collections.singletonList(result))); } catch (ProjectBuildingException e) { event.setNextScreen(new ErrorMessageScreen("Error validating project", "An exception occurred while validating the project: " + e.getProjectId() + NEWLINE + NEWLINE + e.getMessage())); } catch (PomToolsException e) { throw new ConsoleExecutionException("Unable to validate model", e); } } }); // Validate Model Listener ced.add(new MatchingListener("trans", "View transitive dependency information.") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { event.setNextScreen(new ListTransitiveDependenciesScreen()); } }); // Quit listener ced.add(new MatchingListener(new String[] { "q", "quit", "x", "exit" }, "Quit", "q[uit]") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { if (isModified()) { ConsoleEventClosure yesClosure = new ConsoleEventClosure() { public void execute(ConsoleEvent event) throws ConsoleExecutionException { event.setExitApplication(true); } }; event.setNextScreen(new ConfirmYesNoScreen( "You have unsaved changes. " + "Are you sure you want to exit?", yesClosure, null)); } else { event.setExitApplication(true); } } }); // // Previous screen // ced.add( new MatchingListener( new String[] { "prev", "p" }, // "Return to previous screen.", "p[rev]" ) // { // public void processEvent( ConsoleEvent event ) // throws ConsoleExecutionException // { // event.setReturnToPreviousScreen( ); // } // } ); // Default listener if (includeDefaultListener) { ced.add(new DefaultListener("Return to previous screen") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { event.setReturnToPreviousScreen(); } }); } // Help listener ced.add(new MatchingListener(new String[] { "?", "h", "help" }, "Display this help message.") { public void processEvent(ConsoleEvent event) throws ConsoleExecutionException { event.setNextScreen(new HelpScreen(thisScreen)); } }); return ced; }
From source file:org.codehaus.mojo.pomtools.console.screens.AbstractModelScreen.java
License:Apache License
protected void doSave(ConsoleEvent event) throws ConsoleExecutionException { if (getModelContext().isModified()) { boolean failure = false; try {/* ww w . j a v a2 s . c om*/ List saveResults = getModelContext().saveAllProjects(); for (Iterator i = saveResults.iterator(); i.hasNext();) { ProjectValidationResult result = (ProjectValidationResult) i.next(); if (result.isValid()) { event.addConsoleMessage(result.getProject().getValueLabel() + " saved."); } else { event.addConsoleMessage( result.getProject().getValueLabel() + " was not saved due to validation errors."); failure = true; } } if (failure) { event.addConsoleMessage("Error: Not all projects were saved. Some projects did not validate."); event.setNextScreen(new ModelValidationScreen(saveResults)); } } catch (ProjectBuildingException e) { event.setNextScreen(new ErrorMessageScreen("Error saving project", "Error: Not all projects were saved. Exception thrown " + "while validating: " + e.getProjectId() + NEWLINE + NEWLINE + e.getMessage())); } catch (PomToolsException e) { throw new ConsoleExecutionException(e); } } else { event.addConsoleMessage("No changes to save."); } }