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);
}
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());
}
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());
}
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();
}
}));
}
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);
}
}
}
Aggregations