private void collectDependens(Set<ResolvedDependencyResult> compileOnlyDependencySet) { for (ResolvedDependencyResult resolvedDependencyResult : compileOnlyDependencySet) { compileDependencies.add(resolvedDependencyResult.getSelected() .getModuleVersion() .getGroup() + "-" + resolvedDependencyResult.getSelected() .getModuleVersion() .getName()); Set<ResolvedDependencyResult> resolvedDependencyResults = new HashSet<ResolvedDependencyResult>(); if (null != resolvedDependencyResult.getSelected().getDependencies()) { for (DependencyResult sub : resolvedDependencyResult.getSelected() .getDependencies()) { if (sub instanceof ResolvedDependencyResult) { resolvedDependencyResults.add((ResolvedDependencyResult) sub); } } } collectDependens(resolvedDependencyResults); } }
private Set<String> getBundleDependencies(Configuration compileClasspath, Set<? extends DependencyResult> bundleDependencies) { Set<String> bundleSets = new HashSet<>(); for (DependencyResult dependencyResult : bundleDependencies) { bundleSets.add(dependencyResult.toString()); } for (Dependency dependency : compileClasspath.getAllDependencies()) { if (dependency instanceof DefaultExternalModuleDependency) { DefaultExternalModuleDependency externalModuleDependency = (DefaultExternalModuleDependency)dependency; if (!((DefaultExternalModuleDependency)dependency).getArtifacts().isEmpty()) { if (StringUtils.equalsIgnoreCase("awb", ((DefaultExternalModuleDependency)dependency).getArtifacts() .iterator().next().getType())) { bundleSets.add( dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion()); } } } } return bundleSets; }
public Set<? extends DependencyResult> getAllDependencies() { try { return resolutionResult.getAllDependencies(); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
public Set<? extends DependencyResult> getAllDependencies() { final Set<DependencyResult> out = new LinkedHashSet<DependencyResult>(); allDependencies(new Action<DependencyResult>() { public void execute(DependencyResult dep) { out.add(dep); } }); return out; }
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); } } }
private List createInsight(ModuleIdentifier module, final Configuration configuration) { final Spec<DependencyResult> dependencySpec = new StrictDependencyResultSpec(module); ResolutionResult result = configuration.getIncoming().getResolutionResult(); final Set<DependencyResult> selectedDependencies = new LinkedHashSet<DependencyResult>(); result.allDependencies(new Action<DependencyResult>() { @Override public void execute(DependencyResult it) { if (dependencySpec.isSatisfiedBy(it)) { selectedDependencies.add(it); } } }); Collection<RenderableDependency> sortedDeps = new DependencyInsightReporter().prepare(selectedDependencies, versionSelectorScheme, versionComparator); return CollectionUtils.collect(sortedDeps, new Transformer<Object, RenderableDependency>() { @Override public Object transform(RenderableDependency dependency) { String name = replaceArrow(dependency.getName()); LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(5); map.put("name", replaceArrow(dependency.getName())); map.put("description", dependency.getDescription()); map.put("resolvable", dependency.getResolutionState()); map.put("hasConflict", !name.equals(dependency.getName())); map.put("children", createInsightDependencyChildren(dependency, new HashSet<Object>(), configuration)); return map; } }); }
@Override public boolean isSatisfiedBy(DependencyResult candidate) { if (candidate instanceof ResolvedDependencyResult) { return matchesRequested(candidate) || matchesSelected((ResolvedDependencyResult) candidate); } else { return matchesRequested(candidate); } }
private boolean matchesRequested(DependencyResult candidate) { ComponentSelector requested = candidate.getRequested(); if (moduleIdentifier != null && requested instanceof ModuleComponentSelector) { ModuleComponentSelector requestedSelector = (ModuleComponentSelector) requested; return requestedSelector.getGroup().equals(moduleIdentifier.getGroup()) && requestedSelector.getModule().equals(moduleIdentifier.getName()); } return false; }
@Override public void convert(String notation, NotationConvertResult<? super Spec<DependencyResult>> result) throws TypeConversionException { final String stringNotation = notation.trim(); if (stringNotation.length() > 0) { result.converted(new DependencyResultSpec(stringNotation)); } }
public static NotationParser<Object, Spec<DependencyResult>> parser() { return NotationParserBuilder .toType(new TypeInfo<Spec<DependencyResult>>(Spec.class)) .invalidNotationMessage("Please check the input for the DependencyInsight.dependency element.") .fromType(Closure.class, new ClosureToSpecNotationConverter<DependencyResult>(DependencyResult.class)) .fromCharSequence(new DependencyResultSpecNotationConverter()) .toComposite(); }
@Override public boolean isSatisfiedBy(DependencyResult candidate) { //The matching is very simple at the moment but it should solve majority of cases. //It operates using String#contains and it tests either requested or selected module. if (candidate instanceof ResolvedDependencyResult) { return matchesRequested(candidate) || matchesSelected((ResolvedDependencyResult) candidate); } else { return matchesRequested(candidate); } }
private boolean matchesRequested(DependencyResult candidate) { ComponentSelector requested = candidate.getRequested(); if(requested instanceof ModuleComponentSelector) { ModuleComponentSelector requestedModule = (ModuleComponentSelector)requested; String requestedCandidate = requestedModule.getGroup() + ":" + requestedModule.getModule() + ":" + requestedModule.getVersion(); return requestedCandidate.contains(stringNotation); } return false; }
public Collection<RenderableDependency> prepare(Collection<DependencyResult> input, VersionSelectorScheme versionSelectorScheme, VersionComparator versionComparator) { LinkedList<RenderableDependency> out = new LinkedList<RenderableDependency>(); List<DependencyEdge> dependencies = CollectionUtils.collect(input, new Transformer<DependencyEdge, DependencyResult>() { @Override public DependencyEdge transform(DependencyResult result) { if (result instanceof UnresolvedDependencyResult) { return new UnresolvedDependencyEdge((UnresolvedDependencyResult) result); } else { return new ResolvedDependencyEdge((ResolvedDependencyResult) result); } } }); Collection<DependencyEdge> sorted = DependencyResultSorter.sort(dependencies, versionSelectorScheme, versionComparator); //remember if module id was annotated HashSet<ComponentIdentifier> annotated = new HashSet<ComponentIdentifier>(); RequestedVersion current = null; for (DependencyEdge dependency : sorted) { //add description only to the first module if (annotated.add(dependency.getActual())) { //add a heading dependency with the annotation if the dependency does not exist in the graph if (!dependency.getRequested().matchesStrictly(dependency.getActual())) { out.add(new DependencyReportHeader(dependency)); current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null); out.add(current); } else { current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), getReasonDescription(dependency.getReason())); out.add(current); } } else if (!current.getRequested().equals(dependency.getRequested())) { current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null); out.add(current); } current.addChild(dependency); } return out; }
@Override public Set<RenderableDependency> getChildren() { Set<RenderableDependency> out = new LinkedHashSet<RenderableDependency>(); for (DependencyResult d : dependency.getSelected().getDependencies()) { if (d instanceof UnresolvedDependencyResult) { out.add(new RenderableUnresolvedDependencyResult((UnresolvedDependencyResult) d)); } else { out.add(new RenderableDependencyResult((ResolvedDependencyResult) d)); } } return out; }
@Override public Set<RenderableDependency> getChildren() { Set<RenderableDependency> out = new LinkedHashSet<RenderableDependency>(); for (DependencyResult d : module.getDependencies()) { if (d instanceof UnresolvedDependencyResult) { out.add(new RenderableUnresolvedDependencyResult((UnresolvedDependencyResult) d)); } else { out.add(new RenderableDependencyResult((ResolvedDependencyResult) d)); } } return out; }
/** * Finds all unresolved dependency results. * * @param dependencies Unfiltered dependencies * @return Unresolved dependency results. */ private List<UnresolvedDependencyResult> findAllUnresolvedDependencyResults(Set<? extends DependencyResult> dependencies) { List<UnresolvedDependencyResult> unresolvedDependencyResults = new ArrayList<UnresolvedDependencyResult>(); for (DependencyResult dependencyResult : dependencies) { if (dependencyResult instanceof UnresolvedDependencyResult) { unresolvedDependencyResults.add((UnresolvedDependencyResult) dependencyResult); } } return unresolvedDependencyResults; }
private Set<DependencyResult> getDependencyResults(LibVariantContext libVariantContext, String name) { return (Set<DependencyResult>) libVariantContext.getProject() .getConfigurations() .getAt(name) .getIncoming() .getResolutionResult() .getRoot() .getDependencies(); }
public List<ResolvedDependencyInfo> resolve(List<DependencyResult> dependencyResults, boolean mainBundle) { Multimap<String, ResolvedDependencyInfo> dependenciesMap = LinkedHashMultimap.create(); // Instead of using the official flat dependency treatment, you can use your own tree dependence; For application dependencies, we only take compile dependencies Set<ModuleVersionIdentifier> directDependencies = new HashSet<ModuleVersionIdentifier>(); Set<String> resolveSets = new HashSet<>(); for (DependencyResult dependencyResult : dependencyResults) { if (dependencyResult instanceof ResolvedDependencyResult) { ModuleVersionIdentifier moduleVersion = ((ResolvedDependencyResult)dependencyResult).getSelected() .getModuleVersion(); CircleDependencyCheck circleDependencyCheck = new CircleDependencyCheck(moduleVersion); if (!directDependencies.contains(moduleVersion)) { directDependencies.add(moduleVersion); resolveDependency(null, ((ResolvedDependencyResult)dependencyResult).getSelected(), artifacts, variantDeps, 0, circleDependencyCheck, circleDependencyCheck.getRootDependencyNode(), dependenciesMap, resolveSets); } } } List<ResolvedDependencyInfo> mainResolvdInfo = resolveAllDependencies(dependenciesMap); if (mainBundle) { for (ResolvedDependencyInfo resolvedDependencyInfo : mainResolvdInfo) { addMainDependencyInfo(resolvedDependencyInfo); } } return mainResolvdInfo; }
public AtlasDependencyTree parseDependencyTree(@NonNull VariantDependencies variantDeps) { String name = variantDeps.getName().toLowerCase(); if (!name.endsWith("debug") && !name.endsWith("release")) { return new AtlasDependencyTree(new ArrayList<>()); } Configuration compileClasspath = variantDeps.getCompileConfiguration(); Configuration packageClasspath = variantDeps.getPackageConfiguration(); Configuration bundleClasspath = project.getConfigurations().maybeCreate(AtlasPlugin.BUNDLE_COMPILE); ensureConfigured(compileClasspath); ensureConfigured(packageClasspath); ensureConfigured(bundleClasspath); Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts = Maps.newHashMap(); collectArtifacts(compileClasspath, artifacts); collectArtifacts(packageClasspath, artifacts); collectArtifacts(bundleClasspath, artifacts); //Rely on the group DependencyGroup dependencyGroup = new DependencyGroup(compileClasspath, bundleClasspath,artifacts); DependencyResolver dependencyResolver = new DependencyResolver(project, variantDeps, artifacts, dependencyGroup.bundleProvidedMap, apDependencies); mResolvedDependencies.addAll(dependencyResolver.resolve(dependencyGroup.compileDependencies, true)); for (DependencyResult dependencyResult : dependencyGroup.bundleDependencies) { mResolvedDependencies.addAll(dependencyResolver.resolve(Arrays.asList(dependencyResult), false)); } AtlasDependencyTree atlasDependencyTree = toAtlasDependencyTree(); check(atlasDependencyTree); return atlasDependencyTree; }
public static boolean isAwbDependency(DependencyResult dependencyResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) { if (dependencyResult instanceof ResolvedDependencyResult) { ResolvedDependencyResult resolvedDependencyResult = (ResolvedDependencyResult)dependencyResult; ModuleVersionIdentifier moduleVersionIdentifier = resolvedDependencyResult.getSelected().getModuleVersion(); List<ResolvedArtifact> resolvedArtifacts = artifacts.get(moduleVersionIdentifier); if (resolvedArtifacts.size() > 0) { ResolvedArtifact resolvedArtifact = resolvedArtifacts.get(0); return ("awb".equals(resolvedArtifact.getType())); } } return false; }
public Set<? extends DependencyResult> getAllDependencies() { try { return resolutionResult.getAllDependencies(); } catch (Throwable e) { throw wrapException(e, configuration); } }
public boolean isSatisfiedBy(DependencyResult candidate) { if (candidate instanceof ResolvedDependencyResult) { return matchesRequested(candidate) || matchesSelected((ResolvedDependencyResult) candidate); } else { return matchesRequested(candidate); } }
public static NotationParser<Object, Spec<DependencyResult>> create() { return NotationParserBuilder .toType(new TypeInfo<Spec<DependencyResult>>(Spec.class)) .invalidNotationMessage("Please check the input for the DependencyInsight.dependency element.") .fromType(Closure.class, new ClosureToSpecNotationParser<DependencyResult>(DependencyResult.class)) .fromCharSequence(new DependencyResultSpecNotationParser()) .toComposite(); }
public boolean isSatisfiedBy(DependencyResult candidate) { //The matching is very simple at the moment but it should solve majority of cases. //It operates using String#contains and it tests either requested or selected module. if (candidate instanceof ResolvedDependencyResult) { return matchesRequested(candidate) || matchesSelected((ResolvedDependencyResult) candidate); } else { return matchesRequested(candidate); } }
public Set<RenderableDependency> getChildren() { Set<RenderableDependency> out = new LinkedHashSet<RenderableDependency>(); for (DependencyResult d : dependency.getSelected().getDependencies()) { if (d instanceof UnresolvedDependencyResult) { out.add(new RenderableUnresolvedDependencyResult((UnresolvedDependencyResult) d)); } else { out.add(new RenderableDependencyResult((ResolvedDependencyResult) d)); } } return out; }
public Set<RenderableDependency> getChildren() { Set<RenderableDependency> out = new LinkedHashSet<RenderableDependency>(); for (DependencyResult d : module.getDependencies()) { if (d instanceof UnresolvedDependencyResult) { out.add(new RenderableUnresolvedDependencyResult((UnresolvedDependencyResult) d)); } else { out.add(new RenderableDependencyResult((ResolvedDependencyResult) d)); } } return out; }
public Spec<DependencyResult> parseNotation(final Object notation) throws UnsupportedNotationException { if (notation instanceof CharSequence) { final String stringNotation = notation.toString().trim(); if (stringNotation.length() > 0) { return new DependencyResultSpec(stringNotation); } } throw new UnsupportedNotationException(notation); }
public static NotationParser<Object, Spec<DependencyResult>> create() { return new NotationParserBuilder<Spec<DependencyResult>>() .resultingType(new TypeInfo<Spec<DependencyResult>>(Spec.class)) .invalidNotationMessage("Please check the input for the DependencyInsight.dependency element.") .parser(new ClosureToSpecNotationParser<DependencyResult>()) .parser(new DependencyResultSpecNotationParser()) .toComposite(); }