Ejemplo n.º 1
0
  @Override
  public DiscoveryResult<MavenHostedRepository> discoverLocalContent(
      final MavenHostedRepository mavenRepository) throws IOException {
    final DiscoveryResult<MavenHostedRepository> discoveryResult =
        new DiscoveryResult<MavenHostedRepository>(mavenRepository);
    final WalkerContext context =
        new DefaultWalkerContext(
            mavenRepository, new ResourceStoreRequest("/"), new DefaultStoreWalkerFilter(), true);
    final PrefixCollectorProcessor prefixCollectorProcessor = new PrefixCollectorProcessor();
    context.getProcessors().add(prefixCollectorProcessor);

    try {
      walker.walk(context);
      final ParentOMatic parentOMatic = prefixCollectorProcessor.getParentOMatic();
      if (parentOMatic.getRoot().isLeaf()) {
        // tree is basically empty, so make the list too
        discoveryResult.recordSuccess(
            ID,
            "Repository crawled successfully (is empty)",
            new ArrayListPrefixSource(Collections.<String>emptyList()));
      } else {
        discoveryResult.recordSuccess(
            ID,
            "Repository crawled successfully",
            new ArrayListPrefixSource(getAllLeafPaths(parentOMatic, config.getLocalScrapeDepth())));
      }
    } catch (WalkerException e) {
      if (e.getWalkerContext().getStopCause() != null) {
        discoveryResult.recordError(ID, e.getWalkerContext().getStopCause());
      } else {
        discoveryResult.recordError(ID, e);
      }
    }
    return discoveryResult;
  }
Ejemplo n.º 2
0
  /**
   * Removes the snapshots from maven repository.
   *
   * @param repository the repository
   * @throws Exception the exception
   */
  protected SnapshotRemovalRepositoryResult removeSnapshotsFromMavenRepository(
      MavenRepository repository, SnapshotRemovalRequest request) {
    TaskUtil.checkInterruption();

    SnapshotRemovalRepositoryResult result =
        new SnapshotRemovalRepositoryResult(repository.getId(), 0, 0, true);

    if (!repository.getLocalStatus().shouldServiceRequest()) {
      return result;
    }

    // we are already processed here, so skip repo
    if (request.isProcessedRepo(repository.getId())) {
      return new SnapshotRemovalRepositoryResult(repository.getId(), true);
    }

    request.addProcessedRepo(repository.getId());

    // if this is not snap repo, do nothing
    if (!RepositoryPolicy.SNAPSHOT.equals(repository.getRepositoryPolicy())) {
      return result;
    }

    if (getLogger().isDebugEnabled()) {
      getLogger()
          .debug(
              "Collecting deletable snapshots on repository "
                  + repository.getId()
                  + " from storage directory "
                  + repository.getLocalUrl());
    }

    request.getMetadataRebuildPaths().clear();

    // create a walker to collect deletables and let it loose on collections only
    SnapshotRemoverWalkerProcessor snapshotRemoveProcessor =
        new SnapshotRemoverWalkerProcessor(repository, request);

    DefaultWalkerContext ctxMain =
        new DefaultWalkerContext(
            repository, new ResourceStoreRequest("/"), new DottedStoreWalkerFilter());

    ctxMain.getProcessors().add(snapshotRemoveProcessor);

    walker.walk(ctxMain);

    if (ctxMain.getStopCause() != null) {
      result.setSuccessful(false);
    }

    // and collect results
    result.setDeletedSnapshots(snapshotRemoveProcessor.getDeletedSnapshots());
    result.setDeletedFiles(snapshotRemoveProcessor.getDeletedFiles());

    if (getLogger().isDebugEnabled()) {
      getLogger()
          .debug(
              "Collected and deleted "
                  + snapshotRemoveProcessor.getDeletedSnapshots()
                  + " snapshots with alltogether "
                  + snapshotRemoveProcessor.getDeletedFiles()
                  + " files on repository "
                  + repository.getId());
    }

    repository.expireCaches(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT));

    RecreateMavenMetadataWalkerProcessor metadataRebuildProcessor =
        new RecreateMavenMetadataWalkerProcessor(getLogger());

    for (String path : request.getMetadataRebuildPaths()) {
      DefaultWalkerContext ctxMd =
          new DefaultWalkerContext(
              repository, new ResourceStoreRequest(path), new DottedStoreWalkerFilter());

      ctxMd.getProcessors().add(metadataRebuildProcessor);

      try {
        walker.walk(ctxMd);
      } catch (WalkerException e) {
        if (!(e.getCause() instanceof ItemNotFoundException)) {
          // do not ignore it
          throw e;
        }
      }
    }

    return result;
  }