Esempio n. 1
0
 private ResolvedModuleRevision checkForcedResolvedModuleRevision(ResolvedModuleRevision rmr) {
   if (rmr == null) {
     return null;
   }
   if (!isForce() || rmr.isForce()) {
     return rmr;
   }
   return new ResolvedModuleRevision(
       rmr.getResolver(), rmr.getArtifactResolver(), rmr.getDescriptor(), rmr.getReport(), true);
 }
Esempio n. 2
0
  protected boolean shouldReturnResolvedModule(DependencyDescriptor dd, ResolvedModuleRevision mr) {
    // a resolved module revision has already been found by a prior dependency resolver
    // let's see if it should be returned and bypass this resolver

    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid);
    boolean shouldReturn = mr.isForce();
    shouldReturn |= !isDynamic && !mr.getDescriptor().isDefault();
    shouldReturn &= !isForce();

    return shouldReturn;
  }
Esempio n. 3
0
  public void testTarResourceInclusion() throws Exception {
    Locale oldLocale = Locale.getDefault();

    try {
      // set the locale to UK as workaround for SUN bug 6240963
      Locale.setDefault(Locale.UK);

      // Create and configure resolver
      PackagerResolver resolver = new PackagerResolver();
      resolver.setSettings(settings);
      String repoRoot =
          new File("test/repositories/IVY-1179/repo").toURI().toURL().toExternalForm();
      resolver.addIvyPattern(repoRoot + "[organisation]/[module]/[revision]/ivy.xml");
      resolver.setPackagerPattern(repoRoot + "[organisation]/[module]/[revision]/packager.xml");
      resolver.setBuildRoot(builddir);
      resolver.setResourceCache(cachedir);
      resolver.setPreserveBuildDirectories(true);
      resolver.setVerbose(true);

      resolver.setProperty(
          "packager.website.url",
          new File("test/repositories/IVY-1179/website").toURI().toURL().toExternalForm());

      resolver.setName("packager");

      // Get module descriptor
      ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "B", "1.0");
      ResolvedModuleRevision rmr =
          resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);

      // Download artifact
      Artifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "B", "jar", "jar");
      resolver.download(new Artifact[] {artifact}, downloadOptions());

      // assert that the file B.jar is extracted from the archive
      File jar = new File(builddir, "org/B/1.0/artifacts/jars/B.jar");
      assertTrue(jar.exists());

      // assert that the file README is not extracted from the archive
      File readme = new File(builddir, "org/B/1.0/extract/B-1.0/README");
      assertFalse(readme.exists());
    } finally {
      Locale.setDefault(oldLocale);
    }
  }
Esempio n. 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();
    }
  }
 private void assertFound(String module, ResolvedModuleRevision rmr) {
   assertNotNull(rmr);
   assertEquals(module, rmr.getId().toString());
 }
Esempio n. 6
0
  public void testFile() throws Exception {
    Locale oldLocale = Locale.getDefault();

    try {
      // set the locale to UK as workaround for SUN bug 6240963
      Locale.setDefault(Locale.UK);

      // Create and configure resolver
      PackagerResolver resolver = new PackagerResolver();
      resolver.setSettings(settings);
      String repoRoot =
          new File("test/repositories/packager/repo").toURI().toURL().toExternalForm();
      resolver.addIvyPattern(repoRoot + "[organisation]/[module]/[revision]/ivy.xml");
      resolver.setPackagerPattern(repoRoot + "[organisation]/[module]/[revision]/packager.xml");
      resolver.setBuildRoot(builddir);
      resolver.setResourceCache(cachedir);
      resolver.setPreserveBuildDirectories(true);
      resolver.setVerbose(true);

      resolver.setProperty(
          "packager.website.url",
          new File("test/repositories/packager/website").toURI().toURL().toExternalForm());

      resolver.setName("packager");
      assertEquals("packager", resolver.getName());

      // Get module descriptor
      ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "mod", "1.0");
      ResolvedModuleRevision rmr =
          resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
      assertNotNull(rmr);

      assertEquals(mrid, rmr.getId());
      Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
      assertEquals(pubdate, rmr.getPublicationDate());

      // Download artifact
      Artifact artifact = new DefaultArtifact(mrid, pubdate, "mod", "jar", "jar");
      DownloadReport report = resolver.download(new Artifact[] {artifact}, downloadOptions());
      assertNotNull(report);

      assertEquals(1, report.getArtifactsReports().length);

      ArtifactDownloadReport ar = report.getArtifactReport(artifact);
      System.out.println("downloaddetails: " + ar.getDownloadDetails());
      assertNotNull(ar);

      assertEquals(artifact, ar.getArtifact());
      assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());

      // Verify resource cache now contains the distribution archive
      assertTrue(new File(cachedir, "mod-1.0.tar.gz").exists());

      // Download again, should use Ivy cache this time
      report = resolver.download(new Artifact[] {artifact}, downloadOptions());
      assertNotNull(report);

      assertEquals(1, report.getArtifactsReports().length);

      ar = report.getArtifactReport(artifact);
      assertNotNull(ar);

      assertEquals(artifact, ar.getArtifact());
      assertEquals(DownloadStatus.NO, ar.getDownloadStatus());

      // Now download the maven2 artifact
      artifact = DefaultArtifact.cloneWithAnotherName(artifact, "foobar-janfu");
      report = resolver.download(new Artifact[] {artifact}, downloadOptions());
      assertNotNull(report);

      assertEquals(1, report.getArtifactsReports().length);

      ar = report.getArtifactReport(artifact);
      assertNotNull(ar);

      assertEquals(artifact, ar.getArtifact());
      assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    } finally {
      Locale.setDefault(oldLocale);
    }
  }