Java Code Examples for com.intellij.openapi.module.ModifiableModuleModel#newModule()

The following examples show how to use com.intellij.openapi.module.ModifiableModuleModel#newModule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectFromSourcesBuilderImplModified.java    From tmc-intellij with MIT License 6 votes vote down vote up
private static Module createModule(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final Map<LibraryDescriptor, Library> projectLibs,
        final ModifiableModuleModel moduleModel) {

    logger.info("Starting createModule in ProjectFromSourcesBuilderImplModified");
    final String moduleFilePath = descriptor.computeModuleFilePath();
    ModuleBuilder.deleteModuleFile(moduleFilePath);

    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);
    modifiableModel.commit();
    logger.info("ending createModule in ProjectFromSourcesBuilderImplModified");
    return module;
}
 
Example 2
Source File: ModulePointerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testDisposePointerFromUncommitedModifiableModel() throws Exception {
  final NamedPointer<Module> pointer = ModuleUtilCore.createPointer(getProject(), "xxx");

  final ModifiableModuleModel modifiableModel = getModuleManager().getModifiableModel();
  final Module module = modifiableModel.newModule("xxx", myProject.getBaseDir().getPath());
  assertSame(pointer, ModuleUtilCore.createPointer(module));
  assertSame(pointer, ModuleUtilCore.createPointer(getProject(), "xxx"));

  assertSame(module, pointer.get());
  assertEquals("xxx", pointer.getName());

  modifiableModel.dispose();

  assertNull(pointer.get());
  assertEquals("xxx", pointer.getName());
}
 
Example 3
Source File: ModulePointerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Module addModule(final String name) {
  final ModifiableModuleModel model = getModuleManager().getModifiableModel();
  final Module module = model.newModule(name, myProject.getBaseDir().getPath());
  commitModel(model);
  disposeOnTearDown(new Disposable() {
    @Override
    public void dispose() {
      if (!module.isDisposed()) {
        getModuleManager().disposeModule(module);
      }
    }
  });
  return module;
}
 
Example 4
Source File: SandModuleImportProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull ModuleImportContext context, @Nonnull Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer) {
  String path = context.getPath();

  Module module = model.newModule(context.getName(), path);

  ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
  modifiableModel.addContentEntry(VfsUtil.pathToUrl(path));
  WriteAction.runAndWait(modifiableModel::commit);

  newModuleConsumer.accept(module);
}
 
Example 5
Source File: Unity3dModuleImportProvider.java    From consulo-unity3d with Apache License 2.0 3 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull UnityModuleImportContext context, @Nonnull Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer)
{
	Sdk unitySdk = context.getSdk();
	UnityOpenFilePostHandlerRequest requestor = context.getRequestor();

	Module rootModule = model.newModule(project.getName(), project.getBasePath());


	newModuleConsumer.accept(rootModule);

	StartupManager.getInstance(project).registerPostStartupActivity(() -> Unity3dProjectImportUtil.syncProjectStep1(project, unitySdk, requestor, true));

}