ModifiableModuleModel accepts module type ID as string; move it to projectModel-api

This commit is contained in:
Dmitry Jemerov
2012-05-17 13:04:31 +02:00
parent 507bc08020
commit 0acac64246
17 changed files with 99 additions and 39 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -280,7 +280,7 @@ public class ProjectFromSourcesBuilderImpl extends ProjectBuilder implements Pro
final String moduleFilePath = descriptor.computeModuleFilePath();
ModuleBuilder.deleteModuleFile(moduleFilePath);
final Module module = moduleModel.newModule(moduleFilePath, descriptor.getModuleType());
final Module module = moduleModel.newModule(moduleFilePath, descriptor.getModuleType().getId());
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
setupRootModel(projectDescriptor, descriptor, modifiableModel, projectLibs);
descriptor.updateModuleConfiguration(module, modifiableModel);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class ModulePointerTest extends PlatformTestCase {
final ModulePointer pointer = getPointerManager().create("xxx");
final ModifiableModuleModel modifiableModel = getModuleManager().getModifiableModel();
final Module module = modifiableModel.newModule(myProject.getBaseDir().getPath() + "/xxx.iml", EmptyModuleType.getInstance());
final Module module = modifiableModel.newModule(myProject.getBaseDir().getPath() + "/xxx.iml", EmptyModuleType.getInstance().getId());
assertSame(pointer, getPointerManager().create(module));
assertSame(pointer, getPointerManager().create("xxx"));
@@ -89,7 +89,7 @@ public class ModulePointerTest extends PlatformTestCase {
private Module addModule(final String name) {
final ModifiableModuleModel model = getModuleManager().getModifiableModel();
final Module module = model.newModule(myProject.getBaseDir().getPath() + "/" + name + ".iml", EmptyModuleType.getInstance());
final Module module = model.newModule(myProject.getBaseDir().getPath() + "/" + name + ".iml", EmptyModuleType.getInstance().getId());
commitModel(model);
disposeOnTearDown(new Disposable() {
@Override
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.resolve;
import com.intellij.openapi.application.ApplicationManager;
@@ -197,7 +212,7 @@ public class ResolveClassTest extends ResolveTestCase {
@Override
public void run() {
ModifiableModuleModel modifiableModel = ModuleManager.getInstance(getProject()).getModifiableModel();
Module module = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA);
Module module = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
modifiableModel.commit();
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.search;
import com.intellij.JavaTestUtil;
@@ -117,7 +132,7 @@ public class FindUsagesTest extends PsiTestCase{
@Override
protected void run(Result result) throws Throwable {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA);
moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA.getId());
moduleModel.commit();
tdf.createFile("plugin.xml", "<document>\n" +
@@ -1,6 +1,17 @@
/*
* Copyright (c) 2000-2004 by JetBrains s.r.o. All Rights Reserved.
* Use is subject to license terms.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.roots;
@@ -36,9 +47,9 @@ public class ExportingModulesTest extends IdeaTestCase {
@Override
public void run() {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel();
final Module moduleA = moduleModel.newModule("A.iml", StdModuleTypes.JAVA);
final Module moduleB = moduleModel.newModule("B.iml", StdModuleTypes.JAVA);
final Module moduleC = moduleModel.newModule("C.iml", StdModuleTypes.JAVA);
final Module moduleA = moduleModel.newModule("A.iml", StdModuleTypes.JAVA.getId());
final Module moduleB = moduleModel.newModule("B.iml", StdModuleTypes.JAVA.getId());
final Module moduleC = moduleModel.newModule("C.iml", StdModuleTypes.JAVA.getId());
moduleModel.commit();
configureModule(moduleA, testRoot, "A");
@@ -68,8 +68,8 @@ public class MultiModuleEditingTest extends ModuleTestCase {
{
final ModifiableModuleModel modifiableModel = moduleManager.getModifiableModel();
moduleA = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA);
moduleB = modifiableModel.newModule("b.iml", StdModuleTypes.JAVA);
moduleA = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = modifiableModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
assertEquals("Changes are not applied until commit", 0, moduleManager.getModules().length);
//noinspection SSBasedInspection
moduleListener.assertCorrectEvents(new String[0][]);
@@ -115,8 +115,8 @@ public class MultiModuleEditingTest extends ModuleTestCase {
final Module moduleB;
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA);
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA);
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelB.addModuleOrderEntry(moduleA);
@@ -157,9 +157,9 @@ public class MultiModuleEditingTest extends ModuleTestCase {
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA);
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA);
final Module moduleC = moduleModel.newModule("c.iml", StdModuleTypes.JAVA);
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
final Module moduleC = moduleModel.newModule("c.iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelB.addModuleOrderEntry(moduleC);
moduleModel.disposeModule(moduleC);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -162,7 +162,7 @@ public abstract class ModuleBuilder extends ProjectBuilder{
deleteModuleFile(myModuleFilePath);
final ModuleType moduleType = getModuleType();
final Module module = moduleModel.newModule(myModuleFilePath, moduleType);
final Module module = moduleModel.newModule(myModuleFilePath, moduleType.getId());
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
setupRootModel(modifiableModel);
for (ModuleConfigurationUpdater updater : myUpdaters) {
@@ -475,7 +475,7 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent
public Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType) {
myModificationCount++;
final ModifiableModuleModel modifiableModel = getModifiableModel();
final Module module = modifiableModel.newModule(filePath, moduleType);
final Module module = modifiableModel.newModule(filePath, moduleType.getId());
modifiableModel.commit();
return module;
}
@@ -688,19 +688,21 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent
}
@NotNull
public Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType) {
return newModule(filePath,moduleType,null);
public Module newModule(@NotNull String filePath, final String moduleTypeId) {
return newModule(filePath, moduleTypeId, null);
}
@NotNull
public Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType, @Nullable Map<String, String> options) {
public Module newModule(@NotNull String filePath,
final String moduleTypeId,
@Nullable Map<String, String> options) {
assertWritable();
filePath = resolveShortWindowsName(filePath);
ModuleImpl module = getModuleByFilePath(filePath);
if (module == null) {
module = new ModuleImpl(filePath, myProject);
module.setOption(Module.ELEMENT_TYPE, moduleType.getId());
module.setOption(Module.ELEMENT_TYPE, moduleTypeId);
if (options != null) {
for ( Map.Entry<String,String> option : options.entrySet()) {
module.setOption(option.getKey(),option.getValue());
@@ -43,22 +43,23 @@ public interface ModifiableModuleModel {
* bring the changes in effect.
*
* @param filePath the path at which the module is created.
* @param moduleType the type of the module to create.
* @param moduleTypeId the ID of the module type to create.
* @return the module instance.
*/
@NotNull Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType);
@NotNull Module newModule(@NotNull String filePath, final String moduleTypeId);
/**
* Creates a module of the specified type at the specified path and adds it to the project
* to which the module manager is related. {@link #commit()} must be called to
* bring the changes in effect.
*
*
* @param filePath the path at which the module is created.
* @param moduleType the type of the module to create.
* @param moduleTypeId ID of the module type to create.
* @param options map of module options to be used when creating the module
* @return the module instance.
*/
@NotNull Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType, @Nullable Map<String,String> options);
@NotNull Module newModule(@NotNull String filePath, final String moduleTypeId, @Nullable Map<String, String> options);
/**
* Loads a module from an .iml file with the specified path and adds it to the project.
@@ -323,7 +323,7 @@ import java.util.List;
@Override
protected void run(Result<Module> result) throws Throwable {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
String moduleName = moduleModel.newModule(root.getPath() + "/" + name + ".iml", type).getName();
String moduleName = moduleModel.newModule(root.getPath() + "/" + name + ".iml", type.getId()).getName();
moduleModel.commit();
final Module dep = ModuleManager.getInstance(project).findModuleByName(moduleName);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -372,7 +372,7 @@ public abstract class AndroidFacetImporterBase extends FacetImporter<AndroidFace
if (apklibModule == null) {
final String genModuleFilePath = genExternalApklibsDirPath + '/' + genModuleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
apklibModule = moduleModel.newModule(genModuleFilePath, StdModuleTypes.JAVA);
apklibModule = moduleModel.newModule(genModuleFilePath, StdModuleTypes.JAVA.getId());
}
final ModifiableRootModel apklibModuleModel = modelsProvider.getRootModel(apklibModule);
@@ -263,7 +263,8 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
if (modulesDirectory == null) {
modulesDirectory = path;
}
final Module module = moduleModel.newModule(modulesDirectory + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA);
final Module module = moduleModel.newModule(modulesDirectory + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT,
StdModuleTypes.JAVA.getId());
result.add(module);
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
rootModels[idx++] = rootModel;
@@ -186,7 +186,7 @@ public class GradleModulesImporter {
Application application = ApplicationManager.getApplication();
application.assertWriteAccessAllowed();
final String moduleFilePath = module.getModuleFilePath();
return model.newModule(moduleFilePath, StdModuleTypes.JAVA);
return model.newModule(moduleFilePath, StdModuleTypes.JAVA.getId());
}
/**
@@ -557,7 +557,7 @@ public class MvcModuleStructureUtil {
}
}
moduleModel.newModule(moduleFilePath, StdModuleTypes.JAVA);
moduleModel.newModule(moduleFilePath, StdModuleTypes.JAVA.getId());
moduleModel.commit();
Module pluginsModule = moduleManager.findModuleByName(moduleName);
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.compiler;
import com.intellij.compiler.CompileServerManager;
@@ -161,7 +176,7 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
final VirtualFile depRoot = myFixture.getTempDirFixture().findOrCreateDir(name);
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
String moduleName = moduleModel.newModule(depRoot.getPath() + "/" + name + ".iml", StdModuleTypes.JAVA).getName();
String moduleName = moduleModel.newModule(depRoot.getPath() + "/" + name + ".iml", StdModuleTypes.JAVA.getId()).getName();
moduleModel.commit();
final Module dep = ModuleManager.getInstance(getProject()).findModuleByName(moduleName);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -464,7 +464,7 @@ public class MavenProjectImporter {
// have to remove it beforehand.
deleteExistingImlFile(path);
final Module module = myModuleModel.newModule(path, project.getModuleType());
final Module module = myModuleModel.newModule(path, project.getModuleType().getId());
myMavenProjectToModule.put(project, module);
myCreatedModules.add(module);
return true;