org.gradle.api.artifacts.result.ResolvedComponentResult Java Examples

The following examples show how to use org.gradle.api.artifacts.result.ResolvedComponentResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamingResolutionResultBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedComponentResult create() {
    synchronized (lock) {
        return cache.load(new Factory<ResolvedComponentResult>() {
            public ResolvedComponentResult create() {
                try {
                    return data.read(new BinaryStore.ReadAction<ResolvedComponentResult>() {
                        public ResolvedComponentResult read(Decoder decoder) throws IOException {
                            return deserialize(decoder);
                        }
                    });
                } finally {
                    try {
                        data.close();
                    } catch (IOException e) {
                        throw throwAsUncheckedException(e);
                    }
                }
            }
        });
    }
}
 
Example #2
Source File: StreamingResolutionResultBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedComponentResult create() {
    synchronized (lock) {
        return cache.load(new Factory<ResolvedComponentResult>() {
            public ResolvedComponentResult create() {
                try {
                    return data.read(new BinaryStore.ReadAction<ResolvedComponentResult>() {
                        public ResolvedComponentResult read(Decoder decoder) throws IOException {
                            return deserialize(decoder);
                        }
                    });
                } finally {
                    try {
                        data.close();
                    } catch (IOException e) {
                        throw throwAsUncheckedException(e);
                    }
                }
            }
        });
    }
}
 
Example #3
Source File: DependencyOrder.java    From pygradle with Apache License 2.0 6 votes vote down vote up
/**
 * Traverses the dependency tree post-order and collects dependencies.
 * <p>
 * The recursive post-order traversal returns the root of the (sub)tree.
 * This allows the post-order adding into the set of dependencies as we
 * return from the recursive calls. The set of seen dependencies ensures
 * ensures that the cycles in Ivy metadata do not cause cycles in our
 * recursive calls.
 *
 * @param root         the root of the dependency (sub)tree
 * @param seen         the input set of already seen dependencies
 * @param dependencies the output set of dependencies in post-order
 * @return the root itself
 */
public static ResolvedComponentResult postOrderDependencies(
    ResolvedComponentResult root,
    Set<ComponentIdentifier> seen,
    Set<ResolvedComponentResult> dependencies) {
    for (DependencyResult d : root.getDependencies()) {
        if (!(d instanceof ResolvedDependencyResult)) {
            throw new GradleException("Unresolved dependency found for " + d.toString());
        }

        ResolvedComponentResult component = ((ResolvedDependencyResult) d).getSelected();
        ComponentIdentifier id = component.getId();

        if (!seen.contains(id)) {
            seen.add(id);
            dependencies.add(postOrderDependencies(component, seen, dependencies));
        }
    }

    return root;
}
 
Example #4
Source File: StreamingResolutionResultBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedComponentResult create() {
    synchronized (lock) {
        return cache.load(new Factory<ResolvedComponentResult>() {
            public ResolvedComponentResult create() {
                try {
                    return data.read(new BinaryStore.ReadAction<ResolvedComponentResult>() {
                        public ResolvedComponentResult read(Decoder decoder) throws IOException {
                            return deserialize(decoder);
                        }
                    });
                } finally {
                    try {
                        data.close();
                    } catch (IOException e) {
                        throw throwAsUncheckedException(e);
                    }
                }
            }
        });
    }
}
 
Example #5
Source File: ErrorHandlingArtifactDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ResolvedComponentResult> getAllComponents() {
    try {
        return resolutionResult.getAllComponents();
    } catch (Throwable e) {
        throw wrapException(e, configuration);
    }
}
 
Example #6
Source File: DependencyOrder.java    From pygradle with Apache License 2.0 5 votes vote down vote up
/**
 * Collects configuration dependencies in post-order.
 *
 * @param configuration Gradle configuration to work with
 * @return set of resolved dependencies in post-order
 */
public static Set<ResolvedComponentResult> configurationPostOrderDependencies(Configuration configuration) {
    ResolvedComponentResult root = configuration.getIncoming().getResolutionResult().getRoot();
    Set<ResolvedComponentResult> dependencies = new LinkedHashSet<>();
    Set<ComponentIdentifier> seen = new HashSet<>();

    postOrderDependencies(root, seen, dependencies);

    return dependencies;
}
 
Example #7
Source File: ErrorHandlingArtifactDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedComponentResult getRoot() {
    try {
        return resolutionResult.getRoot();
    } catch (Throwable e) {
        throw wrapException(e, configuration);
    }
}
 
Example #8
Source File: ErrorHandlingArtifactDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ResolvedComponentResult> getAllComponents() {
    try {
        return resolutionResult.getAllComponents();
    } catch (Throwable e) {
        throw wrapException(e, configuration);
    }
}
 
Example #9
Source File: CachingDependencyResultFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public UnresolvedDependencyResult createUnresolvedDependency(ComponentSelector requested, ResolvedComponentResult from,
                                                   ComponentSelectionReason reason, ModuleVersionResolveException failure) {
    List<Object> key = asList(requested, from);
    if (!unresolvedDependencies.containsKey(key)) {
        unresolvedDependencies.put(key, new DefaultUnresolvedDependencyResult(requested, reason, from, failure));
    }
    return unresolvedDependencies.get(key);
}
 
Example #10
Source File: AbstractDependencyResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AbstractDependencyResult(ComponentSelector requested, ResolvedComponentResult from) {
    assert requested != null;
    assert from != null;

    this.from = from;
    this.requested = requested;
}
 
Example #11
Source File: CachingDependencyResultFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedDependencyResult createResolvedDependency(ComponentSelector requested, ResolvedComponentResult from, DefaultResolvedComponentResult selected) {
    List<Object> key = asList(requested, from, selected);
    if (!resolvedDependencies.containsKey(key)) {
        resolvedDependencies.put(key, new DefaultResolvedDependencyResult(requested, selected, from));
    }
    return resolvedDependencies.get(key);
}
 
Example #12
Source File: DefaultResolutionResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example #13
Source File: ResolutionResultsStoreFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public StoreSet createStoreSet() {
    return new StoreSet() {
        int storeSetId = storeSetBaseId++;
        int binaryStoreId;
        public DefaultBinaryStore nextBinaryStore() {
            //one binary store per id+threadId
            String storeKey = Thread.currentThread().getId() + "-" + binaryStoreId++;
            return createBinaryStore(storeKey);
        }

        public Store<ResolvedComponentResult> oldModelStore() {
            if (oldModelCache == null) {
                oldModelCache = new CachedStoreFactory("Resolution result");
                cleanUpLater.add(oldModelCache);
            }
            return oldModelCache.createCachedStore(storeSetId);
        }

        public Store<TransientConfigurationResults> newModelStore() {
            if (newModelCache == null) {
                newModelCache = new CachedStoreFactory("Resolved configuration");
                cleanUpLater.add(newModelCache);
            }
            return newModelCache.createCachedStore(storeSetId);
        }
    };
}
 
Example #14
Source File: CachingDependencyResultFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedDependencyResult createResolvedDependency(ComponentSelector requested, ResolvedComponentResult from, DefaultResolvedComponentResult selected) {
    List<Object> key = asList(requested, from, selected);
    if (!resolvedDependencies.containsKey(key)) {
        resolvedDependencies.put(key, new DefaultResolvedDependencyResult(requested, selected, from));
    }
    return resolvedDependencies.get(key);
}
 
Example #15
Source File: ResolutionResultsStoreFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public StoreSet createStoreSet() {
    return new StoreSet() {
        int storeSetId = storeSetBaseId++;
        int binaryStoreId;
        public DefaultBinaryStore nextBinaryStore() {
            //one binary store per id+threadId
            String storeKey = Thread.currentThread().getId() + "-" + binaryStoreId++;
            return createBinaryStore(storeKey);
        }

        public Store<ResolvedComponentResult> oldModelStore() {
            if (oldModelCache == null) {
                oldModelCache = new CachedStoreFactory("Resolution result");
                cleanUpLater.add(oldModelCache);
            }
            return oldModelCache.createCachedStore(storeSetId);
        }

        public Store<TransientConfigurationResults> newModelStore() {
            if (newModelCache == null) {
                newModelCache = new CachedStoreFactory("Resolved configuration");
                cleanUpLater.add(newModelCache);
            }
            return newModelCache.createCachedStore(storeSetId);
        }
    };
}
 
Example #16
Source File: ErrorHandlingArtifactDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedComponentResult getRoot() {
    try {
        return resolutionResult.getRoot();
    } catch (Throwable e) {
        throw wrapException(e, configuration);
    }
}
 
Example #17
Source File: CachingDependencyResultFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedDependencyResult createResolvedDependency(ComponentSelector requested, ResolvedComponentResult from, DefaultResolvedComponentResult selected) {
    List<Object> key = asList(requested, from, selected);
    if (!resolvedDependencies.containsKey(key)) {
        resolvedDependencies.put(key, new DefaultResolvedDependencyResult(requested, selected, from));
    }
    return resolvedDependencies.get(key);
}
 
Example #18
Source File: ErrorHandlingArtifactDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedComponentResult getRoot() {
    try {
        return resolutionResult.getRoot();
    } catch (Throwable e) {
        throw wrapException(e, configuration);
    }
}
 
Example #19
Source File: LinkageCheckTask.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private void recordDependencyPaths(
    ImmutableListMultimap.Builder<String, String> output,
    ArrayDeque<ResolvedComponentResult> stack,
    ImmutableSet<String> targetCoordinates) {
  ResolvedComponentResult item = stack.getLast();
  ModuleVersionIdentifier identifier = item.getModuleVersion();
  String coordinates =
      String.format(
          "%s:%s:%s", identifier.getGroup(), identifier.getName(), identifier.getVersion());
  if (targetCoordinates.contains(coordinates)) {
    String dependencyPath =
        stack.stream().map(this::formatComponentResult).collect(Collectors.joining(" / "));
    output.put(coordinates, dependencyPath);
  }

  for (DependencyResult dependencyResult : item.getDependencies()) {
    if (dependencyResult instanceof ResolvedDependencyResult) {
      ResolvedDependencyResult resolvedDependencyResult =
          (ResolvedDependencyResult) dependencyResult;
      ResolvedComponentResult child = resolvedDependencyResult.getSelected();
      stack.add(child);
      recordDependencyPaths(output, stack, targetCoordinates);
    } else if (dependencyResult instanceof UnresolvedDependencyResult) {
      UnresolvedDependencyResult unresolvedResult = (UnresolvedDependencyResult) dependencyResult;
      getLogger()
          .error(
              "Could not resolve dependency: "
                  + unresolvedResult.getAttempted().getDisplayName());
    } else {
      throw new IllegalStateException("Unexpected dependency result type: " + dependencyResult);
    }
  }

  stack.removeLast();
}
 
Example #20
Source File: DefaultResolutionResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example #21
Source File: DefaultResolutionResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example #22
Source File: DefaultResolutionResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example #23
Source File: DefaultUnresolvedDependencyResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultUnresolvedDependencyResult(ComponentSelector requested, ComponentSelectionReason reason,
                                         ResolvedComponentResult from, ModuleVersionResolveException failure) {
    super(requested, from);
    this.reason = reason;
    this.failure = failure;
}
 
Example #24
Source File: DefaultResolvedDependencyResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ResolvedComponentResult getSelected() {
    return selected;
}
 
Example #25
Source File: DefaultResolvedDependencyResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultResolvedDependencyResult(ComponentSelector requested, ResolvedComponentResult selected, ResolvedComponentResult from) {
    super(requested, from);
    this.selected = selected;
}
 
Example #26
Source File: DefaultResolutionResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ResolvedComponentResult getRoot() {
    return rootSource.create();
}
 
Example #27
Source File: DefaultResolutionResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void allComponents(final Closure closure) {
    allComponents(new ClosureBackedAction<ResolvedComponentResult>(closure));
}
 
Example #28
Source File: AbstractDependencyResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ResolvedComponentResult getFrom() {
    return from;
}
 
Example #29
Source File: LinkageCheckTask.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
/** Returns true iff {@code configuration}'s artifacts contain linkage errors. */
private boolean findLinkageErrors(Configuration configuration) throws IOException {
  ImmutableList.Builder<ClassPathEntry> classPathBuilder = ImmutableList.builder();

  // TODO(suztomo): Should this include optional dependencies?
  //  Once we decide what to do with the optional dependencies, let's revisit this logic.
  for (ResolvedArtifact resolvedArtifact :
      configuration.getResolvedConfiguration().getResolvedArtifacts()) {
    ModuleVersionIdentifier moduleVersionId = resolvedArtifact.getModuleVersion().getId();
    DefaultArtifact artifact =
        new DefaultArtifact(
            moduleVersionId.getGroup(),
            moduleVersionId.getName(),
            null,
            null,
            moduleVersionId.getVersion(),
            null,
            resolvedArtifact.getFile());
    classPathBuilder.add(new ClassPathEntry(artifact));
  }

  ImmutableList<ClassPathEntry> classPath = classPathBuilder.build();

  if (!classPath.isEmpty()) {
    String exclusionFileName = extension.getExclusionFile();
    Path exclusionFile = exclusionFileName == null ? null : Paths.get(exclusionFileName);
    if (exclusionFile != null && !exclusionFile.isAbsolute()) {
      // Relative path from the project root
      Path projectRoot = getProject().getRootDir().toPath();
      exclusionFile = projectRoot.resolve(exclusionFile).toAbsolutePath();
    }

    // TODO(suztomo): Specify correct entry points if reportOnlyReachable is true.
    LinkageChecker linkageChecker = LinkageChecker.create(classPath, classPath, exclusionFile);

    ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems =
        linkageChecker.findSymbolProblems();

    int errorCount = symbolProblems.keySet().size();

    // TODO(suztomo): Show the dependency paths to the problematic artifacts.
    if (errorCount > 0) {
      getLogger().error(
          "Linkage Checker rule found {} error{}. Linkage error report:\n{}",
          errorCount,
          errorCount > 1 ? "s" : "",
          SymbolProblem.formatSymbolProblems(symbolProblems));

      ResolutionResult result = configuration.getIncoming().getResolutionResult();
      ResolvedComponentResult root = result.getRoot();
      String dependencyPaths = dependencyPathsOfProblematicJars(root, symbolProblems);
      getLogger().error(dependencyPaths);
      getLogger()
          .info(
              "For the details of the linkage errors, see "
                  + "https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/Linkage-Checker-Messages");
    }
    return errorCount > 0;
  }
  // When the configuration does not have any artifacts, there's no linkage error.
  return false;
}
 
Example #30
Source File: StreamingResolutionResultBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public StreamingResolutionResultBuilder(BinaryStore store, Store<ResolvedComponentResult> cache) {
    this.store = store;
    this.cache = cache;
}