use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class SingleLibraryDependencyDetails method display.
@Override
public void display(@NotNull PsDependency dependency, @Nullable String configurationNames) {
myDependency = (PsLibraryDependency) dependency;
PsArtifactDependencySpec spec = myDependency.getDeclaredSpec();
if (spec == null) {
spec = myDependency.getResolvedSpec();
}
myGroupIdLabel.setText(spec.group);
myArtifactNameLabel.setText(spec.name);
myResolvedVersionLabel.setText(myDependency.getResolvedSpec().version);
myRequestedVersionLabel.setText(spec.version);
String scopeToDisplay = isNotEmpty(configurationNames) ? configurationNames : dependency.getJoinedConfigurationNames();
myScopeLabel.setText(scopeToDisplay);
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class TargetModulesTreeStructure method displayTargetModules.
void displayTargetModules(@NotNull List<AbstractDependencyNode<? extends PsAndroidDependency>> dependencyNodes) {
// Key: module name, Value: pair of module and version of the dependency used in the module.
Map<String, Pair<PsAndroidModule, String>> modules = Maps.newHashMap();
// Key: module name, Value: configuration names.
Multimap<String, Configuration> configurationNamesByModule = HashMultimap.create();
// From the list of AbstractDependencyNode:
// 1. Extract modules (to show them as top-level nodes)
// 2. Extract variants/artifact (i.e. PsDependencyContainer) per module (to show them as children nodes of the module nodes)
dependencyNodes.forEach(node -> {
List<AbstractDependencyNode<? extends PsAndroidDependency>> declaredDependencyNodes = getDeclaredDependencyNodeHierarchy(node);
Map<String, String> versionByModule = Maps.newHashMap();
for (PsAndroidDependency dependency : node.getModels()) {
if (dependency instanceof PsLibraryAndroidDependency) {
PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
PsArtifactDependencySpec spec = libraryDependency.getDeclaredSpec();
if (spec == null) {
spec = libraryDependency.getResolvedSpec();
}
PsAndroidModule module = dependency.getParent();
versionByModule.put(module.getName(), spec.version);
}
}
AbstractDependencyNode<? extends PsAndroidDependency> topParentNode = declaredDependencyNodes.get(declaredDependencyNodes.size() - 1);
for (PsAndroidDependency dependency : topParentNode.getModels()) {
PsAndroidModule module = dependency.getParent();
String moduleName = module.getName();
Pair<PsAndroidModule, String> existing = modules.get(moduleName);
if (existing == null) {
modules.put(moduleName, Pair.create(module, versionByModule.get(moduleName)));
}
}
declaredDependencyNodes.forEach(declaredDependencyNode -> {
List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(declaredDependencyNode);
declaredDependencies.forEach(declaredDependency -> {
List<String> configurationNames = declaredDependency.getConfigurationNames();
assert !configurationNames.isEmpty();
PsAndroidModule module = declaredDependency.getParent();
String moduleName = module.getName();
for (PsDependencyContainer container : declaredDependency.getContainers()) {
PsAndroidArtifact artifact = container.findArtifact(module, false);
for (String configurationName : configurationNames) {
if (artifact != null && artifact.containsConfigurationName(configurationName)) {
boolean transitive = declaredDependencyNode != node;
Collection<Configuration> configurations = configurationNamesByModule.get(moduleName);
boolean found = false;
for (Configuration configuration : configurations) {
if (configuration.getName().equals(configurationName)) {
configuration.addType(transitive);
found = true;
break;
}
}
if (!found) {
Icon icon = artifact.getIcon();
configurationNamesByModule.put(moduleName, new Configuration(configurationName, icon, transitive));
}
}
}
}
});
});
});
// Now we create the tree nodes.
List<TargetAndroidModuleNode> children = Lists.newArrayList();
for (Pair<PsAndroidModule, String> moduleAndVersion : modules.values()) {
PsAndroidModule module = moduleAndVersion.getFirst();
TargetAndroidModuleNode moduleNode = new TargetAndroidModuleNode(myRootNode, module, moduleAndVersion.getSecond());
List<Configuration> configurations = Lists.newArrayList(configurationNamesByModule.get(module.getName()));
Collections.sort(configurations);
List<TargetConfigurationNode> nodes = Lists.newArrayList();
configurations.forEach(configuration -> nodes.add(new TargetConfigurationNode(configuration)));
moduleNode.setChildren(nodes);
children.add(moduleNode);
}
Collections.sort(children, new SimpleNodeComparator<>());
myRootNode.setChildren(children);
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class AddLibraryDependencyDialog method doValidate.
@Override
@Nullable
protected ValidationInfo doValidate() {
List<Exception> searchErrors = myLibraryDependenciesForm.getSearchErrors();
if (!searchErrors.isEmpty()) {
StringBuilder buffer = new StringBuilder();
searchErrors.forEach(e -> buffer.append(getErrorMessage(e)).append("\n"));
return new ValidationInfo(buffer.toString(), myLibraryDependenciesForm.getPreferredFocusedComponent());
}
String selectedLibrary = myLibraryDependenciesForm.getSelectedLibrary();
if (isEmpty(selectedLibrary)) {
return new ValidationInfo("Please specify the library to add as dependency", myLibraryDependenciesForm.getPreferredFocusedComponent());
}
PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(selectedLibrary);
PsModule module = getModule();
if (spec != null && module instanceof PsAndroidModule) {
PsAndroidModule androidModule = (PsAndroidModule) module;
Ref<Boolean> found = new Ref<>(false);
androidModule.forEachDeclaredDependency(dependency -> {
if (dependency instanceof PsLibraryAndroidDependency) {
PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
PsArtifactDependencySpec resolvedSpec = libraryDependency.getResolvedSpec();
if (Objects.equals(spec.group, resolvedSpec.group) && Objects.equals(spec.name, resolvedSpec.name)) {
found.set(true);
}
}
});
if (found.get()) {
String msg = String.format("Library '%1$s' is already a dependency", spec.name);
return new ValidationInfo(msg, myLibraryDependenciesForm.getPreferredFocusedComponent());
}
}
return getScopesPanel().validateInput();
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class LibraryDependencyNode method getText.
@NotNull
private String getText(@NotNull PsLibraryAndroidDependency dependency) {
PsArtifactDependencySpec resolvedSpec = dependency.getResolvedSpec();
if (dependency.hasPromotedVersion() && !(getParent() instanceof LibraryDependencyNode)) {
// Show only "promoted" version for declared nodes.
PsArtifactDependencySpec declaredSpec = dependency.getDeclaredSpec();
assert declaredSpec != null;
String version = declaredSpec.version + "→" + resolvedSpec.version;
return getTextForSpec(declaredSpec.name, version, declaredSpec.group);
}
return resolvedSpec.getDisplayText();
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class AbstractDeclaredDependenciesTableModelTest method testShowArtifactDependencySpec.
public void testShowArtifactDependencySpec() {
PsArtifactDependencySpec spec = new PsArtifactDependencySpec("appcompat-v7", "com.android.support", "23.1.0");
when(myLibraryDependency.getResolvedSpec()).thenReturn(spec);
when(myLibraryDependency.getDeclaredSpec()).thenReturn(spec);
when(myLibraryDependency.toText(PLAIN_TEXT)).thenReturn("com.android.support:appcompat-v7:23.1.0");
ColumnInfo[] columnInfos = myTableModel.getColumnInfos();
PsUISettings.getInstance().DECLARED_DEPENDENCIES_SHOW_GROUP_ID = true;
//noinspection unchecked
ColumnInfo<PsAndroidDependency, String> specColumnInfo = columnInfos[0];
DependencyCellRenderer renderer = (DependencyCellRenderer) specColumnInfo.getRenderer(myLibraryDependency);
assertNotNull(renderer);
String text = renderer.getText();
assertEquals("com.android.support:appcompat-v7:23.1.0", text);
PsUISettings.getInstance().DECLARED_DEPENDENCIES_SHOW_GROUP_ID = false;
text = renderer.getText();
assertEquals("appcompat-v7:23.1.0", text);
}
Aggregations