use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.
the class DependencyNodes method addTransitive.
private static void addTransitive(@NotNull PsDependency dependency, @NotNull Multimap<PsDependency, PsDependency> allTransitive) {
if (allTransitive.containsKey(dependency)) {
return;
}
if (dependency instanceof PsLibraryAndroidDependency) {
PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
ImmutableCollection<PsDependency> transitives = libraryDependency.getTransitiveDependencies();
allTransitive.putAll(dependency, transitives);
for (PsDependency transitive : transitives) {
addTransitive(transitive, allTransitive);
}
}
}
use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.
the class LibraryDependencyNode method matches.
@Override
public boolean matches(@NotNull PsModel model) {
if (model instanceof PsLibraryAndroidDependency) {
PsLibraryAndroidDependency other = (PsLibraryAndroidDependency) model;
List<PsLibraryAndroidDependency> models = getModels();
for (PsLibraryAndroidDependency dependency : models) {
if (dependency.getResolvedSpec().equals(other.getResolvedSpec())) {
return true;
}
}
}
return false;
}
use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency in project android by JetBrains.
the class LibraryDependencyNode method setUp.
private void setUp(@NotNull PsLibraryAndroidDependency dependency) {
myName = getText(dependency);
ImmutableCollection<PsDependency> transitiveDependencies = dependency.getTransitiveDependencies();
transitiveDependencies.stream().filter(transitive -> transitive instanceof PsLibraryAndroidDependency).forEach(transitive -> {
PsLibraryAndroidDependency transitiveLibrary = (PsLibraryAndroidDependency) transitive;
LibraryDependencyNode child = new LibraryDependencyNode(this, transitiveLibrary);
myChildren.add(child);
});
Collections.sort(myChildren, DependencyNodeComparator.INSTANCE);
}
use of com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency 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.android.PsLibraryAndroidDependency in project android by JetBrains.
the class DependenciesTreeBuilder method find.
@Nullable
public LibraryDependencyNode find(@NotNull PsArtifactDependencySpec spec) {
DefaultMutableTreeNode rootNode = getRootNode();
if (rootNode == null) {
return null;
}
int childCount = rootNode.getChildCount();
for (int i = 0; i < childCount; i++) {
TreeNode child = rootNode.getChildAt(i);
if (!(child instanceof DefaultMutableTreeNode)) {
continue;
}
Object userObject = ((DefaultMutableTreeNode) child).getUserObject();
if (!(userObject instanceof LibraryDependencyNode)) {
continue;
}
LibraryDependencyNode node = (LibraryDependencyNode) userObject;
for (PsLibraryAndroidDependency dependency : node.getModels()) {
if (spec.equals(dependency.getDeclaredSpec())) {
return node;
}
}
}
return null;
}
Aggregations