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;
  }
  @Override
  public void beforeWalk(WalkerContext context) throws Exception {
    isHostedRepo = false;

    repository =
        context.getRepository() instanceof MavenRepository
            ? (MavenRepository) context.getRepository()
            : null;

    if (repository != null) {
      mdHelper = new DefaultMetadataHelper(logger, repository, deleteOperation);

      isHostedRepo = repository.getRepositoryKind().isFacetAvailable(HostedRepository.class);
    }

    setActive(isHostedRepo);
  }