diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameStep.java index 7a6d9951771f..d1ec12bde806 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameStep.java @@ -88,8 +88,8 @@ public class ProjectNameStep extends ModuleWizardStep { final ProjectBuilder moduleBuilder = myMode.getModuleBuilder(); myWizardContext.setProjectBuilder(moduleBuilder); myFormatPanel.updateData(myWizardContext); - if (moduleBuilder instanceof SourcePathsBuilder) { - ((SourcePathsBuilder)moduleBuilder).setContentEntryPath(projectFileDirectory); + if (moduleBuilder instanceof ModuleBuilder) { + ((ModuleBuilder)moduleBuilder).setContentEntryPath(projectFileDirectory); } } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java index 89a8e94e8c3e..60d3cfe94716 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java @@ -320,7 +320,7 @@ public class ProjectNameWithTypeStep extends ProjectNameStep { assert builder != null; builder.setName(myModuleName.getText()); builder.setModuleFilePath(FileUtil.toSystemIndependentName(myModuleFileLocation.getText()) + "/" + myModuleName.getText() + ModuleFileType.DOT_DEFAULT_EXTENSION); - ((SourcePathsBuilder)builder).setContentEntryPath(FileUtil.toSystemIndependentName(myModuleContentRoot.getText())); + builder.setContentEntryPath(FileUtil.toSystemIndependentName(myModuleContentRoot.getText())); } else { mySequence.setType(null); super.updateDataModel(); diff --git a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java index a62a3679d4a8..d9bcd46b688b 100644 --- a/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java +++ b/java/openapi/src/com/intellij/ide/util/projectWizard/JavaModuleBuilder.java @@ -41,8 +41,6 @@ import java.util.ArrayList; import java.util.List; public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuilder { - - private String myContentEntryPath; private String myCompilerOutputPath; // Pair private List> mySourcePaths; @@ -50,37 +48,6 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild private final List> myModuleLibraries = new ArrayList>(); private Sdk myJdk; - @Nullable - public final String getContentEntryPath() { - if (myContentEntryPath == null) { - final String directory = getModuleFileDirectory(); - if (directory == null) { - return null; - } - new File(directory).mkdirs(); - return directory; - } - return myContentEntryPath; - } - - public final void setContentEntryPath(String moduleRootPath) { - final String path = acceptParameter(moduleRootPath); - if (path != null) { - try { - myContentEntryPath = FileUtil.resolveShortWindowsName(path); - } - catch (IOException e) { - myContentEntryPath = path; - } - } - else { - myContentEntryPath = null; - } - if (myContentEntryPath != null) { - myContentEntryPath = myContentEntryPath.replace(File.separatorChar, '/'); - } - } - public final void setCompilerOutputPath(String compilerOutputPath) { myCompilerOutputPath = acceptParameter(compilerOutputPath); } @@ -120,19 +87,16 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild rootModel.inheritSdk(); } - final String moduleRootPath = getContentEntryPath(); - if (moduleRootPath != null) { - final LocalFileSystem lfs = LocalFileSystem.getInstance(); - VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(moduleRootPath)); - if (moduleContentRoot != null) { - final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot); - final List> sourcePaths = getSourcePaths(); - if (sourcePaths != null) { - for (final Pair sourcePath : sourcePaths) { - final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourcePath.first)); - if (sourceRoot != null) { - contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second); - } + ContentEntry contentEntry = doAddContentEntry(rootModel); + if (contentEntry != null) { + final List> sourcePaths = getSourcePaths(); + + if (sourcePaths != null) { + for (final Pair sourcePath : sourcePaths) { + final VirtualFile sourceRoot = LocalFileSystem.getInstance() + .refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourcePath.first)); + if (sourceRoot != null) { + contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second); } } } diff --git a/platform/lang-api/src/com/intellij/ide/util/projectWizard/ModuleBuilder.java b/platform/lang-api/src/com/intellij/ide/util/projectWizard/ModuleBuilder.java index b61b1e3af5ef..04a228641b48 100644 --- a/platform/lang-api/src/com/intellij/ide/util/projectWizard/ModuleBuilder.java +++ b/platform/lang-api/src/com/intellij/ide/util/projectWizard/ModuleBuilder.java @@ -24,6 +24,7 @@ import com.intellij.openapi.module.*; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; @@ -54,6 +55,7 @@ public abstract class ModuleBuilder extends ProjectBuilder{ private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.projectWizard.ModuleBuilder"); private String myName; @NonNls private String myModuleFilePath; + private String myContentEntryPath; private final List myUpdaters = new ArrayList(); private final EventDispatcher myDispatcher = EventDispatcher.create(ModuleBuilderListener.class); @@ -101,6 +103,45 @@ public abstract class ModuleBuilder extends ProjectBuilder{ myModuleFilePath = acceptParameter(path); } + @Nullable + public String getContentEntryPath() { + if (myContentEntryPath == null) { + final String directory = getModuleFileDirectory(); + if (directory == null) { + return null; + } + new File(directory).mkdirs(); + return directory; + } + return myContentEntryPath; + } + + public void setContentEntryPath(String moduleRootPath) { + final String path = acceptParameter(moduleRootPath); + if (path != null) { + try { + myContentEntryPath = FileUtil.resolveShortWindowsName(path); + } + catch (IOException e) { + myContentEntryPath = path; + } + } + else { + myContentEntryPath = null; + } + if (myContentEntryPath != null) { + myContentEntryPath = myContentEntryPath.replace(File.separatorChar, '/'); + } + } + + protected @Nullable ContentEntry doAddContentEntry(ModifiableRootModel modifiableRootModel) { + final String contentEntryPath = getContentEntryPath(); + if (contentEntryPath == null) return null; + final VirtualFile moduleContentRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(contentEntryPath.replace('\\', '/')); + if (moduleContentRoot == null) return null; + return modifiableRootModel.addContentEntry(moduleContentRoot); + } + @Nullable public String getModuleFileDirectory() { if (myModuleFilePath == null) { diff --git a/platform/lang-impl/src/com/intellij/openapi/module/WebModuleType.java b/platform/lang-impl/src/com/intellij/openapi/module/WebModuleType.java new file mode 100644 index 000000000000..f53bfa74482f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/module/WebModuleType.java @@ -0,0 +1,30 @@ +package com.intellij.openapi.module; + +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.roots.ModifiableRootModel; +import org.jetbrains.annotations.NotNull; + +/** + * @author yole + */ +public class WebModuleType extends WebModuleTypeBase { + @NotNull + public static WebModuleType getInstance() { + return (WebModuleType)ModuleTypeManager.getInstance().findByID(WEB_MODULE); + } + + public ModuleBuilder createModuleBuilder() { + return new ModuleBuilder() { + @Override + public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { + doAddContentEntry(modifiableRootModel); + } + + @Override + public ModuleType getModuleType() { + return getInstance(); + } + }; + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/module/PlatformWebModuleType.java b/platform/lang-impl/src/com/intellij/openapi/module/WebModuleTypeBase.java similarity index 59% rename from platform/lang-impl/src/com/intellij/openapi/module/PlatformWebModuleType.java rename to platform/lang-impl/src/com/intellij/openapi/module/WebModuleTypeBase.java index 134caaa150e6..b4fca6d4f1af 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/PlatformWebModuleType.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/WebModuleTypeBase.java @@ -1,39 +1,25 @@ package com.intellij.openapi.module; -import com.intellij.ide.util.projectWizard.EmptyModuleBuilder; +import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ex.ApplicationInfoEx; +import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.util.IconLoader; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; import javax.swing.*; /** * @author yole */ -public class PlatformWebModuleType extends ModuleType { +public abstract class WebModuleTypeBase extends ModuleType { @NonNls public static final String WEB_MODULE = "WEB_MODULE"; - public PlatformWebModuleType() { + public WebModuleTypeBase() { super(WEB_MODULE); } - @NotNull - public static PlatformWebModuleType getInstance() { - return (PlatformWebModuleType)ModuleTypeManager.getInstance().findByID(WEB_MODULE); - } - - public EmptyModuleBuilder createModuleBuilder() { - return new EmptyModuleBuilder() { - @Override - public ModuleType getModuleType() { - return getInstance(); - } - }; - } - public String getName() { return ProjectBundle.message("module.web.title"); } @@ -49,4 +35,4 @@ public class PlatformWebModuleType extends ModuleType { public Icon getNodeIcon(boolean isOpened) { return getBigIcon(); } -} \ No newline at end of file +} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilder.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilder.java index 64572a8c0ae4..0d7273eac2ae 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilder.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilder.java @@ -45,8 +45,6 @@ import java.util.List; public class MavenModuleBuilder extends ModuleBuilder implements SourcePathsBuilder { private static final Icon BIG_ICON = IconLoader.getIcon("/modules/javaModule.png"); - private String myContentRootPath; - private MavenProject myAggregatorProject; private MavenProject myParentProject; @@ -104,7 +102,7 @@ public class MavenModuleBuilder extends ModuleBuilder implements SourcePathsBuil public MavenProject findPotentialParentProject(Project project) { if (!MavenProjectsManager.getInstance(project).isMavenizedProject()) return null; - File parentDir = new File(myContentRootPath).getParentFile(); + File parentDir = new File(getContentEntryPath()).getParentFile(); if (parentDir == null) return null; VirtualFile parentPom = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(parentDir, "pom.xml")); if (parentPom == null) return null; @@ -113,19 +111,11 @@ public class MavenModuleBuilder extends ModuleBuilder implements SourcePathsBuil } private VirtualFile createAndGetContentEntry() { - String path = FileUtil.toSystemIndependentName(myContentRootPath); + String path = FileUtil.toSystemIndependentName(getContentEntryPath()); new File(path).mkdirs(); return LocalFileSystem.getInstance().refreshAndFindFileByPath(path); } - public String getContentEntryPath() { - return myContentRootPath; - } - - public void setContentEntryPath(String path) { - myContentRootPath = path; - } - public List> getSourcePaths() { return Collections.emptyList(); }