use of org.apache.maven.execution.MavenExecutionRequest in project meecrowave by apache.
the class MeecrowaveBundleMojoTest method bundle.
@Test
public void bundle() throws Exception {
final File moduleBase = jarLocation(MeecrowaveBundleMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final Build build = new Build();
final File buildDir = new File("target/" + getClass().getName() + "/build");
build.setDirectory(buildDir.getAbsolutePath());
project.setBuild(build);
final MavenSession session = mojo.newMavenSession(project);
final MojoExecution execution = mojo.newMojoExecution("bundle");
execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("conf") {
{
setValue("src/main/meecrowave/conf");
}
});
execution.getConfiguration().addChild(new Xpp3Dom("webapp") {
{
setValue("src/main/webapp");
}
});
mojo.executeMojo(session, project, execution);
assertTrue(buildDir.exists());
try (final ZipFile zip = new ZipFile(new File(buildDir, "test-meecrowave-distribution.zip"))) {
assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
}
}
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();
}
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 AFSettingsXmlConfigurationProcessor method process.
@Override
public void process(AFCliRequest cliRequest) throws Exception {
CommandLine commandLine = cliRequest.getCommandLine();
String workingDirectory = cliRequest.getWorkingDirectory();
MavenExecutionRequest request = cliRequest.getRequest();
Path userSettingsFile;
if (commandLine.hasOption(CLIManager.ALTERNATE_USER_SETTINGS)) {
String settingsFromCLi = commandLine.getOptionValue(CLIManager.ALTERNATE_USER_SETTINGS);
logger.info("userSettings:" + settingsFromCLi);
if (settingsFromCLi != null) {
userSettingsFile = Paths.get(settingsFromCLi.trim());
if (!Files.isRegularFile(userSettingsFile)) {
throw new FileNotFoundException("The specified user settings file does not exist: " + userSettingsFile);
}
} else {
userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
logger.info("Using default userSettings:" + userSettingsFile);
}
} else {
userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
}
Path globalSettingsFile;
if (commandLine.hasOption(CLIManager.ALTERNATE_GLOBAL_SETTINGS)) {
globalSettingsFile = Paths.get(commandLine.getOptionValue(CLIManager.ALTERNATE_GLOBAL_SETTINGS));
globalSettingsFile = resolvePath(globalSettingsFile, workingDirectory);
if (!Files.isRegularFile(globalSettingsFile)) {
throw new FileNotFoundException("The specified global settings file does not exist: " + globalSettingsFile);
}
} else {
globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
}
request.setGlobalSettingsFile(globalSettingsFile.toFile());
request.setUserSettingsFile(userSettingsFile.toFile());
AFSettingsBuildingRequest settingsRequest = new AFSettingsBuildingRequest();
settingsRequest.setGlobalSettingsFile(globalSettingsFile.toFile());
settingsRequest.setUserSettingsFile(userSettingsFile.toFile());
settingsRequest.setSystemProperties(cliRequest.getSystemProperties());
settingsRequest.setUserProperties(cliRequest.getUserProperties());
if (request.getEventSpyDispatcher() != null) {
request.getEventSpyDispatcher().onEvent(settingsRequest);
}
logger.debug("Reading global settings from " + getLocation(settingsRequest.getGlobalSettingsSource(), settingsRequest.getGlobalSettingsPath()));
logger.debug("Reading user settings from " + getLocation(settingsRequest.getUserSettingsSource(), settingsRequest.getUserSettingsPath()));
SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
if (request.getEventSpyDispatcher() != null) {
request.getEventSpyDispatcher().onEvent(settingsResult);
}
populateFromSettings(request, settingsResult.getEffectiveSettings());
if (!settingsResult.getProblems().isEmpty() && logger.isWarnEnabled()) {
logger.warn("");
logger.warn("Some problems were encountered while building the effective settings");
for (SettingsProblem problem : settingsResult.getProblems()) {
logger.warn(problem.getMessage() + " @ " + problem.getLocation());
}
logger.warn("");
}
}
use of org.apache.maven.execution.MavenExecutionRequest in project kie-wb-common by kiegroup.
the class ReusableAFMavenCli method execute.
protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
MavenExecutionRequest request = reusableExecutionRequestPopulator.populateDefaults(cliRequest.getRequest());
reusableEventSpyDispatcher.onEvent(request);
MavenExecutionResult result = reusableMaven.execute(request);
reusableEventSpyDispatcher.onEvent(result);
reusableEventSpyDispatcher.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();
}
}
reusableSlf4jLogger.error("");
if (!cliRequest.isShowErrors()) {
reusableSlf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
}
if (!reusableSlf4jLogger.isDebugEnabled()) {
reusableSlf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
}
if (!references.isEmpty()) {
reusableSlf4jLogger.error("");
reusableSlf4jLogger.error("For more information about the errors and possible solutions" + ", please read the following articles:");
for (Entry<String, String> entry : references.entrySet()) {
reusableSlf4jLogger.error(entry.getValue() + " " + entry.getKey());
}
}
if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
reusableSlf4jLogger.error("");
reusableSlf4jLogger.error("After correcting the problems, you can resume the build with the command");
reusableSlf4jLogger.error(" mvn <goals> -rf :" + project.getArtifactId());
}
if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.getRequest().getReactorFailureBehavior())) {
reusableSlf4jLogger.info("Build failures were ignored.");
return 0;
} else {
return 1;
}
} else {
return 0;
}
}
Aggregations