use of org.apache.maven.execution.MavenExecutionResult in project kie-wb-common by kiegroup.
the class MavenBuildExecutor method executeMaven.
public static void executeMaven(final File pom, final PrintStream stdout, final PrintStream stderr, final Properties properties, final String... goals) {
final PrintStream oldout = System.out;
final PrintStream olderr = System.err;
final Properties oldProperties = System.getProperties();
if (properties != null) {
properties.keySet().forEach((o) -> {
if (properties.getProperty((String) o) != null) {
System.setProperty((String) o, properties.getProperty((String) o));
}
});
}
final MavenEmbedder mavenEmbedder = newMavenEmbedder();
try {
if (stdout != null) {
System.setOut(stdout);
}
if (stderr != null) {
System.setErr(stderr);
}
final MavenRequest mavenRequest = MavenProjectLoader.createMavenRequest(false);
mavenRequest.setGoals(Arrays.asList(goals));
mavenRequest.setPom(pom.getAbsolutePath());
final MavenExecutionResult result = mavenEmbedder.execute(mavenRequest);
if (result.hasExceptions()) {
for (Throwable t : result.getExceptions()) {
LOG.error("Error Running Maven", t);
}
throw new BuildException("Maven found issues trying to build the pom file: " + pom.getAbsolutePath() + ". Look at the Error Logs for more information");
}
} catch (final MavenEmbedderException ex) {
throw new BuildException("Maven coudn't build the project for pom file: " + pom.getAbsolutePath(), ex);
} finally {
System.setProperties(oldProperties);
mavenEmbedder.dispose();
System.setOut(oldout);
System.setErr(olderr);
}
}
use of org.apache.maven.execution.MavenExecutionResult 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.execution.MavenExecutionResult in project tycho by eclipse.
the class ArtifactDependencyWalkerTest method getTargetPlatform.
protected DependencyArtifacts getTargetPlatform() throws Exception {
LocalDependencyResolver resolver = (LocalDependencyResolver) lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setLocalRepository(new StubArtifactRepository(System.getProperty("java.io.tmpdir")));
MavenExecutionResult result = new DefaultMavenExecutionResult();
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
session.setProjects(new ArrayList<MavenProject>());
lookup(LegacySupport.class).setSession(session);
MavenProject project = new MavenProject();
resolver.setLocation(new File("src/test/resources/targetplatforms/basic"));
DependencyArtifacts platform = resolver.resolveDependencies(session, project, null, DefaultReactorProject.adapt(session), null);
return platform;
}
use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.
the class LocalDependencyResolverTest method getTargetPlatform.
protected DependencyArtifacts getTargetPlatform(File location) throws Exception, IOException {
LocalDependencyResolver resolver = (LocalDependencyResolver) lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setLocalRepository(new StubArtifactRepository(location.getAbsolutePath()));
MavenExecutionResult result = new DefaultMavenExecutionResult();
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
session.setProjects(new ArrayList<MavenProject>());
lookup(LegacySupport.class).setSession(session);
MavenProject project = new MavenProject();
resolver.setLocation(location);
DependencyArtifacts platform = resolver.resolveDependencies(session, project, null, DefaultReactorProject.adapt(session), null);
return platform;
}
use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.
the class MavenDependencyCollectorTest method getSortedProjects.
private List<MavenProject> getSortedProjects(MavenExecutionRequest request) {
request.getProjectBuildingRequest().setProcessPlugins(false);
MavenExecutionResult result = maven.execute(request);
if (result.hasExceptions()) {
throw new CompoundRuntimeException(result.getExceptions());
}
return result.getTopologicallySortedProjects();
}
Aggregations