/** Cache is only used for remote repos; see issue #47. */
  private Node fromRepositories(
      Iterable<CmrRepository> repositories, ArtifactContext context, boolean addLeaf) {
    log.debug("Looking for " + context);

    for (CmrRepository repository : repositories) {
      log.debug(" Looking in " + repository);
      if (!repository.supportsNamespace(context.getNamespace())) {
        log.debug(" -> does not support namespace " + context.getNamespace());
        continue;
      }
      Node child = fromRepository(repository, context, addLeaf);
      if (child != null) {
        log.debug(" -> Found");
        return child;
      }

      log.debug("  -> Not Found");
    }

    log.debug(" -> Artifact " + context + " not found in any repository");
    return null;
  }
Ejemplo n.º 2
0
 private void addSearchResult(
     String groupId,
     String artifactId,
     String version,
     ModuleVersionResult result,
     Overrides overrides,
     String repositoryDisplayString)
     throws AetherException {
   ArtifactOverrides artifactOverrides = null;
   if (overrides != null) {
     ArtifactContext ctx =
         new ArtifactContext(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version);
     // see if this artifact is replaced
     ArtifactContext replaceContext = overrides.replace(ctx);
     if (replaceContext != null) {
       String[] groupArtifactIds = nameToGroupArtifactIds(replaceContext.getName());
       if (groupArtifactIds == null) return; // abort
       groupId = groupArtifactIds[0];
       artifactId = groupArtifactIds[1];
       version = replaceContext.getVersion();
       ctx = replaceContext;
     } else if (overrides.isVersionOverridden(ctx)) {
       // perhaps its version is overridden?
       version = overrides.getVersionOverride(ctx);
       ctx.setVersion(version);
     }
     artifactOverrides = overrides.getArtifactOverrides(ctx);
   }
   DependencyDescriptor info =
       impl.getDependencies(groupId, artifactId, version, null, "pom", false);
   if (info != null) {
     StringBuilder description = new StringBuilder();
     StringBuilder licenseBuilder = new StringBuilder();
     collectInfo(info, description, licenseBuilder);
     Set<ModuleDependencyInfo> dependencies = new HashSet<>();
     Set<ModuleVersionArtifact> artifactTypes = new HashSet<>();
     artifactTypes.add(new ModuleVersionArtifact(".jar", null, null));
     Set<String> authors = new HashSet<>();
     for (DependencyDescriptor dep : info.getDependencies()) {
       String namespace = MavenRepository.NAMESPACE;
       String depName = dep.getGroupId() + ":" + dep.getArtifactId();
       String depVersion = dep.getVersion();
       boolean export = false;
       boolean optional = dep.isOptional();
       if (overrides != null) {
         ArtifactContext depCtx = new ArtifactContext(namespace, depName, dep.getVersion());
         if (overrides.isRemoved(depCtx)
             || (artifactOverrides != null
                 && (artifactOverrides.isRemoved(depCtx)
                     || artifactOverrides.isAddedOrUpdated(depCtx)))) continue;
         ArtifactContext replaceCtx = overrides.replace(depCtx);
         if (replaceCtx != null) {
           depCtx = replaceCtx;
           namespace = replaceCtx.getNamespace();
           depName = replaceCtx.getName();
         }
         if (overrides.isVersionOverridden(depCtx))
           depVersion = overrides.getVersionOverride(depCtx);
         if (artifactOverrides != null) {
           if (artifactOverrides.isShareOverridden(depCtx))
             export = artifactOverrides.isShared(depCtx);
           if (artifactOverrides.isOptionalOverridden(depCtx))
             optional = artifactOverrides.isOptional(depCtx);
         }
       }
       ModuleDependencyInfo moduleDependencyInfo =
           new ModuleDependencyInfo(namespace, depName, depVersion, optional, export);
       dependencies.add(moduleDependencyInfo);
     }
     if (artifactOverrides != null) {
       for (DependencyOverride add : artifactOverrides.getAdd()) {
         ArtifactContext ac = add.getArtifactContext();
         ModuleDependencyInfo moduleDependencyInfo =
             new ModuleDependencyInfo(
                 ac.getNamespace(),
                 ac.getName(),
                 ac.getVersion(),
                 add.isOptional(),
                 add.isShared());
         dependencies.add(moduleDependencyInfo);
       }
     }
     ModuleVersionDetails moduleVersionDetails =
         new ModuleVersionDetails(
             MavenRepository.NAMESPACE,
             groupId + ":" + artifactId,
             version,
             description.length() > 0 ? description.toString() : null,
             licenseBuilder.length() > 0 ? licenseBuilder.toString() : null,
             authors,
             dependencies,
             artifactTypes,
             true,
             repositoryDisplayString);
     result.addVersion(moduleVersionDetails);
   }
 }