use of com.android.tools.lint.client.api.LintClient in project android by JetBrains.
the class RepositoryUrlManager method resolveDynamicCoordinateVersion.
@Nullable
@VisibleForTesting
String resolveDynamicCoordinateVersion(@NotNull GradleCoordinate coordinate, @Nullable Project project, @NotNull AndroidSdkHandler sdkHandler) {
if (coordinate.getGroupId() == null || coordinate.getArtifactId() == null) {
return null;
}
String filter = coordinate.getRevision();
if (!filter.endsWith("+")) {
// Already resolved. That was easy.
return filter;
}
filter = filter.substring(0, filter.length() - 1);
File sdkLocation = sdkHandler.getLocation();
if (sdkLocation != null) {
// If this coordinate points to an artifact in one of our repositories, mark it will a comment if they don't
// have that repository available.
String libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, false, sdkLocation, sdkHandler.getFileOp());
if (libraryCoordinate != null) {
return libraryCoordinate;
}
// If that didn't yield any matches, try again, this time allowing preview platforms.
// This is necessary if the artifact filter includes enough of a version where there are
// only preview matches.
libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, true, sdkLocation, sdkHandler.getFileOp());
if (libraryCoordinate != null) {
return libraryCoordinate;
}
}
// Regular Gradle dependency? Look in Gradle cache
GradleVersion versionFound = GradleLocalCache.getInstance().findLatestArtifactVersion(coordinate, project, filter);
if (versionFound != null) {
return versionFound.toString();
}
// Maybe it's available for download as an SDK component
RemotePackage sdkPackage = SdkMavenRepository.findLatestRemoteVersion(coordinate, sdkHandler, new StudioLoggerProgressIndicator(getClass()));
if (sdkPackage != null) {
GradleCoordinate found = SdkMavenRepository.getCoordinateFromSdkPath(sdkPackage.getPath());
if (found != null) {
return found.getRevision();
}
}
// Perform network lookup to resolve current best version, if possible
if (project != null) {
LintClient client = new LintIdeClient(project);
Revision latest = GradleDetector.getLatestVersionFromRemoteRepo(client, coordinate, coordinate.isPreview());
if (latest != null) {
String version = latest.toShortString();
if (version.startsWith(filter)) {
return version;
}
}
}
return null;
}
Aggregations