Example usage for org.apache.maven.execution MavenExecutionRequest setSystemProperties

List of usage examples for org.apache.maven.execution MavenExecutionRequest setSystemProperties

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenExecutionRequest setSystemProperties.

Prototype

MavenExecutionRequest setSystemProperties(Properties systemProperties);

Source Link

Document

Sets the system properties to use for interpolation and profile activation.

Usage

From source file:com.github.swt_release_fetcher.Artifact.java

License:Apache License

public void runMavenDeploy(File pomFile, File jarFile, File sourcesFile) {
    Properties properties = new Properties();
    properties.put("pomFile", pomFile.getAbsolutePath());
    properties.put("file", jarFile.getAbsolutePath());
    properties.put("sources", sourcesFile.getAbsolutePath());
    properties.put("repositoryId", "googlecode");
    properties.put("url", REPOSITORY_URL);

    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setPom(pomFile);//  www .j  a v  a  2s .co m
    request.setGoals(Arrays.asList(new String[] { "deploy:deploy-file" }));
    request.setSystemProperties(properties);

    Maven maven = EmbeddedMaven.get();
    MavenExecutionResult result = maven.execute(request);

    if (result.hasExceptions()) {
        System.out.println("Maven deploy failed!");
        System.out.println(result.getExceptions());
        throw new RuntimeException("Maven deploy failed!", result.getExceptions().get(0));
    } else {
        System.out.println("Maven deploy succeeded!");
    }
}

From source file:com.ruleoftech.markdown.page.generator.plugin.BetterAbstractMojoTestCase.java

protected MavenSession newMavenSession() {
    try {//from w w  w.j  ava 2  s  . co m
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        MavenExecutionResult result = new DefaultMavenExecutionResult();

        // populate sensible defaults, including repository basedir and remote repos
        MavenExecutionRequestPopulator populator;
        populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
        populator.populateDefaults(request);

        // this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
        // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
        request.setSystemProperties(System.getProperties());

        // and this is needed so that the repo session in the maven session 
        // has a repo manager, and it points at the local repo
        // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
        DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
        DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven
                .newRepositorySession(request);
        repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession,
                new LocalRepository(request.getLocalRepository().getBasedir())));

        @SuppressWarnings("deprecation")
        MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
        return session;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vladsch.flexmark.page.generator.plugin.BetterAbstractMojoTestCase.java

protected MavenSession newMavenSession() {
    try {/*  www.ja v  a  2  s . c om*/
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        MavenExecutionResult result = new DefaultMavenExecutionResult();

        // populate sensible defaults, including repository basedir and remote repos
        MavenExecutionRequestPopulator populator;
        populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
        populator.populateDefaults(request);

        // this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
        // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
        request.setSystemProperties(System.getProperties());

        // and this is needed so that the repo session in the maven session
        // has a repo manager, and it points at the local repo
        // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
        DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
        DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven
                .newRepositorySession(request);
        repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession,
                new LocalRepository(request.getLocalRepository().getBasedir())));

        @SuppressWarnings("deprecation")
        MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
        return session;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:info.debatty.sparkpackages.maven.plugin.MojoTestCase.java

License:Open Source License

/**
 * Create an instance of Mojo corresponding to the provided goal.
 * The Mojo will be configured according to values provided in the pom.
 * @param pom//from   ww w.j  ava 2  s  . co m
 * @param goal
 * @return
 * @throws Exception if something went wrong...
 */
public final Mojo lookupConfiguredMojo(final File pom, final String goal) throws Exception {

    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    MavenExecutionResult result = new DefaultMavenExecutionResult();

    // populate default values for (a.o.) repository basedir and
    // remote repos
    MavenExecutionRequestPopulator populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
    populator.populateDefaults(request);

    // this is needed to allow java profiles to get resolved;
    // i.e. avoid during project builds:
    // [ERROR] Failed to determine Java version for profile
    // java-1.5-detected
    request.setSystemProperties(System.getProperties());

    // and this is needed so that the repo session in the maven session
    // has a repo manager, and it points at the local repo
    // (cf MavenRepositorySystemUtils.newSession() which is what is
    // otherwise done)
    DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
    DefaultRepositorySystemSession repo_session = (DefaultRepositorySystemSession) maven
            .newRepositorySession(request);
    repo_session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repo_session,
            new LocalRepository(request.getLocalRepository().getBasedir())));

    @SuppressWarnings("deprecation")
    MavenSession session = new MavenSession(getContainer(), repo_session, request, result);

    ProjectBuildingRequest building_request = session.getProjectBuildingRequest();
    ProjectBuilder project_builder = lookup(ProjectBuilder.class);
    MavenProject project = project_builder.build(pom, building_request).getProject();

    return super.lookupConfiguredMojo(project, goal);

}

From source file:io.takari.maven.testing.Maven30xRuntime.java

License:Open Source License

@SuppressWarnings("deprecation")
protected MavenExecutionRequest newExecutionRequest() throws Exception {

    // system properties
    Properties buildProperties = getMavenBuildProperties();
    String mavenVersion = buildProperties.getProperty("version");
    Properties systemProperties = new Properties();
    systemProperties.putAll(System.getProperties()); // TODO not thread safe
    systemProperties.setProperty("maven.version", mavenVersion);
    systemProperties.setProperty("maven.build.version", mavenVersion);

    // request with initial configuration
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setLocalRepositoryPath(properties.getLocalRepository());
    request.setUserSettingsFile(properties.getUserSettings());
    request.setGlobalSettingsFile(properties.getGlobalSettings());
    request.setOffline(properties.getOffline());
    request.setUpdateSnapshots(properties.getUpdateSnapshots());
    request.setSystemProperties(systemProperties);

    // read settings
    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(request.getGlobalSettingsFile());
    settingsRequest.setUserSettingsFile(request.getUserSettingsFile());
    settingsRequest.setSystemProperties(request.getSystemProperties());
    settingsRequest.setUserProperties(request.getUserProperties());
    Settings settings = lookup(SettingsBuilder.class).build(settingsRequest).getEffectiveSettings();

    MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
    request = populator.populateFromSettings(request, settings);
    return populator.populateDefaults(request);
}

From source file:org.eclipse.che.maven.server.MavenServerImpl.java

License:Open Source License

public MavenExecutionRequest newMavenRequest(File pom, List<String> activeProfiles,
        List<String> inactiveProfiles, List<String> goals) {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    try {//w  w  w. j a v  a 2  s.  c  o m
        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);
    }
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.java

License:Open Source License

public static void populateSystemProperties(MavenExecutionRequest request) {
    // temporary solution for https://issues.sonatype.org/browse/MNGECLIPSE-1607
    // oddly, there are no unit tests that fail if this is commented out
    Properties systemProperties = new Properties();
    EnvironmentUtils.addEnvVars(systemProperties);
    systemProperties.putAll(System.getProperties());
    request.setSystemProperties(systemProperties);
}

From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java

License:Open Source License

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);/*from w  ww.j a  v  a  2 s.c  om*/
    request.setSystemProperties(systemProps);
    request.setUserProperties(userProps);
    request.setLocalRepository(getLocalRepository());

    request.setGoals(Arrays.asList("validate"));

    return request;
}

From source file:org.jetbrains.idea.maven.server.Maven30ServerEmbedderImpl.java

License:Apache License

public MavenExecutionRequest createRequest(File file, List<String> activeProfiles,
        List<String> inactiveProfiles, List<String> goals) throws RemoteException {
    //Properties executionProperties = myMavenSettings.getProperties();
    //if (executionProperties == null) {
    //  executionProperties = new Properties();
    //}//from  ww w . j  a v a  2s. co m

    MavenExecutionRequest result = new DefaultMavenExecutionRequest();

    try {
        getComponent(MavenExecutionRequestPopulator.class).populateFromSettings(result, myMavenSettings);

        result.setGoals(goals);

        result.setPom(file);

        getComponent(MavenExecutionRequestPopulator.class).populateDefaults(result);

        result.setSystemProperties(mySystemProperties);

        result.setActiveProfiles(activeProfiles);
        result.setInactiveProfiles(inactiveProfiles);

        result.setStartTime(myBuildStartTime);

        return result;
    } catch (MavenExecutionRequestPopulationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jetbrains.idea.maven.server.Maven32ServerEmbedderImpl.java

License:Apache License

public MavenExecutionRequest createRequest(File file, List<String> activeProfiles,
        List<String> inactiveProfiles, List<String> goals) throws RemoteException {
    //Properties executionProperties = myMavenSettings.getProperties();
    //if (executionProperties == null) {
    //  executionProperties = new Properties();
    //}/*ww  w  . j a v a2  s  .c  o m*/

    MavenExecutionRequest result = new DefaultMavenExecutionRequest();

    try {
        getComponent(MavenExecutionRequestPopulator.class).populateFromSettings(result, myMavenSettings);

        result.setGoals(goals);

        result.setPom(file);

        getComponent(MavenExecutionRequestPopulator.class).populateDefaults(result);

        result.setSystemProperties(mySystemProperties);

        result.setActiveProfiles(activeProfiles);
        result.setInactiveProfiles(inactiveProfiles);

        result.setStartTime(myBuildStartTime);

        final Method setMultiModuleProjectDirectoryMethod = getSetMultiModuleProjectDirectoryMethod(result);
        if (setMultiModuleProjectDirectoryMethod != null) {
            try {
                if (file == null) {
                    file = new File(MavenFileUtil.getTempDirectory());
                }
                setMultiModuleProjectDirectoryMethod.invoke(result, MavenServerUtil.findMavenBasedir(file));
            } catch (Exception e) {
                Maven3ServerGlobals.getLogger().error(e);
            }
        }

        return result;
    } catch (MavenExecutionRequestPopulationException e) {
        throw new RuntimeException(e);
    }
}