Search in sources :

Example 6 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class AndroidGradleProjectResolver method createJavaProject.

private void createJavaProject(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, boolean androidProjectWithoutVariants) {
    //noinspection deprecation
    ModuleExtendedModel model = resolverCtx.getExtraProject(gradleModule, ModuleExtendedModel.class);
    JavaModuleModel javaModuleModel = new JavaModuleModel(gradleModule, model, androidProjectWithoutVariants);
    ideModule.createChild(JAVA_MODULE_MODEL, javaModuleModel);
}
Also used : ModuleExtendedModel(org.jetbrains.plugins.gradle.model.ModuleExtendedModel) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel)

Example 7 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class JavaModuleModelDataServiceTest method testImportData.

public void testImportData() {
    String appModuleName = "app";
    Module appModule = createModule(appModuleName);
    JavaModuleModel model = mock(JavaModuleModel.class);
    when(model.getModuleName()).thenReturn(appModuleName);
    DataNode<JavaModuleModel> dataNode = new DataNode<>(JAVA_MODULE_MODEL, model, null);
    Collection<DataNode<JavaModuleModel>> dataNodes = Collections.singleton(dataNode);
    myDataService.importData(dataNodes, null, getProject(), myModelsProvider);
    verify(myModuleSetup).setUpModule(appModule, myModelsProvider, model, null, null);
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module)

Example 8 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModule.

public void testDoSetUpModule() throws IOException {
    Module module = getModule();
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    File jarFilePath = createTempFile("fake.jar", "");
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    JavaModuleModel model = new JavaModuleModel(module.getName(), Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, null, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertJarIsLibrary(jarFilePath);
    // This is the first time we create the library, it shouldn't be marked as "used".
    verify(myLibraryRegistry, never()).markAsUsed(any(), any());
}
Also used : Project(com.intellij.openapi.project.Project) Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 9 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModuleWithExistingLibrary.

public void testDoSetUpModuleWithExistingLibrary() throws IOException {
    File jarFilePath = createTempFile("fake.jar", "");
    // Create the library, to ensure that is marked as "used".
    Library library = createLibrary(jarFilePath);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    Module module = getModule();
    JavaModuleModel model = new JavaModuleModel(module.getName(), Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, null, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertJarIsLibrary(jarFilePath);
    // This is an existing library, it should be marked as "used".
    verify(myLibraryRegistry, times(1)).markAsUsed(library, jarFilePath);
}
Also used : Project(com.intellij.openapi.project.Project) Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Library(com.intellij.openapi.roots.libraries.Library) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 10 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel 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)

Aggregations

JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)12 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)4 Facets.createAndAddJavaFacet (com.android.tools.idea.testing.Facets.createAndAddJavaFacet)3 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)3 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)3 Project (com.intellij.openapi.project.Project)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 Library (com.intellij.openapi.roots.libraries.Library)2 ModuleExtendedModel (org.jetbrains.plugins.gradle.model.ModuleExtendedModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1 JarLibraryDependency (com.android.tools.idea.gradle.model.java.JarLibraryDependency)1 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)1 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1