Search in sources :

Example 1 with ExpectedArtifactDependency

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency in project android by JetBrains.

the class BuildScriptModelTest method testParseDependencies.

public void testParseDependencies() throws IOException {
    String text = "buildscript {\n" + "  dependencies {\n" + "    classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) 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)

Example 2 with ExpectedArtifactDependency

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency in project android by JetBrains.

the class BuildScriptModelTest method testEditDependency.

public void testEditDependency() throws IOException {
    String text = "buildscript {\n" + "  dependencies {\n" + "    classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    ArtifactDependencyModel actual = dependencies.get(0);
    expected.assertMatches(actual);
    actual.setVersion("2.0.1");
    expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.1");
    expected.assertMatches(actual);
    assertTrue(buildModel.isModified());
    applyChanges(buildModel);
    assertFalse(buildModel.isModified());
    buildModel.reparse();
    dependencies = buildModel.buildscript().dependencies().artifacts();
    assertThat(dependencies).hasSize(1);
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) 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)

Example 3 with ExpectedArtifactDependency

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency in project android by JetBrains.

the class BuildScriptModelTest method testAddDependency.

public void testAddDependency() throws IOException {
    String text = "";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildScriptModel buildScriptModel = buildModel.buildscript();
    DependenciesModel dependenciesModel = buildScriptModel.dependencies();
    assertFalse(buildScriptModel.hasValidPsiElement());
    assertFalse(dependenciesModel.hasValidPsiElement());
    assertThat(dependenciesModel.artifacts()).isEmpty();
    dependenciesModel.addArtifact("classpath", "com.android.tools.build:gradle:2.0.0-alpha2");
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    expected.assertMatches(dependencies.get(0));
    assertTrue(buildModel.isModified());
    applyChanges(buildModel);
    assertFalse(buildModel.isModified());
    buildModel.reparse();
    buildScriptModel = buildModel.buildscript();
    dependenciesModel = buildScriptModel.dependencies();
    assertTrue(buildScriptModel.hasValidPsiElement());
    assertTrue(dependenciesModel.hasValidPsiElement());
    dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) 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)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)3 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)3 ExpectedArtifactDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency)3 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)3