mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Maven importer should be able to create module of any type
This commit is contained in:
@@ -17,9 +17,12 @@ package org.jetbrains.idea.maven.importing;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.model.MavenArtifact;
|
||||
import org.jetbrains.idea.maven.project.*;
|
||||
@@ -57,6 +60,11 @@ public abstract class MavenImporter {
|
||||
return mavenProject.findPlugin(myPluginGroupID, myPluginArtifactID) != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ModuleType getModuleType() {
|
||||
return StdModuleTypes.JAVA;
|
||||
}
|
||||
|
||||
public void getSupportedPackagings(Collection<String> result) {
|
||||
}
|
||||
|
||||
|
||||
+45
-21
@@ -176,50 +176,74 @@ public class MavenProjectImporter {
|
||||
}
|
||||
|
||||
private boolean deleteIncompatibleModules() {
|
||||
final List<Pair<MavenProject, Module>> incompatible = collectIncompatibleModulesWithProjects();
|
||||
if (incompatible.isEmpty()) return false;
|
||||
final Pair<List<Pair<MavenProject, Module>>, List<Pair<MavenProject, Module>>> incompatible = collectIncompatibleModulesWithProjects();
|
||||
final List<Pair<MavenProject, Module>> incompatibleMavenized = incompatible.first;
|
||||
final List<Pair<MavenProject, Module>> incompatibleNotMavenized = incompatible.second;
|
||||
|
||||
if (incompatibleMavenized.isEmpty() && incompatibleNotMavenized.isEmpty()) return false;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
// For already mavenized modules the type may change because maven project plugins were resolved and MavenImporter asked to create a module of a different type.
|
||||
// In such cases we must change module type silently.
|
||||
for (Pair<MavenProject, Module> each : incompatibleMavenized) {
|
||||
myFileToModuleMapping.remove(each.first.getFile());
|
||||
myModuleModel.disposeModule(each.second);
|
||||
changed |= true;
|
||||
}
|
||||
|
||||
if (incompatibleNotMavenized.isEmpty()) return changed;
|
||||
|
||||
final int[] result = new int[1];
|
||||
MavenUtil.invokeAndWait(myProject, myModelsProvider.getModalityStateForQuestionDialogs(), new Runnable() {
|
||||
public void run() {
|
||||
String message = ProjectBundle.message("maven.import.incompatible.modules",
|
||||
formatProjectsWithModules(incompatible),
|
||||
incompatible.size() == 1 ? "" : "s");
|
||||
incompatibleNotMavenized.size(),
|
||||
formatProjectsWithModules(incompatibleNotMavenized));
|
||||
String[] options = {
|
||||
ProjectBundle.message("maven.import.incompatible.modules.recreate"),
|
||||
ProjectBundle.message("maven.import.incompatible.modules.ignore")
|
||||
};
|
||||
|
||||
result[0] = Messages.showOkCancelDialog(myProject, message,
|
||||
ProjectBundle.message("maven.tab.importing"),
|
||||
options[0], options[1], Messages.getQuestionIcon());
|
||||
ProjectBundle.message("maven.project.import.title"),
|
||||
options[0], options[1], Messages.getQuestionIcon());
|
||||
}
|
||||
});
|
||||
|
||||
if (result[0] == 0) {
|
||||
for (Pair<MavenProject, Module> each : incompatible) {
|
||||
for (Pair<MavenProject, Module> each : incompatibleNotMavenized) {
|
||||
myFileToModuleMapping.remove(each.first.getFile());
|
||||
myModuleModel.disposeModule(each.second);
|
||||
}
|
||||
return true;
|
||||
changed |= true;
|
||||
}
|
||||
else {
|
||||
myProjectsTree.setIgnoredState(MavenUtil.collectFirsts(incompatible), true, true);
|
||||
return false;
|
||||
myProjectsTree.setIgnoredState(MavenUtil.collectFirsts(incompatibleNotMavenized), true, true);
|
||||
changed |= false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private List<Pair<MavenProject, Module>> collectIncompatibleModulesWithProjects() {
|
||||
List<Pair<MavenProject, Module>> incompatible = new ArrayList<Pair<MavenProject, Module>>();
|
||||
/**
|
||||
* Collects modules that need to change module type
|
||||
* @return the first List in returned Pair contains already mavenized modules, the second List - not mavenized
|
||||
*/
|
||||
private Pair<List<Pair<MavenProject, Module>>, List<Pair<MavenProject, Module>>> collectIncompatibleModulesWithProjects() {
|
||||
List<Pair<MavenProject, Module>> incompatibleMavenized = new ArrayList<Pair<MavenProject, Module>>();
|
||||
List<Pair<MavenProject, Module>> incompatibleNotMavenized = new ArrayList<Pair<MavenProject, Module>>();
|
||||
|
||||
MavenProjectsManager manager = MavenProjectsManager.getInstance(myProject);
|
||||
for (MavenProject each : myAllProjects) {
|
||||
Module module = myFileToModuleMapping.get(each.getFile());
|
||||
if (module == null) continue;
|
||||
|
||||
if (shouldCreateModuleFor(each) && !(ModuleType.get(module) instanceof JavaModuleType)) {
|
||||
incompatible.add(Pair.create(each, module));
|
||||
if (shouldCreateModuleFor(each) && !(ModuleType.get(module).equals(each.getModuleType()))) {
|
||||
(manager.isMavenizedModule(module) ? incompatibleMavenized : incompatibleNotMavenized).add(Pair.create(each, module));
|
||||
}
|
||||
}
|
||||
return incompatible;
|
||||
return Pair.create(incompatibleMavenized, incompatibleNotMavenized);
|
||||
}
|
||||
|
||||
private static String formatProjectsWithModules(List<Pair<MavenProject, Module>> projectsWithModules) {
|
||||
@@ -230,9 +254,8 @@ public class MavenProjectImporter {
|
||||
return ModuleType.get(module).getName() +
|
||||
" '" +
|
||||
module.getName() +
|
||||
"' for Maven project '" +
|
||||
project.getMavenId().getDisplayString() +
|
||||
"'";
|
||||
"' for Maven project " +
|
||||
project.getMavenId().getDisplayString();
|
||||
}
|
||||
}, "<br>");
|
||||
}
|
||||
@@ -248,7 +271,7 @@ public class MavenProjectImporter {
|
||||
public void run() {
|
||||
result[0] = Messages.showYesNoDialog(myProject,
|
||||
ProjectBundle.message("maven.import.message.delete.obsolete", formatModules(obsoleteModules)),
|
||||
ProjectBundle.message("maven.tab.importing"),
|
||||
ProjectBundle.message("maven.project.import.title"),
|
||||
Messages.getQuestionIcon());
|
||||
}
|
||||
});
|
||||
@@ -271,8 +294,9 @@ public class MavenProjectImporter {
|
||||
}
|
||||
|
||||
List<Module> obsolete = new ArrayList<Module>();
|
||||
final MavenProjectsManager manager = MavenProjectsManager.getInstance(myProject);
|
||||
for (Module each : remainingModules) {
|
||||
if (MavenProjectsManager.getInstance(myProject).isMavenizedModule(each)) {
|
||||
if (manager.isMavenizedModule(each)) {
|
||||
obsolete.add(each);
|
||||
}
|
||||
}
|
||||
@@ -440,7 +464,7 @@ public class MavenProjectImporter {
|
||||
// have to remove it beforehand.
|
||||
deleteExistingImlFile(path);
|
||||
|
||||
final Module module = myModuleModel.newModule(path, StdModuleTypes.JAVA);
|
||||
final Module module = myModuleModel.newModule(path, project.getModuleType());
|
||||
myMavenProjectToModule.put(project, module);
|
||||
myCreatedModules.add(module);
|
||||
return true;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.project;
|
||||
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
@@ -796,6 +798,21 @@ public class MavenProject {
|
||||
return MavenImporter.getSuitableImporters(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ModuleType getModuleType() {
|
||||
ModuleType typeFromImporter = null;
|
||||
for (MavenImporter each : getSuitableImporters()) {
|
||||
final ModuleType moduleType = each.getModuleType();
|
||||
if (typeFromImporter != null && !typeFromImporter.equals(moduleType)) {
|
||||
MavenLog.LOG.error("Incompatible plugins: " + each.getClass().getName() + " wants to create " +
|
||||
moduleType.getName() + " for project " + getName() + " whereas some other importer requires " +
|
||||
typeFromImporter.getName());
|
||||
}
|
||||
typeFromImporter = moduleType;
|
||||
}
|
||||
return typeFromImporter != null ? typeFromImporter : StdModuleTypes.JAVA;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Pair<String, String> getClassifierAndExtension(@NotNull MavenArtifact artifact, @NotNull MavenExtraArtifactType type) {
|
||||
for (MavenImporter each : getSuitableImporters()) {
|
||||
|
||||
+9
@@ -111,6 +111,15 @@ public class MavenProjectsManagerWatcher {
|
||||
MavenProject mavenProject = myManager.findProject(module);
|
||||
if (mavenProject != null) myManager.setIgnoredState(Collections.singletonList(mavenProject), true);
|
||||
}
|
||||
|
||||
public void moduleAdded(final Project project, final Module module) {
|
||||
// this method is needed to return non-ignored status for modules that were deleted (and thus ignored) and then created again with a different module type
|
||||
if (myManager.isMavenizedModule(module)) {
|
||||
MavenProject mavenProject = myManager.findProject(module);
|
||||
if (mavenProject != null) myManager.setIgnoredState(Collections.singletonList(mavenProject), false);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
DocumentAdapter myDocumentListener = new DocumentAdapter() {
|
||||
|
||||
@@ -24,6 +24,7 @@ maven.project.changed=Maven projects need to be imported
|
||||
maven.project.importChanged=Import Changes
|
||||
maven.project.enableAutoImport=Enable Auto-Import
|
||||
maven.project.importing=Importing Maven projects
|
||||
maven.project.import.title=Import Maven Projects
|
||||
maven.project.importing.finished=Finished importing Maven projects
|
||||
maven.project.import.waiting.for.active.process=Waiting for an active process
|
||||
maven.post.processing=Configuring Maven projects
|
||||
@@ -37,11 +38,9 @@ maven.import.environment.settings.title=Maven environment
|
||||
maven.import.title.module.dir=Select directory for IDEA module files (*.iml)
|
||||
|
||||
maven.import.incompatible.modules=<html>\
|
||||
Maven import needs to recreate<br>{0}<br><br>\
|
||||
<i>Maven Integration supports only Java modules. Your modules will be recreated as <br>\
|
||||
Java modules and configured according to settings in your pom.xml files.<br>\
|
||||
If you do not want the modules to be recreated, corresponding Maven projects will be marked as<br>\
|
||||
''Ignored'' and you can unignore them afterwards in the Maven Projects tool window.<i></html>
|
||||
The following {0,choice,1#module has|2#modules have} incorrect type and {0,choice,1#needs|2#need} to be recreated:<br><br>{1}<br><br>\
|
||||
If you do not want the {0,choice,1#module|2#modules} to be recreated, corresponding Maven projects will be marked as ignored,<br>\
|
||||
you will be able to unignore them afterwards in the Maven Projects tool window.</html>
|
||||
maven.import.incompatible.modules.recreate=Recreate
|
||||
maven.import.incompatible.modules.ignore=Ignore These Projects
|
||||
|
||||
|
||||
Reference in New Issue
Block a user