use of com.intellij.openapi.module.ModuleWithNameAlreadyExists in project intellij-plugins by StepicOrg.
the class StepikProjectManager method refreshCourse.
private void refreshCourse() {
if (project == null || root == null) {
return;
}
root.setProject(project);
executor.execute(() -> {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
if (isAuthenticated()) {
root.reloadData(project, stepikApiClient);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Synchronize Project") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (project.isDisposed()) {
return;
}
repairProjectFiles(root);
repairSandbox();
ApplicationManager.getApplication().invokeLater(() -> {
VirtualFileManager.getInstance().syncRefresh();
setSelected(selected, false);
});
}
private void repairSandbox() {
VirtualFile projectDir = project.getBaseDir();
if (projectDir != null && projectDir.findChild(EduNames.SANDBOX_DIR) == null) {
Application application = ApplicationManager.getApplication();
ModifiableModuleModel model = application.runReadAction((Computable<ModifiableModuleModel>) () -> ModuleManager.getInstance(project).getModifiableModel());
application.invokeLater(() -> application.runWriteAction(() -> {
try {
new SandboxModuleBuilder(projectDir.getPath()).createModule(model);
model.commit();
} catch (IOException | ConfigurationException | JDOMException | ModuleWithNameAlreadyExists e) {
logger.warn("Failed repair Sandbox", e);
}
}));
}
}
});
});
}
use of com.intellij.openapi.module.ModuleWithNameAlreadyExists in project intellij-community by JetBrains.
the class RenameProjectHandler method renameProject.
public static boolean renameProject(@NotNull ProjectEx project, @Nullable Module module, String newName) {
if (shouldRenameProject(project, module, newName)) {
project.setProjectName(newName);
project.save();
}
if (module != null && !newName.equals(module.getName())) {
final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel();
try {
modifiableModel.renameModule(module, newName);
} catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
Messages.showErrorDialog(project, IdeBundle.message("error.module.already.exists", newName), IdeBundle.message("title.rename.module"));
return false;
}
final Ref<Boolean> success = Ref.create(Boolean.TRUE);
CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> modifiableModel.commit()), IdeBundle.message("command.renaming.module", module.getName()), null);
return success.get().booleanValue();
}
return true;
}
use of com.intellij.openapi.module.ModuleWithNameAlreadyExists in project intellij-community by JetBrains.
the class AbstractIdeModifiableModelsProvider method newModule.
@NotNull
@Override
public Module newModule(@NotNull final String filePath, final String moduleTypeId) {
Module module = getModifiableModuleModel().newModule(filePath, moduleTypeId);
final String moduleName = FileUtil.getNameWithoutExtension(new File(filePath));
if (!module.getName().equals(moduleName)) {
try {
getModifiableModuleModel().renameModule(module, moduleName);
} catch (ModuleWithNameAlreadyExists exists) {
LOG.warn(exists);
}
}
// set module type id explicitly otherwise it can not be set if there is an existing module (with the same filePath) and w/o 'type' attribute
module.setOption(Module.ELEMENT_TYPE, moduleTypeId);
return module;
}
use of com.intellij.openapi.module.ModuleWithNameAlreadyExists in project android by JetBrains.
the class ImportModuleTask method perform.
@Override
public Exception perform() {
final Module[] moduleWrapper = { null };
final Exception exception = ApplicationManager.getApplication().runWriteAction(new Computable<Exception>() {
@Override
public Exception compute() {
try {
moduleWrapper[0] = ModuleManager.getInstance(myProject).loadModule(myModuleFilePath);
} catch (InvalidDataException e) {
return e;
} catch (IOException e) {
return e;
} catch (JDOMException e) {
return e;
} catch (ModuleWithNameAlreadyExists e) {
return e;
}
return null;
}
});
if (exception != null) {
return exception;
}
assert moduleWrapper[0] != null;
if (AndroidFacet.getInstance(moduleWrapper[0]) == null) {
AndroidUtils.addAndroidFacetInWriteAction(moduleWrapper[0], myContentRoot, true);
}
AndroidSdkUtils.setupAndroidPlatformIfNecessary(moduleWrapper[0], false);
setDepModule(moduleWrapper[0]);
return null;
}
use of com.intellij.openapi.module.ModuleWithNameAlreadyExists in project intellij-plugins by StepicOrg.
the class ModuleUtils method createStepModule.
static void createStepModule(@NotNull Project project, @NotNull StepNode step, @NotNull ModifiableModuleModel moduleModel) {
StudyNode lesson = step.getParent();
if (lesson != null) {
String moduleDir = String.join("/", project.getBasePath(), lesson.getPath());
StepModuleBuilder stepModuleBuilder = new StepModuleBuilder(moduleDir, step);
try {
stepModuleBuilder.createModule(moduleModel);
} catch (IOException | ModuleWithNameAlreadyExists | JDOMException | ConfigurationException e) {
logger.warn("Cannot create step: " + step.getDirectory(), e);
}
}
}
Aggregations