use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class UpgradeAppenginePluginVersionHyperlink method execute.
@Override
protected void execute(@NotNull Project project) {
ExternalRepository repository = ServiceManager.getService(ExternalRepository.class);
GradleVersion latest = repository.getLatest(APPENGINE_PLUGIN_GROUP_ID, APPENGINE_PLUGIN_ARTIFACT_ID);
if (latest == null) {
latest = DEFAULT_APPENGINE_PLUGIN_VERSION;
}
myDependency.setVersion(latest.toString());
runWriteCommandAction(project, myBuildModel::applyChanges);
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class PsLibraryDependency method setVersion.
default default void setVersion(@NotNull String version) {
boolean modified = false;
ArtifactDependencyModel reference = null;
for (DependencyModel parsedDependency : getParsedModels()) {
if (parsedDependency instanceof ArtifactDependencyModel) {
ArtifactDependencyModel dependency = (ArtifactDependencyModel) parsedDependency;
dependency.setVersion(version);
if (reference == null) {
reference = dependency;
}
modified = true;
}
}
if (modified) {
GradleVersion parsedVersion = GradleVersion.parse(version);
PsArtifactDependencySpec resolvedSpec = getResolvedSpec();
String resolvedVersion = nullToEmpty(resolvedSpec.version);
if (parsedVersion.compareTo(resolvedVersion) != 0) {
// Update the "resolved" spec with the new version
resolvedSpec = new PsArtifactDependencySpec(resolvedSpec.name, resolvedSpec.group, version);
setResolvedSpec(resolvedSpec);
}
setDeclaredSpec(createSpec(reference));
setModified(true);
getParent().fireDependencyModifiedEvent((PsDependency) this);
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class PsParsedDependencies method findLibraryDependency.
@Nullable
public ArtifactDependencyModel findLibraryDependency(@NotNull GradleModuleVersion moduleVersion) {
Collection<ArtifactDependencyModel> potentialMatches = myParsedArtifactDependencies.get(createIdFrom(moduleVersion));
if (potentialMatches.size() == 1) {
// Only one found. Just use it.
return getFirstItem(potentialMatches);
}
String version = nullToEmpty(moduleVersion.getVersion());
Map<GradleVersion, ArtifactDependencyModel> dependenciesByVersion = Maps.newHashMap();
for (ArtifactDependencyModel potentialMatch : potentialMatches) {
String potentialVersion = nullToEmpty(potentialMatch.version().value());
if (version.equals(potentialVersion)) {
// Perfect version match. Use it.
return potentialMatch;
}
if (isNotEmpty(potentialVersion)) {
// Collect all the "parsed" dependencies with same group and name, to make a best guess later.
GradleVersion parsedVersion = GradleVersion.tryParse(potentialVersion);
if (parsedVersion != null) {
dependenciesByVersion.put(parsedVersion, potentialMatch);
}
}
}
if (isNotEmpty(version) && !dependenciesByVersion.isEmpty()) {
GradleVersion parsedVersion = GradleVersion.tryParse(version);
if (parsedVersion != null) {
for (GradleVersion potentialVersion : dependenciesByVersion.keySet()) {
if (parsedVersion.compareTo(potentialVersion) > 0) {
return dependenciesByVersion.get(potentialVersion);
}
}
}
}
return null;
}
use of com.android.ide.common.repository.GradleVersion 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.ide.common.repository.GradleVersion in project android by JetBrains.
the class GradleSyncState method syncEnded.
public void syncEnded() {
LOG.info(String.format("Sync with Gradle successful for project '%1$s'.", myProject.getName()));
addInfoToEventLog("Gradle sync completed");
// Temporary: Clear resourcePrefix flag in case it was set to false when working with
// an older model. TODO: Remove this when we no longer support models older than 0.10.
//noinspection AssignmentToStaticFieldFromInstanceMethod
LintUtils.sTryPrefixLookup = true;
syncFinished();
syncPublisher(() -> myMessageBus.syncPublisher(GRADLE_SYNC_TOPIC).syncSucceeded(myProject));
GradleVersion gradleVersion = GradleVersions.getInstance().getGradleVersion(myProject);
String gradleVersionString = gradleVersion != null ? gradleVersion.toString() : "";
// @formatter:off
AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder().setCategory(GRADLE_SYNC).setKind(GRADLE_SYNC_ENDED).setGradleVersion(gradleVersionString);
// @formatter:on
UsageTracker.getInstance().log(event);
}
Aggregations