Search in sources :

Example 61 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class GradleUtil method getDirectLibraryDependencies.

/**
   * Returns the library dependencies in the given variant. This method checks dependencies in the main and test (as currently selected
   * in the UI) artifacts. The dependency lookup is not transitive (only direct dependencies are returned.)
   */
@NotNull
public static List<AndroidLibrary> getDirectLibraryDependencies(@NotNull Variant variant, @NotNull AndroidModuleModel androidModel) {
    List<AndroidLibrary> libraries = Lists.newArrayList();
    GradleVersion modelVersion = androidModel.getModelVersion();
    AndroidArtifact mainArtifact = variant.getMainArtifact();
    Dependencies dependencies = getDependencies(mainArtifact, modelVersion);
    libraries.addAll(dependencies.getLibraries());
    for (BaseArtifact testArtifact : getTestArtifacts(variant)) {
        dependencies = getDependencies(testArtifact, modelVersion);
        libraries.addAll(dependencies.getLibraries());
    }
    return libraries;
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class NewModuleWizardDynamic method determineGradlePluginVersion.

@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
    if (project != null) {
        GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
        if (versionInUse != null) {
            return versionInUse.toString();
        }
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
        if (androidPluginInfo != null) {
            GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
            if (pluginVersion != null) {
                return pluginVersion.toString();
            }
        }
    }
    return AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) GradleVersion(com.android.ide.common.repository.GradleVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class DefaultRecipeExecutor method addClasspath.

@Override
public void addClasspath(@NotNull String mavenUrl) {
    mavenUrl = mavenUrl.trim();
    myReferences.addClasspath(mavenUrl);
    ArtifactDependencySpec toBeAddedDependency = ArtifactDependencySpec.create(mavenUrl);
    if (toBeAddedDependency == null) {
        throw new RuntimeException(mavenUrl + " is not a valid classpath dependency");
    }
    Project project = myContext.getProject();
    File rootBuildFile = getGradleBuildFilePath(getBaseDirPath(project));
    if (project.isInitialized()) {
        GradleBuildModel buildModel = getBuildModel(rootBuildFile, project);
        DependenciesModel buildscriptDependencies = buildModel.buildscript().dependencies();
        ArtifactDependencyModel targetDependencyModel = null;
        for (ArtifactDependencyModel dependencyModel : buildscriptDependencies.artifacts(CLASSPATH_CONFIGURATION_NAME)) {
            if (toBeAddedDependency.equalsIgnoreVersion(ArtifactDependencySpec.create(dependencyModel))) {
                targetDependencyModel = dependencyModel;
            }
        }
        if (targetDependencyModel == null) {
            buildscriptDependencies.addArtifact(CLASSPATH_CONFIGURATION_NAME, toBeAddedDependency);
        } else {
            GradleVersion toBeAddedDependencyVersion = GradleVersion.parse(nullToEmpty(toBeAddedDependency.version));
            GradleVersion existingDependencyVersion = GradleVersion.parse(nullToEmpty(targetDependencyModel.version().value()));
            if (toBeAddedDependencyVersion.compareTo(existingDependencyVersion) > 0) {
                targetDependencyModel.setVersion(nullToEmpty(toBeAddedDependency.version));
            }
        }
        myIO.applyChanges(buildModel);
    } else {
        String destinationContents = rootBuildFile.exists() ? nullToEmpty(readTextFile(rootBuildFile)) : "";
        String result = myIO.mergeGradleFiles(formatClasspath(mavenUrl), destinationContents, project, "");
        try {
            myIO.writeFile(this, result, rootBuildFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    myNeedsGradleSync = true;
}
Also used : Project(com.intellij.openapi.project.Project) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel) IOException(java.io.IOException) GradleVersion(com.android.ide.common.repository.GradleVersion) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel.parseBuildFile(com.android.tools.idea.gradle.dsl.model.GradleBuildModel.parseBuildFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) ArtifactDependencySpec(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)

Example 64 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class AndroidPluginInfoTest method testFindWithStablePlugin.

public void testFindWithStablePlugin() throws Exception {
    loadSimpleApplication();
    AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(getProject());
    assertNotNull(androidPluginInfo);
    assertNotNull(androidPluginInfo.getModule());
    assertEquals("app", androidPluginInfo.getModule().getName());
    assertEquals(ORIGINAL, androidPluginInfo.getPluginGeneration());
    assertNull(androidPluginInfo.getPluginBuildFile());
    GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
    assertNotNull(pluginVersion);
    assertEquals(BuildEnvironment.getInstance().getGradlePluginVersion(), pluginVersion.toString());
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 65 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class AndroidPluginInfoTest method testFindWithStablePluginReadingBuildFilesOnly.

public void testFindWithStablePluginReadingBuildFilesOnly() throws Exception {
    loadSimpleApplication();
    AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(getProject());
    assertNotNull(androidPluginInfo);
    assertNotNull(androidPluginInfo.getModule());
    assertEquals("app", androidPluginInfo.getModule().getName());
    assertEquals(ORIGINAL, androidPluginInfo.getPluginGeneration());
    assertNotNull(androidPluginInfo.getPluginBuildFile());
    assertEquals(new File(getProjectFolderPath(), FN_BUILD_GRADLE), new File(androidPluginInfo.getPluginBuildFile().getPath()));
    GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
    assertNotNull(pluginVersion);
    assertEquals(BuildEnvironment.getInstance().getGradlePluginVersion(), pluginVersion.toString());
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Aggregations

GradleVersion (com.android.ide.common.repository.GradleVersion)77 File (java.io.File)25 Test (org.junit.Test)16 Module (com.intellij.openapi.module.Module)12 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)5 IOException (java.io.IOException)5 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)4 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)3 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)3 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 ZipFile (java.util.zip.ZipFile)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 Variant (com.android.builder.model.Variant)2 IDevice (com.android.ddmlib.IDevice)2 Revision (com.android.repository.Revision)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2