Beispiel #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);
 }
Beispiel #2
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);
              }
            }
          }
        });
  }
  @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();
    }
  }
Beispiel #4
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();
    }
  }