Search in sources :

Example 6 with MavenExecutionRequest

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)) {
        userSettingsFile = Paths.get(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_SETTINGS));
        userSettingsFile = resolvePath(userSettingsFile, workingDirectory);
        if (!Files.isRegularFile(userSettingsFile)) {
            throw new FileNotFoundException("The specified user settings file does not exist: " + 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("");
    }
}
Also used : Path(java.nio.file.Path) CommandLine(org.apache.commons.cli.CommandLine) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) FileNotFoundException(java.io.FileNotFoundException) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 7 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project unleash-maven-plugin by shillner.

the class BuildProject method setupInvocationRequest.

private InvocationRequest setupInvocationRequest() throws MojoExecutionException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(this.project.getFile());
    // installation and deployment are performed in a later step. We first need to ensure that there are no changes in
    // the scm, ...
    request.setGoals(this.goals);
    request.setProperties(this.releaseArgs);
    request.setProfiles(this.profiles);
    request.setShellEnvironmentInherited(true);
    for (String key : this.releaseEnvironmentVariables.keySet()) {
        request.addShellEnvironment(key, this.releaseEnvironmentVariables.get(key));
    }
    request.addShellEnvironment("isUnleashBuild", "true");
    request.setOffline(this.settings.isOffline());
    request.setInteractive(this.settings.isInteractiveMode());
    MavenExecutionRequest originalRequest = this.session.getRequest();
    File globalSettingsFile = originalRequest.getGlobalSettingsFile();
    if (globalSettingsFile != null && globalSettingsFile.exists() && globalSettingsFile.isFile()) {
        request.setGlobalSettingsFile(globalSettingsFile);
    }
    File userSettingsFile = originalRequest.getUserSettingsFile();
    if (userSettingsFile != null && userSettingsFile.exists() && userSettingsFile.isFile()) {
        request.setUserSettingsFile(userSettingsFile);
    }
    File toolchainsFile = originalRequest.getUserToolchainsFile();
    if (toolchainsFile.exists() && toolchainsFile.isFile()) {
        request.setToolchainsFile(toolchainsFile);
    }
    return request;
}
Also used : DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) File(java.io.File)

Example 8 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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;
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) MavenSession(org.apache.maven.execution.MavenSession) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) File(java.io.File)

Example 9 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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;
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) MavenSession(org.apache.maven.execution.MavenSession) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository)

Example 10 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project tycho by eclipse.

the class AbstractTychoMojoTestCase method newMavenExecutionRequest.

protected MavenExecutionRequest newMavenExecutionRequest(File pom) throws Exception {
    Properties systemProps = new Properties();
    systemProps.putAll(System.getProperties());
    Properties userProps = new Properties();
    userProps.put("tycho-version", "0.0.0");
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(pom.getParentFile());
    request.setPom(pom);
    request.setSystemProperties(systemProps);
    request.setUserProperties(userProps);
    request.setLocalRepository(getLocalRepository());
    request.setStartTime(new Date());
    File settingsFile = getUserSettingsFile();
    if (settingsFile.isFile()) {
        request.setUserSettingsFile(settingsFile);
    }
    Settings settings = settingsBuilder.buildSettings(request);
    requestPopulator.populateFromSettings(request, settings);
    request.setGoals(Arrays.asList("validate"));
    return request;
}
Also used : MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) Properties(java.util.Properties) File(java.io.File) Date(java.util.Date) Settings(org.apache.maven.settings.Settings)

Aggregations

MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)56 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)40 File (java.io.File)24 MavenSession (org.apache.maven.execution.MavenSession)20 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)14 MavenProject (org.apache.maven.project.MavenProject)14 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)10 IOException (java.io.IOException)9 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)9 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)9 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)6 Path (java.nio.file.Path)6 Properties (java.util.Properties)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)6 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)5 ProjectBuilder (org.apache.maven.project.ProjectBuilder)5