Search in sources :

Example 16 with GradleCoordinate

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));
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) RepoManager(com.android.repository.api.RepoManager) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RemotePackage(com.android.repository.api.RemotePackage) File(java.io.File)

Example 17 with GradleCoordinate

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;
}
Also used : BuildFileStatement(com.android.tools.idea.gradle.parser.BuildFileStatement) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) Dependency(com.android.tools.idea.gradle.parser.Dependency)

Example 18 with GradleCoordinate

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;
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 19 with GradleCoordinate

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();
}
Also used : FileOp(com.android.repository.io.FileOp) GRADLE_PLUGIN_RECOMMENDED_VERSION(com.android.SdkConstants.GRADLE_PLUGIN_RECOMMENDED_VERSION) IdeInfo(com.android.tools.idea.IdeInfo) COMPARE_PLUS_HIGHER(com.android.ide.common.repository.GradleCoordinate.COMPARE_PLUS_HIGHER) Nullable(com.android.annotations.Nullable) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Collection(java.util.Collection) FileOp(com.android.repository.io.FileOp) MavenRepositories.getHighestInstalledVersion(com.android.ide.common.repository.MavenRepositories.getHighestInstalledVersion) GENERATION_COMPONENT(com.android.builder.model.AndroidProject.GENERATION_COMPONENT) File(java.io.File) AndroidPlugin.isGuiTestingMode(org.jetbrains.android.AndroidPlugin.isGuiTestingMode) List(java.util.List) GradleValue.getValues(com.android.tools.idea.gradle.dsl.model.values.GradleValue.getValues) FileOpUtils(com.android.repository.io.FileOpUtils) GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION(com.android.SdkConstants.GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) EmbeddedDistributionPaths(com.android.tools.idea.gradle.util.EmbeddedDistributionPaths) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) NotNull(org.jetbrains.annotations.NotNull) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with GradleCoordinate

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();
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) ImmutableList(com.google.common.collect.ImmutableList) RepositoryUrlManager(com.android.tools.idea.templates.RepositoryUrlManager) SupportLibrary(com.android.tools.idea.templates.SupportLibrary) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)35 File (java.io.File)9 GradleDependencyManager (com.android.tools.idea.gradle.dependencies.GradleDependencyManager)5 NotNull (org.jetbrains.annotations.NotNull)5 RemotePackage (com.android.repository.api.RemotePackage)4 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)3 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)3 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 Nullable (org.jetbrains.annotations.Nullable)3 Nullable (com.android.annotations.Nullable)2 SdkMavenRepository (com.android.ide.common.repository.SdkMavenRepository)2 RepoManager (com.android.repository.api.RepoManager)2 RepoPackage (com.android.repository.api.RepoPackage)2 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)2 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)2 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2