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

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

Introduction

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

Prototype

MavenExecutionRequest addProfile(Profile profile);

Source Link

Usage

From source file:com.googlecode.ounit.executor.MavenRunner.java

License:Open Source License

public MavenExecutionResult execute(File baseDirectory, List<String> goals, String outputDirectory) {

    baseDirectory = baseDirectory.getAbsoluteFile();
    File pom = modelProcessor.locatePom(baseDirectory);

    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(baseDirectory).setPom(pom).setExecutionListener(executionListener)
            .setTransferListener(transferListener).setSystemProperties(systemProperties)
            //.setUserProperties( userProperties )
            .setLoggingLevel(logLevel).setInteractiveMode(false)
            //.setOffline( true )
            .setCacheNotFound(true).setCacheTransferError(false).setGoals(goals);

    /* Apply base profiles */
    for (Profile p : baseProfiles)
        request.addProfile(p.clone());

    // TODO: Implement system specific settings.xml file

    /* Create a build profile to set outputDirectory */
    if (outputDirectory != null) {
        Build b = new Build();
        b.setDirectory(outputDirectory);
        Activation a = new Activation();
        a.setActiveByDefault(true);// ww  w . ja va2s .  co m
        Profile p = new Profile();
        p.setId("ounitExecutorCustomOutputDirectoryProfile");
        p.setActivation(a);
        p.setBuild(b);
        request.addProfile(p);
    }

    container.getLoggerManager().setThresholds(request.getLoggingLevel());

    MavenExecutionResult r = maven.execute(request);

    return r;
}

From source file:hudson.maven.MavenEmbedder.java

License:Apache License

protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest)
        throws MavenEmbedderException, ComponentLookupException {
    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();

    if (mavenRequest.getGlobalSettingsFile() != null) {
        mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile()));
    }// w  w w .ja v a  2 s .c  om

    if (mavenExecutionRequest.getUserSettingsFile() != null) {
        mavenExecutionRequest.setUserSettingsFile(new File(mavenRequest.getUserSettingsFile()));
    }

    try {
        lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings());

        lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest);
    } catch (MavenExecutionRequestPopulationException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    }

    ArtifactRepository localRepository = getLocalRepository();
    mavenExecutionRequest.setLocalRepository(localRepository);
    mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir());
    mavenExecutionRequest.setOffline(mavenRequest.isOffline());

    mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots());

    // TODO check null and create a console one ?
    mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener());

    mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound());
    mavenExecutionRequest.setCacheTransferError(true);

    mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties());
    mavenExecutionRequest.getSystemProperties().putAll(System.getProperties());
    if (mavenRequest.getSystemProperties() != null) {
        mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties());
    }
    mavenExecutionRequest.getSystemProperties().putAll(getEnvVars());

    if (this.mavenHome != null) {
        mavenExecutionRequest.getSystemProperties().put("maven.home", this.mavenHome.getAbsolutePath());
    }

    if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) {
        for (String id : mavenRequest.getProfiles()) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            mavenExecutionRequest.addProfile(p);
            mavenExecutionRequest.addActiveProfile(id);
        }
    }

    mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel());

    lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel());

    mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener())
            .setInteractiveMode(mavenRequest.isInteractive())
            .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals());

    if (mavenRequest.getPom() != null) {
        mavenExecutionRequest.setPom(new File(mavenRequest.getPom()));
    }

    if (mavenRequest.getWorkspaceReader() != null) {
        mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader());
    }

    // FIXME inactive profiles 

    //this.mavenExecutionRequest.set

    return mavenExecutionRequest;

}

From source file:org.appformer.maven.integration.embedder.MavenEmbedder.java

License:Apache License

protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest)
        throws MavenEmbedderException, ComponentLookupException {
    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();

    if (mavenRequest.getGlobalSettingsFile() != null) {
        mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile()));
    }/*  w w  w. jav a2 s.  c  om*/

    SettingsSource userSettings = mavenRequest.getUserSettingsSource();
    if (userSettings != null) {
        if (userSettings instanceof FileSettingsSource) {
            mavenExecutionRequest.setUserSettingsFile(((FileSettingsSource) userSettings).getSettingsFile());
        } else {
            try {
                mavenExecutionRequest.setUserSettingsFile(copyInTempFile(userSettings.getInputStream(), "xml"));
            } catch (IOException ioe) {
                log.warn("Unable to use maven settings defined in " + userSettings, ioe);
            }
        }
    }

    try {
        componentProvider.lookup(MavenExecutionRequestPopulator.class)
                .populateFromSettings(mavenExecutionRequest, getSettings());
        componentProvider.lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest);
    } catch (MavenExecutionRequestPopulationException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    }

    ArtifactRepository localRepository = getLocalRepository();
    mavenExecutionRequest.setLocalRepository(localRepository);
    mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir());
    mavenExecutionRequest.setOffline(mavenRequest.isOffline());

    mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots());

    // TODO check null and create a console one ?
    mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener());

    mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound());
    mavenExecutionRequest.setCacheTransferError(true);

    mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties());
    mavenExecutionRequest.getSystemProperties().putAll(System.getProperties());
    if (mavenRequest.getSystemProperties() != null) {
        mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties());
    }
    mavenExecutionRequest.getSystemProperties().putAll(getEnvVars());

    if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) {
        for (String id : mavenRequest.getProfiles()) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            mavenExecutionRequest.addProfile(p);
            mavenExecutionRequest.addActiveProfile(id);
        }
    }

    MavenRepositoryConfiguration mavenRepoConf = getMavenRepositoryConfiguration();

    //DROOLS-899: Copy repositories defined in settings to execution request
    for (ArtifactRepository artifactRepository : mavenRepoConf.getArtifactRepositoriesForRequest()) {
        mavenExecutionRequest.addRemoteRepository(artifactRepository);
    }

    mavenExecutionRequest.setProxies(mavenRepoConf.getProxies());

    mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel());

    componentProvider.lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel());

    mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener())
            .setInteractiveMode(mavenRequest.isInteractive())
            .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals());

    if (mavenRequest.getPom() != null) {
        mavenExecutionRequest.setPom(new File(mavenRequest.getPom()));
    }

    if (mavenRequest.getWorkspaceReader() != null) {
        mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader());
    }

    return mavenExecutionRequest;
}

From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenUpdateChecker.java

License:Apache License

ProjectBuildingRequest getProjectBuildingRequest(Properties userProperties, PlexusContainer plexusContainer)
        throws ComponentLookupException, SettingsBuildingException, MavenExecutionRequestPopulationException,
        InvalidRepositoryException {//from w w  w .  j av a2  s .  c om

    MavenExecutionRequest request = new DefaultMavenExecutionRequest();

    request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);

    request.setWorkspaceReader(new ReactorReader(new HashMap<String, MavenProject>(0)));

    SettingsBuilder settingsBuilder = plexusContainer.lookup(SettingsBuilder.class);

    RepositorySystem repositorySystem = plexusContainer.lookup(RepositorySystem.class);

    org.sonatype.aether.RepositorySystem repoSystem = plexusContainer
            .lookup(org.sonatype.aether.RepositorySystem.class);

    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();

    if (globalSettings != null) {
        mavenUpdateCheckerResult.addDebugLine("globalSettings " + globalSettings.getRemote());
        settingsRequest.setGlobalSettingsFile(new File(globalSettings.getRemote()));
    } else {
        File globalSettings = new File(mavenHome, "conf/settings.xml");
        if (globalSettings.exists()) {
            settingsRequest.setGlobalSettingsFile(globalSettings);
        }
    }
    if (alternateSettings != null) {
        mavenUpdateCheckerResult.addDebugLine("alternateSettings " + alternateSettings.getRemote());
        settingsRequest.setUserSettingsFile(new File(alternateSettings.getRemote()));
        request.setUserSettingsFile(new File(alternateSettings.getRemote()));
    } else {
        File defaultUserSettings = new File(new File(System.getProperty("user.home"), ".m2"), "settings.xml");
        settingsRequest.setUserSettingsFile(defaultUserSettings);
        request.setUserSettingsFile(defaultUserSettings);
    }
    settingsRequest.setSystemProperties(System.getProperties());
    settingsRequest.setUserProperties(userProperties);

    SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(settingsRequest);

    MavenExecutionRequestPopulator executionRequestPopulator = plexusContainer
            .lookup(MavenExecutionRequestPopulator.class);

    executionRequestPopulator.populateFromSettings(request, settingsBuildingResult.getEffectiveSettings());

    executionRequestPopulator.populateDefaults(request);

    MavenRepositorySystemSession session = new MavenRepositorySystemSession();

    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);

    SnapshotTransfertListener snapshotTransfertListener = new SnapshotTransfertListener(this.lastBuildTime);
    session.setTransferListener(snapshotTransfertListener);

    LocalRepository localRepo = getLocalRepo(settingsBuildingResult);

    session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(localRepo));

    ArtifactRepository localArtifactRepository = getLocalArtifactRepo(settingsBuildingResult, repositorySystem);

    request.setLocalRepository(localArtifactRepository);

    if (this.activeProfiles != null && !this.activeProfiles.isEmpty()) {
        for (String id : this.activeProfiles) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            request.addProfile(p);
            request.addActiveProfile(id);
        }
    }

    ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
    return projectBuildingRequest.setRepositorySession(session);
}

From source file:org.kie.scanner.embedder.MavenEmbedder.java

License:Apache License

protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest)
        throws MavenEmbedderException, ComponentLookupException {
    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();

    if (mavenRequest.getGlobalSettingsFile() != null) {
        mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile()));
    }// w  w  w  . j a v a2s  . c o m

    if (mavenExecutionRequest.getUserSettingsFile() != null) {
        mavenExecutionRequest.setUserSettingsFile(new File(mavenRequest.getUserSettingsFile()));
    }

    try {
        lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings());

        lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest);
    } catch (MavenExecutionRequestPopulationException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    }

    ArtifactRepository localRepository = getLocalRepository();
    mavenExecutionRequest.setLocalRepository(localRepository);
    mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir());
    mavenExecutionRequest.setOffline(mavenRequest.isOffline());

    mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots());

    // TODO check null and create a console one ?
    mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener());

    mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound());
    mavenExecutionRequest.setCacheTransferError(true);

    mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties());
    mavenExecutionRequest.getSystemProperties().putAll(System.getProperties());
    if (mavenRequest.getSystemProperties() != null) {
        mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties());
    }
    mavenExecutionRequest.getSystemProperties().putAll(getEnvVars());

    if (this.mavenHome != null) {
        mavenExecutionRequest.getSystemProperties().put("maven.home", this.mavenHome.getAbsolutePath());
    }

    if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) {
        for (String id : mavenRequest.getProfiles()) {
            Profile p = new Profile();
            p.setId(id);
            p.setSource("cli");
            mavenExecutionRequest.addProfile(p);
            mavenExecutionRequest.addActiveProfile(id);
        }
    }

    mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel());

    lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel());

    mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener())
            .setInteractiveMode(mavenRequest.isInteractive())
            .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals());

    if (mavenRequest.getPom() != null) {
        mavenExecutionRequest.setPom(new File(mavenRequest.getPom()));
    }

    if (mavenRequest.getWorkspaceReader() != null) {
        mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader());
    }

    return mavenExecutionRequest;
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFConfigurationProcessor.java

License:Apache License

private MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings)
        throws MavenExecutionRequestPopulationException {
    if (settings == null) {
        return request;
    } else {//from w  ww  .  j  a  v a 2 s . c o m
        request.setOffline(settings.isOffline());
        request.setInteractiveMode(settings.isInteractiveMode());
        request.setPluginGroups(settings.getPluginGroups());
        request.setLocalRepositoryPath(settings.getLocalRepository());
        Iterator i$ = settings.getServers().iterator();

        while (i$.hasNext()) {
            Server server = (Server) i$.next();
            server = server.clone();
            request.addServer(server);
        }

        i$ = settings.getProxies().iterator();

        while (i$.hasNext()) {
            Proxy proxy = (Proxy) i$.next();
            if (proxy.isActive()) {
                proxy = proxy.clone();
                request.addProxy(proxy);
            }
        }

        i$ = settings.getMirrors().iterator();

        while (i$.hasNext()) {
            Mirror mirror = (Mirror) i$.next();
            mirror = mirror.clone();
            request.addMirror(mirror);
        }

        request.setActiveProfiles(settings.getActiveProfiles());
        i$ = settings.getProfiles().iterator();

        while (true) {
            Profile rawProfile;
            do {
                if (!i$.hasNext()) {
                    return request;
                }

                rawProfile = (Profile) i$.next();
                request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile));
            } while (!settings.getActiveProfiles().contains(rawProfile.getId()));

            List<Repository> remoteRepositories = rawProfile.getRepositories();
            Iterator i$2 = remoteRepositories.iterator();

            while (i$2.hasNext()) {
                Repository remoteRepository = (Repository) i$.next();

                try {
                    request.addRemoteRepository(
                            MavenRepositorySystem.buildArtifactRepository(remoteRepository));
                } catch (InvalidRepositoryException var10) {
                    logger.error(var10.getMessage());
                }
            }

            List<Repository> pluginRepositories = rawProfile.getPluginRepositories();
            Iterator i$3 = pluginRepositories.iterator();

            while (i$3.hasNext()) {
                Repository pluginRepository = (Repository) i$.next();

                try {
                    request.addPluginArtifactRepository(
                            MavenRepositorySystem.buildArtifactRepository(pluginRepository));
                } catch (InvalidRepositoryException var11) {
                    logger.error(var11.getMessage());
                }
            }
        }
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFSettingsXmlConfigurationProcessor.java

License:Apache License

private MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings)
        throws MavenExecutionRequestPopulationException {
    if (settings == null) {
        return request;
    }//from  w  ww  . j a va 2s.com

    request.setOffline(settings.isOffline());

    request.setInteractiveMode(settings.isInteractiveMode());

    request.setPluginGroups(settings.getPluginGroups());

    request.setLocalRepositoryPath(settings.getLocalRepository());

    for (Server server : settings.getServers()) {
        server = server.clone();

        request.addServer(server);
    }

    //  <proxies>
    //    <proxy>
    //      <active>true</active>
    //      <protocol>http</protocol>
    //      <host>proxy.somewhere.com</host>
    //      <port>8080</port>
    //      <username>proxyuser</username>
    //      <password>somepassword</password>
    //      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    //    </proxy>
    //  </proxies>

    for (Proxy proxy : settings.getProxies()) {
        if (!proxy.isActive()) {
            continue;
        }

        proxy = proxy.clone();

        request.addProxy(proxy);
    }

    // <mirrors>
    //   <mirror>
    //     <id>nexus</id>
    //     <mirrorOf>*</mirrorOf>
    //     <url>http://repository.sonatype.org/content/groups/public</url>
    //   </mirror>
    // </mirrors>

    for (Mirror mirror : settings.getMirrors()) {
        mirror = mirror.clone();

        request.addMirror(mirror);
    }

    request.setActiveProfiles(settings.getActiveProfiles());

    for (org.apache.maven.settings.Profile rawProfile : settings.getProfiles()) {
        request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile));

        if (settings.getActiveProfiles().contains(rawProfile.getId())) {
            List<Repository> remoteRepositories = rawProfile.getRepositories();
            for (Repository remoteRepository : remoteRepositories) {
                try {
                    request.addRemoteRepository(
                            MavenRepositorySystem.buildArtifactRepository(remoteRepository));
                } catch (InvalidRepositoryException e) {
                    // do nothing for now
                }
            }

            List<Repository> pluginRepositories = rawProfile.getPluginRepositories();
            for (Repository pluginRepository : pluginRepositories) {
                try {
                    request.addPluginArtifactRepository(
                            MavenRepositorySystem.buildArtifactRepository(pluginRepository));
                } catch (InvalidRepositoryException e) {
                    // do nothing for now
                }
            }
        }
    }
    return request;
}