use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class ImportModule method getLatestVersion.
@Nullable
public GradleCoordinate getLatestVersion(String artifact) {
int compileVersion = GradleImport.CURRENT_COMPILE_VERSION;
AndroidVersion version = getCompileSdkVersion();
if (version != AndroidVersion.DEFAULT) {
compileVersion = version.getFeatureLevel();
}
// from version 18 (earliest version where we have all the libs in the m2 repository)
if (compileVersion < 18) {
compileVersion = 18;
}
String compileVersionString = Integer.toString(compileVersion);
if (myImporter.getSdkLocation() != null) {
@SuppressWarnings("UnnecessaryLocalVariable") String filter = compileVersionString;
GradleCoordinate max = SdkMavenRepository.ANDROID.getHighestInstalledVersion(myImporter.getSdkLocation(), SUPPORT_GROUP_ID, artifact, filter, true);
if (max != null) {
return max;
}
}
String coordinate = SUPPORT_GROUP_ID + ':' + artifact + ':' + compileVersionString + ".+";
return GradleCoordinate.parseCoordinateString(coordinate);
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class RepositoryUrlManager method getLatestVersionFromMavenMetadata.
/**
* Parses a Maven metadata file and returns a string of the highest found version
*
* @param metadataFile the files to parse
* @param includePreviews if false, preview versions of the library will not be returned
* @return the string representing the highest version found in the file or "0.0.0" if no versions exist in the file
*/
@Nullable
private static String getLatestVersionFromMavenMetadata(@NotNull File metadataFile, @Nullable String filterPrefix, boolean includePreviews, @NotNull FileOp fileOp) throws IOException {
String xml = fileOp.toString(metadataFile, StandardCharsets.UTF_8);
List<GradleCoordinate> versions = Lists.newLinkedList();
try {
SAXParserFactory.newInstance().newSAXParser().parse(IOUtils.toInputStream(xml), new DefaultHandler() {
boolean inVersionTag = false;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equals(TAG_VERSION)) {
inVersionTag = true;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
// Get the version and compare it to the current known max version
if (inVersionTag) {
inVersionTag = false;
String revision = new String(ch, start, length);
//noinspection StatementWithEmptyBody
if (!includePreviews && "5.2.08".equals(revision) && metadataFile.getPath().contains(PLAY_SERVICES.getArtifactId())) {
// This version (despite not having -rcN in its version name is actually a preview
// (See https://code.google.com/p/android/issues/detail?id=75292)
// Ignore it
} else if (filterPrefix == null || revision.startsWith(filterPrefix)) {
versions.add(GradleCoordinate.parseVersionOnly(revision));
}
}
}
});
} catch (Exception e) {
LOG.warn(e);
}
if (versions.isEmpty()) {
return REVISION_ANY;
} else if (includePreviews) {
return GRADLE_COORDINATE_ORDERING.max(versions).getRevision();
} else {
return versions.stream().filter(v -> !v.isPreview()).max(GRADLE_COORDINATE_ORDERING).map(GradleCoordinate::getRevision).orElse(null);
}
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class RepositoryUrlManager method getLibraryRevision.
/**
* Returns the string for the specific version number of the most recent version of the given library
* (matching the given prefix filter, if any) in one of the Sdk repositories.
*
* @param groupId the group id
* @param artifactId the artifact id
* @param filterPrefix a prefix, if any
* @param includePreviews whether to include preview versions of libraries
* @return
*/
@Nullable
public String getLibraryRevision(@NotNull String groupId, @NotNull String artifactId, @Nullable String filterPrefix, boolean includePreviews, @NotNull File sdkLocation, @NotNull FileOp fileOp) {
// Try the new, combined repository first:
File combinedRepo = FileUtils.join(sdkLocation, FD_EXTRAS, FD_M2_REPOSITORY);
if (fileOp.isDirectory(combinedRepo)) {
GradleCoordinate versionInCombined = MavenRepositories.getHighestInstalledVersion(groupId, artifactId, combinedRepo, filterPrefix, includePreviews, fileOp);
if (versionInCombined != null) {
return versionInCombined.getRevision();
}
}
// Now try the "old" repositories, "google" and "android":
SdkMavenRepository repository = SdkMavenRepository.find(sdkLocation, groupId, artifactId, fileOp);
if (repository == null) {
// Try the repo embedded in AS. We distribute for example the constraint layout there for now.
List<File> paths = EmbeddedDistributionPaths.getInstance().findAndroidStudioLocalMavenRepoPaths();
for (File path : paths) {
if (path != null && path.isDirectory()) {
GradleCoordinate versionInEmbedded = MavenRepositories.getHighestInstalledVersion(groupId, artifactId, path, filterPrefix, includePreviews, fileOp);
if (versionInEmbedded != null) {
return versionInEmbedded.getRevision();
}
}
}
return null;
}
File repositoryLocation = repository.getRepositoryLocation(sdkLocation, true, fileOp);
if (repositoryLocation == null) {
return null;
}
// Try using the POM file:
File mavenMetadataFile = MavenRepositories.getMavenMetadataFile(repositoryLocation, groupId, artifactId);
if (fileOp.isFile(mavenMetadataFile)) {
try {
return getLatestVersionFromMavenMetadata(mavenMetadataFile, filterPrefix, includePreviews, fileOp);
} catch (IOException e) {
return null;
}
}
// Just scan all the directories:
GradleCoordinate max = repository.getHighestInstalledVersion(sdkLocation, groupId, artifactId, filterPrefix, includePreviews, fileOp);
if (max == null) {
return null;
}
return max.getRevision();
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class GradleDependencyManagerTest method testDependencyCanBeCancelledByUser.
public void testDependencyCanBeCancelledByUser() throws Exception {
loadSimpleApplication();
List<GradleCoordinate> dependencies = Collections.singletonList(RECYCLER_VIEW_DEPENDENCY);
GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(getProject());
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isNotEmpty();
Messages.setTestDialog(new TestMessagesDialog(Messages.NO));
boolean found = dependencyManager.ensureLibraryIsIncluded(myModules.getAppModule(), dependencies, null);
assertThat(found).isFalse();
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isNotEmpty();
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class DependencyManager method checkForNewMissingDependencies.
private boolean checkForNewMissingDependencies() {
Set<String> missing = Collections.emptySet();
if (myModule != null) {
GradleDependencyManager manager = GradleDependencyManager.getInstance(myProject);
List<GradleCoordinate> coordinates = toGradleCoordinatesFromIds(myPalette.getGradleCoordinateIds());
missing = fromGradleCoordinatesToIds(manager.findMissingDependencies(myModule, coordinates));
if (myMissingLibraries.equals(missing)) {
return false;
}
}
myMissingLibraries.clear();
myMissingLibraries.addAll(missing);
return true;
}
Aggregations