use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.
the class AFMavenCli method logSummary.
protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
String referenceKey = "";
if (StringUtils.isNotEmpty(summary.getReference())) {
referenceKey = references.get(summary.getReference());
if (referenceKey == null) {
referenceKey = "[Help " + (references.size() + 1) + "]";
references.put(summary.getReference(), referenceKey);
}
}
String msg = summary.getMessage();
if (StringUtils.isNotEmpty(referenceKey)) {
if (msg.indexOf('\n') < 0) {
msg += " -> " + referenceKey;
} else {
msg += "\n-> " + referenceKey;
}
}
String[] lines = msg.split("(\r\n)|(\r)|(\n)");
for (int i = 0; i < lines.length; i++) {
String line = indent + lines[i].trim();
if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
slf4jLogger.error(line, summary.getException());
} else {
slf4jLogger.error(line);
}
}
indent += " ";
for (ExceptionSummary child : summary.getChildren()) {
logSummary(child, references, indent, showErrors);
}
}
use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.
the class AFMavenCli method execute.
protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());
eventSpyDispatcher.onEvent(request);
MavenExecutionResult result = maven.execute(request);
eventSpyDispatcher.onEvent(result);
eventSpyDispatcher.close();
if (result.hasExceptions()) {
ExceptionHandler handler = new DefaultExceptionHandler();
Map<String, String> references = new LinkedHashMap<String, String>();
MavenProject project = null;
for (Throwable exception : result.getExceptions()) {
ExceptionSummary summary = handler.handleException(exception);
logSummary(summary, references, "", cliRequest.isShowErrors());
if (project == null && exception instanceof LifecycleExecutionException) {
project = ((LifecycleExecutionException) exception).getProject();
}
}
slf4jLogger.error("");
if (!cliRequest.isShowErrors()) {
slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
}
if (!slf4jLogger.isDebugEnabled()) {
slf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
}
if (!references.isEmpty()) {
slf4jLogger.error("");
slf4jLogger.error("For more information about the errors and possible solutions" + ", please read the following articles:");
for (Entry<String, String> entry : references.entrySet()) {
slf4jLogger.error(entry.getValue() + " " + entry.getKey());
}
}
if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
slf4jLogger.error("");
slf4jLogger.error("After correcting the problems, you can resume the build with the command");
slf4jLogger.error(" mvn <goals> -rf :" + project.getArtifactId());
}
if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.getRequest().getReactorFailureBehavior())) {
slf4jLogger.info("Build failures were ignored.");
return 0;
} else {
return 1;
}
} else {
return 0;
}
}
use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.
the class AFMavenCli method logSummary.
protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
String referenceKey = "";
if (StringUtils.isNotEmpty(summary.getReference())) {
referenceKey = references.get(summary.getReference());
if (referenceKey == null) {
referenceKey = "[Help " + (references.size() + 1) + "]";
references.put(summary.getReference(), referenceKey);
}
}
String msg = summary.getMessage();
if (StringUtils.isNotEmpty(referenceKey)) {
if (msg.indexOf('\n') < 0) {
msg += " -> " + referenceKey;
} else {
msg += "\n-> " + referenceKey;
}
}
String[] lines = msg.split("(\r\n)|(\r)|(\n)");
for (int i = 0; i < lines.length; i++) {
String line = indent + lines[i].trim();
if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
slf4jLogger.error(line, summary.getException());
} else {
slf4jLogger.error(line);
}
}
indent += " ";
for (ExceptionSummary child : summary.getChildren()) {
logSummary(child, references, indent, showErrors);
}
}
use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.
the class AFMavenCli method execute.
protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());
eventSpyDispatcher.onEvent(request);
MavenExecutionResult result = maven.execute(request);
eventSpyDispatcher.onEvent(result);
eventSpyDispatcher.close();
if (result.hasExceptions()) {
ExceptionHandler handler = new DefaultExceptionHandler();
Map<String, String> references = new LinkedHashMap<String, String>();
MavenProject project = null;
for (Throwable exception : result.getExceptions()) {
ExceptionSummary summary = handler.handleException(exception);
logSummary(summary, references, "", cliRequest.isShowErrors());
if (project == null && exception instanceof LifecycleExecutionException) {
project = ((LifecycleExecutionException) exception).getProject();
}
}
slf4jLogger.error("");
if (!cliRequest.isShowErrors()) {
slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
}
if (!slf4jLogger.isDebugEnabled()) {
slf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
}
if (!references.isEmpty()) {
slf4jLogger.error("");
slf4jLogger.error("For more information about the errors and possible solutions" + ", please read the following articles:");
for (Entry<String, String> entry : references.entrySet()) {
slf4jLogger.error(entry.getValue() + " " + entry.getKey());
}
}
if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
slf4jLogger.error("");
slf4jLogger.error("After correcting the problems, you can resume the build with the command");
slf4jLogger.error(" mvn <goals> -rf :" + project.getArtifactId());
}
if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.getRequest().getReactorFailureBehavior())) {
slf4jLogger.info("Build failures were ignored.");
return 0;
} else {
return 1;
}
} else {
return 0;
}
}
use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.
the class ReusableAFMavenCli method logSummary.
protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
String referenceKey = "";
if (StringUtils.isNotEmpty(summary.getReference())) {
referenceKey = references.get(summary.getReference());
if (referenceKey == null) {
referenceKey = "[Help " + (references.size() + 1) + "]";
references.put(summary.getReference(), referenceKey);
}
}
String msg = summary.getMessage();
if (StringUtils.isNotEmpty(referenceKey)) {
if (msg.indexOf('\n') < 0) {
msg += " -> " + referenceKey;
} else {
msg += "\n-> " + referenceKey;
}
}
String[] lines = msg.split("(\r\n)|(\r)|(\n)");
for (int i = 0; i < lines.length; i++) {
String line = indent + lines[i].trim();
if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
reusableSlf4jLogger.error(line, summary.getException());
} else {
reusableSlf4jLogger.error(line);
}
}
indent += " ";
for (ExceptionSummary child : summary.getChildren()) {
logSummary(child, references, indent, showErrors);
}
}
Aggregations