mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
reuse existing .imls if found during create project from existing sources
This commit is contained in:
@@ -36,12 +36,21 @@ public class ModuleDescriptor {
|
||||
private static final String[] ourModuleNameStoplist = new String[] {
|
||||
"java", "src", "source", "sources", "C:", "D:", "E:", "F:", "temp", "tmp"
|
||||
};
|
||||
|
||||
private boolean myReuseExistingElement;
|
||||
|
||||
public ModuleDescriptor(final File contentRoot, final Set<File> sourceRoots) {
|
||||
myName = suggestModuleName(contentRoot);
|
||||
myContentToSourceRoots.put(contentRoot, sourceRoots);
|
||||
}
|
||||
|
||||
public void reuseExisting(boolean reuseExistingElement) {
|
||||
myReuseExistingElement = reuseExistingElement;
|
||||
}
|
||||
|
||||
public boolean isReuseExistingElement() {
|
||||
return myReuseExistingElement;
|
||||
}
|
||||
|
||||
private static String suggestModuleName(final File contentRoot) {
|
||||
for (File dir = contentRoot; dir != null; dir = dir.getParentFile()) {
|
||||
final String suggestion = dir.getName();
|
||||
|
||||
@@ -26,10 +26,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -109,24 +106,27 @@ public class ModulesDetectionStep extends AbstractStepWithProgress<List<ModuleDe
|
||||
}
|
||||
|
||||
final List<ModuleDescriptor> modules = myModulesLayoutPanel.getChosenEntries();
|
||||
List<String> errors = new ArrayList<String>();
|
||||
final Map<String, ModuleDescriptor> errors = new LinkedHashMap<String, ModuleDescriptor>();
|
||||
for (ModuleDescriptor module : modules) {
|
||||
try {
|
||||
final String moduleFilePath = module.computeModuleFilePath();
|
||||
if (new File(moduleFilePath).exists()) {
|
||||
errors.add(IdeBundle.message("warning.message.the.module.file.0.already.exist.and.will.be.overwritten", moduleFilePath));
|
||||
errors.put(IdeBundle.message("warning.message.the.module.file.0.already.exist.and.will.be.overwritten", moduleFilePath), module);
|
||||
}
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
errors.add(e.getMessage());
|
||||
errors.put(e.getMessage(), module);
|
||||
}
|
||||
}
|
||||
if (!errors.isEmpty()) {
|
||||
final int answer = Messages.showYesNoDialog(getComponent(),
|
||||
IdeBundle.message("warning.text.0.do.you.want.to.continue", StringUtil.join(errors, "\n")),
|
||||
IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon());
|
||||
final int answer = Messages.showYesNoCancelDialog(getComponent(),
|
||||
IdeBundle.message("warning.text.0.do.you.want.to.continue",
|
||||
StringUtil.join(errors.keySet(), "\n")),
|
||||
IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon());
|
||||
if (answer != 0) {
|
||||
return false;
|
||||
for (ModuleDescriptor moduleDescriptor : errors.values()) {
|
||||
moduleDescriptor.reuseExisting(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+10
-1
@@ -19,6 +19,8 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.util.importProject.LibraryDescriptor;
|
||||
import com.intellij.ide.util.importProject.ModuleDescriptor;
|
||||
import com.intellij.ide.util.importProject.ModuleInsight;
|
||||
import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode;
|
||||
import com.intellij.ide.util.projectWizard.ExistingModuleLoader;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ProjectBuilder;
|
||||
import com.intellij.ide.util.projectWizard.SourcePathsBuilder;
|
||||
@@ -131,7 +133,14 @@ public class ProjectFromSourcesBuilder extends ProjectBuilder implements SourceP
|
||||
try {
|
||||
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
|
||||
for (final ModuleDescriptor moduleDescriptor : myChosenModules) {
|
||||
final Module module = createModule(project, moduleDescriptor, sourceRootToPrefixMap, projectLibs, moduleModel);
|
||||
final Module module;
|
||||
if (moduleDescriptor.isReuseExistingElement()) {
|
||||
final ExistingModuleLoader moduleLoader = ImportImlMode.setUpLoader(FileUtil.toSystemIndependentName(moduleDescriptor.computeModuleFilePath()));
|
||||
module = moduleLoader.createModule(moduleModel);
|
||||
}
|
||||
else {
|
||||
module = createModule(project, moduleDescriptor, sourceRootToPrefixMap, projectLibs, moduleModel);
|
||||
}
|
||||
result.add(module);
|
||||
descriptorToModuleMap.put(moduleDescriptor, module);
|
||||
}
|
||||
|
||||
@@ -66,8 +66,11 @@ public class ImportImlMode extends WizardMode {
|
||||
}
|
||||
|
||||
public ProjectBuilder getModuleBuilder() {
|
||||
return setUpLoader(FileUtil.toSystemIndependentName(myModulePathFieldPanel.getText().trim()));
|
||||
}
|
||||
|
||||
public static ExistingModuleLoader setUpLoader(final String moduleFilePath) {
|
||||
final ExistingModuleLoader moduleLoader = new ExistingModuleLoader();
|
||||
final String moduleFilePath = FileUtil.toSystemIndependentName(myModulePathFieldPanel.getText().trim());
|
||||
moduleLoader.setModuleFilePath(moduleFilePath);
|
||||
final int startIndex = moduleFilePath.lastIndexOf('/');
|
||||
final int endIndex = moduleFilePath.lastIndexOf(".");
|
||||
|
||||
@@ -749,8 +749,8 @@ prompt.new.project.file.name=Enter a file name to create a new {0} {1}
|
||||
prompt.enter.project.file.location=Enter {0} file location
|
||||
directory.project.file.directory=The {0} file directory\n
|
||||
prompt.overwrite.project.file=The {1} file \n''{0}''\nalready exists.\nWould you like to overwrite it?
|
||||
warning.message.the.module.file.0.already.exist.and.will.be.overwritten=The module file ''{0}'' already exist and will be overwritten.
|
||||
warning.text.0.do.you.want.to.continue={0}\nDo you want to continue?
|
||||
warning.message.the.module.file.0.already.exist.and.will.be.overwritten=The module file ''{0}'' already exist.
|
||||
warning.text.0.do.you.want.to.continue={0}\nWould you like to overwrite it?
|
||||
title.select.jdk=Select JDK
|
||||
button.configure.e=Configure...
|
||||
label.scope.pattern=&Pattern:
|
||||
|
||||
Reference in New Issue
Block a user