Search in sources :

Example 1 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project che by eclipse.

the class MavenServerImpl method getSettings.

private Settings getSettings(SettingsBuilder builder, MavenSettings settings, Properties systemProperties, Properties userProperties) throws RemoteException {
    SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    request.setGlobalSettingsFile(settings.getGlobalSettings());
    request.setUserSettingsFile(settings.getUserSettings());
    request.setSystemProperties(systemProperties);
    request.setUserProperties(userProperties);
    Settings result = new Settings();
    try {
        result = builder.build(request).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        MavenServerContext.getLogger().info(e);
    }
    result.setOffline(settings.isOffline());
    if (settings.getLocalRepository() != null) {
        result.setLocalRepository(settings.getLocalRepository().getPath());
    }
    if (result.getLocalRepository() == null) {
        result.setLocalRepository(new File(System.getProperty("user.home"), ".m2/repository").getPath());
    }
    return result;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) 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 2 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method buildSettings.

private static Settings buildSettings(SettingsBuilder builder, MavenServerSettings settings, Properties systemProperties, Properties userProperties) throws RemoteException {
    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(settings.getGlobalSettingsFile());
    settingsRequest.setUserSettingsFile(settings.getUserSettingsFile());
    settingsRequest.setSystemProperties(systemProperties);
    settingsRequest.setUserProperties(userProperties);
    Settings result = new Settings();
    try {
        result = builder.build(settingsRequest).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        Maven3ServerGlobals.getLogger().info(e);
    }
    result.setOffline(settings.isOffline());
    if (settings.getLocalRepository() != null) {
        result.setLocalRepository(settings.getLocalRepository().getPath());
    }
    if (result.getLocalRepository() == null) {
        result.setLocalRepository(new File(SystemProperties.getUserHome(), ".m2/repository").getPath());
    }
    return result;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) 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 3 with SettingsBuildingRequest

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

the class MavenConfigurationSupport method readSettings.

/**
 * Reads on demand <code>settings.xml</code> file - without password decryption. Also
 * collects declared servers by ID.
 * @param settingsFile
 */
protected synchronized Settings readSettings(File settingsFile) throws SettingsBuildingException {
    if (!settingsFile.isFile() || !settingsFile.canRead()) {
        return null;
    }
    try {
        DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
        DefaultSettingsBuilder builder = factory.newInstance();
        SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
        request.setUserSettingsFile(settingsFile);
        SettingsBuildingResult result = builder.build(request);
        if (result.getProblems().size() > 0) {
            for (SettingsProblem problem : result.getProblems()) {
                System.err.println(problem);
            }
            return null;
        } else {
            Settings settings = result.getEffectiveSettings();
            if (settings.getServers() != null) {
                for (Server server : settings.getServers()) {
                    servers.put(server.getId(), server);
                }
            }
            return settings;
        }
    } catch (Throwable e) {
        System.err.println(e.getMessage());
        LOG.error(e.getMessage(), e);
        throw e;
    }
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 4 with SettingsBuildingRequest

use of org.apache.maven.settings.building.SettingsBuildingRequest in project spring-cloud-function by spring-cloud.

the class MavenSettingsReader method loadSettings.

private Settings loadSettings() {
    File settingsFile = new File(this.homeDir, ".m2/settings.xml");
    if (settingsFile.exists()) {
        log.info("Reading settings from: " + settingsFile);
    } else {
        log.info("No settings found at: " + settingsFile);
    }
    SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    request.setUserSettingsFile(settingsFile);
    request.setSystemProperties(System.getProperties());
    try {
        return new DefaultSettingsBuilderFactory().newInstance().build(request).getEffectiveSettings();
    } catch (SettingsBuildingException ex) {
        throw new IllegalStateException("Failed to build settings from " + settingsFile, ex);
    }
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) File(java.io.File) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest)

Example 5 with SettingsBuildingRequest

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

the class MavenSettingsReader method loadSettings.

private Settings loadSettings() {
    File settingsFile = new File(this.homeDir, ".m2/settings.xml");
    SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    request.setUserSettingsFile(settingsFile);
    request.setSystemProperties(System.getProperties());
    try {
        return new DefaultSettingsBuilderFactory().newInstance().build(request).getEffectiveSettings();
    } catch (SettingsBuildingException ex) {
        throw new IllegalStateException("Failed to build settings from " + settingsFile, ex);
    }
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) File(java.io.File) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest)

Aggregations

DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)12 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)12 File (java.io.File)10 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)9 Settings (org.apache.maven.settings.Settings)8 DefaultSettingsBuilderFactory (org.apache.maven.settings.building.DefaultSettingsBuilderFactory)5 DefaultSettingsBuilder (org.apache.maven.settings.building.DefaultSettingsBuilder)3 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)3 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