Search in sources :

Example 36 with GradleBuildModel

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

the class FileTreeDependencyTest method testSetDirWhenIncludeSpecified.

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

Example 37 with GradleBuildModel

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

the class FileTreeDependencyTest method testAddFileTreeWithDirAndIncludeAttributePattern.

public void testAddFileTreeWithDirAndIncludeAttributePattern() 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", ImmutableList.of("*.jar"), null);
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependencies = buildModel.dependencies();
    fileTrees = dependencies.fileTrees();
    assertThat(fileTrees).hasSize(1);
    FileTreeDependencyModel fileTree = fileTrees.get(0);
    assertEquals("libs", fileTree.dir());
    assertEquals(ImmutableList.of("*.jar"), fileTree.includes());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 38 with GradleBuildModel

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

the class ArtifactDependencyTest method testReset.

public void testReset() throws IOException {
    String text = "dependencies {\n" + "    compile group: 'com.google.code.guice', name: 'guice', version: '1.0'\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    ArtifactDependencyModel guice = dependencies.get(0);
    guice.setVersion("1.2.3");
    assertTrue(buildModel.isModified());
    buildModel.resetState();
    assertFalse(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency(COMPILE, "guice", "com.google.code.guice", "1.0");
    expected.assertMatches(dependencies.get(0));
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel)

Example 39 with GradleBuildModel

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

the class ArtifactDependencyTest method testRemoveDependencyWithMapNotationAndSingleConfigurationName.

public void testRemoveDependencyWithMapNotationAndSingleConfigurationName() throws IOException {
    String text = "dependencies {\n" + "    runtime(\n" + "        [group: 'com.google.code.guice', name: 'guice', version: '1.0'],\n" + "        [group: 'com.google.guava', name: 'guava', version: '18.0'],\n" + "        [group: 'com.android.support', name: 'appcompat-v7', version: '22.1.1']\n" + "    )\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(RUNTIME, "guice", "com.google.code.guice", "1.0");
    expected.assertMatches(dependencies.get(0));
    expected = new ExpectedArtifactDependency(RUNTIME, "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 40 with GradleBuildModel

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

the class FileTreeDependencyTest method testAddFileTreeWithDirAndIncludeAttributeList.

public void testAddFileTreeWithDirAndIncludeAttributeList() 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", ImmutableList.of("*.jar", "*.aar"), null);
    assertTrue(buildModel.isModified());
    applyChangesAndReparse(buildModel);
    dependencies = buildModel.dependencies();
    fileTrees = dependencies.fileTrees();
    assertThat(fileTrees).hasSize(1);
    FileTreeDependencyModel fileTree = fileTrees.get(0);
    assertEquals("libs", fileTree.dir());
    assertEquals(ImmutableList.of("*.jar", "*.aar"), fileTree.includes());
}
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