Search in sources :

Example 11 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project gate-core by GateNLP.

the class Utils method loadMavenSettings.

public static Settings loadMavenSettings() throws SettingsBuildingException {
    // http://stackoverflow.com/questions/27818659/loading-mavens-settings-xml-for-jcabi-aether-to-use
    SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest();
    settingsBuildingRequest.setSystemProperties(System.getProperties());
    settingsBuildingRequest.setUserSettingsFile(new File(settingsXml));
    settingsBuildingRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
    SettingsBuildingResult settingsBuildingResult;
    DefaultSettingsBuilderFactory mvnSettingBuilderFactory = new DefaultSettingsBuilderFactory();
    DefaultSettingsBuilder settingsBuilder = mvnSettingBuilderFactory.newInstance();
    settingsBuildingResult = settingsBuilder.build(settingsBuildingRequest);
    Settings effectiveSettings = settingsBuildingResult.getEffectiveSettings();
    return effectiveSettings;
}
Also used : DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) File(java.io.File) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 12 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project sts4 by spring-projects.

the class MavenBridge method getSettings.

public synchronized Settings getSettings(final boolean force_reload) throws MavenException {
    // MUST NOT use createRequest!
    File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE;
    if (mavenConfiguration.getUserSettingsFile() != null) {
        userSettingsFile = new File(mavenConfiguration.getUserSettingsFile());
    }
    boolean reload = force_reload || settings == null;
    if (!reload && userSettingsFile != null) {
        reload = userSettingsFile.lastModified() != settings_timestamp || userSettingsFile.length() != settings_length;
    }
    if (reload) {
        // TODO: Can't that delegate to buildSettings()?
        SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
        // 440696 guard against ConcurrentModificationException
        Properties systemProperties = new Properties();
        copyProperties(systemProperties, System.getProperties());
        request.setSystemProperties(systemProperties);
        if (mavenConfiguration.getGlobalSettingsFile() != null) {
            request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
        }
        if (userSettingsFile != null) {
            request.setUserSettingsFile(userSettingsFile);
        }
        try {
            settings = lookup(SettingsBuilder.class).build(request).getEffectiveSettings();
        } catch (SettingsBuildingException ex) {
            String msg = "Could not read settings.xml, assuming default values";
            log.error(msg, ex);
            /*
				 * NOTE: This method provides input for various other core
				 * functions, just bailing out would make m2e highly unusuable.
				 * Instead, we fail gracefully and just ignore the broken
				 * settings, using defaults.
				 */
            settings = new Settings();
        }
        if (userSettingsFile != null) {
            settings_length = userSettingsFile.length();
            settings_timestamp = userSettingsFile.lastModified();
        }
    }
    return settings;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) Properties(java.util.Properties) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 13 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project maven-plugins by apache.

the class AbstractInvokerMojo method mergeSettings.

/**
 * Merge the settings file
 *
 * @param interpolatedSettingsFile The interpolated settings file.
 * @return The merged settings file.
 * @throws MojoExecutionException Fail the build in case the merged settings file can't be created.
 */
private File mergeSettings(File interpolatedSettingsFile) throws MojoExecutionException {
    File mergedSettingsFile;
    Settings mergedSettings = this.settings;
    if (mergeUserSettings) {
        if (interpolatedSettingsFile != null) {
            // Have to merge the specified settings file (dominant) and the one of the invoking Maven process
            try {
                SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
                request.setGlobalSettingsFile(interpolatedSettingsFile);
                Settings dominantSettings = settingsBuilder.build(request).getEffectiveSettings();
                Settings recessiveSettings = cloneSettings();
                SettingsUtils.merge(dominantSettings, recessiveSettings, TrackableBase.USER_LEVEL);
                mergedSettings = dominantSettings;
                getLog().debug("Merged specified settings file with settings of invoking process");
            } catch (SettingsBuildingException e) {
                throw new MojoExecutionException("Could not read specified settings file", e);
            }
        }
    }
    if (this.settingsFile != null && !mergeUserSettings) {
        mergedSettingsFile = interpolatedSettingsFile;
    } else {
        try {
            mergedSettingsFile = writeMergedSettingsFile(mergedSettings);
        } catch (IOException e) {
            throw new MojoExecutionException("Could not create temporary file for invoker settings.xml", e);
        }
    }
    return mergedSettingsFile;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) IOException(java.io.IOException) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Aggregations

DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)13 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)13 File (java.io.File)11 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)10 Settings (org.apache.maven.settings.Settings)9 DefaultSettingsBuilderFactory (org.apache.maven.settings.building.DefaultSettingsBuilderFactory)6 DefaultSettingsBuilder (org.apache.maven.settings.building.DefaultSettingsBuilder)4 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)4 IOException (java.io.IOException)1 Properties (java.util.Properties)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Profile (org.apache.maven.settings.Profile)1 Repository (org.apache.maven.settings.Repository)1 Server (org.apache.maven.settings.Server)1 FileSettingsSource (org.apache.maven.settings.building.FileSettingsSource)1 SettingsBuilder (org.apache.maven.settings.building.SettingsBuilder)1 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)1 SettingsSource (org.apache.maven.settings.building.SettingsSource)1 IoUtils.copyInTempFile (org.kie.maven.integration.IoUtils.copyInTempFile)1