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());
}
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());
}
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));
}
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));
}
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());
}
Aggregations