use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testCreateIntegerValue.
@SuppressWarnings("unchecked")
public void testCreateIntegerValue() throws Exception {
final GradleBuildFile file = getTestFile(getSimpleTestFile());
final GrStatementOwner closure = file.getClosure("android/productFlavors/flavor1");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.VERSION_CODE, 199);
}
});
StringBuilder expected = new StringBuilder(getSimpleTestFile());
int position = expected.indexOf("\n", expected.indexOf("proguard-flavor1.txt")) + 1;
expected.insert(position, " versionCode 199\n");
assertContents(expected.toString());
Object value = file.getValue(BuildFileKey.FLAVORS);
assertNotNull("flavors should be parsed", value);
final List<NamedObject> flavors = (List<NamedObject>) value;
assertEquals(2, flavors.size());
assertEquals(199, flavors.get(0).getValue(BuildFileKey.VERSION_CODE));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testSetFileValue.
public void testSetFileValue() throws Exception {
final GradleBuildFile file = getTestFile(getSimpleTestFile());
final GrStatementOwner closure = file.getClosure("android/signingConfigs/debug");
final File replacementFile = new File("abc/def/foo.keystore");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.STORE_FILE, replacementFile);
}
});
// We always expect system independent paths in build.gradle files.
String expected = getSimpleTestFile().replaceAll("debug.keystore", "abc/def/foo.keystore");
assertContents(expected);
assertEquals(replacementFile, file.getValue(closure, BuildFileKey.STORE_FILE));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testSetIntegerOrStringAsString.
public void testSetIntegerOrStringAsString() throws Exception {
final GradleBuildFile file = getTestFile("android {\n" + " defaultConfig {\n" + " }\n" + "}\n");
final GrStatementOwner closure = file.getClosure("android/defaultConfig");
assertNotNull(closure);
WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.TARGET_SDK_VERSION, "foo");
}
});
String expected = "android {\n" + " defaultConfig {\n" + " targetSdkVersion 'foo'\n" + " }\n" + "}\n";
assertContents(expected);
}
Aggregations