use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createChildren.
@NotNull
private List<? extends AndroidArtifactNode> createChildren(@NotNull PsAndroidModule module, @NotNull Map<String, PsVariant> variantsByName) {
List<AndroidArtifactNode> childrenNodes = Lists.newArrayList();
// [Outer map] key: variant name, value: dependencies by artifact
// [Inner map] key: artifact name, value: dependencies
Map<String, Map<String, List<PsDependency>>> dependenciesByVariantAndArtifact = Maps.newHashMap();
module.forEachDependency(dependency -> {
if (!dependency.isDeclared()) {
return;
}
for (PsDependencyContainer container : dependency.getContainers()) {
Map<String, List<PsDependency>> dependenciesByArtifact = dependenciesByVariantAndArtifact.get(container.getVariant());
if (dependenciesByArtifact == null) {
dependenciesByArtifact = Maps.newHashMap();
dependenciesByVariantAndArtifact.put(container.getVariant(), dependenciesByArtifact);
}
List<PsDependency> artifactDependencies = dependenciesByArtifact.get(container.getArtifact());
if (artifactDependencies == null) {
artifactDependencies = Lists.newArrayList();
dependenciesByArtifact.put(container.getArtifact(), artifactDependencies);
}
artifactDependencies.add(dependency);
}
});
List<String> variantNames = Lists.newArrayList(dependenciesByVariantAndArtifact.keySet());
Collections.sort(variantNames);
for (String variantName : variantNames) {
PsVariant variant = variantsByName.get(variantName);
Map<String, List<PsDependency>> dependenciesByArtifact = dependenciesByVariantAndArtifact.get(variantName);
if (dependenciesByArtifact != null) {
List<String> artifactNames = Lists.newArrayList(dependenciesByArtifact.keySet());
//noinspection TestOnlyProblems
Collections.sort(artifactNames, ArtifactComparator.byName());
for (String artifactName : artifactNames) {
PsAndroidArtifact artifact = variant.findArtifact(artifactName);
assert artifact != null;
AndroidArtifactNode mainArtifactNode = null;
String mainArtifactName = ARTIFACT_MAIN;
if (!mainArtifactName.equals(artifactName)) {
// Add "main" artifact as a dependency of "unit test" or "android test" artifact.
PsAndroidArtifact mainArtifact = variant.findArtifact(mainArtifactName);
if (mainArtifact != null) {
List<PsDependency> artifactDependencies = dependenciesByArtifact.get(mainArtifactName);
if (artifactDependencies == null) {
artifactDependencies = Collections.emptyList();
}
mainArtifactNode = createArtifactNode(mainArtifact, artifactDependencies, null);
}
}
AndroidArtifactNode artifactNode = createArtifactNode(artifact, dependenciesByArtifact.get(artifactName), mainArtifactNode);
if (artifactNode != null) {
childrenNodes.add(artifactNode);
}
}
}
}
return childrenNodes;
}
use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createArtifactNode.
@Nullable
private AndroidArtifactNode createArtifactNode(@NotNull List<PsAndroidArtifact> artifacts, @NotNull List<PsDependency> dependencies, @Nullable AndroidArtifactNode mainArtifactNode) {
if (!dependencies.isEmpty() || mainArtifactNode != null) {
AndroidArtifactNode artifactNode = new AndroidArtifactNode(this, artifacts);
populate(artifactNode, dependencies, mainArtifactNode);
return artifactNode;
}
return null;
}
use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createGroupedChildren.
@NotNull
private List<? extends AbstractPsModelNode> createGroupedChildren(@NotNull PsAndroidModule module, @NotNull Map<String, PsVariant> variantsByName) {
Map<String, List<PsDependencyContainer>> containersWithMainArtifactByVariant = Maps.newHashMap();
Map<List<PsDependencyContainer>, List<PsDependency>> groupedDependencies = groupDependencies(module);
for (List<PsDependencyContainer> containers : groupedDependencies.keySet()) {
for (PsDependencyContainer container : containers) {
if (container.getArtifact().endsWith(ARTIFACT_MAIN)) {
containersWithMainArtifactByVariant.put(container.getVariant(), containers);
break;
}
}
}
List<AndroidArtifactNode> children = Lists.newArrayList();
for (List<PsDependencyContainer> containers : groupedDependencies.keySet()) {
List<PsAndroidArtifact> groupArtifacts = extractArtifacts(containers, variantsByName);
AndroidArtifactNode mainArtifactNode = null;
if (!containersWithMainArtifactByVariant.values().contains(containers)) {
// This is a node for "Unit Test" or "Android Test"
if (containers.size() == 1) {
// This is not a group. Create the "main" artifact node for the same variant
PsDependencyContainer container = containers.get(0);
String variantName = container.getVariant();
PsVariant variant = variantsByName.get(variantName);
assert variant != null;
PsAndroidArtifact mainArtifact = variant.findArtifact(ARTIFACT_MAIN);
if (mainArtifact != null) {
List<PsDependencyContainer> mainArtifactContainers = containersWithMainArtifactByVariant.get(variantName);
if (mainArtifactContainers != null) {
List<PsDependency> mainArtifactDependencies = groupedDependencies.get(mainArtifactContainers);
mainArtifactNode = createArtifactNode(mainArtifact, mainArtifactDependencies, null);
}
}
} else {
// Create the node that contains all the containers with "main" artifacts
for (PsDependencyContainer container : containers) {
List<PsDependencyContainer> mainArtifactContainers = containersWithMainArtifactByVariant.get(container.getVariant());
if (mainArtifactContainers != null) {
List<PsAndroidArtifact> mainArtifacts = extractArtifacts(mainArtifactContainers, variantsByName);
mainArtifactNode = createArtifactNode(mainArtifacts, groupedDependencies.get(mainArtifactContainers), null);
break;
}
}
}
}
Collections.sort(groupArtifacts, ArtifactComparator.INSTANCE);
AndroidArtifactNode artifactNode = createArtifactNode(groupArtifacts, groupedDependencies.get(containers), mainArtifactNode);
if (artifactNode != null) {
children.add(artifactNode);
}
}
Collections.sort(children, (a1, a2) -> a1.getName().compareTo(a2.getName()));
return children;
}
use of com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AndroidArtifactNode in project android by JetBrains.
the class ResolvedDependenciesTreeRootNode method createArtifactNode.
@Nullable
private AndroidArtifactNode createArtifactNode(@NotNull PsAndroidArtifact artifact, @NotNull List<PsDependency> dependencies, @Nullable AndroidArtifactNode mainArtifactNode) {
if (!dependencies.isEmpty() || mainArtifactNode != null) {
AndroidArtifactNode artifactNode = new AndroidArtifactNode(this, artifact);
populate(artifactNode, dependencies, mainArtifactNode);
return artifactNode;
}
return null;
}
Aggregations