use of com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel 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.DependenciesModel 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.DependenciesModel in project android by JetBrains.
the class GradleBuildModel method dependencies.
public DependenciesModel dependencies() {
DependenciesDslElement dependenciesDslElement = myGradleDslFile.getPropertyElement(DEPENDENCIES_BLOCK_NAME, DependenciesDslElement.class);
if (dependenciesDslElement == null) {
dependenciesDslElement = new DependenciesDslElement(myGradleDslFile);
myGradleDslFile.setNewElement(DEPENDENCIES_BLOCK_NAME, dependenciesDslElement);
}
return new DependenciesModel(dependenciesDslElement);
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel 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();
});
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel in project android by JetBrains.
the class GradleProjectDependencyParser method parse.
@NotNull
private static Set<String> parse(@NotNull VirtualFile moduleRoot, @NotNull Project project) {
VirtualFile buildFile = moduleRoot.findChild(FN_BUILD_GRADLE);
if (buildFile == null) {
return Collections.emptySet();
} else {
Set<String> result = Sets.newHashSet();
GradleBuildModel buildModel = parseBuildFile(buildFile, project);
DependenciesModel dependenciesModel = buildModel.dependencies();
if (dependenciesModel != null) {
for (ModuleDependencyModel dependency : dependenciesModel.modules()) {
String modulePath = dependency.path().value();
result.add(modulePath);
}
}
return result;
}
}
Aggregations