Search in sources :

Example 1 with BaseArtifact

use of com.android.builder.model.BaseArtifact in project android by JetBrains.

the class GradleBuildInvoker method findAndAddGradleBuildTasks.

private static void findAndAddGradleBuildTasks(@NotNull Module module, @NotNull BuildMode buildMode, @NotNull List<String> tasks, @NotNull TestCompileType testCompileType) {
    GradleFacet gradleFacet = GradleFacet.getInstance(module);
    if (gradleFacet == null) {
        return;
    }
    String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
    if (isEmpty(gradlePath)) {
        // Gradle project path is never, ever null. If the path is empty, it shows as ":". We had reports of this happening. It is likely that
        // users manually added the Android-Gradle facet to a project. After all it is likely not to be a Gradle module. Better quit and not
        // build the module.
        String msg = String.format("Module '%1$s' does not have a Gradle path. It is likely that this module was manually added by the user.", module.getName());
        getLogger().info(msg);
        return;
    }
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet != null) {
        JpsAndroidModuleProperties properties = androidFacet.getProperties();
        AndroidModuleModel androidModel = AndroidModuleModel.get(module);
        switch(buildMode) {
            // Intentional fall-through.
            case CLEAN:
            case SOURCE_GEN:
                addAfterSyncTasks(tasks, gradlePath, properties);
                addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
                break;
            case ASSEMBLE:
                tasks.add(createBuildTask(gradlePath, properties.ASSEMBLE_TASK_NAME));
                // Add assemble tasks for tests.
                if (testCompileType != TestCompileType.NONE) {
                    for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
                        addTaskIfSpecified(tasks, gradlePath, artifact.getAssembleTaskName());
                    }
                }
                break;
            default:
                addAfterSyncTasks(tasks, gradlePath, properties);
                addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
                // no *.class files and would be just a waste of time.
                if (testCompileType != TestCompileType.UNIT_TESTS) {
                    addTaskIfSpecified(tasks, gradlePath, properties.COMPILE_JAVA_TASK_NAME);
                }
                // Add compile tasks for tests.
                for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
                    addTaskIfSpecified(tasks, gradlePath, artifact.getCompileTaskName());
                }
                break;
        }
    } else {
        JavaFacet javaFacet = JavaFacet.getInstance(module);
        if (javaFacet != null && javaFacet.getConfiguration().BUILDABLE) {
            String gradleTaskName = javaFacet.getGradleTaskName(buildMode);
            if (gradleTaskName != null) {
                tasks.add(createBuildTask(gradlePath, gradleTaskName));
            }
            if (testCompileType == TestCompileType.UNIT_TESTS) {
                tasks.add(createBuildTask(gradlePath, JavaFacet.TEST_CLASSES_TASK_NAME));
            }
        }
    }
}
Also used : JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) BaseArtifact(com.android.builder.model.BaseArtifact) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 2 with BaseArtifact

use of com.android.builder.model.BaseArtifact in project android by JetBrains.

the class GradleUtilTest method getGeneratedSources.

@Test
public void getGeneratedSources() {
    Collection<File> folders = Lists.newArrayList(new File(""));
    BaseArtifact baseArtifact = mock(BaseArtifact.class);
    when(baseArtifact.getGeneratedSourceFolders()).thenReturn(folders);
    Collection<File> actual = GradleUtil.getGeneratedSourceFolders(baseArtifact);
    assertThat(actual).isSameAs(folders);
}
Also used : File(java.io.File) BaseArtifact(com.android.builder.model.BaseArtifact) Test(org.junit.Test)

Example 3 with BaseArtifact

use of com.android.builder.model.BaseArtifact in project android by JetBrains.

the class GradleUtilTest method getGeneratedSourcesWithOldModel.

@Test
public void getGeneratedSourcesWithOldModel() {
    BaseArtifact baseArtifact = mock(BaseArtifact.class);
    when(baseArtifact.getGeneratedSourceFolders()).thenThrow(new UnsupportedMethodException(""));
    Collection<File> actual = GradleUtil.getGeneratedSourceFolders(baseArtifact);
    assertThat(actual).isEmpty();
}
Also used : UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) BaseArtifact(com.android.builder.model.BaseArtifact) File(java.io.File) Test(org.junit.Test)

Aggregations

BaseArtifact (com.android.builder.model.BaseArtifact)3 File (java.io.File)2 Test (org.junit.Test)2 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 UnsupportedMethodException (org.gradle.tooling.model.UnsupportedMethodException)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)1