Search in sources :

Example 11 with SourceDirectoryModel

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

the class SourceSetModel method jniLibs.

@NotNull
public SourceDirectoryModel jniLibs() {
    SourceDirectoryDslElement jniLibs = myDslElement.getPropertyElement(JNI_LIBS, SourceDirectoryDslElement.class);
    if (jniLibs == null) {
        jniLibs = new SourceDirectoryDslElement(myDslElement, JNI_LIBS);
        myDslElement.setNewElement(JNI_LIBS, jniLibs);
    }
    return new SourceDirectoryModel(jniLibs);
}
Also used : SourceDirectoryModel(com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel) SourceDirectoryDslElement(com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceDirectoryDslElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with SourceDirectoryModel

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

the class SourceSetModel method res.

@NotNull
public SourceDirectoryModel res() {
    SourceDirectoryDslElement res = myDslElement.getPropertyElement(RES, SourceDirectoryDslElement.class);
    if (res == null) {
        res = new SourceDirectoryDslElement(myDslElement, RES);
        myDslElement.setNewElement(RES, res);
    }
    return new SourceDirectoryModel(res);
}
Also used : SourceDirectoryModel(com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel) SourceDirectoryDslElement(com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceDirectoryDslElement) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with SourceDirectoryModel

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

the class SourceDirectoryModelTest method testSourceDirectoryEntriesReplaceAndApply.

public void testSourceDirectoryEntriesReplaceAndApply() throws Exception {
    writeToBuildFile(GRADLE_TEXT);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceDirectoryEntries(buildModel, 1, 2);
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SourceSetModel sourceSet = android.sourceSets().get(0);
    SourceDirectoryModel java = sourceSet.java();
    java.replaceSrcDir("javaSource1", "javaSource0");
    java.replaceInclude("javaInclude1", "javaInclude0");
    java.replaceExclude("javaExclude1", "javaExclude0");
    SourceDirectoryModel jni = sourceSet.jni();
    jni.replaceSrcDir("jniSource1", "jniSource0");
    jni.replaceInclude("jniInclude1", "jniInclude0");
    jni.replaceExclude("jniExclude1", "jniExclude0");
    verifySourceDirectoryEntries(buildModel, 0, 2);
    applyChangesAndReparse(buildModel);
    verifySourceDirectoryEntries(buildModel, 0, 2);
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) SourceDirectoryModel(com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)

Example 14 with SourceDirectoryModel

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

the class SourceDirectoryModelTest method testSourceDirectoryEntriesRemoveAllAndApply.

public void testSourceDirectoryEntriesRemoveAllAndApply() throws Exception {
    writeToBuildFile(GRADLE_TEXT);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceDirectoryEntries(buildModel, 1, 2);
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SourceSetModel sourceSet = android.sourceSets().get(0);
    SourceDirectoryModel java = sourceSet.java();
    java.removeAllSrcDirs();
    java.removeAllIncludes();
    java.removeAllExcludes();
    SourceDirectoryModel jni = sourceSet.jni();
    jni.removeAllSrcDirs();
    jni.removeAllIncludes();
    jni.removeAllExcludes();
    verifySourceDirectoryEntries(buildModel);
    applyChangesAndReparse(buildModel);
    android = buildModel.android();
    assertNotNull(android);
    // Whole android block gets removed as it would become empty.
    assertFalse(android.hasValidPsiElement());
    assertEmpty(android.sourceSets());
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) SourceDirectoryModel(com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)

Example 15 with SourceDirectoryModel

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

the class SourceDirectoryModelTest method testSourceDirectoryEntriesRemoveAndReset.

public void testSourceDirectoryEntriesRemoveAndReset() throws Exception {
    writeToBuildFile(GRADLE_TEXT);
    GradleBuildModel buildModel = getGradleBuildModel();
    verifySourceDirectoryEntries(buildModel, 1, 2);
    AndroidModel android = buildModel.android();
    assertNotNull(android);
    SourceSetModel sourceSet = android.sourceSets().get(0);
    SourceDirectoryModel java = sourceSet.java();
    java.removeSrcDir("javaSource2");
    java.removeInclude("javaInclude2");
    java.removeExclude("javaExclude2");
    SourceDirectoryModel jni = sourceSet.jni();
    jni.removeSrcDir("jniSource2");
    jni.removeInclude("jniInclude2");
    jni.removeExclude("jniExclude2");
    verifySourceDirectoryEntries(buildModel, 1);
    buildModel.resetState();
    verifySourceDirectoryEntries(buildModel, 1, 2);
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) SourceDirectoryModel(com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)

Aggregations

SourceDirectoryModel (com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceDirectoryModel)17 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)8 SourceDirectoryDslElement (com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceDirectoryDslElement)8 NotNull (org.jetbrains.annotations.NotNull)8 SourceFileModel (com.android.tools.idea.gradle.dsl.model.android.sourceSets.SourceFileModel)1