/**
   * Use the async http client library to download artifacts and metadata.
   *
   * @param artifactDownloads The artifact downloads to perform, may be {@code null} or empty.
   * @param metadataDownloads The metadata downloads to perform, may be {@code null} or empty.
   */
  public void get(
      Collection<? extends ArtifactDownload> artifactDownloads,
      Collection<? extends MetadataDownload> metadataDownloads) {
    if (closed.get()) {
      throw new IllegalStateException("connector closed");
    }

    artifactDownloads = safe(artifactDownloads);
    metadataDownloads = safe(metadataDownloads);

    CountDownLatch latch = new CountDownLatch(artifactDownloads.size() + metadataDownloads.size());

    Collection<GetTask<?>> tasks = new ArrayList<GetTask<?>>();

    for (MetadataDownload download : metadataDownloads) {
      String resource = layout.getPath(download.getMetadata()).getPath();
      GetTask<?> task =
          new GetTask<MetadataTransfer>(
              resource,
              download.getFile(),
              download.getChecksumPolicy(),
              latch,
              download,
              METADATA,
              false);
      tasks.add(task);
      task.run();
    }

    for (ArtifactDownload download : artifactDownloads) {
      String resource = layout.getPath(download.getArtifact()).getPath();
      GetTask<?> task =
          new GetTask<ArtifactTransfer>(
              resource,
              download.isExistenceCheck() ? null : download.getFile(),
              download.getChecksumPolicy(),
              latch,
              download,
              ARTIFACT,
              true);
      tasks.add(task);
      task.run();
    }

    try {
      latch.await();

      for (GetTask<?> task : tasks) {
        task.flush();
      }
    } catch (InterruptedException e) {
      for (GetTask<?> task : tasks) {
        task.flush(e);
      }
    }
  }
Пример #2
0
 @Override
 public void get(
     Collection<? extends ArtifactDownload> artifactDownloads,
     Collection<? extends MetadataDownload> metadataDownloads) {
   if (artifactDownloads != null) {
     for (ArtifactDownload a : artifactDownloads) {
       a.setException(new ArtifactNotFoundException(a.getArtifact(), repository));
     }
   }
   if (metadataDownloads != null) {
     for (MetadataDownload m : metadataDownloads) {
       m.setException(new MetadataNotFoundException(m.getMetadata(), repository));
     }
   }
 }