Search in sources :

Example 6 with JavaFacet

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

the class JavaFacetModuleSetupStep method setAndGetJavaGradleFacet.

@NotNull
private static JavaFacet setAndGetJavaGradleFacet(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
    JavaFacet facet = findFacet(module, modelsProvider, JavaFacet.getFacetTypeId());
    if (facet != null) {
        return facet;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = modelsProvider.getModifiableFacetModel(module);
    facet = facetManager.createFacet(JavaFacet.getFacetType(), JavaFacet.getFacetName(), null);
    model.addFacet(facet);
    return facet;
}
Also used : JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with JavaFacet

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

the class DependencySetupTest method testWithLocalJarsArModules.

public void testWithLocalJarsArModules() throws Exception {
    loadProject(LOCAL_JARS_AS_MODULES);
    Module localJarModule = myModules.getModule("localJarAsModule");
    // Module should be a Java module, not buildable (since it doesn't have source code).
    JavaFacet javaFacet = JavaFacet.getInstance(localJarModule);
    assertNotNull(javaFacet);
    assertFalse(javaFacet.getConfiguration().BUILDABLE);
    assertAbout(libraryDependencies()).that(localJarModule).contains("localJarAsModule.local");
}
Also used : JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) Module(com.intellij.openapi.module.Module)

Example 8 with JavaFacet

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

the class JavaFacetModuleSetupStepTest method testDoSetUpModuleWithNewJavaFacet.

public void testDoSetUpModuleWithNewJavaFacet() throws IOException {
    createAndAddGradleFacet(getModule());
    File buildFolderPath = createTempDir("build", true);
    boolean buildable = true;
    JavaModuleModel javaModel = mock(JavaModuleModel.class);
    when(javaModel.getBuildFolderPath()).thenReturn(buildFolderPath);
    when(javaModel.isBuildable()).thenReturn(buildable);
    Module module = getModule();
    mySetupStep.doSetUpModule(module, myModelsProvider, javaModel, null, null);
    ApplicationManager.getApplication().runWriteAction(() -> myModelsProvider.commit());
    JavaFacet facet = findJavaFacet(module);
    assertNotNull(facet);
    verifyFacetConfiguration(facet, javaModel, buildFolderPath, buildable);
}
Also used : Facets.createAndAddJavaFacet(com.android.tools.idea.testing.Facets.createAndAddJavaFacet) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 9 with JavaFacet

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

the class JavaFacetModuleSetupStepTest method testDoSetUpModuleWithoutGradleFacet.

public void testDoSetUpModuleWithoutGradleFacet() throws IOException {
    File buildFolderPath = createTempDir("build", true);
    boolean buildable = true;
    JavaModuleModel javaModel = mock(JavaModuleModel.class);
    when(javaModel.getBuildFolderPath()).thenReturn(buildFolderPath);
    when(javaModel.isBuildable()).thenReturn(buildable);
    Module module = getModule();
    mySetupStep.doSetUpModule(module, myModelsProvider, javaModel, null, null);
    ApplicationManager.getApplication().runWriteAction(() -> myModelsProvider.commit());
    JavaFacet facet = findJavaFacet(module);
    assertNotNull(facet);
    assertNull(facet.getJavaModuleModel());
}
Also used : Facets.createAndAddJavaFacet(com.android.tools.idea.testing.Facets.createAndAddJavaFacet) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 10 with JavaFacet

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

the class JavaFacetModuleSetupStepTest method testDoSetUpModuleWithExistingJavaFacet.

public void testDoSetUpModuleWithExistingJavaFacet() throws IOException {
    createAndAddGradleFacet(getModule());
    JavaFacet facet = createAndAddJavaFacet(getModule());
    File buildFolderPath = createTempDir("build", true);
    boolean buildable = true;
    JavaModuleModel javaModel = mock(JavaModuleModel.class);
    when(javaModel.getBuildFolderPath()).thenReturn(buildFolderPath);
    when(javaModel.isBuildable()).thenReturn(buildable);
    Module module = getModule();
    mySetupStep.doSetUpModule(module, myModelsProvider, javaModel, null, null);
    ApplicationManager.getApplication().runWriteAction(() -> myModelsProvider.commit());
    // JavaFacet should be reused.
    assertSame(facet, findJavaFacet(module));
    verifyFacetConfiguration(facet, javaModel, buildFolderPath, buildable);
}
Also used : Facets.createAndAddJavaFacet(com.android.tools.idea.testing.Facets.createAndAddJavaFacet) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File)

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