示例#1
0
  private ModuleRevisionId getRevision(
      ResolvedResource ivyRef, ModuleRevisionId askedMrid, ModuleDescriptor md)
      throws ParseException {
    Map allAttributes = new HashMap();
    allAttributes.putAll(md.getQualifiedExtraAttributes());
    allAttributes.putAll(askedMrid.getQualifiedExtraAttributes());

    String revision = ivyRef.getRevision();
    if (revision == null) {
      Message.debug("no revision found in reference for " + askedMrid);
      if (getSettings().getVersionMatcher().isDynamic(askedMrid)) {
        if (md.getModuleRevisionId().getRevision() == null) {
          revision = "working@" + getName();
        } else {
          Message.debug("using " + askedMrid);
          revision = askedMrid.getRevision();
        }
      } else {
        Message.debug("using " + askedMrid);
        revision = askedMrid.getRevision();
      }
    }

    return ModuleRevisionId.newInstance(
        askedMrid.getOrganisation(),
        askedMrid.getName(),
        askedMrid.getBranch(),
        revision,
        allAttributes);
  }
  public void testUpdateWithExcludeConfigurations1() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl =
        new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs1.xml")
            .toURL();
    XmlModuleDescriptorUpdater.update(
        settingsUrl,
        buffer,
        getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] {"myconf2"}));

    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", 3, configs.length);

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

    // test that the other configurations aren't removed
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
  }
  public void testUpdateWithExcludeConfigurations4() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl =
        new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs4.xml")
            .toURL();
    XmlModuleDescriptorUpdater.update(
        settingsUrl,
        buffer,
        getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] {"myconf2"}));

    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
    Artifact[] artifacts = updatedMd.getAllArtifacts();
    assertNotNull("Published artifacts shouldn't be null", artifacts);
    assertEquals("Number of published artifacts incorrect", 4, artifacts.length);

    // test that the correct configuration has been removed
    for (int i = 0; i < artifacts.length; i++) {
      Artifact current = artifacts[i];
      List currentConfs = Arrays.asList(current.getConfigurations());
      assertTrue(
          "myconf2 hasn't been removed for artifact " + current.getName(),
          !currentConfs.contains("myconf2"));
    }
  }
示例#4
0
 private void resolveAndCheckRevision(
     ModuleDescriptor systemMd,
     ModuleRevisionId dependencyConstraint,
     ResolvedResource ivyRef,
     boolean isDynamic) {
   // we get the resolved module revision id from the descriptor: it may contain extra
   // attributes that were not included in the dependency constraint
   ModuleRevisionId resolvedMrid = systemMd.getResolvedModuleRevisionId();
   if (resolvedMrid.getRevision() == null
       || resolvedMrid.getRevision().length() == 0
       || resolvedMrid.getRevision().startsWith("working@")) {
     if (!isDynamic) {
       resolvedMrid =
           ModuleRevisionId.newInstance(resolvedMrid, dependencyConstraint.getRevision());
     } else if (ivyRef == null) {
       resolvedMrid = systemMd.getMetadataArtifact().getModuleRevisionId();
     } else if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) {
       resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@" + getName());
     } else {
       resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef.getRevision());
     }
   }
   if (isDynamic) {
     Message.verbose(
         "\t\t["
             + toSystem(resolvedMrid).getRevision()
             + "] "
             + dependencyConstraint.getModuleId());
   }
   systemMd.setResolvedModuleRevisionId(resolvedMrid);
   checkModuleDescriptorRevision(systemMd, dependencyConstraint);
 }
  public void testUpdateWithExcludeConfigurations5() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl =
        new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs5.xml")
            .toURL();
    XmlModuleDescriptorUpdater.update(
        settingsUrl,
        buffer,
        getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] {"myconf2"}));

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

    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 8, deps.length);

    // check that none of the dependencies contains myconf2
    for (int i = 0; i < deps.length; i++) {
      String name = deps[i].getDependencyId().getName();
      assertFalse(
          "Dependency " + name + " shouldn't have myconf2 as module configuration",
          Arrays.asList(deps[i].getModuleConfigurations()).contains("myconf2"));
      assertEquals(
          "Dependency " + name + " shouldn't have a dependency artifact for configuration myconf2",
          0,
          deps[i].getDependencyArtifacts("myconf2").length);
    }
  }
 private void fillModuleDependencies()
     throws IvySettingsNotFoundException, IvySettingsFileReadException {
   final ModuleDescriptor descriptor = ivyManager.getModuleDescriptor(module);
   if (descriptor != null) {
     final DependencyDescriptor[] ivyDependencies = descriptor.getDependencies();
     for (Module dependencyModule :
         IntellijUtils.getAllModulesWithIvyIdeaFacet(module.getProject())) {
       if (!module.equals(dependencyModule)) {
         for (DependencyDescriptor ivyDependency : ivyDependencies) {
           final ModuleId ivyDependencyId = ivyDependency.getDependencyId();
           final ModuleId dependencyModuleId = getModuleId(dependencyModule);
           if (ivyDependencyId.equals(dependencyModuleId)) {
             LOGGER.info(
                 "Recognized dependency "
                     + ivyDependency
                     + " as intellij module '"
                     + dependencyModule.getName()
                     + "' in this project!");
             moduleDependencies.put(dependencyModuleId, dependencyModule);
             break;
           }
         }
       }
     }
   }
 }
 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);
   }
 }
  private ModuleDescriptor findProject(DependencyDescriptor descriptor) {
    String projectPathValue = descriptor.getAttribute(DependencyDescriptorFactory.PROJECT_PATH_KEY);
    if (projectPathValue == null) {
      return null;
    }
    Project project = gradle.getRootProject().project(projectPathValue);
    Module projectModule = ((ProjectInternal) project).getModule();
    ModuleDescriptor projectDescriptor =
        moduleDescriptorConverter.convert(
            project.getConfigurations().getAll(),
            projectModule,
            IvyContext.getContext().getIvy().getSettings());

    for (DependencyArtifactDescriptor artifactDescriptor : descriptor.getAllDependencyArtifacts()) {
      for (Artifact artifact : projectDescriptor.getAllArtifacts()) {
        if (artifact.getName().equals(artifactDescriptor.getName())
            && artifact.getExt().equals(artifactDescriptor.getExt())) {
          String path =
              artifact.getExtraAttribute(DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE);
          ReflectionUtil.invoke(
              artifactDescriptor,
              "setExtraAttribute",
              new Object[] {DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE, path});
        }
      }
    }

    return projectDescriptor;
  }
 /**
  * Return true if this module match the DependencyDescriptor with the given versionMatcher. If
  * this module has no version defined, then true is always returned.
  */
 public boolean match(DependencyDescriptor descriptor, VersionMatcher versionMatcher) {
   ModuleDescriptor md = module;
   return md.getResolvedModuleRevisionId().getRevision() == null
       || md.getResolvedModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision())
       || versionMatcher.accept(descriptor.getDependencyRevisionId(), md);
   // Checking md.getResolvedModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()
   // allow to consider any local non resolved ivy.xml
   // as a valid module.
 }
示例#10
0
 protected long getPublicationDate(
     ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) {
   if (md.getPublicationDate() != null) {
     return md.getPublicationDate().getTime();
   }
   ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data);
   if (artifactRef != null) {
     return artifactRef.getLastModified();
   }
   return -1;
 }
示例#11
0
 protected ResolvedResource findFirstArtifactRef(
     ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) {
   ResolvedResource ret = null;
   String[] conf = md.getConfigurationsNames();
   for (int i = 0; i < conf.length; i++) {
     Artifact[] artifacts = md.getArtifacts(conf[i]);
     for (int j = 0; j < artifacts.length; j++) {
       ret = getArtifactRef(artifacts[j], data.getDate());
       if (ret != null) {
         return ret;
       }
     }
   }
   return null;
 }
示例#12
0
 private void resolveAndCheckPublicationDate(
     DependencyDescriptor systemDd,
     ModuleDescriptor systemMd,
     ModuleRevisionId systemMrid,
     ResolveData data) {
   // resolve and check publication date
   if (data.getDate() != null) {
     long pubDate = getPublicationDate(systemMd, systemDd, data);
     if (pubDate > data.getDate().getTime()) {
       throw new UnresolvedDependencyException(
           "\t"
               + getName()
               + ": unacceptable publication date => was="
               + new Date(pubDate)
               + " required="
               + data.getDate());
     } else if (pubDate == -1) {
       throw new UnresolvedDependencyException(
           "\t"
               + getName()
               + ": impossible to guess publication date: artifact missing for "
               + systemMrid);
     }
     systemMd.setResolvedPublicationDate(new Date(pubDate));
   }
 }
 @Nullable
 private ModuleId getModuleId(Module module)
     throws IvySettingsNotFoundException, IvySettingsFileReadException {
   if (!moduleDependencies.values().contains(module)) {
     final ModuleDescriptor ivyModuleDescriptor = ivyManager.getModuleDescriptor(module);
     if (ivyModuleDescriptor != null) {
       moduleDependencies.put(ivyModuleDescriptor.getModuleRevisionId().getModuleId(), module);
     }
   }
   for (ModuleId moduleId : moduleDependencies.keySet()) {
     if (module.equals(moduleDependencies.get(moduleId))) {
       return moduleId;
     }
   }
   return null;
 }
 public void resolve(DependencyMetaData dependency, BuildableModuleVersionResolveResult result) {
   DependencyDescriptor descriptor = dependency.getDescriptor();
   if (descriptor instanceof ProjectDependencyDescriptor) {
     ProjectDependencyDescriptor desc = (ProjectDependencyDescriptor) descriptor;
     ModuleDescriptor moduleDescriptor = projectModuleRegistry.findProject(desc);
     final ModuleRevisionId moduleRevisionId = moduleDescriptor.getModuleRevisionId();
     final DefaultModuleVersionIdentifier moduleVersionIdentifier =
         new DefaultModuleVersionIdentifier(
             moduleRevisionId.getOrganisation(),
             moduleRevisionId.getName(),
             moduleRevisionId.getRevision());
     result.resolved(moduleVersionIdentifier, moduleDescriptor, artifactResolver);
   } else {
     resolver.resolve(dependency, result);
   }
 }
 /**
  * This ModuleInSort has already been analyzed. It is either already added to the sorted list,
  * either it is included in a loop and will be added when the root of the loop will be added to
  * the list.
  */
 public boolean isProcessed() {
   if (isSorted || isLoopIntermediateElement) {
     Message.debug("Module descriptor is processed : " + module.getModuleRevisionId().toString());
     return true;
   } else {
     return false;
   }
 }
 /** This ModuleInSort has been placed on the sorted list */
 public boolean isSorted() {
   if (isSorted) {
     Message.debug(
         "Module descriptor already sorted : " + module.getModuleRevisionId().toString());
     return true;
   } else {
     return false;
   }
 }
  // 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;
  }
示例#18
0
  private void cacheModuleDescriptor(
      ModuleDescriptor systemMd,
      ModuleRevisionId systemMrid,
      ResolvedResource ivyRef,
      ResolvedModuleRevision rmr) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();

    final ModuleDescriptorParser parser = systemMd.getParser();

    // the metadata artifact which was used to cache the original metadata file
    Artifact requestedMetadataArtifact =
        ivyRef == null
            ? systemMd.getMetadataArtifact()
            : parser.getMetadataArtifact(
                ModuleRevisionId.newInstance(systemMrid, ivyRef.getRevision()),
                ivyRef.getResource());

    cacheManager.originalToCachedModuleDescriptor(
        this,
        ivyRef,
        requestedMetadataArtifact,
        rmr,
        new ModuleDescriptorWriter() {
          public void write(
              ResolvedResource originalMdResource, ModuleDescriptor md, File src, File dest)
              throws IOException, ParseException {
            if (originalMdResource == null) {
              // a basic ivy file is written containing default data
              XmlModuleDescriptorWriter.write(md, dest);
            } else {
              // copy and update ivy file from source to cache
              parser.toIvyFile(
                  new FileInputStream(src), originalMdResource.getResource(), dest, md);
              long repLastModified = originalMdResource.getLastModified();
              if (repLastModified > 0) {
                dest.setLastModified(repLastModified);
              }
            }
          }
        });
  }
  public void testUpdateWithComments() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl =
        new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-with-comments.xml").toURL();
    XmlModuleDescriptorUpdater.update(
        settingsUrl,
        new BufferedOutputStream(buffer, 1024),
        getUpdateOptions("release", "mynewrev"));

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

    DependencyDescriptor[] dependencies = updatedMd.getDependencies();
    assertNotNull(dependencies);
    assertEquals(3, dependencies.length);
  }
示例#20
0
 protected void checkModuleDescriptorRevision(
     ModuleDescriptor systemMd, ModuleRevisionId systemMrid) {
   if (!getSettings().getVersionMatcher().accept(systemMrid, systemMd)) {
     throw new UnresolvedDependencyException(
         "\t"
             + getName()
             + ": unacceptable revision => was="
             + systemMd.getResolvedModuleRevisionId().getRevision()
             + " required="
             + systemMrid.getRevision());
   }
 }
  @Override
  public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
      throws ParseException {
    ModuleDescriptor moduleDescriptor = findProject(dd);
    if (moduleDescriptor == null) {
      return data.getCurrentResolvedModuleRevision();
    }

    IvyContext context = IvyContext.pushNewCopyContext();
    try {
      context.setDependencyDescriptor(dd);
      context.setResolveData(data);
      MetadataArtifactDownloadReport downloadReport =
          new MetadataArtifactDownloadReport(moduleDescriptor.getMetadataArtifact());
      downloadReport.setDownloadStatus(DownloadStatus.NO);
      downloadReport.setSearched(false);
      return new ResolvedModuleRevision(this, this, moduleDescriptor, downloadReport);
    } finally {
      IvyContext.popContext();
    }
  }
示例#22
0
  // ---------------------------------------------------------------------------
  public void doMakeAction(Rule rule) throws TablesawException {
    System.out.println("Ivy retrieving dependencies.");
    try {
      ModuleDescriptor md = m_resolveRule.getReport().getModuleDescriptor();

      Ivy ivy = m_resolveRule.getIvyInstance();

      String pattern;

      if (m_useWorkingDir && m_make.getWorkingDirectory() != null) {
        pattern = m_make.getWorkingDirectory().getPath();
        pattern += "/" + m_retrievePattern;
      } else pattern = m_retrievePattern;

      if (m_make.isVerbose()) System.out.println("Ivy retrieve pattern: " + pattern);

      ivy.retrieve(md.getModuleRevisionId(), pattern, m_retreiveOptions);
    } catch (IOException ioe) {
      throw new TablesawException(ioe);
    }
  }
 private Artifact expectedIvyArtifact(
     Configuration configuration,
     ModuleDescriptor moduleDescriptor,
     Map<String, String> additionalExtraAttributes) {
   PublishArtifact publishArtifact = configuration.getArtifacts().iterator().next();
   Map<String, String> extraAttributes =
       WrapUtil.toMap(Dependency.CLASSIFIER, publishArtifact.getClassifier());
   extraAttributes.putAll(additionalExtraAttributes);
   return new DefaultArtifact(
       moduleDescriptor.getModuleRevisionId(),
       publishArtifact.getDate(),
       publishArtifact.getName(),
       publishArtifact.getType(),
       publishArtifact.getExtension(),
       extraAttributes);
 }
示例#24
0
 private void checkNotConvertedExclusionRule(
     ModuleDescriptor systemMd, ResolvedResource ivyRef, ResolveData data) {
   if (!getNamespace().equals(Namespace.SYSTEM_NAMESPACE)
       && !systemMd.isDefault()
       && data.getSettings().logNotConvertedExclusionRule()
       && systemMd instanceof DefaultModuleDescriptor) {
     DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) systemMd;
     if (dmd.isNamespaceUseful()) {
       Message.warn(
           "the module descriptor "
               + ivyRef.getResource()
               + " has information which can't be converted into "
               + "the system namespace. "
               + "It will require the availability of the namespace '"
               + getNamespace().getName()
               + "' to be fully usable.");
     }
   }
 }
示例#25
0
  public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
      throws ParseException {
    IvyContext context = IvyContext.pushNewCopyContext();
    try {
      ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
      if (mr != null) {
        if (shouldReturnResolvedModule(dd, mr)) {
          return mr;
        }
      }

      if (isForce()) {
        dd =
            dd.clone(
                ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), "latest.integration"));
      }
      DependencyDescriptor systemDd = dd;
      DependencyDescriptor nsDd = fromSystem(dd);
      context.setDependencyDescriptor(systemDd);
      context.setResolveData(data);

      clearIvyAttempts();
      clearArtifactAttempts();
      ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
      ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();

      checkRevision(systemMrid);

      boolean isDynamic = getAndCheckIsDynamic(systemMrid);

      // we first search for the dependency in cache
      ResolvedModuleRevision rmr = null;
      rmr = findModuleInCache(systemDd, data);
      if (rmr != null) {
        if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
          Message.verbose(
              "\t"
                  + getName()
                  + ": found revision in cache: "
                  + systemMrid
                  + " (resolved by "
                  + rmr.getResolver().getName()
                  + "): but it's a default one, maybe we can find a better one");
        } else if (isForce() && rmr.getResolver() != this) {
          Message.verbose(
              "\t"
                  + getName()
                  + ": found revision in cache: "
                  + systemMrid
                  + " (resolved by "
                  + rmr.getResolver().getName()
                  + "): but we are in force mode, let's try to find one ourself");
        } else {
          Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
          return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
        }
      }
      if (data.getOptions().isUseCacheOnly()) {
        throw new UnresolvedDependencyException(
            "\t" + getName() + " (useCacheOnly) : no ivy file found for " + systemMrid, false);
      }

      checkInterrupted();

      ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
      checkInterrupted();

      // get module descriptor
      ModuleDescriptor nsMd;
      ModuleDescriptor systemMd = null;
      if (ivyRef == null) {
        if (!isAllownomd()) {
          throw new UnresolvedDependencyException(
              "\t" + getName() + ": no ivy file found for " + systemMrid, false);
        }
        nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd.getAllDependencyArtifacts());
        ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
        checkInterrupted();
        if (artifactRef == null) {
          throw new UnresolvedDependencyException(
              "\t" + getName() + ": no ivy file nor artifact found for " + systemMrid, false);
        } else {
          long lastModified = artifactRef.getLastModified();
          if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
            ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
          }
          Message.verbose(
              "\t" + getName() + ": no ivy file found for " + systemMrid + ": using default data");
          if (isDynamic) {
            nsMd.setResolvedModuleRevisionId(
                ModuleRevisionId.newInstance(nsMrid, artifactRef.getRevision()));
          }
          systemMd = toSystem(nsMd);
          MetadataArtifactDownloadReport madr =
              new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
          madr.setDownloadStatus(DownloadStatus.NO);
          madr.setSearched(true);
          rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
          getRepositoryCacheManager()
              .cacheModuleDescriptor(
                  this,
                  artifactRef,
                  toSystem(dd),
                  systemMd.getAllArtifacts()[0],
                  null,
                  getCacheOptions(data));
        }
      } else {
        if (ivyRef instanceof MDResolvedResource) {
          rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
        }
        if (rmr == null) {
          rmr = parse(ivyRef, systemDd, data);
          if (rmr == null) {
            throw new UnresolvedDependencyException();
          }
        }
        if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
          return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
        } else {
          nsMd = rmr.getDescriptor();

          // check descriptor data is in sync with resource revision and names
          systemMd = toSystem(nsMd);
          if (isCheckconsistency()) {
            checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
            checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
          } else {
            if (systemMd instanceof DefaultModuleDescriptor) {
              DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
              ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
              defaultMd.setModuleRevisionId(revision);
              defaultMd.setResolvedModuleRevisionId(revision);
            } else {
              Message.warn(
                  "consistency disabled with instance of non DefaultModuleDescriptor..."
                      + " module info can't be updated, so consistency check will be done");
              checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
              checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
            }
          }
          rmr =
              new ResolvedModuleRevision(
                  this, this, systemMd, toSystem(rmr.getReport()), isForce());
        }
      }

      resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
      resolveAndCheckPublicationDate(systemDd, systemMd, systemMrid, data);
      checkNotConvertedExclusionRule(systemMd, ivyRef, data);

      if (ivyRef == null || ivyRef.getResource() != null) {
        cacheModuleDescriptor(systemMd, systemMrid, ivyRef, rmr);
      }

      return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
    } catch (UnresolvedDependencyException ex) {
      if (ex.getMessage().length() > 0) {
        if (ex.isError()) {
          Message.error(ex.getMessage());
        } else {
          Message.verbose(ex.getMessage());
        }
      }
      return data.getCurrentResolvedModuleRevision();
    } finally {
      IvyContext.popContext();
    }
  }
 public DependencyDescriptor[] getDependencies() {
   return module.getDependencies();
 }
 public String toString() {
   return module.getModuleRevisionId().toString();
 }
示例#28
0
 // private boolean isResolved(ResolveData data, ModuleRevisionId mrid) {
 // IvyNode node = getSystemNode(data, mrid);
 // return node != null && node.getModuleRevision() != null;
 // }
 //
 private void checkDescriptorConsistency(
     ModuleRevisionId mrid, ModuleDescriptor md, ResolvedResource ivyRef) throws ParseException {
   boolean ok = true;
   StringBuffer errors = new StringBuffer();
   if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) {
     Message.error(
         "\t"
             + getName()
             + ": bad organisation found in "
             + ivyRef.getResource()
             + ": expected='"
             + mrid.getOrganisation()
             + "' found='"
             + md.getModuleRevisionId().getOrganisation()
             + "'");
     errors.append(
         "bad organisation: expected='"
             + mrid.getOrganisation()
             + "' found='"
             + md.getModuleRevisionId().getOrganisation()
             + "'; ");
     ok = false;
   }
   if (!mrid.getName().equals(md.getModuleRevisionId().getName())) {
     Message.error(
         "\t"
             + getName()
             + ": bad module name found in "
             + ivyRef.getResource()
             + ": expected='"
             + mrid.getName()
             + " found='"
             + md.getModuleRevisionId().getName()
             + "'");
     errors.append(
         "bad module name: expected='"
             + mrid.getName()
             + "' found='"
             + md.getModuleRevisionId().getName()
             + "'; ");
     ok = false;
   }
   if (mrid.getBranch() != null
       && !mrid.getBranch().equals(md.getModuleRevisionId().getBranch())) {
     Message.error(
         "\t"
             + getName()
             + ": bad branch name found in "
             + ivyRef.getResource()
             + ": expected='"
             + mrid.getBranch()
             + " found='"
             + md.getModuleRevisionId().getBranch()
             + "'");
     errors.append(
         "bad branch name: expected='"
             + mrid.getBranch()
             + "' found='"
             + md.getModuleRevisionId().getBranch()
             + "'; ");
     ok = false;
   }
   if (ivyRef.getRevision() != null && !ivyRef.getRevision().startsWith("working@")) {
     ModuleRevisionId expectedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision());
     if (!getSettings().getVersionMatcher().accept(expectedMrid, md)) {
       Message.error(
           "\t"
               + getName()
               + ": bad revision found in "
               + ivyRef.getResource()
               + ": expected='"
               + ivyRef.getRevision()
               + " found='"
               + md.getModuleRevisionId().getRevision()
               + "'");
       errors.append(
           "bad revision: expected='"
               + ivyRef.getRevision()
               + "' found='"
               + md.getModuleRevisionId().getRevision()
               + "'; ");
       ok = false;
     }
   }
   if (!getSettings().getStatusManager().isStatus(md.getStatus())) {
     Message.error(
         "\t"
             + getName()
             + ": bad status found in "
             + ivyRef.getResource()
             + ": '"
             + md.getStatus()
             + "'");
     errors.append("bad status: '" + md.getStatus() + "'; ");
     ok = false;
   }
   for (Iterator it = mrid.getExtraAttributes().entrySet().iterator(); it.hasNext(); ) {
     Entry extra = (Entry) it.next();
     if (extra.getValue() != null
         && !extra.getValue().equals(md.getExtraAttribute((String) extra.getKey()))) {
       String errorMsg =
           "bad "
               + extra.getKey()
               + " found in "
               + ivyRef.getResource()
               + ": expected='"
               + extra.getValue()
               + "' found='"
               + md.getExtraAttribute((String) extra.getKey())
               + "'";
       Message.error("\t" + getName() + ": " + errorMsg);
       errors.append(errorMsg + ";");
       ok = false;
     }
   }
   if (!ok) {
     throw new ParseException(
         "inconsistent module descriptor file found in '" + ivyRef.getResource() + "': " + errors,
         0);
   }
 }
示例#29
0
  /**
   * When the resolver has many choices, this function helps choosing one
   *
   * @param rress the list of resolved resource which the resolver found to fit the requirement
   * @param rmdparser the parser of module descriptor
   * @param mrid the module being resolved
   * @param date the current date
   * @return the selected resource
   */
  public ResolvedResource findResource(
      ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
    String name = getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();

    ResolvedResource found = null;
    List sorted = getLatestStrategy().sort(rress);
    List rejected = new ArrayList();
    List foundBlacklisted = new ArrayList();
    IvyContext context = IvyContext.getContext();

    for (ListIterator iter = sorted.listIterator(sorted.size()); iter.hasPrevious(); ) {
      ResolvedResource rres = (ResolvedResource) iter.previous();
      // we start by filtering based on information already available,
      // even though we don't even know if the resource actually exist.
      // But checking for existence is most of the time more costly than checking
      // name, blacklisting and first level version matching
      if (filterNames(new ArrayList(Collections.singleton(rres.getRevision()))).isEmpty()) {
        Message.debug("\t" + name + ": filtered by name: " + rres);
        continue;
      }
      ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());

      ResolveData data = context.getResolveData();
      if (data != null
          && data.getReport() != null
          && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
        Message.debug("\t" + name + ": blacklisted: " + rres);
        rejected.add(rres.getRevision() + " (blacklisted)");
        foundBlacklisted.add(foundMrid);
        continue;
      }

      if (!versionMatcher.accept(mrid, foundMrid)) {
        Message.debug("\t" + name + ": rejected by version matcher: " + rres);
        rejected.add(rres.getRevision());
        continue;
      }
      if (rres.getResource() != null && !rres.getResource().exists()) {
        Message.debug("\t" + name + ": unreachable: " + rres + "; res=" + rres.getResource());
        rejected.add(rres.getRevision() + " (unreachable)");
        continue;
      }
      if ((date != null && rres.getLastModified() > date.getTime())) {
        Message.verbose("\t" + name + ": too young: " + rres);
        rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
        continue;
      }
      if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
        ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
        if (r == null) {
          Message.debug("\t" + name + ": impossible to get module descriptor resource: " + rres);
          rejected.add(rres.getRevision() + " (no or bad MD)");
          continue;
        }
        ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision().getDescriptor();
        if (md.isDefault()) {
          Message.debug(
              "\t"
                  + name
                  + ": default md rejected by version matcher"
                  + "requiring module descriptor: "
                  + rres);
          rejected.add(rres.getRevision() + " (MD)");
          continue;
        } else if (!versionMatcher.accept(mrid, md)) {
          Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
          rejected.add(rres.getRevision() + " (MD)");
          continue;
        } else {
          found = r;
        }
      } else {
        found = rres;
      }

      if (found != null) {
        break;
      }
    }
    if (found == null && !rejected.isEmpty()) {
      logAttempt(rejected.toString());
    }
    if (found == null && !foundBlacklisted.isEmpty()) {
      // all acceptable versions have been blacklisted, this means that an unsolvable conflict
      // has been found
      DependencyDescriptor dd = context.getDependencyDescriptor();
      IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
      ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
      cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
    }

    return found;
  }