Search in sources :

Example 1 with JavaFacet

use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.

the class DataNodeCaches method isCacheMissingModels.

private static boolean isCacheMissingModels(@NotNull DataNode<ModuleData> cache, @NotNull Module module) {
    GradleFacet gradleFacet = GradleFacet.getInstance(module);
    if (gradleFacet != null) {
        DataNode<GradleModuleModel> gradleDataNode = find(cache, GRADLE_MODULE_MODEL);
        if (gradleDataNode == null) {
            return true;
        }
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        if (androidFacet != null) {
            DataNode<AndroidModuleModel> androidDataNode = find(cache, ANDROID_MODEL);
            if (androidDataNode == null || !isValidProxyObject(androidDataNode.getData().getAndroidProject())) {
                return true;
            }
        } else {
            JavaFacet javaFacet = JavaFacet.getInstance(module);
            if (javaFacet != null) {
                DataNode<JavaModuleModel> javaProjectDataNode = find(cache, JAVA_MODULE_MODEL);
                if (javaProjectDataNode == null) {
                    return true;
                }
            }
        }
    }
    NdkFacet ndkFacet = NdkFacet.getInstance(module);
    if (ndkFacet != null) {
        DataNode<NdkModuleModel> ndkModuleModelDataNode = find(cache, NDK_MODEL);
        if (ndkModuleModelDataNode == null || !isValidProxyObject(ndkModuleModelDataNode.getData().getAndroidProject())) {
            return true;
        }
    }
    return false;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 2 with JavaFacet

use of com.android.tools.idea.gradle.project.facet.java.JavaFacet 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 3 with JavaFacet

use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.

the class JavaFacetModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    JavaFacet facet = setAndGetJavaGradleFacet(module, ideModelsProvider);
    GradleFacet gradleFacet = findFacet(module, ideModelsProvider, GradleFacet.getFacetTypeId());
    if (gradleFacet != null) {
        // This is an actual Gradle module, because it has the GradleFacet. Top-level modules in a multi-module project usually don't
        // have this facet.
        facet.setJavaModuleModel(javaModuleModel);
    }
    File buildFolderPath = javaModuleModel.getBuildFolderPath();
    JavaFacetConfiguration facetProperties = facet.getConfiguration();
    facetProperties.BUILD_FOLDER_PATH = buildFolderPath != null ? toSystemIndependentName(buildFolderPath.getPath()) : "";
    facetProperties.BUILDABLE = javaModuleModel.isBuildable();
}
Also used : JavaFacetConfiguration(com.android.tools.idea.gradle.project.facet.java.JavaFacetConfiguration) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) File(java.io.File)

Example 4 with JavaFacet

use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.

the class AndroidGradleJavaProjectModelModifier method changeLanguageLevel.

@Nullable
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level) {
    Project project = module.getProject();
    if (!isBuildWithGradle(module)) {
        return null;
    }
    GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (buildModel == null) {
        return null;
    }
    if (getAndroidModel(module) != null) {
        AndroidModel android = buildModel.android();
        if (android == null) {
            return null;
        }
        CompileOptionsModel compileOptions = android.compileOptions();
        compileOptions.setSourceCompatibility(level);
        compileOptions.setTargetCompatibility(level);
    } else {
        JavaFacet javaFacet = JavaFacet.getInstance(module);
        if (javaFacet == null || javaFacet.getJavaModuleModel() == null) {
            return null;
        }
        JavaModel javaModel = buildModel.java();
        javaModel.setSourceCompatibility(level);
        javaModel.setTargetCompatibility(level);
    }
    new WriteCommandAction(project, "Change Gradle Language Level") {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            buildModel.applyChanges();
            registerUndoAction(project);
        }
    }.execute();
    return requestProjectSync(project);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Projects.getAndroidModel(com.android.tools.idea.gradle.util.Projects.getAndroidModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel) CompileOptionsModel(com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel) Result(com.intellij.openapi.application.Result) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JavaFacet

use of com.android.tools.idea.gradle.project.facet.java.JavaFacet in project android by JetBrains.

the class ProjectStructureCleanupStep method updateTransitiveDependencies.

// See: https://code.google.com/p/android/issues/detail?id=213627
private void updateTransitiveDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @NotNull AndroidProject androidProject, @Nullable Module dependency) {
    if (dependency == null) {
        return;
    }
    JavaFacet javaFacet = JavaFacet.getInstance(dependency);
    if (javaFacet != null && // BUILDABLE == false -> means this is an AAR-based module, not a regular Java lib module
    javaFacet.getConfiguration().BUILDABLE) {
        // Ignore Java lib modules. They are already set up properly.
        return;
    }
    AndroidProject dependencyAndroidProject = getAndroidProject(dependency);
    if (dependencyAndroidProject != null) {
        AndroidModuleModel androidModel = AndroidModuleModel.get(dependency);
        if (androidModel != null) {
            DependencySet dependencies = myDependenciesExtractor.extractFrom(androidModel);
            for (LibraryDependency libraryDependency : dependencies.onLibraries()) {
                myDependenciesModuleSetupStep.updateLibraryDependency(module, ideModifiableModelsProvider, libraryDependency, androidModel.getAndroidProject());
            }
            Project project = module.getProject();
            for (ModuleDependency moduleDependency : dependencies.onModules()) {
                Module module1 = moduleDependency.getModule(project);
                updateTransitiveDependencies(module, ideModifiableModelsProvider, androidProject, module1);
            }
        }
    } else {
        LibraryDependency backup = getModuleCompiledArtifact(dependency);
        if (backup != null) {
            myDependenciesModuleSetupStep.updateLibraryDependency(module, ideModifiableModelsProvider, backup, androidProject);
        }
    }
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) GradleUtil.getNativeAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) Project(com.intellij.openapi.project.Project) GradleUtil.getAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) GradleUtil.getNativeAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) GradleUtil.getAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject) Module(com.intellij.openapi.module.Module)

Aggregations

JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)10 Module (com.intellij.openapi.module.Module)5 JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)4 File (java.io.File)4 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 Facets.createAndAddJavaFacet (com.android.tools.idea.testing.Facets.createAndAddJavaFacet)3 Project (com.intellij.openapi.project.Project)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 AndroidProject (com.android.builder.model.AndroidProject)1 BaseArtifact (com.android.builder.model.BaseArtifact)1 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 CompileOptionsModel (com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel)1 JavaModel (com.android.tools.idea.gradle.dsl.model.java.JavaModel)1 JavaFacetConfiguration (com.android.tools.idea.gradle.project.facet.java.JavaFacetConfiguration)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1