use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec in project android by JetBrains.
the class PsAndroidModuleTest method testEditableDependenciesWithPlusInVersion.
public void testEditableDependenciesWithPlusInVersion() throws Throwable {
loadProject(PROJECT_WITH_APPAND_LIB);
Project resolvedProject = myFixture.getProject();
PsProject project = new PsProject(resolvedProject);
PsAndroidModule appModule = (PsAndroidModule) project.findModuleByName("app");
assertNotNull(appModule);
List<PsAndroidDependency> declaredDependencies = getDeclaredDependencies(appModule);
assertThat(declaredDependencies).hasSize(1);
// Verify that appcompat is considered a "editable" dependency, and it was matched properly
PsLibraryAndroidDependency appCompatV7 = (PsLibraryAndroidDependency) declaredDependencies.get(0);
assertTrue(appCompatV7.isDeclared());
PsArtifactDependencySpec declaredSpec = appCompatV7.getDeclaredSpec();
assertNotNull(declaredSpec);
assertEquals("com.android.support:appcompat-v7:+", declaredSpec.toString());
PsArtifactDependencySpec resolvedSpec = appCompatV7.getResolvedSpec();
assertEquals("com.android.support", resolvedSpec.group);
assertEquals("appcompat-v7", resolvedSpec.name);
assertThat(resolvedSpec.version).isNotEqualTo("+");
// Verify that the variants where appcompat is are properly registered.
Collection<String> variants = appCompatV7.getVariants();
assertThat(variants).containsExactly("paidDebug", "paidRelease", "basicDebug", "basicRelease");
for (String variant : variants) {
assertNotNull(appModule.findVariant(variant));
}
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec 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.PsArtifactDependencySpec in project android by JetBrains.
the class MavenPoms method createSpec.
@Nullable
private static PsArtifactDependencySpec createSpec(@NotNull Element dependencyElement) {
String artifactId = null;
String groupId = null;
String version = null;
String scope = null;
boolean optional = false;
for (Element childElement : dependencyElement.getChildren()) {
String name = childElement.getName();
if ("artifactId".equals(name)) {
artifactId = textOf(childElement);
} else if ("groupId".equals(name)) {
groupId = textOf(childElement);
} else if ("version".equals(name)) {
version = textOf(childElement);
} else if ("optional".equals(name)) {
optional = Boolean.valueOf(textOf(childElement));
} else if ("scope".equals(name)) {
scope = textOf(childElement);
}
}
if (isNotEmpty(artifactId) && !optional && ("compile".equals(scope) || isEmpty(scope))) {
return new PsArtifactDependencySpec(artifactId, groupId, version);
}
return null;
}
use of com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec 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.PsArtifactDependencySpec in project android by JetBrains.
the class MultipleLibraryDependenciesDetails method display.
@Override
public void display(@NotNull PsDependency dependency) {
myDependency = (PsLibraryDependency) dependency;
PsArtifactDependencySpec resolvedSpec = myDependency.getResolvedSpec();
myArtifactNameLabel.setText(resolvedSpec.name);
myGroupIdLabel.setText(resolvedSpec.group);
}
Aggregations