コード例 #1
0
  private Registry readDefaultConfiguration() {
    // if it contains some old configuration, remove it (Archiva 0.9)
    registry.removeSubset(KEY);

    try {
      registry.addConfigurationFromResource(
          "org/apache/archiva/configuration/default-archiva.xml", KEY);
      this.isConfigurationDefaulted = true;
    } catch (RegistryException e) {
      throw new ConfigurationRuntimeException(
          "Fatal error: Unable to find the built-in default configuration and load it into the registry",
          e);
    }
    return registry.getSubset(KEY);
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  private Configuration load() {
    // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys
    // properties)
    Registry subset = registry.getSubset(KEY);
    if (subset.getString("version") == null) {
      // a little autodetection of v1, even if version is omitted (this was previously allowed)
      if (subset.getSubset("repositoryScanning").isEmpty()) {
        // only for empty, or v < 1
        subset = readDefaultConfiguration();
      }
    }

    Configuration config = new ConfigurationRegistryReader().read(subset);

    config.getRepositoryGroups();
    config.getRepositoryGroupsAsMap();
    if (!config.getRepositories().isEmpty()) {
      for (V1RepositoryConfiguration r : config.getRepositories()) {
        r.setScanned(r.isIndexed());

        if (StringUtils.startsWith(r.getUrl(), "file://")) {
          r.setLocation(r.getUrl().substring(7));
          config.addManagedRepository(r);
        } else if (StringUtils.startsWith(r.getUrl(), "file:")) {
          r.setLocation(r.getUrl().substring(5));
          config.addManagedRepository(r);
        } else if (StringUtils.isEmpty(r.getUrl())) {
          // in case of empty url we can consider it as a managed one
          // check if location is null
          // file://${appserver.base}/repositories/${id}
          if (StringUtils.isEmpty(r.getLocation())) {
            r.setLocation("file://${appserver.base}/repositories/" + r.getId());
          }
          config.addManagedRepository(r);
        } else {
          RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
          repo.setId(r.getId());
          repo.setLayout(r.getLayout());
          repo.setName(r.getName());
          repo.setUrl(r.getUrl());
          config.addRemoteRepository(repo);
        }
      }

      // Prevent duplicate repositories from showing up.
      config.getRepositories().clear();

      registry.removeSubset(KEY + ".repositories");
    }

    if (!CollectionUtils.isEmpty(config.getRemoteRepositories())) {
      List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
      for (RemoteRepositoryConfiguration repo : remoteRepos) {
        // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be
        // created in configuration.
        if (StringUtils.isBlank(repo.getUsername())) {
          repo.setUsername(null);
        }

        if (StringUtils.isBlank(repo.getPassword())) {
          repo.setPassword(null);
        }
      }
    }

    if (!config.getProxyConnectors().isEmpty()) {
      // Fix Proxy Connector Settings.

      // Create a copy of the list to read from (to prevent concurrent modification exceptions)
      List<ProxyConnectorConfiguration> proxyConnectorList =
          new ArrayList<>(config.getProxyConnectors());
      // Remove the old connector list.
      config.getProxyConnectors().clear();

      for (ProxyConnectorConfiguration connector : proxyConnectorList) {
        // Fix policies
        boolean connectorValid = true;

        Map<String, String> policies = new HashMap<>();
        // Make copy of policies
        policies.putAll(connector.getPolicies());
        // Clear out policies
        connector.getPolicies().clear();

        // Work thru policies. cleaning them up.
        for (Entry<String, String> entry : policies.entrySet()) {
          String policyId = entry.getKey();
          String setting = entry.getValue();

          // Upgrade old policy settings.
          if ("releases".equals(policyId) || "snapshots".equals(policyId)) {
            if ("ignored".equals(setting)) {
              setting = AbstractUpdatePolicy.ALWAYS;
            } else if ("disabled".equals(setting)) {
              setting = AbstractUpdatePolicy.NEVER;
            }
          } else if ("cache-failures".equals(policyId)) {
            if ("ignored".equals(setting)) {
              setting = CachedFailuresPolicy.NO;
            } else if ("cached".equals(setting)) {
              setting = CachedFailuresPolicy.YES;
            }
          } else if ("checksum".equals(policyId)) {
            if ("ignored".equals(setting)) {
              setting = ChecksumPolicy.IGNORE;
            }
          }

          // Validate existance of policy key.
          if (policyExists(policyId)) {
            Policy policy = findPolicy(policyId);
            // Does option exist?
            if (!policy.getOptions().contains(setting)) {
              setting = policy.getDefaultOption();
            }
            connector.addPolicy(policyId, setting);
          } else {
            // Policy key doesn't exist. Don't add it to golden version.
            log.warn("Policy [{}] does not exist.", policyId);
          }
        }

        if (connectorValid) {
          config.addProxyConnector(connector);
        }
      }

      // Normalize the order fields in the proxy connectors.
      Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap =
          config.getProxyConnectorAsMap();

      for (List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values()) {
        // Sort connectors by order field.
        Collections.sort(connectors, ProxyConnectorConfigurationOrderComparator.getInstance());

        // Normalize the order field values.
        int order = 1;
        for (ProxyConnectorConfiguration connector : connectors) {
          connector.setOrder(order++);
        }
      }
    }

    return config;
  }