use of org.apache.maven.execution.MavenExecutionRequest in project che by eclipse.
the class MavenServerImpl method newMavenRequest.
public MavenExecutionRequest newMavenRequest(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
try {
getMavenComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, settings);
request.setGoals(goals);
request.setPom(pom);
getMavenComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
request.setSystemProperties(properties);
request.setActiveProfiles(activeProfiles);
request.setInactiveProfiles(inactiveProfiles);
request.setStartTime(buildDate);
return request;
} catch (MavenExecutionRequestPopulationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.maven.execution.MavenExecutionRequest in project intellij-community by JetBrains.
the class MavenEmbedder method readProject.
@NotNull
public MavenExecutionResult readProject(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles) {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
request.getGlobalProfileManager().loadSettingsProfiles(mySettings);
request.setRecursive(false);
return readProject(request);
}
use of org.apache.maven.execution.MavenExecutionRequest in project intellij-community by JetBrains.
the class MavenEmbedder method execute.
@NotNull
public MavenExecutionResult execute(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, @NotNull final List<String> goals, @NotNull final List<String> selectedProjects, boolean alsoMake, boolean alsoMakeDependents) {
try {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, goals);
if (!selectedProjects.isEmpty()) {
request.setRecursive(true);
request.setSelectedProjects(selectedProjects);
if (alsoMake && alsoMakeDependents) {
request.setMakeBehavior(ReactorManager.MAKE_BOTH_MODE);
} else if (alsoMake) {
request.setMakeBehavior(ReactorManager.MAKE_MODE);
} else if (alsoMakeDependents) {
request.setMakeBehavior(ReactorManager.MAKE_DEPENDENTS_MODE);
}
}
Maven maven = getComponent(Maven.class);
Method method = maven.getClass().getDeclaredMethod("doExecute", MavenExecutionRequest.class, EventDispatcher.class);
method.setAccessible(true);
ReactorManager reactor = (ReactorManager) method.invoke(maven, request, request.getEventDispatcher());
return new MavenExecutionResult(reactor.getTopLevelProject(), Collections.<Exception>emptyList());
} catch (InvocationTargetException e) {
return handleException(e.getTargetException());
} catch (NoSuchMethodException e) {
// should never happen
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
// should never happen
throw new RuntimeException(e);
}
}
use of org.apache.maven.execution.MavenExecutionRequest 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.MavenExecutionRequest in project kie-wb-common by kiegroup.
the class AFMavenCli method loadCoreExtensions.
protected List<CoreExtensionEntry> loadCoreExtensions(AFCliRequest cliRequest, ClassRealm containerRealm, Set<String> providedArtifacts) {
if (cliRequest.getMultiModuleProjectDirectory() == null) {
return Collections.emptyList();
}
Path extensionsFile = Paths.get(cliRequest.getMultiModuleProjectDirectory().toString(), EXTENSIONS_FILENAME);
if (!java.nio.file.Files.isRegularFile(extensionsFile)) {
return Collections.emptyList();
}
try {
List<CoreExtension> extensions = readCoreExtensionsDescriptor(extensionsFile);
if (extensions.isEmpty()) {
return Collections.emptyList();
}
ContainerConfiguration cc = //
new DefaultContainerConfiguration().setClassWorld(//
cliRequest.getClassWorld()).setRealm(//
containerRealm).setClassPathScanning(//
PlexusConstants.SCANNING_INDEX).setAutoWiring(//
true).setName("maven");
DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
}
});
try {
container.setLookupRealm(null);
container.setLoggerManager(plexusLoggerManager);
container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
configure(cliRequest);
MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(cliRequest.getRequest());
request = populateRequest(cliRequest, request);
request = executionRequestPopulator.populateDefaults(request);
BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
return resolver.loadCoreExtensions(request, providedArtifacts, extensions);
} finally {
executionRequestPopulator = null;
container.dispose();
}
} catch (RuntimeException e) {
// runtime exceptions are most likely bugs in maven, let them bubble up to the user
throw e;
} catch (Exception e) {
slf4jLogger.warn("Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage());
}
return Collections.emptyList();
}
Aggregations