コード例 #1
0
  public void testUpdateWithExcludeConfigurations3() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl =
        new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs3.xml")
            .toURL();

    XmlModuleDescriptorUpdater.update(
        settingsUrl,
        buffer,
        getUpdateOptions("release", "mynewrev")
            .setConfsToExclude(new String[] {"myconf2", "conf2"}));

    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd =
        parser.parseDescriptor(
            new IvySettings(),
            new ByteArrayInputStream(buffer.toByteArray()),
            new BasicResource("test", false, 0, 0, false),
            true);

    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 4, configs.length);

    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2"));

    // test that the other configurations aren't removed
    assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1"));
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
  }
 private void collectTargetConfiguration(
     DependencyDescriptor dependencyDescriptor,
     ConfigurationMetaData fromConfiguration,
     String mappingRhs,
     ModuleDescriptor targetModule,
     Collection<String> targetConfigs) {
   String[] dependencyConfigurations =
       dependencyDescriptor.getDependencyConfigurations(mappingRhs, fromConfiguration.getName());
   for (String target : dependencyConfigurations) {
     String candidate = target;
     int startFallback = candidate.indexOf('(');
     if (startFallback >= 0) {
       if (candidate.charAt(candidate.length() - 1) == ')') {
         String preferred = candidate.substring(0, startFallback);
         if (targetModule.getConfiguration(preferred) != null) {
           targetConfigs.add(preferred);
           continue;
         }
         candidate = candidate.substring(startFallback + 1, candidate.length() - 1);
       }
     }
     if (candidate.equals("*")) {
       Collections.addAll(targetConfigs, targetModule.getPublicConfigurationsNames());
       continue;
     }
     targetConfigs.add(candidate);
   }
 }
  // TODO - don't pass in 'from' configuration - the dependency should have whatever context it
  // needs
  public Set<ConfigurationMetaData> resolveTargetConfigurations(
      DependencyMetaData dependencyMetaData,
      ConfigurationMetaData fromConfiguration,
      ModuleVersionMetaData targetModuleVersion) {
    // TODO - resolve directly to config meta data
    ModuleDescriptor targetDescriptor = targetModuleVersion.getDescriptor();
    DependencyDescriptor dependencyDescriptor = dependencyMetaData.getDescriptor();
    Set<String> targetConfigurationNames = new LinkedHashSet<String>();
    for (String config : dependencyDescriptor.getModuleConfigurations()) {
      if (config.equals("*") || config.equals("%")) {
        collectTargetConfiguration(
            dependencyDescriptor,
            fromConfiguration,
            fromConfiguration.getName(),
            targetDescriptor,
            targetConfigurationNames);
      } else if (fromConfiguration.getHierarchy().contains(config)) {
        collectTargetConfiguration(
            dependencyDescriptor,
            fromConfiguration,
            config,
            targetDescriptor,
            targetConfigurationNames);
      }
    }

    Set<ConfigurationMetaData> targets = new LinkedHashSet<ConfigurationMetaData>();
    for (String targetConfigurationName : targetConfigurationNames) {
      // TODO - move this down below
      if (targetDescriptor.getConfiguration(targetConfigurationName) == null) {
        throw new RuntimeException(
            String.format(
                "Module version %s, configuration '%s' declares a dependency on configuration '%s' which is not declared in the module descriptor for %s",
                fromConfiguration.getModuleVersion().getId(),
                fromConfiguration.getName(),
                targetConfigurationName,
                targetModuleVersion.getId()));
      }
      ConfigurationMetaData targetConfiguration =
          targetModuleVersion.getConfiguration(targetConfigurationName);
      targets.add(targetConfiguration);
    }
    return targets;
  }