Exemple #1
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);
 }
Exemple #2
0
 public boolean exists(Artifact artifact) {
   ResolvedResource artifactRef = getArtifactRef(artifact, null);
   if (artifactRef != null) {
     return artifactRef.getResource().exists();
   }
   return false;
 }
Exemple #3
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;
 }
Exemple #4
0
 public ArtifactOrigin locate(Artifact artifact) {
   ArtifactOrigin origin = getRepositoryCacheManager().getSavedArtifactOrigin(toSystem(artifact));
   if (!ArtifactOrigin.isUnknown(origin)) {
     return origin;
   }
   ResolvedResource artifactRef = getArtifactRef(artifact, null);
   if (artifactRef != null && artifactRef.getResource().exists()) {
     return new ArtifactOrigin(
         artifact, artifactRef.getResource().isLocal(), artifactRef.getResource().getName());
   }
   return null;
 }
Exemple #5
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);
  }
Exemple #6
0
  public ResolvedModuleRevision parse(
      final ResolvedResource mdRef, DependencyDescriptor dd, ResolveData data)
      throws ParseException {

    DependencyDescriptor nsDd = dd;
    dd = toSystem(nsDd);

    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    ModuleDescriptorParser parser =
        ModuleDescriptorParserRegistry.getInstance().getParser(mdRef.getResource());
    if (parser == null) {
      Message.warn("no module descriptor parser available for " + mdRef.getResource());
      return null;
    }
    Message.verbose("\t" + getName() + ": found md file for " + mrid);
    Message.verbose("\t\t=> " + mdRef);
    Message.debug("\tparser = " + parser);

    ModuleRevisionId resolvedMrid = mrid;

    // first check if this dependency has not yet been resolved
    if (getSettings().getVersionMatcher().isDynamic(mrid)) {
      resolvedMrid = ModuleRevisionId.newInstance(mrid, mdRef.getRevision());
      IvyNode node = data.getNode(resolvedMrid);
      if (node != null && node.getModuleRevision() != null) {
        // this revision has already be resolved : return it
        if (node.getDescriptor() != null && node.getDescriptor().isDefault()) {
          Message.verbose(
              "\t"
                  + getName()
                  + ": found already resolved revision: "
                  + resolvedMrid
                  + ": but it's a default one, maybe we can find a better one");
        } else {
          Message.verbose("\t" + getName() + ": revision already resolved: " + resolvedMrid);
          node.getModuleRevision().getReport().setSearched(true);
          return node.getModuleRevision();
        }
      }
    }

    Artifact moduleArtifact = parser.getMetadataArtifact(resolvedMrid, mdRef.getResource());
    return getRepositoryCacheManager()
        .cacheModuleDescriptor(this, mdRef, dd, moduleArtifact, downloader, getCacheOptions(data));
  }
Exemple #7
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);
              }
            }
          }
        });
  }
Exemple #8
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.");
     }
   }
 }
Exemple #9
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;
  }
Exemple #10
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);
   }
 }
Exemple #11
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();
    }
  }