contentRootPath / create content entry code moved to ModuleBuilder, allow instantiation of WebModule

This commit is contained in:
Maxim.Mossienko
2011-05-24 16:06:25 +04:00
parent 1829dcc66c
commit 9692106b81
7 changed files with 91 additions and 80 deletions
@@ -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);
}
}
@@ -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();
@@ -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<Source Path, Package Prefix>
private List<Pair<String,String>> mySourcePaths;
@@ -50,37 +48,6 @@ public class JavaModuleBuilder extends ModuleBuilder implements SourcePathsBuild
private final List<Pair<String, String>> myModuleLibraries = new ArrayList<Pair<String, String>>();
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<Pair<String,String>> sourcePaths = getSourcePaths();
if (sourcePaths != null) {
for (final Pair<String, String> 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<Pair<String,String>> sourcePaths = getSourcePaths();
if (sourcePaths != null) {
for (final Pair<String, String> sourcePath : sourcePaths) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance()
.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourcePath.first));
if (sourceRoot != null) {
contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
}
}
}
@@ -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<ModuleConfigurationUpdater> myUpdaters = new ArrayList<ModuleConfigurationUpdater>();
private final EventDispatcher<ModuleBuilderListener> 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) {
@@ -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<ModuleBuilder> {
@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();
}
};
}
}
@@ -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<EmptyModuleBuilder> {
public abstract class WebModuleTypeBase<T extends ModuleBuilder> extends ModuleType<T> {
@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<EmptyModuleBuilder> {
public Icon getNodeIcon(boolean isOpened) {
return getBigIcon();
}
}
}
@@ -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<Pair<String, String>> getSourcePaths() {
return Collections.emptyList();
}