use of com.android.tools.idea.gradle.structure.model.PsParsedDependencies 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.structure.model.PsParsedDependencies 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.structure.model.PsParsedDependencies in project android by JetBrains.
the class PsAndroidDependencyCollection method addLibrary.
@Nullable
private PsAndroidDependency addLibrary(@NotNull Library library, @NotNull PsAndroidArtifact artifact) {
PsParsedDependencies parsedDependencies = myParent.getParsedDependencies();
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates != null) {
PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(coordinates);
ArtifactDependencyModel matchingParsedDependency = parsedDependencies.findLibraryDependency(coordinates, artifact::contains);
if (matchingParsedDependency != null) {
String parsedVersionValue = matchingParsedDependency.version().value();
if (parsedVersionValue != null) {
// The dependency has a version in the build.gradle file.
// "tryParse" just in case the build.file has an invalid version.
GradleVersion parsedVersion = GradleVersion.tryParse(parsedVersionValue);
GradleVersion versionFromGradle = GradleVersion.parse(coordinates.getVersion());
if (parsedVersion != null && compare(parsedVersion, versionFromGradle) == 0) {
// Match.
return addLibrary(library, spec, artifact, matchingParsedDependency);
} else {
// Version mismatch. This can happen when the project specifies an artifact version but Gradle uses a different version
// from a transitive dependency.
// Example:
// 1. Module 'app' depends on module 'lib'
// 2. Module 'app' depends on Guava 18.0
// 3. Module 'lib' depends on Guava 19.0
// Gradle will force module 'app' to use Guava 19.0
// This is a case that may look as a version mismatch:
//
// testCompile 'junit:junit:4.11+'
// androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
//
// Here 'espresso' brings junit 4.12, but there is no mismatch with junit 4.11, because they are in different artifacts.
PsLibraryAndroidDependency potentialDuplicate = null;
for (PsLibraryAndroidDependency dependency : myLibraryDependenciesBySpec.values()) {
if (dependency.getParsedModels().contains(matchingParsedDependency)) {
potentialDuplicate = dependency;
break;
}
}
if (potentialDuplicate != null) {
// TODO match ArtifactDependencyModel#configurationName with potentialDuplicate.getContainers().artifact
}
// Create the dependency model that will be displayed in the "Dependencies" table.
addLibrary(library, spec, artifact, matchingParsedDependency);
// Create a dependency model for the transitive dependency, so it can be displayed in the "Variants" tool window.
return addLibrary(library, spec, artifact, null);
}
}
} else {
// This dependency was not declared, it could be a transitive one.
return addLibrary(library, spec, artifact, null);
}
}
return null;
}
use of com.android.tools.idea.gradle.structure.model.PsParsedDependencies in project android by JetBrains.
the class PsAndroidDependencyCollection method addModule.
private void addModule(@NotNull String gradlePath, @NotNull PsAndroidArtifact artifact, @Nullable String projectVariant) {
PsParsedDependencies parsedDependencies = myParent.getParsedDependencies();
ModuleDependencyModel matchingParsedDependency = parsedDependencies.findModuleDependency(gradlePath, artifact::contains);
Module resolvedModule = null;
PsModule module = myParent.getParent().findModuleByGradlePath(gradlePath);
if (module != null) {
resolvedModule = module.getResolvedModel();
}
PsModuleAndroidDependency dependency = findElement(gradlePath, PsModuleAndroidDependency.class);
if (dependency == null) {
dependency = new PsModuleAndroidDependency(myParent, gradlePath, artifact, projectVariant, resolvedModule, matchingParsedDependency);
myModuleDependenciesByGradlePath.put(gradlePath, dependency);
}
updateDependency(dependency, artifact, matchingParsedDependency);
}
use of com.android.tools.idea.gradle.structure.model.PsParsedDependencies in project android by JetBrains.
the class PsJavaModule method addLibraryDependency.
public void addLibraryDependency(@NotNull String library, @NotNull List<String> scopesNames) {
// Update/reset the "parsed" model.
addLibraryDependencyToParsedModel(scopesNames, library);
// Reset dependencies.
myDependencyCollection = null;
PsJavaDependencyCollection dependencyCollection = getOrCreateDependencyCollection();
PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(library);
assert spec != null;
PsParsedDependencies parsedDependencies = getParsedDependencies();
List<ArtifactDependencyModel> matchingParsedDependencies = parsedDependencies.findLibraryDependencies(spec, null);
for (ArtifactDependencyModel parsedDependency : matchingParsedDependencies) {
dependencyCollection.addLibraryDependency(spec, parsedDependency);
}
fireLibraryDependencyAddedEvent(spec);
setModified(true);
}
Aggregations