use of com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue in project android by JetBrains.
the class ExtModelTest method testResolveMultiModuleExtPropertyWithHistory.
public void testResolveMultiModuleExtPropertyWithHistory() throws IOException {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "ext.FIRST = 123";
String subModuleText = "ext.SECOND = FIRST";
writeToSettingsFile(settingsText);
writeToBuildFile(mainModuleText);
writeToSubModuleBuildFile(subModuleText);
GradleBuildModel buildModel = getSubModuleGradleBuildModel();
ExtModel extModel = buildModel.ext();
GradleNullableValue<Integer> second = extModel.getLiteralProperty("SECOND", Integer.class);
verifyGradleValue(second, "ext.SECOND", "FIRST", toSystemIndependentPath(mySubModuleBuildFile.getPath()));
assertEquals(Integer.valueOf(123), second.value());
Map<String, GradleNotNullValue<Object>> secondResolvedVariables = second.getResolvedVariables();
assertEquals(1, secondResolvedVariables.size());
GradleNotNullValue<Object> first = secondResolvedVariables.get("FIRST");
assertNotNull(first);
verifyGradleValue(first, "ext.FIRST", "123");
assertEquals(Integer.valueOf(123), first.value());
assertEquals(0, first.getResolvedVariables().size());
}
use of com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue in project android by JetBrains.
the class ExtModelTest method testResolveMultiLevelExtPropertyWithHistory.
public void testResolveMultiLevelExtPropertyWithHistory() throws IOException {
String text = "ext.FIRST = 123\n" + "ext.SECOND = FIRST\n" + "ext.THIRD = SECOND";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
ExtModel extModel = buildModel.ext();
GradleNullableValue<Integer> third = extModel.getLiteralProperty("THIRD", Integer.class);
verifyGradleValue(third, "ext.THIRD", "SECOND");
assertEquals(Integer.valueOf(123), third.value());
Map<String, GradleNotNullValue<Object>> thirdResolvedVariables = third.getResolvedVariables();
assertEquals(1, thirdResolvedVariables.size());
GradleNotNullValue<Object> second = thirdResolvedVariables.get("SECOND");
assertNotNull(second);
verifyGradleValue(second, "ext.SECOND", "FIRST");
assertEquals(Integer.valueOf(123), second.value());
Map<String, GradleNotNullValue<Object>> secondResolvedVariables = second.getResolvedVariables();
assertEquals(1, secondResolvedVariables.size());
GradleNotNullValue<Object> first = secondResolvedVariables.get("FIRST");
assertNotNull(first);
verifyGradleValue(first, "ext.FIRST", "123");
assertEquals(Integer.valueOf(123), first.value());
assertEquals(0, first.getResolvedVariables().size());
}
use of com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue in project android by JetBrains.
the class ArtifactDependencyTest method testParseMapNotationClosureWithVariables.
public void testParseMapNotationClosureWithVariables() throws IOException {
String text = "ext {\n" + " guavaVersion = '18.0'\n" + "}\n" + "dependencies {\n" + " compile(group: 'com.google.guava', name: 'guava', version: \"$guavaVersion\") {\n" + " }\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.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.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());
}
use of com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue in project android by JetBrains.
the class ArtifactDependencyTest method testParseCompactNotationWithVariables.
public void testParseCompactNotationWithVariables() 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\n" + " runtime \"com.google.guava:guava:$guavaVersion\"\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", "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(RUNTIME, "guava", "com.google.guava", "18.0");
ArtifactDependencyModel guavaDependencyModel = dependencies.get(1);
expected.assertMatches(guavaDependencyModel);
GradleNotNullValue<String> guavaDependency = guavaDependencyModel.compactNotation();
verifyGradleValue(guavaDependency, "dependencies.runtime", "\"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());
}
Aggregations