Search in sources :

Example 1 with SettingsSource

use of org.apache.maven.settings.building.SettingsSource in project drools by kiegroup.

the class MavenEmbedder method buildMavenExecutionRequest.

protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException {
    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
    if (mavenRequest.getGlobalSettingsFile() != null) {
        mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile()));
    }
    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());
    }
    if (mavenRequest.getBaseDirectory() != null) {
        mavenExecutionRequest.setBaseDirectory(new File(mavenRequest.getBaseDirectory()));
    }
    return mavenExecutionRequest;
}
Also used : FileSettingsSource(org.apache.maven.settings.building.FileSettingsSource) SettingsSource(org.apache.maven.settings.building.SettingsSource) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) MavenRepositoryConfiguration(org.kie.maven.integration.MavenRepositoryConfiguration) Logger(org.codehaus.plexus.logging.Logger) Profile(org.apache.maven.model.Profile) FileSettingsSource(org.apache.maven.settings.building.FileSettingsSource) File(java.io.File) IoUtils.copyInTempFile(org.kie.maven.integration.IoUtils.copyInTempFile) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 2 with SettingsSource

use of org.apache.maven.settings.building.SettingsSource in project drools by kiegroup.

the class MavenEmbedder method getSettings.

public Settings getSettings() throws MavenEmbedderException, ComponentLookupException {
    SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest();
    if (this.mavenRequest.getGlobalSettingsFile() != null) {
        settingsBuildingRequest.setGlobalSettingsFile(new File(this.mavenRequest.getGlobalSettingsFile()));
    } else {
        settingsBuildingRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
    }
    if (this.mavenRequest.getUserSettingsSource() != null) {
        settingsBuildingRequest.setUserSettingsSource(this.mavenRequest.getUserSettingsSource());
    } else {
        SettingsSource userSettingsSource = MavenSettings.getUserSettingsSource();
        if (userSettingsSource != null) {
            settingsBuildingRequest.setUserSettingsSource(userSettingsSource);
        }
    }
    settingsBuildingRequest.setUserProperties(this.mavenRequest.getUserProperties());
    settingsBuildingRequest.getSystemProperties().putAll(System.getProperties());
    settingsBuildingRequest.getSystemProperties().putAll(this.mavenRequest.getSystemProperties());
    settingsBuildingRequest.getSystemProperties().putAll(getEnvVars());
    try {
        return componentProvider.lookup(SettingsBuilder.class).build(settingsBuildingRequest).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    }
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) FileSettingsSource(org.apache.maven.settings.building.FileSettingsSource) SettingsSource(org.apache.maven.settings.building.SettingsSource) File(java.io.File) IoUtils.copyInTempFile(org.kie.maven.integration.IoUtils.copyInTempFile) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Aggregations

File (java.io.File)2 FileSettingsSource (org.apache.maven.settings.building.FileSettingsSource)2 SettingsSource (org.apache.maven.settings.building.SettingsSource)2 IoUtils.copyInTempFile (org.kie.maven.integration.IoUtils.copyInTempFile)2 IOException (java.io.IOException)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)1 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)1 Profile (org.apache.maven.model.Profile)1 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)1 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)1 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)1 Logger (org.codehaus.plexus.logging.Logger)1 MavenRepositoryConfiguration (org.kie.maven.integration.MavenRepositoryConfiguration)1