Search in sources :

Example 31 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.

the class ArtifactDependencyTest method testParseMapNotationWithVariables.

public void testParseMapNotationWithVariables() throws IOException {
    String text = "ext {\n" + "    guavaVersion = '18.0'\n" + "}\n" + "dependencies {\n" + "    compile group: 'com.google.guava', name: 'guava', version: \"$guavaVersion\"\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency(COMPILE, "guava", "com.google.guava", "18.0");
    ArtifactDependencyModel guavaDependencyModel = dependencies.get(0);
    expected.assertMatches(guavaDependencyModel);
    GradleNotNullValue<String> guavaDependency = guavaDependencyModel.compactNotation();
    verifyGradleValue(guavaDependency, "dependencies.compile", "group: 'com.google.guava', name: 'guava', version: \"$guavaVersion\"");
    assertEquals(expected.compactNotation(), guavaDependency.value());
    Map<String, GradleNotNullValue<Object>> guavaResolvedVariables = guavaDependency.getResolvedVariables();
    assertEquals(1, guavaResolvedVariables.size());
    GradleNotNullValue<Object> guavaVersionVariable = guavaResolvedVariables.get("guavaVersion");
    assertNotNull(guavaVersionVariable);
    verifyGradleValue(guavaVersionVariable, "ext.guavaVersion", "'18.0'");
    assertEquals("18.0", guavaVersionVariable.value());
    assertEquals(0, guavaVersionVariable.getResolvedVariables().size());
    // Now test that resolved variables are not reported for group and name properties.
    GradleNullableValue<String> group = guavaDependencyModel.group();
    assertEquals("com.google.guava", group.value());
    assertEquals(0, group.getResolvedVariables().size());
    GradleNotNullValue<String> name = guavaDependencyModel.name();
    assertEquals("guava", name.value());
    assertEquals(0, name.getResolvedVariables().size());
    // and thee guavaVersion variable is reported for version property.
    GradleNullableValue<String> version = guavaDependencyModel.version();
    verifyGradleValue(version, "dependencies.compile.version", "\"$guavaVersion\"");
    assertEquals("18.0", version.value());
    guavaResolvedVariables = version.getResolvedVariables();
    assertEquals(1, guavaResolvedVariables.size());
    guavaVersionVariable = guavaResolvedVariables.get("guavaVersion");
    assertNotNull(guavaVersionVariable);
    verifyGradleValue(guavaVersionVariable, "ext.guavaVersion", "'18.0'");
    assertEquals("18.0", guavaVersionVariable.value());
    assertEquals(0, guavaVersionVariable.getResolvedVariables().size());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) GradleNotNullValue(com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)

Example 32 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.

the class ArtifactDependencyTest method testRemoveDependencyWithMapNotation.

public void testRemoveDependencyWithMapNotation() throws IOException {
    String text = "dependencies {\n" + "    compile group: 'com.google.code.guice', name: 'guice', version: '1.0'\n" + "    compile group: 'com.google.guava', name: 'guava', version: '18.0'\n" + "    compile group: 'com.android.support', name: 'appcompat-v7', version: '22.1.1'\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(3);
    ArtifactDependencyModel guava = dependencies.get(1);
    dependenciesModel.remove(guava);
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(2);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("compile", "guice", "com.google.code.guice", "1.0");
    expected.assertMatches(dependencies.get(0));
    expected = new ExpectedArtifactDependency(COMPILE, "appcompat-v7", "com.android.support", "22.1.1");
    expected.assertMatches(dependencies.get(1));
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 33 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.

the class ArtifactDependencyTest method testParseCompactNotationClosureWithVariables.

public void testParseCompactNotationClosureWithVariables() throws IOException {
    String text = "ext {\n" + "    appcompat = 'com.android.support:appcompat-v7:22.1.1'\n" + "    guavaVersion = '18.0'\n" + "}\n" + "dependencies {\n" + "    compile(appcompat, \"com.google.guava:guava:$guavaVersion\") {\n" + "    }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(2);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency(COMPILE, "appcompat-v7", "com.android.support", "22.1.1");
    ArtifactDependencyModel appcompatDependencyModel = dependencies.get(0);
    expected.assertMatches(appcompatDependencyModel);
    GradleNotNullValue<String> appcompatDependency = appcompatDependencyModel.compactNotation();
    verifyGradleValue(appcompatDependency, "dependencies.compile.compile", "appcompat");
    assertEquals(expected.compactNotation(), appcompatDependency.value());
    Map<String, GradleNotNullValue<Object>> appcompatResolvedVariables = appcompatDependency.getResolvedVariables();
    assertEquals(1, appcompatResolvedVariables.size());
    GradleNotNullValue<Object> appcompatVariable = appcompatResolvedVariables.get("appcompat");
    assertNotNull(appcompatVariable);
    verifyGradleValue(appcompatVariable, "ext.appcompat", "'com.android.support:appcompat-v7:22.1.1'");
    assertEquals("com.android.support:appcompat-v7:22.1.1", appcompatVariable.value());
    assertEquals(0, appcompatVariable.getResolvedVariables().size());
    expected = new ExpectedArtifactDependency(COMPILE, "guava", "com.google.guava", "18.0");
    ArtifactDependencyModel guavaDependencyModel = dependencies.get(1);
    expected.assertMatches(guavaDependencyModel);
    GradleNotNullValue<String> guavaDependency = guavaDependencyModel.compactNotation();
    verifyGradleValue(guavaDependency, "dependencies.compile.compile", "\"com.google.guava:guava:$guavaVersion\"");
    assertEquals(expected.compactNotation(), guavaDependency.value());
    Map<String, GradleNotNullValue<Object>> guavaResolvedVariables = guavaDependency.getResolvedVariables();
    assertEquals(1, guavaResolvedVariables.size());
    GradleNotNullValue<Object> guavaVersionVariable = guavaResolvedVariables.get("guavaVersion");
    assertNotNull(guavaVersionVariable);
    verifyGradleValue(guavaVersionVariable, "ext.guavaVersion", "'18.0'");
    assertEquals("18.0", guavaVersionVariable.value());
    assertEquals(0, guavaVersionVariable.getResolvedVariables().size());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) GradleNotNullValue(com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)

Example 34 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.

the class ArtifactDependencyTest method testAddDependencyWithConfigurationClosure.

public void testAddDependencyWithConfigurationClosure() throws IOException {
    String text = "dependencies {\n" + "    runtime group: 'org.gradle.test.classifiers', name: 'service', version: '1.0', classifier: 'jdk14', ext: 'jar'\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    ArtifactDependencySpec newDependency = new ArtifactDependencySpec("espresso-contrib", "com.android.support.test.espresso", "2.2.2");
    dependenciesModel.addArtifact(ANDROID_TEST_COMPILE, newDependency, ImmutableList.of(new ArtifactDependencySpec("support-v4", "com.android.support", null), new ArtifactDependencySpec("support-annotations", "com.android.support", null), new ArtifactDependencySpec("recyclerview-v7", "com.android.support", null), new ArtifactDependencySpec("design", "com.android.support", null)));
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependenciesModel = buildModel.dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(2);
    ArtifactDependencyModel jdkDependency = dependencies.get(0);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency(RUNTIME, "service", "org.gradle.test.classifiers", "1.0");
    expected.classifier = "jdk14";
    expected.extension = "jar";
    expected.assertMatches(jdkDependency);
    assertNull(jdkDependency.configuration());
    ArtifactDependencyModel espressoDependency = dependencies.get(1);
    expected = new ExpectedArtifactDependency(ANDROID_TEST_COMPILE, "espresso-contrib", "com.android.support.test.espresso", "2.2.2");
    expected.assertMatches(espressoDependency);
    DependencyConfigurationModel configuration = espressoDependency.configuration();
    assertNotNull(configuration);
    configuration.excludes();
    List<ExcludedDependencyModel> excludedDependencies = configuration.excludes();
    assertThat(excludedDependencies).hasSize(4);
    ExcludedDependencyModel first = excludedDependencies.get(0);
    assertEquals("com.android.support", first.group().value());
    assertEquals("support-v4", first.module().value());
    ExcludedDependencyModel second = excludedDependencies.get(1);
    assertEquals("com.android.support", second.group().value());
    assertEquals("support-annotations", second.module().value());
    ExcludedDependencyModel third = excludedDependencies.get(2);
    assertEquals("com.android.support", third.group().value());
    assertEquals("recyclerview-v7", third.module().value());
    ExcludedDependencyModel fourth = excludedDependencies.get(3);
    assertEquals("com.android.support", fourth.group().value());
    assertEquals("design", fourth.module().value());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 35 with GradleBuildModel

use of com.android.tools.idea.gradle.dsl.model.GradleBuildModel in project android by JetBrains.

the class FileTreeDependencyTest method testAddFileTreeWithDirOnly.

public void testAddFileTreeWithDirOnly() throws IOException {
    String text = "dependencies {\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependencies = buildModel.dependencies();
    List<FileTreeDependencyModel> fileTrees = dependencies.fileTrees();
    assertThat(fileTrees).isEmpty();
    dependencies.addFileTree("compile", "libs");
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependencies = buildModel.dependencies();
    fileTrees = dependencies.fileTrees();
    assertThat(fileTrees).hasSize(1);
    FileTreeDependencyModel fileTree = fileTrees.get(0);
    assertEquals("libs", fileTree.dir());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)285 ResValue (com.android.tools.idea.gradle.dsl.model.android.AbstractFlavorTypeModel.ResValue)20 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)17 SigningConfigPassword (com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword)15 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)13 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)13 File (java.io.File)13 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 BuildConfigField (com.android.tools.idea.gradle.dsl.model.android.BuildTypeModel.BuildConfigField)10 Module (com.intellij.openapi.module.Module)9 ProductFlavorModel (com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)8 SourceDirectoryModel (com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)8 Result (com.intellij.openapi.application.Result)8 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 GradleNotNullValue (com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)7 ExternalNativeBuildOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.ExternalNativeBuildOptionsModel)6 NotNull (org.jetbrains.annotations.NotNull)6 NdkOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.NdkOptionsModel)5 CMakeOptionsModel (com.android.tools.idea.gradle.dsl.model.android.productFlavors.externalNativeBuild.CMakeOptionsModel)5