use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class GradleOperations method removeDependencies.
@Override
public void removeDependencies(@NotNull Module module, @NotNull DeveloperServiceMetadata metadata) {
final GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
boolean dependenciesChanged = false;
DependenciesModel dependenciesModel = buildModel.dependencies();
if (dependenciesModel != null) {
for (ArtifactDependencyModel dependency : dependenciesModel.artifacts()) {
ArtifactDependencySpec spec = ArtifactDependencySpec.create(dependency);
for (String dependencyValue : metadata.getDependencies()) {
if (spec.equals(ArtifactDependencySpec.create(dependencyValue))) {
dependenciesModel.remove(dependency);
dependenciesChanged = true;
break;
}
}
}
}
final Project project = module.getProject();
if (dependenciesChanged) {
new WriteCommandAction.Simple(project, "Uninstall " + metadata.getName()) {
@Override
public void run() {
buildModel.applyChanges();
}
}.execute();
}
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class GradleOperations method containsAllDependencies.
@Override
public boolean containsAllDependencies(@NotNull Module module, @NotNull DeveloperServiceMetadata metadata) {
// Consider ourselves installed if this service's dependencies are already found in the current
// module.
// TODO: Flesh this simplistic approach out more. We would like to have a way to say a service
// isn't installed even if its dependency happens to be added to the project. For example,
// multiple services might share a dependency but have additional settings that indicate some
// are installed and others aren't.
List<String> moduleDependencyNames = Lists.newArrayList();
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
DependenciesModel dependenciesModel = buildModel.dependencies();
if (dependenciesModel != null) {
for (ArtifactDependencyModel dependency : dependenciesModel.artifacts()) {
String name = dependency.name().value();
moduleDependencyNames.add(name);
}
}
}
boolean allDependenciesFound = true;
for (String serviceDependency : metadata.getDependencies()) {
boolean thisDependencyFound = false;
for (String moduleDependencyName : moduleDependencyNames) {
if (serviceDependency.contains(moduleDependencyName)) {
thisDependencyFound = true;
break;
}
}
if (!thisDependencyFound) {
allDependenciesFound = false;
break;
}
}
return allDependenciesFound;
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class PsJavaDependencyCollection method addDependencies.
private void addDependencies() {
PsParsedDependencies parsedDependencies = myParent.getParsedDependencies();
JavaModuleModel gradleModel = myParent.getGradleModel();
for (JarLibraryDependency libraryDependency : gradleModel.getJarLibraryDependencies()) {
GradleModuleVersion moduleVersion = libraryDependency.getModuleVersion();
if (moduleVersion != null) {
PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(moduleVersion);
ArtifactDependencyModel parsed = parsedDependencies.findLibraryDependency(moduleVersion);
PsLibraryJavaDependency dependency = new PsLibraryJavaDependency(myParent, spec, libraryDependency, parsed);
myLibraryDependenciesBySpec.put(spec.toString(), dependency);
}
}
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class PsAndroidModule method addLibraryDependency.
public void addLibraryDependency(@NotNull String library, @NotNull PsNewDependencyScopes newScopes, @NotNull List<String> scopesNames) {
// Update/reset the "parsed" model.
addLibraryDependencyToParsedModel(scopesNames, library);
// Reset dependencies.
myDependencyCollection = null;
PsAndroidDependencyCollection dependencyCollection = getOrCreateDependencyCollection();
List<PsAndroidArtifact> targetArtifacts = Lists.newArrayList();
forEachVariant(variant -> variant.forEachArtifact(artifact -> {
if (newScopes.contains(artifact)) {
targetArtifacts.add(artifact);
}
}));
assert !targetArtifacts.isEmpty();
PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(library);
assert spec != null;
PsParsedDependencies parsedDependencies = getParsedDependencies();
for (PsAndroidArtifact artifact : targetArtifacts) {
List<ArtifactDependencyModel> matchingParsedDependencies = parsedDependencies.findLibraryDependencies(spec, artifact::contains);
for (ArtifactDependencyModel parsedDependency : matchingParsedDependencies) {
dependencyCollection.addLibraryDependency(spec, artifact, parsedDependency);
}
}
fireLibraryDependencyAddedEvent(spec);
setModified(true);
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class GradleDependencyManager method updateDependencies.
private static void updateDependencies(@NotNull GradleBuildModel buildModel, @NotNull Module module, @NotNull List<GradleCoordinate> coordinates) {
ModuleRootModificationUtil.updateModel(module, model -> {
DependenciesModel dependenciesModel = buildModel.dependencies();
for (GradleCoordinate gc : coordinates) {
List<ArtifactDependencyModel> artifacts = Lists.newArrayList(dependenciesModel.artifacts());
for (ArtifactDependencyModel m : artifacts) {
if (gc.getGroupId() != null && gc.getGroupId().equals(m.group().value()) && gc.getArtifactId() != null && gc.getArtifactId().equals(m.name().value()) && !gc.getRevision().equals(m.version().value())) {
dependenciesModel.remove(m);
dependenciesModel.addArtifact(m.configurationName(), gc.toString());
}
}
}
buildModel.applyChanges();
});
}
Aggregations