use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class RepositoryUrlManagerTest method testResolvedCoordinateRemoteSdk.
public void testResolvedCoordinateRemoteSdk() throws Exception {
RemotePackage pkg = new FakePackage.FakeRemotePackage("extras;m2repository;com;google;android;gms;play-services;4.5.0");
RepositoryPackages pkgs = new RepositoryPackages(ImmutableList.of(), ImmutableList.of(pkg));
RepoManager mgr = new FakeRepoManager(pkgs);
mySdkHandler = new AndroidSdkHandler(new File("/emptysdk"), ANDROID_HOME, myFileOp, mgr);
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString("com.google.android.gms:play-services:4.+");
assertNotNull(coordinate);
assertEquals("4.5.0", resolveDynamicCoordinateVersion(coordinate));
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class ModuleDependenciesTableModel method getRow.
public int getRow(@NotNull GradleCoordinate dependency) {
int rowCount = getRowCount();
for (int i = 0; i < rowCount; i++) {
Object value = getValueAt(i, ITEM_COLUMN);
if (value instanceof ModuleDependenciesTableItem) {
BuildFileStatement entry = ((ModuleDependenciesTableItem) value).getEntry();
if (entry instanceof Dependency) {
String current = ((Dependency) entry).getValueAsString();
GradleCoordinate currentCoordinate = GradleCoordinate.parseCoordinateString(current);
if (currentCoordinate != null && dependency.equals(currentCoordinate)) {
return i;
}
}
}
}
return -1;
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class GradleFilePsiMerger method pullDependenciesIntoMap.
/**
* Looks for statements adding dependencies to different configurations (which look like 'configurationName "dependencyCoordinate"')
* and tries to parse them into Gradle coordinates. If successful, adds the new coordinate to the map and removes the corresponding
* PsiElement from the tree.
*
* @return true if new items were added to the map
*/
private static boolean pullDependenciesIntoMap(@NotNull PsiElement root, @NotNull Map<String, Multimap<String, GradleCoordinate>> allConfigurations, @Nullable List<String> unparsedDependencies) {
boolean wasMapUpdated = false;
for (PsiElement existingElem : root.getChildren()) {
if (existingElem instanceof GrCall) {
PsiElement reference = existingElem.getFirstChild();
if (reference instanceof GrReferenceExpression) {
final String configurationName = reference.getText();
boolean parsed = false;
GrCall call = (GrCall) existingElem;
GrArgumentList arguments = call.getArgumentList();
// Don't try merging dependencies if one of them has a closure block attached.
if (arguments != null && call.getClosureArguments().length == 0) {
GrExpression[] expressionArguments = arguments.getExpressionArguments();
if (expressionArguments.length == 1 && expressionArguments[0] instanceof GrLiteral) {
Object value = ((GrLiteral) expressionArguments[0]).getValue();
if (value instanceof String) {
String coordinateText = (String) value;
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(coordinateText);
if (coordinate != null) {
parsed = true;
Multimap<String, GradleCoordinate> map = allConfigurations.get(configurationName);
if (map == null) {
map = LinkedListMultimap.create();
allConfigurations.put(configurationName, map);
}
if (!map.get(coordinate.getId()).contains(coordinate)) {
map.put(coordinate.getId(), coordinate);
existingElem.delete();
wasMapUpdated = true;
}
}
}
}
if (!parsed && unparsedDependencies != null) {
unparsedDependencies.add(existingElem.getText());
}
}
}
}
}
return wasMapUpdated;
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class AndroidPluginGeneration method getLatestKnownVersion.
@NotNull
protected String getLatestKnownVersion(@NotNull AndroidPluginGeneration generation) {
String artifactId = generation.getArtifactId();
FileOp fileOp = FileOpUtils.create();
List<File> repoPaths = EmbeddedDistributionPaths.getInstance().findAndroidStudioLocalMavenRepoPaths();
Optional<GradleCoordinate> highestValueCoordinate = repoPaths.stream().map(repoPath -> getHighestInstalledVersion(getGroupId(), artifactId, repoPath, null, true, fileOp)).filter(coordinate -> coordinate != null).max(COMPARE_PLUS_HIGHER);
if (!highestValueCoordinate.isPresent()) {
if (IdeInfo.getInstance().isAndroidStudio() && !isGuiTestingMode() && !ApplicationManager.getApplication().isInternal() && !ApplicationManager.getApplication().isUnitTestMode()) {
// In a release build, Android Studio must find the latest version in its offline repo(s).
throw new IllegalStateException("Gradle plugin missing from the offline Maven repo");
} else {
// In all other scenarios we will not throw an exception, but use the last known version from SdkConstants.
// TODO: revisit this when tests are running with the latest (source) build.
String version = generation.getRecommendedVersion();
getLog().info("'" + artifactId + "' plugin missing from the offline Maven repo, will use default " + version);
return version;
}
}
return highestValueCoordinate.get().getRevision();
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class AndroidAddLibraryDependencyAction method findAllDependencies.
/**
* Finds all the "extras repository" dependencies that haven't been already added to the project.
*/
@NotNull
private static ImmutableCollection<String> findAllDependencies(@NotNull GradleBuildModel buildModel) {
HashSet<String> existingDependencies = Sets.newHashSet();
for (ArtifactDependencyModel dependency : buildModel.dependencies().artifacts()) {
existingDependencies.add(dependency.group().value() + ":" + dependency.name().value());
}
ImmutableList.Builder<String> dependenciesBuilder = ImmutableList.builder();
RepositoryUrlManager repositoryUrlManager = RepositoryUrlManager.get();
for (SupportLibrary library : SupportLibrary.values()) {
// Coordinate for any version available
GradleCoordinate libraryCoordinate = library.getGradleCoordinate("+");
// Get from the library coordinate only the group and artifactId to check if we have already added it
if (!existingDependencies.contains(libraryCoordinate.getId())) {
GradleCoordinate coordinate = repositoryUrlManager.resolveDynamicCoordinate(libraryCoordinate, buildModel.getProject());
if (coordinate != null) {
dependenciesBuilder.add(coordinate.toString());
}
}
}
return dependenciesBuilder.build();
}
Aggregations