示例#1
0
  public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();

    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (int i = 0; i < artifacts.length; i++) {
      ArtifactDownloadReport adr =
          cacheManager.download(
              artifacts[i], artifactResourceResolver, downloader, getCacheDownloadOptions(options));
      if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
        if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
          Message.warn("\t" + adr);
        }
      } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
        Message.verbose("\t" + adr);
      } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
        Message.verbose("\t" + adr);
      } else {
        Message.info("\t" + adr);
      }
      dr.addArtifactReport(adr);
      checkInterrupted();
    }
    return dr;
  }
 @Override
 public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
   DownloadReport dr = new DownloadReport();
   for (Artifact artifact : artifacts) {
     ArtifactDownloadReport artifactDownloadReport = new ArtifactDownloadReport(artifact);
     String path =
         artifact.getExtraAttribute(DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE);
     if (path == null) {
       artifactDownloadReport.setDownloadStatus(DownloadStatus.FAILED);
     } else {
       File file = new File(path);
       artifactDownloadReport.setDownloadStatus(DownloadStatus.SUCCESSFUL);
       artifactDownloadReport.setArtifactOrigin(new ArtifactOrigin(artifact, true, getName()));
       artifactDownloadReport.setLocalFile(file);
       artifactDownloadReport.setSize(file.length());
     }
     dr.addArtifactReport(artifactDownloadReport);
   }
   return dr;
 }
示例#3
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);
    }
  }