use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-plugins by JetBrains.
the class FlexTestUtils method createModule.
public static Module createModule(Project project, final String moduleName, final VirtualFile moduleContent) throws IOException {
return WriteAction.compute(() -> {
final ModifiableModuleModel m1 = ModuleManager.getInstance(project).getModifiableModel();
final VirtualFile moduleDir = project.getBaseDir().createChildDirectory(JSTestUtils.class, moduleName);
final Module result = m1.newModule(moduleDir.getPath() + "/" + moduleName + ".iml", FlexModuleType.getInstance().getId());
m1.commit();
if (moduleContent != null) {
VfsUtil.copyDirectory(JSTestUtils.class, moduleContent, moduleDir, null);
PsiTestUtil.addSourceRoot(result, moduleDir);
}
return result;
});
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-plugins by JetBrains.
the class FlexScopeTest method testCircularDependency.
public void testCircularDependency() throws Exception {
final Sdk sdk = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.6"), null, true);
WriteAction.run(() -> {
final ModifiableModuleModel m1 = ModuleManager.getInstance(myProject).getModifiableModel();
final VirtualFile moduleDir = myProject.getBaseDir().createChildDirectory(this, "module2");
final Module module2 = m1.newModule(moduleDir.getPath(), FlexModuleType.getInstance().getId());
m1.commit();
PsiTestUtil.addSourceRoot(module2, moduleDir);
FlexTestUtils.modifyConfigs(myProject, editor -> {
final ModifiableFlexBuildConfiguration app1 = editor.getConfigurations(myModule)[0];
app1.setName("app1");
FlexTestUtils.setSdk(app1, sdk);
final ModifiableFlexBuildConfiguration lib1 = editor.getConfigurations(module2)[0];
lib1.setNature(new BuildConfigurationNature(TargetPlatform.Web, false, OutputType.Library));
app1.setName("lib1");
FlexTestUtils.setSdk(lib1, sdk);
final ModifiableFlexBuildConfiguration lib2 = editor.createConfiguration(myModule);
lib2.setName("lib2");
lib2.setNature(new BuildConfigurationNature(TargetPlatform.Web, false, OutputType.Library));
FlexTestUtils.setSdk(lib2, sdk);
final ModifiableBuildConfigurationEntry dep1 = editor.createBcEntry(app1.getDependencies(), lib1, null);
app1.getDependencies().getModifiableEntries().add(dep1);
final ModifiableBuildConfigurationEntry dep2 = editor.createBcEntry(lib1.getDependencies(), lib2, null);
lib1.getDependencies().getModifiableEntries().add(dep2);
});
});
doHighlightingTest("");
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-plugins by JetBrains.
the class FlashBuilderImportTest method importProject.
protected void importProject(final String dotProjectFileContent, final String dotActionScriptPropertiesFileContent, final Collection<String> otherProjectNames, @Nullable final String flashBuilderWorkspacePath) throws IOException, ConfigurationException {
final VirtualFile dotProjectFile = addFileWithContent(FlashBuilderImporter.DOT_PROJECT, dotProjectFileContent, myFlashBuilderProjectDir);
addFileWithContent(FlashBuilderImporter.DOT_ACTION_SCRIPT_PROPERTIES, dotActionScriptPropertiesFileContent, myFlashBuilderProjectDir);
final FlashBuilderProject flashBuilderProject = FlashBuilderProjectLoadUtil.loadProject(dotProjectFile, false);
final Collection<FlashBuilderProject> allFBProjects = new ArrayList<>();
allFBProjects.add(flashBuilderProject);
for (String name : otherProjectNames) {
allFBProjects.add(FlashBuilderProjectLoadUtil.getDummyFBProject(name));
}
final String moduleFilePath = myFlashBuilderProjectDir.getPath() + "/" + flashBuilderProject.getName() + ModuleFileType.DOT_DEFAULT_EXTENSION;
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel();
myModule = moduleModel.newModule(moduleFilePath, FlexModuleType.getInstance().getId());
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
final FlashBuilderSdkFinder sdkFinder = new FlashBuilderSdkFinder(myProject, StringUtil.notNullize(flashBuilderWorkspacePath), Collections.singletonList(flashBuilderProject));
final FlexProjectConfigurationEditor flexEditor = FlexProjectConfigurationEditor.createEditor(myProject, Collections.singletonMap(myModule, rootModel), null, null);
new FlashBuilderModuleImporter(myProject, flexEditor, allFBProjects, sdkFinder).setupModule(rootModel, flashBuilderProject);
flexEditor.commit();
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(Collections.singletonList(rootModel), moduleModel));
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-plugins by JetBrains.
the class FlashBuilderImporter method commit.
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
//FlexModuleBuilder.setupResourceFilePatterns(project);
final boolean needToCommit = model == null;
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
final List<String> paths = getList();
final boolean isArchive = paths.size() == 1 && FlashBuilderProjectFinder.hasArchiveExtension(paths.get(0));
final List<String> dotProjectPaths = getDotProjectPaths(project);
final List<FlashBuilderProject> flashBuilderProjects = FlashBuilderProjectLoadUtil.loadProjects(dotProjectPaths, isArchive);
final Map<FlashBuilderProject, ModifiableRootModel> flashBuilderProjectToModifiableModelMap = new THashMap<>();
final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new THashMap<>();
final Set<String> moduleNames = new THashSet<>(flashBuilderProjects.size());
final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
assert needToCommit == (currentFlexEditor == null);
for (FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
final String moduleName = makeUnique(flashBuilderProject.getName(), moduleNames);
moduleNames.add(moduleName);
final String moduleFilePath = flashBuilderProject.getProjectRootPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
if (LocalFileSystem.getInstance().findFileByPath(moduleFilePath) != null) {
ApplicationManager.getApplication().runWriteAction(() -> ModuleBuilder.deleteModuleFile(moduleFilePath));
}
final Module module = moduleModel.newModule(moduleFilePath, FlexModuleType.getInstance().getId());
final ModifiableRootModel rootModel = currentFlexEditor != null ? currentFlexEditor.getModifiableRootModel(module) : ModuleRootManager.getInstance(module).getModifiableModel();
flashBuilderProjectToModifiableModelMap.put(flashBuilderProject, rootModel);
moduleToModifiableModelMap.put(module, rootModel);
}
final FlexProjectConfigurationEditor flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(project, moduleToModifiableModelMap, null, null);
final FlashBuilderSdkFinder sdkFinder = new FlashBuilderSdkFinder(project, getParameters().myInitiallySelectedPath, flashBuilderProjects);
final FlashBuilderModuleImporter flashBuilderModuleImporter = new FlashBuilderModuleImporter(project, flexConfigEditor, flashBuilderProjects, sdkFinder);
for (final FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
flashBuilderModuleImporter.setupModule(flashBuilderProjectToModifiableModelMap.get(flashBuilderProject), flashBuilderProject);
}
if (needToCommit) {
try {
flexConfigEditor.commit();
} catch (ConfigurationException e) {
Logger.getInstance(FlashBuilderImporter.class).error(e);
}
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableModelCommitter.multiCommit(moduleToModifiableModelMap.values(), moduleModel);
});
}
return new ArrayList<>(moduleToModifiableModelMap.keySet());
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-leiningen-plugin by derkork.
the class ModuleCreationUtils method importModule.
/**
* This method imports a leiningen module from a leiningen project file and imports it into the idea project.
* <p/>
* Notes:
* <p/>
* Each of the IDEA components has a getModifiableModel on it. This method returns a new instance each time you
* invoke it. Once you have a modifiable model of the component you wish to update, you mutate it to the state
* you wish. Once you're done, you call commit() on the modifiable model and it updates the component it came from.
* <p/>
* Since a lot of the components are persisted in files, commit() updates these files as well. Therefore you need
* to make any calls to commit() from within a WriteAction.
*
* @param ideaProject The IDEA project to add the leiningen module to.
* @param leinProjectFile The leiningen project file
* @return The leiningen project map.
*/
public Map importModule(Project ideaProject, VirtualFile leinProjectFile) {
ClassPathUtils.getInstance().switchToPluginClassLoader();
Map projectMap = LeiningenAPI.loadProject(leinProjectFile.getPath());
String name = (String) projectMap.get(LEIN_PROJECT_NAME);
final ModifiableModuleModel moduleManager = createModuleManager(ideaProject);
final ModifiableRootModel module = createModule(moduleManager, leinProjectFile.getParent().getPath(), name);
initializeModulePaths(projectMap, module, leinProjectFile.getParent());
ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(ideaProject);
module.setSdk(rootManager.getProjectSdk());
//Setup the dependencies
// Based loosely on org.jetbrains.idea.maven.importing.MavenRootModelAdapter#addLibraryDependency
//We could use the module table here, but then the libraries wouldn't be shared across modules.
final LibraryTable.ModifiableModel projectLibraries = ProjectLibraryTable.getInstance(ideaProject).getModifiableModel();
//Load all the dependencies from the project file
List dependencyMaps = LeiningenAPI.loadDependencies(leinProjectFile.getCanonicalPath());
final List<LibraryInfo> dependencies = initializeDependencies(module, projectLibraries, dependencyMaps);
new WriteAction() {
@Override
protected void run(Result result) throws Throwable {
for (LibraryInfo library : dependencies) {
library.modifiableModel.commit();
}
//Save the project libraries
projectLibraries.commit();
//Save the module itself to the module file.
module.commit();
//Save the list of modules that are in this project to the IDEA project file
moduleManager.commit();
}
}.execute();
return projectMap;
}
Aggregations