Search in sources :

Example 1 with DefaultSettingsBuildingRequest

use of org.apache.maven.settings.building.DefaultSettingsBuildingRequest 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 DefaultSettingsBuildingRequest

use of org.apache.maven.settings.building.DefaultSettingsBuildingRequest 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 DefaultSettingsBuildingRequest

use of org.apache.maven.settings.building.DefaultSettingsBuildingRequest 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 DefaultSettingsBuildingRequest

use of org.apache.maven.settings.building.DefaultSettingsBuildingRequest 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 DefaultSettingsBuildingRequest

use of org.apache.maven.settings.building.DefaultSettingsBuildingRequest in project pom-manipulation-ext by release-engineering.

the class SettingsIO method update.

public void update(Settings settings, File settingsFile) throws ManipulationException {
    try {
        Settings defaultSettings = new Settings();
        if (settingsFile.exists()) {
            DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
            settingsRequest.setGlobalSettingsFile(settingsFile);
            defaultSettings = settingsBuilder.build(settingsRequest).getEffectiveSettings();
        }
        for (Profile profile : settings.getProfiles()) {
            Iterator<Profile> i = defaultSettings.getProfiles().iterator();
            while (i.hasNext()) {
                if (i.next().getId().equals(profile.getId())) {
                    i.remove();
                }
            }
            defaultSettings.addProfile(profile);
        }
        for (String activeProfile : settings.getActiveProfiles()) {
            Iterator<String> i = defaultSettings.getActiveProfiles().iterator();
            while (i.hasNext()) {
                if (i.next().equals(activeProfile)) {
                    i.remove();
                }
            }
            defaultSettings.addActiveProfile(activeProfile);
        }
        for (Mirror mirror : settings.getMirrors()) {
            defaultSettings.addMirror(mirror);
        }
        for (Proxy proxy : settings.getProxies()) {
            defaultSettings.addProxy(proxy);
        }
        for (Server server : settings.getServers()) {
            defaultSettings.addServer(server);
        }
        for (String pluginGroup : settings.getPluginGroups()) {
            defaultSettings.addPluginGroup(pluginGroup);
        }
        if (settings.getLocalRepository() != null) {
            defaultSettings.setLocalRepository(settings.getLocalRepository());
        }
        write(defaultSettings, settingsFile);
    } catch (SettingsBuildingException e) {
        throw new ManipulationException("Failed to build existing settings.xml for repo removal backup.", e, settingsFile, e.getMessage());
    }
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) Mirror(org.apache.maven.settings.Mirror) Settings(org.apache.maven.settings.Settings) Profile(org.apache.maven.settings.Profile)

Aggregations

DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)19 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)15 Settings (org.apache.maven.settings.Settings)14 File (java.io.File)13 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)13 DefaultSettingsBuilderFactory (org.apache.maven.settings.building.DefaultSettingsBuilderFactory)10 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)7 DefaultSettingsBuilder (org.apache.maven.settings.building.DefaultSettingsBuilder)6 SettingsBuilder (org.apache.maven.settings.building.SettingsBuilder)4 Profile (org.apache.maven.settings.Profile)3 Server (org.apache.maven.settings.Server)3 IOException (java.io.IOException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 MavenServerRule (com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule)1 Rule (com.google.devtools.build.lib.packages.Rule)1 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)1 RepositoryNotFoundException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryNotFoundException)1 WorkspaceAttributeMapper (com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)1 FileValue (com.google.devtools.build.lib.skyframe.FileValue)1