org.apache.maven.settings.Settings类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中org.apache.maven.settings.Settings类的一些代码示例,展示了Settings类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Settings类的具体详情如下:
包路径:org.apache.maven.settings.Settings
类名称:Settings

Settings介绍

[英]Root element of the user configuration file.
[中]用户配置文件的根元素。

代码示例

代码示例来源:origin: apache/maven

recessive.setSourceLevel( recessiveSourceLevel );
List<String> dominantActiveProfiles = dominant.getActiveProfiles();
List<String> recessiveActiveProfiles = recessive.getActiveProfiles();
    dominant.setActiveProfiles( dominantActiveProfiles );
List<String> dominantPluginGroupIds = dominant.getPluginGroups();
List<String> recessivePluginGroupIds = recessive.getPluginGroups();
    dominant.setPluginGroups( dominantPluginGroupIds );
if ( StringUtils.isEmpty( dominant.getLocalRepository() ) )
  dominant.setLocalRepository( recessive.getLocalRepository() );
shallowMergeById( dominant.getMirrors(), recessive.getMirrors(), recessiveSourceLevel );
shallowMergeById( dominant.getServers(), recessive.getServers(), recessiveSourceLevel );
shallowMergeById( dominant.getProxies(), recessive.getProxies(), recessiveSourceLevel );
shallowMergeById( dominant.getProfiles(), recessive.getProfiles(), recessiveSourceLevel );

代码示例来源:origin: eirslett/frontend-maven-plugin

static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
  if (StringUtils.isEmpty(serverId)) {
    return null;
  }
  Server server = mavenSession.getSettings().getServer(serverId);
  if (server != null) {
    final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
    return decryptedResult.getServer();
  } else {
    LOGGER.warn("Could not find server '" + serverId + "' in settings.xml");
    return null;
  }
}

代码示例来源:origin: apache/maven

/**
   * @param settings could be null
   * @return a new instance of settings or null if settings was null.
   */
  public static Settings copySettings( Settings settings )
  {
    if ( settings == null )
    {
      return null;
    }

    Settings clone = new Settings();
    clone.setActiveProfiles( settings.getActiveProfiles() );
    clone.setInteractiveMode( settings.isInteractiveMode() );
    clone.setLocalRepository( settings.getLocalRepository() );
    clone.setMirrors( settings.getMirrors() );
    clone.setModelEncoding( settings.getModelEncoding() );
    clone.setOffline( settings.isOffline() );
    clone.setPluginGroups( settings.getPluginGroups() );
    clone.setProfiles( settings.getProfiles() );
    clone.setProxies( settings.getProxies() );
    clone.setServers( settings.getServers() );
    clone.setSourceLevel( settings.getSourceLevel() );
    clone.setUsePluginRegistry( settings.isUsePluginRegistry() );

    return clone;
  }
}

代码示例来源:origin: apache/maven

/**
 * Creates a new request to decrypt the specified settings.
 *
 * @param settings The settings to decrypt, must not be {@code null}.
 */
public DefaultSettingsDecryptionRequest( Settings settings )
{
  setServers( settings.getServers() );
  setProxies( settings.getProxies() );
}

代码示例来源:origin: jeremylong/DependencyCheck

settings.setString(Settings.KEYS.PROXY_SERVER, proxy.getHost());
  settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort()));
  final String userName = proxy.getUsername();
settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
if (nexusServerId != null) {
  final Server server = settingsXml.getServer(nexusServerId);
  if (server != null) {
    final String nexusUser = server.getUsername();
    String nexusPassword = null;
    try {
          || (ex.getCause() != null && ex.getCause().getCause() instanceof FileNotFoundException)) {
        final String tmp = server.getPassword();
if (Boolean.TRUE.equals(artifactoryAnalyzerEnabled)) {
  if (artifactoryAnalyzerServerId != null) {
    final Server server = settingsXml.getServer(artifactoryAnalyzerServerId);
    if (server != null) {
      settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_API_USERNAME, server.getUsername());
settings.setStringIfNotEmpty(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
if (databaseUser == null && databasePassword == null && serverId != null) {
  final Server server = settingsXml.getServer(serverId);

代码示例来源:origin: jmeter-maven-plugin/jmeter-maven-plugin

/**
 * Try to load the active maven proxy.
 */
protected void loadMavenProxy() {
  if (settings == null)
    return;
  try {
    Proxy mvnProxy = settings.getActiveProxy();
    if (mvnProxy != null) {
      ProxyConfiguration newProxyConf = new ProxyConfiguration();
      newProxyConf.setHost(mvnProxy.getHost());
      newProxyConf.setPort(mvnProxy.getPort());
      newProxyConf.setUsername(mvnProxy.getUsername());
      newProxyConf.setPassword(mvnProxy.getPassword());
      newProxyConf.setHostExclusions(mvnProxy.getNonProxyHosts());
      proxyConfig = newProxyConf;
      getLog().info("Maven proxy loaded successfully");
    } else {
      getLog().warn("No maven proxy found, but useMavenProxy set to true.");
    }
  } catch (Exception e) {
    getLog().error("Error while loading maven proxy", e);
  }
}

代码示例来源:origin: apache/cxf

protected void configureProxyServerSettings() throws MojoExecutionException {
  Proxy proxy = mavenSession.getSettings().getActiveProxy();
  if (proxy != null) {
    getLog().info("Using proxy server configured in maven.");
    if (proxy.getHost() == null) {
      throw new MojoExecutionException("Proxy in settings.xml has no host");
    }
    if (proxy.getHost() != null) {
      System.setProperty(HTTP_PROXY_HOST, proxy.getHost());
    }
    if (String.valueOf(proxy.getPort()) != null) {
      System.setProperty(HTTP_PROXY_PORT, String.valueOf(proxy.getPort()));
    }
    if (proxy.getNonProxyHosts() != null) {
      System.setProperty(HTTP_NON_PROXY_HOSTS, proxy.getNonProxyHosts());
    }
    if (!StringUtils.isEmpty(proxy.getUsername())
      && !StringUtils.isEmpty(proxy.getPassword())) {
      final String authUser = proxy.getUsername();
      final String authPassword = proxy.getPassword();
      Authenticator.setDefault(new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(authUser, authPassword.toCharArray());
        }
      });
      System.setProperty(HTTP_PROXY_USER, authUser);
      System.setProperty(HTTP_PROXY_PORT, authPassword);
    }
  }
}

代码示例来源:origin: highsource/maven-jaxb2-plugin

protected String getActiveProxyAsHttpproxy() {
  if (getSettings() == null) {
    return null;
  }
  final Settings settings = getSettings();
  final Proxy activeProxy = settings.getActiveProxy();
  if (activeProxy == null || activeProxy.getHost() == null) {
    return null;
  }
  return createXJCProxyArgument(activeProxy.getHost(), activeProxy.getPort(), activeProxy.getUsername(),
      activeProxy.getPassword());
}

代码示例来源:origin: SonarSource/sonar-scanner-maven

public void setProxySystemProperties() {
  Proxy activeProxy = session.getSettings().getActiveProxy();

  if (activeProxy != null && activeProxy.getProtocol() != null && activeProxy.getProtocol().contains("http")) {
   log.debug("Setting proxy properties");
   System.setProperty("http.proxyHost", activeProxy.getHost());
   System.setProperty("http.proxyPort", String.valueOf(activeProxy.getPort()));
   System.setProperty("http.proxyUser", StringUtils.defaultString(activeProxy.getUsername(), ""));
   System.setProperty("http.proxyPassword", StringUtils.defaultString(activeProxy.getPassword(), ""));
   System.setProperty("http.nonProxyHosts", StringUtils.defaultString(activeProxy.getNonProxyHosts(), ""));
  }
 }
}

代码示例来源:origin: danielflower/multi-module-maven-release-plugin

protected CredentialsProvider getCredentialsProvider(final Log log) throws ValidationException {
  if (serverId != null) {
    Server server = settings.getServer(serverId);
    if (server == null) {
      log.warn(format("No server configuration in Maven settings found with id %s", serverId));
    }
    if (server.getUsername() != null && server.getPassword() != null) {
      return new UsernamePasswordCredentialsProvider(server.getUsername(), server.getPassword());
    }
  }
  return null;
}

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

public void executeTask() throws MojoExecutionException, MojoFailureException {
  initSdkStatsFile();
  String localRepository = mavenSession.getSettings().getLocalRepository();
  File mavenHome = new File(localRepository).getParentFile();
  mavenHome.mkdirs();
  File mavenSettings = new File(mavenHome, SDKConstants.MAVEN_SETTINGS);
  try {
    SettingsManager settings = new SettingsManager(mavenSession);
    InputStream settingsStream = getClass().getClassLoader().getResourceAsStream(SDKConstants.MAVEN_SETTINGS);
    SettingsManager defaultSettings = new SettingsManager(settingsStream);
    settings.updateSettings(defaultSettings.getSettings());
    OutputStream out = new FileOutputStream(mavenSettings);
    settings.apply(out);
    getLog().info(String.format(SUCCESS_TEMPLATE, mavenSettings.getPath()));
    getLog().info(SDK_INFO);
  } catch (IOException e) {
    throw new MojoExecutionException(e.getMessage());
  }
}

代码示例来源:origin: wouterd/docker-maven-plugin

private Optional<Credentials> getCredentialsFromSettings() {
  if(settings == null) {
    getLog().debug("No settings.xml");
    return empty();
  }
  Server server = settings.getServer(serverId);
  if(server == null) {
    getLog().debug("Cannot find server " + serverId + " in Maven settings");
    return empty();
  }
  getLog().debug("Using credentials from Maven settings: " + server.getUsername());
  return of(new Credentials(server.getUsername(), server.getPassword(), getEmail(server), null));
}

代码示例来源:origin: org.apache.maven.continuum/continuum-core

private ArtifactRepository getRepository( Settings settings )
{
  // ----------------------------------------------------------------------
  // Set our configured location as the default but try to use the defaults
  // as returned by the MavenSettings component.
  // ----------------------------------------------------------------------
  String localRepo = localRepository;
  if ( !( StringUtils.isEmpty( settings.getLocalRepository() ) ) )
  {
    localRepo = settings.getLocalRepository();
  }
  return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + localRepo, repositoryLayout,
                                null, null );
}

代码示例来源:origin: maven-gae-plugin/maven-gae-plugin

/**
 * Passes command to the Google App Engine AppCfg runner.
 * 
 * @param command command to run through AppCfg
 * @param commandArguments arguments to the AppCfg command.
 * @throws MojoExecutionException If {@link #ensureSystemProperties()} fails
 */
protected final void runAppCfg(final String command, final String... commandArguments) throws MojoExecutionException {
 final List<String> args = new ArrayList<String>();
 args.addAll(getAppCfgArgs());
 args.add(command);
 args.addAll(Arrays.asList(commandArguments));
 if (goalArguments != null) {
  args.addAll(goalArguments);
 }
 ensureSystemProperties();
 getLog().debug("execute AppCfg " + args.toString());
 if (hasServerSettings()) {
  forkPasswordExpectThread(args.toArray(ARG_TYPE), decryptPassword(settings.getServer(serverId).getPassword()));
  return;
 }
 AppCfg.main(args.toArray(ARG_TYPE));
}

代码示例来源:origin: jbossas/jboss-as-maven-plugin

private void getCredentialsFromSettings() {
  if (settings != null) {
    Server server = settings.getServer(id);
    if (server != null) {
      getLog().debug(DEBUG_MESSAGE_SETTINGS_HAS_ID);
      password = decrypt(server);
      username = server.getUsername();
      if (username != null && password != null) {
        getLog().debug(DEBUG_MESSAGE_SETTINGS_HAS_CREDS);
      } else {
        getLog().debug(DEBUG_MESSAGE_NO_CREDS);
      }
    } else {
      getLog().debug(DEBUG_MESSAGE_NO_SERVER_SECTION);
    }
  } else {
    getLog().debug(DEBUG_MESSAGE_NO_SETTINGS_FILE);
  }
}

代码示例来源:origin: eirslett/frontend-maven-plugin

static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) {
  if (mavenSession == null ||
      mavenSession.getSettings() == null ||
      mavenSession.getSettings().getProxies() == null ||
      mavenSession.getSettings().getProxies().isEmpty()) {
    return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
  } else {
    final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();
    final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size());
    for (Proxy mavenProxy : mavenProxies) {
      if (mavenProxy.isActive()) {
        mavenProxy = decryptProxy(mavenProxy, decrypter);
        proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(),
            mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts()));
      }
    }
    LOGGER.info("Found proxies: {}", proxies);
    return new ProxyConfig(proxies);
  }
}

代码示例来源:origin: danielflower/multi-module-maven-release-plugin

protected final void configureJsch(final Log log) {
  if (!disableSshAgent) {
    if (serverId != null) {
      final Server server = settings.getServer(serverId);
      if (server != null) {
        privateKey = privateKey == null ? server.getPrivateKey() : privateKey;
        passphrase = passphrase == null ? server.getPassphrase() : passphrase;
      } else {
        log.warn(format("No server configuration in Maven settings found with id %s", serverId));
      }
    }
    JschConfigSessionFactory.setInstance(new SshAgentSessionFactory(log, knownHosts, privateKey, passphrase));
  }
}

代码示例来源:origin: apache/maven

if ( settings.isUsePluginRegistry() )
List<String> pluginGroups = settings.getPluginGroups();
    if ( StringUtils.isBlank( pluginGroup ) )
List<Server> servers = settings.getServers();
    validateStringNotEmpty( problems, "servers.server[" + i + "].id", server.getId(), null );
    if ( !serverIds.add( server.getId() ) )
             "must be unique but found duplicate server with id " + server.getId() );
List<Mirror> mirrors = settings.getMirrors();
    validateStringNotEmpty( problems, "mirrors.mirror.id", mirror.getId(), mirror.getUrl() );
List<Profile> profiles = settings.getProfiles();
List<Proxy> proxies = settings.getProxies();
    if ( !proxyIds.add( proxy.getId() ) )
             "must be unique but found duplicate proxy with id " + proxy.getId() );
    validateStringNotEmpty( problems, "proxies.proxy.host", proxy.getHost(), proxy.getId() );

代码示例来源:origin: raydac/mvn-golang

@Nullable
private ProxySettings extractProxySettings() {
 final ProxySettings result;
 if (this.isUseMavenProxy()) {
  final Proxy activeMavenProxy = this.settings == null ? null : this.settings.getActiveProxy();
  result = activeMavenProxy == null ? null : new ProxySettings(activeMavenProxy);
  getLog().debug("Detected maven proxy : " + result);
 } else {
  result = this.proxy;
  if (result != null) {
   getLog().debug("Defined proxy : " + result);
  }
 }
 return result;
}

代码示例来源:origin: apache/maven

request.setOffline( settings.isOffline() );
request.setInteractiveMode( settings.isInteractiveMode() );
request.setPluginGroups( settings.getPluginGroups() );
request.setLocalRepositoryPath( settings.getLocalRepository() );
for ( Server server : settings.getServers() )
  server = server.clone();
for ( Proxy proxy : settings.getProxies() )
  if ( !proxy.isActive() )
  proxy = proxy.clone();
for ( Mirror mirror : settings.getMirrors() )
  mirror = mirror.clone();
request.setActiveProfiles( settings.getActiveProfiles() );
for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
  if ( settings.getActiveProfiles().contains( rawProfile.getId() ) )

相关文章