Search in sources :

Example 71 with GradleVersion

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

the class AndroidModelFeaturesTest method withPluginVersion2_1_0.

@Test
public void withPluginVersion2_1_0() {
    GradleVersion version = GradleVersion.parse("2.1.0");
    AndroidModelFeatures features = new AndroidModelFeatures(version);
    assertTrue(features.isIssueReportingSupported());
    assertTrue(features.isShadersSupported());
    assertFalse(features.isTestedTargetVariantsSupported());
    assertFalse(features.isProductFlavorVersionSuffixSupported());
    assertFalse(features.isExternalBuildSupported());
    assertFalse(features.isConstraintLayoutSdkLocationSupported());
    assertFalse(features.isLayoutRenderingIssuePresent());
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) Test(org.junit.Test)

Example 72 with GradleVersion

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

the class AndroidModelFeaturesTest method withPluginVersion1_1_0.

@Test
public void withPluginVersion1_1_0() {
    GradleVersion version = GradleVersion.parse("1.1.0");
    AndroidModelFeatures features = new AndroidModelFeatures(version);
    assertTrue(features.isIssueReportingSupported());
    assertFalse(features.isShadersSupported());
    assertFalse(features.isTestedTargetVariantsSupported());
    assertFalse(features.isProductFlavorVersionSuffixSupported());
    assertFalse(features.isExternalBuildSupported());
    assertFalse(features.isConstraintLayoutSdkLocationSupported());
    assertFalse(features.isLayoutRenderingIssuePresent());
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) Test(org.junit.Test)

Example 73 with GradleVersion

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

the class GradleModuleSetupTest method testSetUpModule.

public void testSetUpModule() {
    when(myModuleModels.getModule()).thenReturn(myModuleModel);
    when(myModuleModels.findModel(BuildScriptClasspathModel.class)).thenReturn(myClasspathModel);
    String gradleVersion = "2.14.1";
    when(myClasspathModel.getGradleVersion()).thenReturn(gradleVersion);
    myModuleSetup.setUpModule(myModule, myModelsProvider, myModuleModels);
    // Apply changes to verify state.
    ApplicationManager.getApplication().runWriteAction(() -> myModelsProvider.commit());
    GradleFacet facet = findFacet(myModule, myModelsProvider, GradleFacet.getFacetTypeId());
    assertNotNull(facet);
    GradleModuleModel gradleModuleModel = facet.getGradleModuleModel();
    assertNotNull(gradleModuleModel);
    assertEquals(":app", gradleModuleModel.getGradlePath());
    assertEquals(gradleVersion, gradleModuleModel.getGradleVersion());
    File buildFilePath = myModuleModel.getGradleProject().getBuildScript().getSourceFile();
    assertAbout(file()).that(gradleModuleModel.getBuildFilePath()).isEquivalentAccordingToCompareTo(buildFilePath);
    GradleVersion actualGradleVersion = mySyncSummary.getGradleVersion();
    assertNotNull(actualGradleVersion);
    assertEquals(gradleVersion, actualGradleVersion.toString());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Example 74 with GradleVersion

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

the class GradleApkProviderTest method GetApksForTestOnlyModule.

public void GetApksForTestOnlyModule() throws Exception {
    loadProject(TEST_ONLY_MODULE, "test");
    GradleApkProvider provider = new GradleApkProvider(myAndroidFacet, new GradleApplicationIdProvider(myAndroidFacet), true);
    Collection<ApkInfo> apks = provider.getApks(mock(IDevice.class));
    ApkInfo testApk = apks.stream().filter(a -> a.getApplicationId().equals("com.example.android.app.test")).findFirst().orElse(null);
    assertThat(testApk).isNotNull();
    GradleVersion modelVersion = getModel().getModelVersion();
    if (modelVersion != null) {
        if (modelVersion.compareIgnoringQualifiers("2.2.0") < 0) {
            // only the test-module apk should be there
            assertThat(apks).hasSize(1);
        } else {
            // both test-module apk and main apk should be there
            assertThat(apks).hasSize(2);
            ApkInfo mainApk = apks.stream().filter(a -> a.getApplicationId().equals("com.example.android.app")).findFirst().orElse(null);
            assertThat(mainApk).isNotNull();
        }
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 75 with GradleVersion

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

the class VersionCompatibilityCheckerTest method testCheckAndReportComponentIncompatibilities.

public void testCheckAndReportComponentIncompatibilities() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    GradleWrapper gradleWrapper = GradleWrapper.find(getProject());
    assertNotNull(gradleWrapper);
    String gradleVersion = gradleWrapper.getGradleVersion();
    assertNotNull(gradleVersion);
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    GradleVersion currentModelVersion = androidModel.getModelVersion();
    assertNotNull(currentModelVersion);
    String failureMessage = "Please use Android Gradle plugin 1.5.0 or newer.";
    @Language("XML") String metadata = "<compatibility version='1'>\n" + "  <check failureType='error'>\n" + "    <component name='gradle' version='[" + gradleVersion + ", +)'>\n" + "      <requires name='android-gradle-plugin' version='[100.0.0, +]'>\n" + "        <failureMsg>\n" + "           <![CDATA[\n" + failureMessage + "\n" + "]]>\n" + "        </failureMsg>\n" + "      </requires>\n" + "    </component>\n" + "  </check>\n" + "</compatibility>";
    VersionCompatibilityChecker checker = VersionCompatibilityChecker.getInstance();
    checker.reloadMetadataForTesting(metadata);
    checker.checkAndReportComponentIncompatibilities(getProject());
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    String firstLine = String.format("Gradle %1$s requires Android Gradle plugin 100.0.0 (or newer) but project is using version %2$s.", gradleVersion, currentModelVersion);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Gradle Sync Issues").hasType(ERROR).hasMessageLine(firstLine, 0).hasMessageLine(failureMessage, 1);
// @formatter:on
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Language(org.intellij.lang.annotations.Language) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper)

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