Search in sources :

Example 6 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project android by JetBrains.

the class ModuleDisposalDataServiceTest method testImportDataWithAndroidStudioAndSuccessfulSync.

public void testImportDataWithAndroidStudioAndSuccessfulSync() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(true);
    when(mySyncState.lastSyncFailedOrHasIssues()).thenReturn(false);
    IdeaModule moduleModel = mock(IdeaModule.class);
    when(moduleModel.getName()).thenReturn(getModule().getName());
    ImportedModule importedModule = new ImportedModule(moduleModel);
    // This module should be disposed.
    Module libModule = createModule("lib");
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Collection<DataNode<ImportedModule>> nodes = Collections.singleton(new DataNode<>(IMPORTED_MODULE, importedModule, null));
    myDataService.importData(nodes, null, project, modelsProvider);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::dispose);
    Collection<Module> modulesToDispose = Collections.singletonList(libModule);
    verify(myModuleDisposer).disposeModulesAndMarkImlFilesForDeletion(modulesToDispose, getProject(), modelsProvider);
}
Also used : Project(com.intellij.openapi.project.Project) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ImportedModule(com.android.tools.idea.gradle.ImportedModule) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ImportedModule(com.android.tools.idea.gradle.ImportedModule) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Example 7 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project intellij-community by JetBrains.

the class ModelBuildScriptClasspathBuilderImplTest method testModelBuildScriptClasspathBuilder.

@Test
@TargetVersions("2.0+")
public void testModelBuildScriptClasspathBuilder() throws Exception {
    DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
    List<BuildScriptClasspathModel> ideaModule = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, BuildScriptClasspathModel>() {

        @Override
        public BuildScriptClasspathModel fun(IdeaModule module) {
            BuildScriptClasspathModel classpathModel = allModels.getExtraProject(module, BuildScriptClasspathModel.class);
            if (module.getName().equals("moduleWithAdditionalClasspath")) {
                assertNotNull(classpathModel);
                assertEquals(3, classpathModel.getClasspath().size());
                assertEquals("junit-4.11.jar", new File(classpathModel.getClasspath().getAt(0).getClasses().iterator().next()).getName());
                assertEquals("hamcrest-core-1.3.jar", new File(classpathModel.getClasspath().getAt(1).getClasses().iterator().next()).getName());
                assertEquals("someDep.jar", new File(classpathModel.getClasspath().getAt(2).getClasses().iterator().next()).getName());
            } else if (module.getName().equals("baseModule") || module.getName().equals("moduleWithInheritedClasspath")) {
                assertNotNull("Null build classpath for module: " + module.getName(), classpathModel);
                assertEquals("Wrong build classpath for module: " + module.getName(), 3, classpathModel.getClasspath().size());
                assertEquals("Wrong build classpath for module: " + module.getName(), "junit-4.11.jar", new File(classpathModel.getClasspath().getAt(0).getClasses().iterator().next()).getName());
                assertEquals("Wrong build classpath for module: " + module.getName(), "hamcrest-core-1.3.jar", new File(classpathModel.getClasspath().getAt(1).getClasses().iterator().next()).getName());
                assertEquals("Wrong build classpath for module: " + module.getName(), "inheritedDep.jar", new File(classpathModel.getClasspath().getAt(2).getClasses().iterator().next()).getName());
            } else if (module.getName().equals("moduleWithoutAdditionalClasspath") || module.getName().equals("testModelBuildScriptClasspathBuilder")) {
                assertNotNull("Wrong build classpath for module: " + module.getName(), classpathModel);
                assertEquals("Wrong build classpath for module: " + module.getName(), 2, classpathModel.getClasspath().size());
            } else {
                fail("Unexpected module found: " + module.getName());
            }
            return classpathModel;
        }
    });
    assertEquals(5, ideaModule.size());
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) BuildScriptClasspathModel(org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel) File(java.io.File) TargetVersions(org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions) Test(org.junit.Test)

Example 8 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project intellij-community by JetBrains.

the class ScalaModelBuilderImplTest method testScalaModel.

@Test
public void testScalaModel() throws Exception {
    DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
    List<ScalaModel> scalaModels = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, ScalaModel>() {

        @Override
        public ScalaModel fun(IdeaModule module) {
            return allModels.getExtraProject(module, ScalaModel.class);
        }
    });
    assertEquals(1, scalaModels.size());
    ScalaModel scalaModel = scalaModels.get(0);
    ScalaCompileOptions scalaCompileOptions = scalaModel.getScalaCompileOptions();
    assertNotNull(scalaCompileOptions);
    assertEquals(1, scalaCompileOptions.getAdditionalParameters().size());
    assertEquals("-opt:opt", scalaCompileOptions.getAdditionalParameters().iterator().next());
}
Also used : ScalaCompileOptions(org.jetbrains.plugins.gradle.model.scala.ScalaCompileOptions) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) ScalaModel(org.jetbrains.plugins.gradle.model.scala.ScalaModel) Test(org.junit.Test)

Example 9 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project intellij-community by JetBrains.

the class WebConfigurationBuilderImplTest method testDefaultWarModel.

@Test
public void testDefaultWarModel() throws Exception {
    DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
    List<WebConfiguration> ideaModule = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, WebConfiguration>() {

        @Override
        public WebConfiguration fun(IdeaModule module) {
            return allModels.getExtraProject(module, WebConfiguration.class);
        }
    });
    assertEquals(1, ideaModule.size());
    WebConfiguration webConfiguration = ideaModule.get(0);
    assertEquals(1, webConfiguration.getWarModels().size());
    final WarModel warModel = webConfiguration.getWarModels().iterator().next();
    assertEquals("src/main/webapp", warModel.getWebAppDirName());
    assertArrayEquals(new String[] { "MANIFEST.MF", "additionalWebInf", "rootContent" }, ContainerUtil.map2Array(warModel.getWebResources(), new Function<WebResource, Object>() {

        @Override
        public String fun(WebResource resource) {
            return resource.getFile().getName();
        }
    }));
}
Also used : Function(com.intellij.util.Function) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) WebResource(org.jetbrains.plugins.gradle.model.web.WebConfiguration.WebResource) WarModel(org.jetbrains.plugins.gradle.model.web.WebConfiguration.WarModel) WebConfiguration(org.jetbrains.plugins.gradle.model.web.WebConfiguration) Test(org.junit.Test)

Example 10 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project intellij-community by JetBrains.

the class GradleProjectResolver method mergeSourceSetContentRoots.

private static void mergeSourceSetContentRoots(@NotNull Map<String, Pair<DataNode<ModuleData>, IdeaModule>> moduleMap, @NotNull ProjectResolverContext resolverCtx) {
    final Factory<Counter> counterFactory = () -> new Counter();
    final Map<String, Counter> weightMap = ContainerUtil.newHashMap();
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleNode = pair.first;
        for (DataNode<ContentRootData> contentRootNode : ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT)) {
            File file = new File(contentRootNode.getData().getRootPath());
            while (file != null) {
                ContainerUtil.getOrCreate(weightMap, file.getPath(), counterFactory).increment();
                file = file.getParentFile();
            }
        }
        for (DataNode<GradleSourceSetData> sourceSetNode : ExternalSystemApiUtil.findAll(moduleNode, GradleSourceSetData.KEY)) {
            final Set<String> set = ContainerUtil.newHashSet();
            for (DataNode<ContentRootData> contentRootNode : ExternalSystemApiUtil.findAll(sourceSetNode, ProjectKeys.CONTENT_ROOT)) {
                File file = new File(contentRootNode.getData().getRootPath());
                while (file != null) {
                    set.add(file.getPath());
                    file = file.getParentFile();
                }
            }
            for (String path : set) {
                ContainerUtil.getOrCreate(weightMap, path, counterFactory).increment();
            }
        }
    }
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleNode = pair.first;
        final ExternalProject externalProject = resolverCtx.getExtraProject(pair.second, ExternalProject.class);
        if (externalProject == null)
            continue;
        if (resolverCtx.isResolveModulePerSourceSet()) {
            for (DataNode<GradleSourceSetData> sourceSetNode : ExternalSystemApiUtil.findAll(moduleNode, GradleSourceSetData.KEY)) {
                mergeModuleContentRoots(weightMap, externalProject, sourceSetNode);
            }
        } else {
            mergeModuleContentRoots(weightMap, externalProject, moduleNode);
        }
    }
}
Also used : GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) File(java.io.File)

Aggregations

IdeaModule (org.gradle.tooling.model.idea.IdeaModule)15 IdeaProject (org.gradle.tooling.model.idea.IdeaProject)5 DataNode (com.intellij.openapi.externalSystem.model.DataNode)4 Module (com.intellij.openapi.module.Module)4 File (java.io.File)4 BasicIdeaProject (org.gradle.tooling.model.idea.BasicIdeaProject)4 NotNull (org.jetbrains.annotations.NotNull)4 GradleProject (org.gradle.tooling.model.GradleProject)3 Test (org.junit.Test)3 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 Project (com.intellij.openapi.project.Project)2 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)2 GradleBuildParticipant (org.jetbrains.plugins.gradle.settings.GradleBuildParticipant)2 ImportedModule (com.android.tools.idea.gradle.ImportedModule)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 Facets.createAndAddAndroidFacet (com.android.tools.idea.testing.Facets.createAndAddAndroidFacet)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 Facet (com.intellij.facet.Facet)1