Java Code Examples for org.apache.maven.settings.Settings#getServers()

The following examples show how to use org.apache.maven.settings.Settings#getServers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthConfigFactory.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private AuthConfig getAuthConfigFromSettings(Settings settings, String user, String registry) throws MojoExecutionException {
    Server defaultServer = null;
    Server found;
    for (Server server : settings.getServers()) {
        String id = server.getId();

        // Remember a default server without user as fallback for later
        if (defaultServer == null) {
            defaultServer = checkForServer(server, id, registry, null);
        }
        // Check for specific server with user part
        found = checkForServer(server, id, registry, user);
        if (found != null) {
            return createAuthConfigFromServer(found);
        }
    }
    return defaultServer != null ? createAuthConfigFromServer(defaultServer) : null;
}
 
Example 2
Source File: MavenUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static List<RegistryServerConfiguration> getRegistryServerFromMavenSettings(Settings settings) {
    List<RegistryServerConfiguration> registryServerConfigurations = new ArrayList<>();
    for (Server server : settings.getServers()) {
        if (server.getUsername() != null) {
            registryServerConfigurations.add(RegistryServerConfiguration.builder()
                    .id(server.getId())
                    .username(server.getUsername())
                    .password(server.getPassword())
                    .configuration(MavenConfigurationExtractor.extract((Xpp3Dom) server.getConfiguration()))
                    .build());
        }
    }
    return registryServerConfigurations;
}
 
Example 3
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private LazyAuthenticationSelector createAuthSelector(final Settings settings,
         final DefaultMirrorSelector mirrorSelector)
{
   LazyAuthenticationSelector authSelector = new LazyAuthenticationSelector(mirrorSelector);
   for (Server server : settings.getServers())
   {
      authSelector.add(
               server.getId(),
               new AuthenticationBuilder().addUsername(server.getUsername()).addPassword(server.getPassword())
                        .addPrivateKey(server.getPrivateKey(), server.getPassphrase()).build());
   }
   return authSelector;
}
 
Example 4
Source File: SettingsIO.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
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() )
        {
            defaultSettings.getProfiles().removeIf( profile1 -> profile1.getId().equals( profile.getId() ) );
            defaultSettings.addProfile( profile );
        }
        for ( String activeProfile : settings.getActiveProfiles() )
        {
            defaultSettings.getActiveProfiles().removeIf( s -> s.equals( activeProfile ) );
            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.", settingsFile, e.getMessage(), e );
    }
}