diff --git a/plugins/devkit/META-INF/plugin.xml b/plugins/devkit/META-INF/plugin.xml
index 31bb99ae3754..66df26db09f1 100644
--- a/plugins/devkit/META-INF/plugin.xml
+++ b/plugins/devkit/META-INF/plugin.xml
@@ -10,25 +10,18 @@
org.jetbrains.idea.devkit.DevKitPlugin
+
+ org.jetbrains.idea.devkit.projectRoots.IdeaJdk
+
org.jetbrains.idea.devkit.run.PluginConfigurationType
-
- org.jetbrains.idea.devkit.sandbox.SandboxManager
-
-
- org.jetbrains.idea.devkit.sandbox.SandboxConfigurable
-
org.jetbrains.idea.devkit.module.PluginTemplatesFactory
-
- org.jetbrains.idea.devkit.module.ModuleSandboxManager
-
-
org.jetbrains.idea.devkit.module.PluginModuleEditorsProvider
@@ -37,7 +30,7 @@
com.intellij.j2ee.make.ModuleBuildProperties
org.jetbrains.idea.devkit.build.PluginModuleBuildProperties
-
+
com.intellij.j2ee.make.ModuleBuildDescriptor
org.jetbrains.idea.devkit.build.PluginModuleBuildDescriptor
@@ -47,5 +40,8 @@
org.jetbrains.idea.devkit.module.PluginModuleProperties
+
diff --git a/plugins/devkit/src/build/PluginBuildUtil.java b/plugins/devkit/src/build/PluginBuildUtil.java
new file mode 100644
index 000000000000..9680c2cbfbea
--- /dev/null
+++ b/plugins/devkit/src/build/PluginBuildUtil.java
@@ -0,0 +1,54 @@
+package org.jetbrains.idea.devkit.build;
+
+import com.intellij.openapi.projectRoots.ProjectJdk;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.OrderEntry;
+import com.intellij.openapi.roots.LibraryOrderEntry;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleType;
+import com.intellij.openapi.diagnostic.Logger;
+import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
+import org.jetbrains.idea.devkit.projectRoots.Sandbox;
+
+import java.util.Set;
+
+/**
+ * User: anna
+ * Date: Nov 24, 2004
+ */
+public class PluginBuildUtil {
+
+ public static String getPluginExPath(Module module){
+ final ProjectJdk jdk = ModuleRootManager.getInstance(module).getJdk();
+ if (! (jdk.getSdkType() instanceof IdeaJdk)){
+ return null;
+ }
+ return ((Sandbox)jdk.getSdkAdditionalData()).getSandboxHome() + "/plugins/" + module.getName();
+ }
+
+ public static void getDependencies(Module module, Set modules) {
+ if (modules.contains(module)) return;
+ Module[] dependencies = ModuleRootManager.getInstance(module).getDependencies();
+ for (int i = 0; i < dependencies.length; i++) {
+ Module dependency = dependencies[i];
+ if (dependency.getModuleType() == ModuleType.JAVA) {
+ modules.add(dependency);
+ getDependencies(dependency, modules);
+ }
+ }
+ }
+
+ public static void getLibraries(Module module, Set libs) {
+ OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
+ for (int i = 0; i < orderEntries.length; i++) {
+ OrderEntry orderEntry = orderEntries[i];
+ if (orderEntry instanceof LibraryOrderEntry) {
+ LibraryOrderEntry libEntry = (LibraryOrderEntry)orderEntry;
+ Library lib = libEntry.getLibrary();
+ if (lib == null) continue;
+ libs.add(lib);
+ }
+ }
+ }
+}
diff --git a/plugins/devkit/src/build/PluginModuleBuildConfEditor.java b/plugins/devkit/src/build/PluginModuleBuildConfEditor.java
new file mode 100644
index 000000000000..41709d1dbec8
--- /dev/null
+++ b/plugins/devkit/src/build/PluginModuleBuildConfEditor.java
@@ -0,0 +1,155 @@
+package org.jetbrains.idea.devkit.build;
+
+import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.module.ModuleConfigurationEditor;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.JDOMExternalizable;
+import com.intellij.openapi.util.InvalidDataException;
+import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.ModifiableRootModel;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+
+import com.intellij.util.ArrayUtil;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.HashSet;
+
+import org.jdom.Element;
+
+/**
+ * User: anna
+ * Date: Nov 24, 2004
+ */
+public class PluginModuleBuildConfEditor implements ModuleConfigurationEditor {
+ private JPanel myWholePanel = new JPanel(new GridBagLayout());
+ private JRadioButton myClasses = new JRadioButton("Classes"); //todo: best Labels
+ private JRadioButton myJar = new JRadioButton("Jar");
+ private JLabel myDesctination = new JLabel();
+
+ private boolean myModified = false;
+
+ private PluginModuleBuildProperties myBuildProperties;
+ private ModuleConfigurationState myState;
+
+ private HashSet mySetDependencyOnPluginModule = new HashSet();
+
+ public PluginModuleBuildConfEditor(PluginModuleBuildProperties buildProperties, ModuleConfigurationState state) {
+ myBuildProperties = buildProperties;
+ myState = state;
+ }
+
+ public JComponent createComponent() {
+ ButtonGroup deployButtonGroup = new ButtonGroup();
+ deployButtonGroup.add(myJar);
+ deployButtonGroup.add(myClasses);
+ myClasses.setSelected(true);
+
+ myJar.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ deploymentMethodChanged();
+ }
+ });
+ myClasses.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ deploymentMethodChanged();
+ }
+ });
+ myWholePanel.add(new JLabel("Choose the plugin deployment method:"), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
+ myWholePanel.add(myJar, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.NONE, new Insets(2, 10, 5, 5), 0, 0));
+ myWholePanel.add(myClasses, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.NONE, new Insets(0, 10, 5, 5), 0, 0));
+
+ myWholePanel.add(myDesctination, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHWEST,
+ GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
+ return myWholePanel;
+ }
+
+ private void deploymentMethodChanged() {
+ myDesctination.setText(
+ myJar.isSelected()
+ ? (myBuildProperties.getJarPath() != null ? "Plugin jar will be put to " + myBuildProperties.getJarPath().replace('/', File.separatorChar) : "")
+ : (myBuildProperties.getExplodedPath() != null ? "Plugin will be put in " + myBuildProperties.getExplodedPath().replace('/', File.separatorChar) : ""));
+ myModified = true;
+ }
+
+ public boolean isModified() {
+ return myModified;
+ }
+
+ public void apply() throws ConfigurationException {
+ if (!mySetDependencyOnPluginModule.isEmpty()) {
+ throw new ConfigurationException("Unable to set dependency on plugin module.");
+ }
+ final String toDelete = !myJar.isSelected() ? myBuildProperties.getJarPath() : myBuildProperties.getExplodedPath();
+ if (toDelete != null && new File(toDelete).exists() && Messages.showYesNoDialog(myBuildProperties.getModule().getProject(),
+ !myJar.isSelected() ? "Delete " : "Clear " + toDelete + "?",
+ "Clean up plugin directory", null) == DialogWrapper.OK_EXIT_CODE) {
+ CommandProcessor.getInstance().executeCommand(myBuildProperties.getModule().getProject(),
+ new Runnable() {
+ public void run() {
+ FileUtil.delete(new File(toDelete));
+ }
+ },
+ "Synchronize plugins directory",
+ null);
+ }
+ myBuildProperties.setJarPlugin(myJar.isSelected());
+ myModified = false;
+ }
+
+ public void reset() {
+ myJar.setSelected(myBuildProperties.isJarPlugin());
+ myClasses.setSelected(!myBuildProperties.isJarPlugin());
+ deploymentMethodChanged();
+ myModified = false;
+ }
+
+ public void disposeUIResources() {}
+
+ public void saveData() {}
+
+ public String getDisplayName() {
+ return "Plugin Deployment";
+ }
+
+ public Icon getIcon() {
+ return IconLoader.getIcon("/nodes/plugin.png");
+ }
+
+ public String getHelpTopic() {
+ return null; //todo
+ }
+
+ public void moduleStateChanged(ModifiableRootModel model) {
+ final String moduleName = myState.getRootModel().getModule().getName();
+ final String changedModuleName = model.getModule().getName();
+ if (ArrayUtil.find(model.getDependencyModuleNames(),
+ moduleName) >
+ -1) {
+ mySetDependencyOnPluginModule.add(changedModuleName);
+ myModified = true;
+ } else {
+ mySetDependencyOnPluginModule.remove(changedModuleName);
+ if (mySetDependencyOnPluginModule.isEmpty()){
+ myModified = true;
+ }
+ }
+ }
+
+
+}
diff --git a/plugins/devkit/src/build/PluginModuleBuildProperties.java b/plugins/devkit/src/build/PluginModuleBuildProperties.java
index d3546bdcd8f4..8aa7e38f13d8 100644
--- a/plugins/devkit/src/build/PluginModuleBuildProperties.java
+++ b/plugins/devkit/src/build/PluginModuleBuildProperties.java
@@ -7,11 +7,16 @@ package org.jetbrains.idea.devkit.build;
import com.intellij.j2ee.make.ModuleBuildProperties;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
-import org.jetbrains.idea.devkit.module.ModuleSandboxManager;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.projectRoots.ProjectJdk;
+import com.intellij.openapi.diagnostic.Logger;
+import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
+import org.jetbrains.idea.devkit.projectRoots.Sandbox;
public class PluginModuleBuildProperties extends ModuleBuildProperties implements ModuleComponent {
private Module myModule;
-
+ private boolean myJarPlugin = false;
+
public PluginModuleBuildProperties(Module module) {
myModule = module;
}
@@ -21,15 +26,19 @@ public class PluginModuleBuildProperties extends ModuleBuildProperties implement
}
public String getJarPath() {
- return getSandboxManager().getSandbox().getSandboxHome() + "/plugins/" + myModule.getName();
+ return PluginBuildUtil.getPluginExPath(myModule) + "/lib/" + myModule.getName() + ".jar";
}
public String getExplodedPath() {
- return getSandboxManager().getSandbox().getSandboxHome() + "/plugins/" + myModule.getName();
+ return PluginBuildUtil.getPluginExPath(myModule);
}
- private ModuleSandboxManager getSandboxManager() {
- return ModuleSandboxManager.getInstance(myModule);
+ public boolean isJarPlugin() {
+ return myJarPlugin;
+ }
+
+ public void setJarPlugin(boolean jarPlugin) {
+ myJarPlugin = jarPlugin;
}
public Module getModule() {
@@ -37,25 +46,20 @@ public class PluginModuleBuildProperties extends ModuleBuildProperties implement
}
public boolean isJarEnabled() {
- return false;
+ return myJarPlugin;
}
public boolean isExplodedEnabled() {
- return isBuildActive();
+ return true;//todo synchronize libs for plugin in jar
}
public boolean isBuildOnFrameDeactivation() {
//TODO
- return isBuildActive();
+ return false;
}
public boolean isSyncExplodedDir() {
- //TODO
- return isBuildActive();
- }
-
- private boolean isBuildActive() {
- return !getSandboxManager().isUnderIDEAProject();
+ return true;
}
public void projectOpened() {}
diff --git a/plugins/devkit/src/module/PluginModuleBuilder.java b/plugins/devkit/src/module/PluginModuleBuilder.java
index 96aa28a36f1d..431c78c74371 100644
--- a/plugins/devkit/src/module/PluginModuleBuilder.java
+++ b/plugins/devkit/src/module/PluginModuleBuilder.java
@@ -6,29 +6,14 @@ package org.jetbrains.idea.devkit.module;
import com.intellij.ide.util.projectWizard.JavaModuleBuilder;
import com.intellij.openapi.module.ModuleType;
-import com.intellij.openapi.roots.ModifiableRootModel;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.options.ConfigurationException;
-import org.jetbrains.idea.devkit.sandbox.Sandbox;
-import org.jetbrains.idea.devkit.sandbox.SandboxManager;
+
public class PluginModuleBuilder extends JavaModuleBuilder{
- private Sandbox mySandbox;
+
public ModuleType getModuleType() {
return PluginModuleType.getInstance();
}
- public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
- super.setupRootModel(rootModel);
- ModuleSandboxManager.getInstance(rootModel.getModule()).setSandbox(getSandbox(), rootModel);
- }
- public void setSandbox(Sandbox sandbox) {
- mySandbox = sandbox;
- }
-
- public Sandbox getSandbox() {
- return mySandbox;
- }
}
diff --git a/plugins/devkit/src/module/PluginModuleEditorsProvider.java b/plugins/devkit/src/module/PluginModuleEditorsProvider.java
index a840f4736a6e..1a0a339143a6 100644
--- a/plugins/devkit/src/module/PluginModuleEditorsProvider.java
+++ b/plugins/devkit/src/module/PluginModuleEditorsProvider.java
@@ -11,6 +11,9 @@ import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
+import com.intellij.j2ee.make.ModuleBuildProperties;
+import org.jetbrains.idea.devkit.build.PluginModuleBuildConfEditor;
+import org.jetbrains.idea.devkit.build.PluginModuleBuildProperties;
public class PluginModuleEditorsProvider implements ModuleComponent, ModuleConfigurationEditorProvider{
public String getComponentName() {
@@ -28,7 +31,7 @@ public class PluginModuleEditorsProvider implements ModuleComponent, ModuleConfi
editorFactory.createDependenciesEditor(state),
editorFactory.createOrderEntriesEditor(state),
editorFactory.createJavadocEditor(state),
- new PluginModuleConfEditor(state.getProject(), module, state.getModulesProvider(), rootModel)
+ new PluginModuleBuildConfEditor((PluginModuleBuildProperties)ModuleBuildProperties.getInstance(module), state)
};
}
diff --git a/plugins/devkit/src/module/PluginModuleType.java b/plugins/devkit/src/module/PluginModuleType.java
index 8abaafa9bfad..6f3536cd1782 100644
--- a/plugins/devkit/src/module/PluginModuleType.java
+++ b/plugins/devkit/src/module/PluginModuleType.java
@@ -64,8 +64,7 @@ public class PluginModuleType extends ModuleType {
return new ModuleWizardStep[] {
nameAndLocationStep,
stepFactory.createSourcePathsStep(nameAndLocationStep, pluginModuleBuilder, ADD_PLUGIN_MODULE_ICON, null),
- new PluginModuleTypeStep(wizardContext, pluginModuleBuilder, ADD_PLUGIN_MODULE_ICON, null),
- stepFactory.createOutputPathPathsStep(nameAndLocationStep, pluginModuleBuilder, ADD_PLUGIN_MODULE_ICON, null)
+ stepFactory.createOutputPathPathsStep(nameAndLocationStep, pluginModuleBuilder, ADD_PLUGIN_MODULE_ICON, null)
};
}
diff --git a/plugins/devkit/src/projectRoots/IdeaJdk.java b/plugins/devkit/src/projectRoots/IdeaJdk.java
new file mode 100644
index 000000000000..e3e85584e4af
--- /dev/null
+++ b/plugins/devkit/src/projectRoots/IdeaJdk.java
@@ -0,0 +1,257 @@
+package org.jetbrains.idea.devkit.projectRoots;
+
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.components.ApplicationComponent;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.projectRoots.*;
+import com.intellij.openapi.util.InvalidDataException;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.vfs.JarFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jdom.Element;
+
+import javax.swing.*;
+import java.io.*;
+import java.util.ArrayList;
+
+/**
+ * User: anna
+ * Date: Nov 22, 2004
+ */
+public class IdeaJdk extends SdkType implements ApplicationComponent {
+ public static final Icon ADD_SDK = IconLoader.getIcon("/add_sdk.png");
+ public static final Icon SDK_OPEN = IconLoader.getIcon("/sdk_open.png");
+ public static final Icon SDK_CLOSED = IconLoader.getIcon("/sdk_closed.png");
+
+ private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.devkit");
+ private static final String VM_EXE_NAME = "java";
+ public IdeaJdk() {
+ super("IDEA JDK");
+ }
+
+ public Icon getIcon() {
+ return SDK_CLOSED;
+ }
+
+ public Icon getIconForExpandedTreeNode() {
+ return SDK_OPEN;
+ }
+
+ public Icon getIconForAddAction() {
+ return ADD_SDK;
+ }
+
+ public boolean isValidSdkHome(String path) {
+ if (isFromIDEAProject(path)){
+ return true;
+ }
+ File home = new File(path);
+ if (!home.exists()) {
+ return false;
+ }
+ if (getBuildNumber(path) == null || !new File(new File(home, "lib"), "openapi.jar").exists()) {
+ return false;
+ }
+ return true;
+ }
+
+ public static boolean isFromIDEAProject(String path) {
+ File home = new File(path);
+ File[] openapiDir = home.listFiles(new FileFilter() {
+ public boolean accept(File pathname) {
+ if (pathname.getName().equals("openapi") && pathname.isDirectory()) return true; //todo
+ return false;
+ }
+ });
+ if (openapiDir == null || openapiDir.length == 0) {
+ return false;
+ }
+ return true;
+ }
+
+ public final String getVersionString(final String sdkHome) {
+ return "1.3"; //todo from ProjectJdkUtil
+ }
+
+ public String suggestSdkName(String currentSdkName, String sdkHome) {
+ return "IDEA " + (getBuildNumber(sdkHome) != null ? getBuildNumber(sdkHome) : "");
+ }
+
+ private String getBuildNumber(String ideaHome) {
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(ideaHome + "/build.txt"));
+ return reader.readLine().trim();
+ }
+ catch (IOException e) {
+ }
+
+ return null;
+ }
+
+ private VirtualFile[] getIdeaLibrary(String home) {
+ ArrayList result = new ArrayList();
+ JarFileSystem jfs = JarFileSystem.getInstance();
+ File lib = new File(home + "/lib");
+ File[] jars = lib.listFiles();
+ if (jars != null) {
+ for (int i = 0; i < jars.length; i++) {
+ File jar = jars[i];
+ String name = jar.getName();
+ if (jar.isFile() && !name.equals("idea.jar") && (name.endsWith(".jar") || name.endsWith(".zip"))) {
+ result.add(jfs.findFileByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR));
+ }
+
+ }
+ }
+ return result.toArray(new VirtualFile[result.size()]);
+ }
+
+
+ public void setupSdkPaths(Sdk sdk) {
+ final SdkModificator sdkModificator = sdk.getSdkModificator();
+ if (!isFromIDEAProject(sdk.getHomePath())) {
+ final VirtualFile[] ideaLib = getIdeaLibrary(sdk.getHomePath());
+ if (ideaLib != null) {
+ for (int i = 0; i < ideaLib.length; i++) {
+ sdkModificator.addRoot(ideaLib[i], ProjectRootType.CLASS);
+ }
+ }
+ }
+ addClasses(new File(new File(sdk.getHomePath()), "jre"), sdkModificator, JarFileSystem.getInstance());
+ sdkModificator.commitChanges();
+ }
+
+ private static void addClasses(File file, SdkModificator sdkModificator, JarFileSystem jarFileSystem) {
+ VirtualFile[] classes = findClasses(file, jarFileSystem);
+ for (int i = 0; i < classes.length; i++) {
+ VirtualFile virtualFile = classes[i];
+ sdkModificator.addRoot(virtualFile, ProjectRootType.CLASS);
+ }
+ }
+
+ private static VirtualFile[] findClasses(File file, JarFileSystem jarFileSystem) {
+ FileFilter jarFileFilter = new FileFilter() {
+ public boolean accept(File f) {
+ if (f.isDirectory()) return false;
+ if (f.getName().endsWith(".jar")) return true;
+ return false;
+ }
+ };
+
+ File[] jarDirs;
+ if (SystemInfo.isMac && !ApplicationManager.getApplication().isUnitTestMode()) {
+ File libFile = new File(file, "lib");
+ File classesFile = new File(file, "../Classes");
+ File libExtFile = new File(libFile, "ext");
+ jarDirs = new File[]{libFile, classesFile, libExtFile};
+ }
+ else {
+ File jreLibFile = new File(file, "lib");
+ File jreLibExtFile = new File(jreLibFile, "ext");
+ jarDirs = new File[]{jreLibFile, jreLibExtFile};
+ }
+
+ ArrayList childrenList = new ArrayList();
+ for (int i = 0; i < jarDirs.length; i++) {
+ File jarDir = jarDirs[i];
+ if ((jarDir != null) && jarDir.isDirectory()) {
+ File[] files = jarDir.listFiles(jarFileFilter);
+ for (int j = 0; j < files.length; j++) {
+ childrenList.add(files[j]);
+ }
+ }
+ }
+
+ ArrayList result = new ArrayList();
+ for (int i = 0; i < childrenList.size(); i++) {
+ File child = (File)childrenList.get(i);
+ String path = child.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
+ // todo ((JarFileSystemEx)jarFileSystem).setNoCopyJarForPath(path);
+ VirtualFile vFile = jarFileSystem.findFileByPath(path);
+ if (vFile != null) {
+ result.add(vFile);
+ }
+ }
+
+ File classesZipFile = new File(new File(file, "lib"), "classes.zip");
+ if ((!classesZipFile.isDirectory()) && classesZipFile.exists()) {
+ String path = classesZipFile.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
+ //todo ((JarFileSystemEx)jarFileSystem).setNoCopyJarForPath(path);
+ VirtualFile vFile = jarFileSystem.findFileByPath(path);
+ if (vFile != null) {
+ result.add(vFile);
+ }
+ }
+
+ return (VirtualFile[])result.toArray(new VirtualFile[result.size()]);
+ }
+
+ public AdditionalDataConfigurable createAdditionalDataConfigurable(SdkModel sdkModel) {
+ return new IdeaJdkConfigurable();
+ }
+
+ public String getBinPath(Sdk sdk) {
+ return getConvertedHomePath(sdk) + "jre" + File.separator + "bin";
+ }
+
+ public String getToolsPath(Sdk sdk) {
+ final String versionString = sdk.getVersionString();
+ final boolean isJdk1_x = versionString.indexOf("1.0") > -1 || versionString.indexOf("1.1") > -1; //todo check
+ return getConvertedHomePath(sdk) + "jre" + File.separator + "lib" + File.separator + (isJdk1_x ? "classes.zip" : "tools.jar");
+ }
+
+ public String getVMExecutablePath(Sdk sdk) {
+ if ("64".equals(System.getProperty("sun.arch.data.model"))) {
+ return getBinPath(sdk) + File.separator + System.getProperty("os.arch") + File.separator + VM_EXE_NAME;
+ }
+ return getBinPath(sdk) + File.separator + VM_EXE_NAME;
+ }
+
+ public String getRtLibraryPath(Sdk sdk) {
+ return getConvertedHomePath(sdk) + "jre" + File.separator + "lib" + File.separator + "rt.jar";
+ }
+
+ private String getConvertedHomePath(Sdk sdk) {
+ String path = sdk.getHomePath().replace('/', File.separatorChar);
+ if (!path.endsWith(File.separator)) {
+ path = path + File.separator;
+ }
+ return path;
+ }
+
+ public void saveAdditionalData(SdkAdditionalData additionalData, Element additional) {
+ if (additionalData instanceof Sandbox) {
+ try {
+ ((Sandbox)additionalData).writeExternal(additional);
+ }
+ catch (WriteExternalException e) {
+ LOG.error(e);
+ }
+ }
+ }
+
+ public SdkAdditionalData loadAdditionalData(Element additional) {
+ Sandbox sandbox = new Sandbox();
+ try {
+ sandbox.readExternal(additional);
+ }
+ catch (InvalidDataException e) {
+ LOG.error(e);
+ }
+ return sandbox;
+ }
+
+ public String getPresentableName() {
+ return "IDEA Jdk";
+ }
+
+ public String getComponentName() {
+ return getName();
+ }
+
+ public void initComponent() {}
+
+ public void disposeComponent() {}
+}
diff --git a/plugins/devkit/src/projectRoots/IdeaJdkConfigurable.java b/plugins/devkit/src/projectRoots/IdeaJdkConfigurable.java
new file mode 100644
index 000000000000..300f067047a2
--- /dev/null
+++ b/plugins/devkit/src/projectRoots/IdeaJdkConfigurable.java
@@ -0,0 +1,76 @@
+package org.jetbrains.idea.devkit.projectRoots;
+
+import com.intellij.openapi.projectRoots.AdditionalDataConfigurable;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.SdkModificator;
+import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.fileChooser.FileChooserDescriptor;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+/**
+ * User: anna
+ * Date: Nov 22, 2004
+ */
+public class IdeaJdkConfigurable implements AdditionalDataConfigurable{
+ private JLabel mySandboxHomeLabel = new JLabel("Sandbox Home:"); //todo best name
+ private TextFieldWithBrowseButton mySandboxHome = new TextFieldWithBrowseButton();
+
+ private Sdk myIdeaJdk;
+
+ private boolean myModified = false;
+
+ public void setSdk(Sdk sdk) {
+ myIdeaJdk = sdk;
+ }
+
+ public JComponent createComponent() {
+ JPanel wholePanel = new JPanel(new BorderLayout());
+ wholePanel.add(mySandboxHomeLabel, BorderLayout.WEST);
+ wholePanel.add(mySandboxHome, BorderLayout.CENTER);
+ mySandboxHome.addBrowseFolderListener("SandBox Home", "Browse folder to put config, system and plugins for target IDEA", null, new FileChooserDescriptor(false, true, false, false, false, false));
+ mySandboxHome.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ myModified = true;
+ }
+ });
+ mySandboxHome.setText("");
+ JPanel doNotExpandPanel = new JPanel(new BorderLayout());
+ doNotExpandPanel.add(wholePanel, BorderLayout.NORTH);
+ return doNotExpandPanel;
+ }
+
+ public boolean isModified() {
+ return myModified;
+ }
+
+ public void apply() throws ConfigurationException {
+ if (mySandboxHome.getText() == null || mySandboxHome.getText().length() == 0){
+ throw new ConfigurationException("Please, configure the sandbox.");
+ }
+ Sandbox sandbox = new Sandbox(mySandboxHome.getText());
+ final SdkModificator modificator = myIdeaJdk.getSdkModificator();
+ modificator.setSdkAdditionalData(sandbox);
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ public void run() {
+ modificator.commitChanges();
+ }
+ });
+ myModified = false;
+ }
+
+ public void reset() {
+ if (myIdeaJdk != null && myIdeaJdk.getSdkAdditionalData() instanceof Sandbox){
+ mySandboxHome.setText(((Sandbox)myIdeaJdk.getSdkAdditionalData()).getSandboxHome());
+ }
+ myModified = false;
+ }
+
+ public void disposeUIResources() {
+ }
+}
diff --git a/plugins/devkit/src/projectRoots/Sandbox.java b/plugins/devkit/src/projectRoots/Sandbox.java
new file mode 100644
index 000000000000..97b0958decf3
--- /dev/null
+++ b/plugins/devkit/src/projectRoots/Sandbox.java
@@ -0,0 +1,40 @@
+package org.jetbrains.idea.devkit.projectRoots;
+
+import com.intellij.openapi.projectRoots.SdkAdditionalData;
+import com.intellij.openapi.util.JDOMExternalizable;
+import com.intellij.openapi.util.InvalidDataException;
+import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.DefaultJDOMExternalizer;
+import org.jdom.Element;
+
+/**
+ * User: anna
+ * Date: Nov 22, 2004
+ */
+public class Sandbox implements SdkAdditionalData, JDOMExternalizable{
+ public String mySandboxHome;
+
+ public Sandbox(String sandboxHome) {
+ mySandboxHome = sandboxHome;
+ }
+
+ //readExternal()
+ public Sandbox() {
+ }
+
+ public String getSandboxHome() {
+ return mySandboxHome;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return new Sandbox(mySandboxHome);
+ }
+
+ public void readExternal(Element element) throws InvalidDataException {
+ DefaultJDOMExternalizer.readExternal(this, element);
+ }
+
+ public void writeExternal(Element element) throws WriteExternalException {
+ DefaultJDOMExternalizer.writeExternal(this, element);
+ }
+}
diff --git a/plugins/devkit/src/run/PluginRunConfiguration.java b/plugins/devkit/src/run/PluginRunConfiguration.java
index 96c76c5da476..ab9c26c685a7 100644
--- a/plugins/devkit/src/run/PluginRunConfiguration.java
+++ b/plugins/devkit/src/run/PluginRunConfiguration.java
@@ -44,46 +44,26 @@ import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdk;
import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.util.InvalidDataException;
-import com.intellij.openapi.util.JDOMExternalizable;
-import com.intellij.openapi.util.SystemInfo;
-import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.*;
+import com.intellij.openapi.application.ApplicationManager;
import org.jdom.Element;
import org.jetbrains.idea.devkit.module.PluginModuleType;
-import org.jetbrains.idea.devkit.sandbox.Sandbox;
-import org.jetbrains.idea.devkit.sandbox.SandboxManager;
+import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
+import org.jetbrains.idea.devkit.projectRoots.Sandbox;
import java.util.ArrayList;
import java.util.List;
+import java.io.File;
public class PluginRunConfiguration extends RunConfigurationBase {
- private List myModuleNames = new ArrayList();
- private String mySandboxName = "";
-
- private String getSandboxPath() {
- return getSandbox().getSandboxHome();
- }
-
- private String getBasePath() {
- return getSandbox().getIdeaHome();
- }
-
- public Sandbox getSandbox() {
- return SandboxManager.getInstance().findByName(mySandboxName);
- }
-
- public void setSandbox(Sandbox box) {
- mySandboxName = box == null ? "" : box.getName();
- }
-
- public static final String INTERNAL_BUILD_MARK = "__BUILD_NUMBER__";
+ private Module myModule;
public PluginRunConfiguration(final Project project, final ConfigurationFactory factory, final String name) {
super(project, factory, name);
}
public SettingsEditor extends RunConfiguration> getConfigurationEditor() {
- return new PluginRunConfigurationEditor();
+ return new PluginRunConfigurationEditor(this);
}
public JDOMExternalizable createRunnerSettings(ConfigurationInfoProvider provider) {
@@ -100,46 +80,38 @@ public class PluginRunConfiguration extends RunConfigurationBase {
ConfigurationPerRunnerSettings configurationSettings) throws ExecutionException {
final JavaCommandLineState state = new JavaCommandLineState(runnerSettings, configurationSettings) {
protected JavaParameters createJavaParameters() throws ExecutionException {
- if (getSandbox() == null){
- throw new CantRunException("No sandbox specified");
+ final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
+ final ProjectJdk jdk = rootManager.getJdk();
+ if (jdk == null) {
+ throw CantRunException.noJdkForModule(myModule);
}
-
- Module[] modules = getModules();
- if (modules.length == 0) {
- throw new CantRunException("No plugin modules selected");
+ if (!(jdk.getSdkType() instanceof IdeaJdk)){
+ throw new ExecutionException("Wrong jdk type for plugin module");
}
-
final JavaParameters params = new JavaParameters();
ParametersList vm = params.getVMParametersList();
- String libPath = getBasePath() + "/lib";
- vm.add("-Xbootclasspath/p:" + libPath + "/boot.jar");
+ String libPath = jdk.getHomePath() + File.separator + "lib";
+ vm.add("-Xbootclasspath/p:" + libPath + File.separator + "boot.jar");
- vm.defineProperty("idea.config.path", getSandboxPath() + "/config");
- vm.defineProperty("idea.system.path", getSandboxPath() + "/system");
- vm.defineProperty("idea.plugins.path", getSandboxPath() + "/plugins");
+ final String sandboxHome = ((Sandbox)jdk.getSdkAdditionalData()).getSandboxHome();
+ vm.defineProperty("idea.config.path", sandboxHome + File.separator + "config");
+ vm.defineProperty("idea.system.path", sandboxHome + File.separator + "system");
+ vm.defineProperty("idea.plugins.path", sandboxHome + File.separator + "plugins");
if (SystemInfo.isMac) {
vm.defineProperty("idea.smooth.progress", "false");
vm.defineProperty("apple.laf.useScreenMenuBar", "true");
}
- params.setWorkingDirectory(getBasePath() + "/bin/");
+ params.setWorkingDirectory(jdk.getHomePath() + File.separator + "bin" + File.separator);
-
-
- //TODO: Should run against same JRE IDEA runs against, right?
- final ModuleRootManager rootManager = ModuleRootManager.getInstance(modules[0]);
- final ProjectJdk jdk = rootManager.getJdk();
- if (jdk == null) {
- throw CantRunException.noJdkForModule(modules[0]);
- }
params.setJdk(jdk);
- params.getClassPath().addFirst(libPath + "/log4j.jar");
- params.getClassPath().addFirst(libPath + "/openapi.jar");
- params.getClassPath().addFirst(libPath + "/idea.jar");
+ params.getClassPath().addFirst(libPath + File.separator + "log4j.jar");
+ params.getClassPath().addFirst(libPath + File.separator + "openapi.jar");
+ params.getClassPath().addFirst(libPath + File.separator + "idea.jar");
params.setMainClass("com.intellij.idea.Main");
@@ -148,52 +120,20 @@ public class PluginRunConfiguration extends RunConfigurationBase {
};
state.setConsoleBuilder(TextConsoleBuidlerFactory.getInstance().createBuilder(getProject()));
- state.setModulesToCompile(getModules());
+ state.setModulesToCompile(getModules()); //todo
return state;
}
public void checkConfiguration() throws RuntimeConfigurationException {
- if (getSandbox() == null){
- throw new RuntimeConfigurationException("No sandbox specified");
- }
- /*
- final Module module = getModule();
- if (module != null) {
- if (module.getModuleType() != PluginModuleType.getInstance()) {
- throw new RuntimeConfigurationError("Module " + module.getName() + " is of wrong type. Should be 'Plugin Module'.");
- }
-
- if (ModuleRootManager.getInstance(module).getJdk() == null) {
- throw new RuntimeConfigurationWarning("No JDK specified for module \"" + module.getName() + "\"");
- }
- else {
- return;
- }
- }
- else {
- if (MODULE_NAME == null || MODULE_NAME.trim().length() == 0) {
- throw new RuntimeConfigurationError("Module not specified");
- }
- else {
- throw new RuntimeConfigurationError("Module \"" + MODULE_NAME + "\" doesn't exist in project");
- }
- }
- */
}
- public void setModules(Module[] modules) {
- myModuleNames.clear();
- for (int i = 0; i < modules.length; i++) {
- myModuleNames.add(modules[i].getName());
- }
- }
public Module[] getModules() {
List modules = new ArrayList();
Module[] allModules = ModuleManager.getInstance(getProject()).getModules();
for (int i = 0; i < allModules.length; i++) {
Module module = allModules[i];
- if (module.getModuleType() == PluginModuleType.getInstance() && myModuleNames.contains(module.getName())) {
+ if (module.getModuleType() == PluginModuleType.getInstance()) {
modules.add(module);
}
}
@@ -201,23 +141,27 @@ public class PluginRunConfiguration extends RunConfigurationBase {
}
public void readExternal(Element element) throws InvalidDataException {
- Element sandbox = element.getChild("sandbox");
- mySandboxName = sandbox == null ? "" : sandbox.getAttributeValue("name");
- List children = element.getChildren("module");
- for (int i = 0; i < children.size(); i++) {
- Element moduleElement = (Element)children.get(i);
- myModuleNames.add(moduleElement.getAttributeValue("name"));
+ Element module = element.getChild("module");
+ if (module != null){
+ myModule = ModuleManager.getInstance(getProject()).findModuleByName(module.getAttributeValue("name"));
}
}
public void writeExternal(Element element) throws WriteExternalException {
- Element sandbox = new Element("sandbox");
- sandbox.setAttribute("name", mySandboxName);
- element.addContent(sandbox);
- for (int i = 0; i < myModuleNames.size(); i++) {
- Element moduleElement = new Element("module");
- moduleElement.setAttribute("name", myModuleNames.get(i));
- element.addContent(moduleElement);
- }
+ Element moduleElement = new Element("module");
+ moduleElement.setAttribute("name", ApplicationManager.getApplication().runReadAction(new Computable() {
+ public String compute() {
+ return myModule != null ? myModule.getName() : "";
+ }
+ }));
+ element.addContent(moduleElement);
+ }
+
+ public Module getModule() {
+ return myModule;
+ }
+
+ public void setModule(Module module) {
+ myModule = module;
}
}
\ No newline at end of file
diff --git a/plugins/devkit/src/run/PluginRunConfigurationEditor.java b/plugins/devkit/src/run/PluginRunConfigurationEditor.java
index 34d77ce50a7c..b736812e36d4 100644
--- a/plugins/devkit/src/run/PluginRunConfigurationEditor.java
+++ b/plugins/devkit/src/run/PluginRunConfigurationEditor.java
@@ -31,143 +31,70 @@
*/
package org.jetbrains.idea.devkit.run;
-import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
-import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
-import com.intellij.ui.ComboboxWithBrowseButton;
-import org.jetbrains.idea.devkit.module.PluginModuleType;
-import org.jetbrains.idea.devkit.sandbox.Sandbox;
-import org.jetbrains.idea.devkit.sandbox.SandboxConfigurable;
-import org.jetbrains.idea.devkit.sandbox.SandboxManager;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
+
import javax.swing.*;
import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
public class PluginRunConfigurationEditor extends SettingsEditor {
- private EditorPanel myEditor;
- private Project myProject;
+
+ private DefaultComboBoxModel myModulesModel = new DefaultComboBoxModel();
+ private JComboBox myModules = new JComboBox(myModulesModel);
+ private JLabel myModuleLabel = new JLabel("Choose classpath and jdk from module:");
+
+
+
+ private PluginRunConfiguration myPRC;
+
+ public PluginRunConfigurationEditor(PluginRunConfiguration prc) {
+ myPRC = prc;
+ }
public void resetEditorFrom(PluginRunConfiguration prc) {
- myProject = prc.getProject();
- Sandbox sandbox = prc.getSandbox();
- myEditor.setSelectedBox(sandbox);
- updateModules(sandbox);
- myEditor.setModules(prc.getModules());
+ myModules.setSelectedItem(prc.getModule());
}
- private void updateModules(Sandbox sandbox) {
- if (myProject != null && sandbox != null) {
- myEditor.setModulesList(sandbox.getModules(myProject));
- }
- else {
- myEditor.setModulesList(new Module[0]);
- }
- }
public void applyEditorTo(PluginRunConfiguration prc) throws ConfigurationException {
- prc.setSandbox(myEditor.getSelectedBox());
- prc.setModules(myEditor.getModules());
+ if (myModules.getSelectedItem() == null){
+ throw new ConfigurationException("No module selected.");
+ }
+ myPRC.setModule(((Module)myModules.getSelectedItem()));
}
public JComponent createEditor() {
- myEditor = new EditorPanel();
- return myEditor.getComponent();
+ myModulesModel = new DefaultComboBoxModel(myPRC.getModules());
+ myModules.setModel(myModulesModel);
+ myModules.setRenderer(new DefaultListCellRenderer() {
+ public Component getListCellRendererComponent(JList list, final Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (value != null) {
+ setText(ApplicationManager.getApplication().runReadAction(new Computable() {
+ public String compute() {
+ return ((Module)value).getName();
+ }
+ }));
+ setIcon(((Module)value).getModuleType().getNodeIcon(true));
+ }
+ return this;
+ }
+ });
+ JPanel wholePanel = new JPanel(new GridBagLayout());
+ wholePanel.add(myModuleLabel, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0));
+ wholePanel.add(myModules, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0));
+ return wholePanel;
}
- private class EditorPanel {
- private JPanel myWholePanel;
- private ComboboxWithBrowseButton mySandboxCombo;
- private JList myModules;
- public EditorPanel() {
- mySandboxCombo.getComboBox().setRenderer(new DefaultListCellRenderer() {
- public Component getListCellRendererComponent(JList jList, Object o, int i, boolean b, boolean b1) {
- super.getListCellRendererComponent(jList, o, i, b, b1);
- if (o != null) {
- setText(((Sandbox)o).getName());
- }
- return this;
- }
- });
-
- mySandboxCombo.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- Sandbox selected = getSelectedBox();
- ShowSettingsUtil.getInstance().editConfigurable(myWholePanel, SandboxConfigurable.getInstance());
- mySandboxCombo.getComboBox().setModel(new DefaultComboBoxModel(SandboxManager.getInstance().getRegisteredSandboxes()));
- setSelectedBox(selected);
- }
- });
-
- myModules.setCellRenderer(new DefaultListCellRenderer() {
- public Component getListCellRendererComponent(JList jList, Object o, int i, boolean b, boolean b1) {
- super.getListCellRendererComponent(jList, o, i, b, b1);
- if (o != null) {
- Module module = (Module)o;
- setText(module.getName());
- setIcon(PluginModuleType.getInstance().getNodeIcon(false));
- }
- return this;
- }
- });
-
-
- mySandboxCombo.getComboBox().setModel(new DefaultComboBoxModel(SandboxManager.getInstance().getRegisteredSandboxes()));
- mySandboxCombo.getComboBox().addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- updateModules((Sandbox)mySandboxCombo.getComboBox().getSelectedItem());
- }
- });
- }
-
- public void setSelectedBox(Sandbox box) {
- mySandboxCombo.getComboBox().setSelectedItem(box);
- }
-
- public Sandbox getSelectedBox() {
- return (Sandbox)mySandboxCombo.getComboBox().getSelectedItem();
- }
-
- public JComponent getComponent() {
- return myWholePanel;
- }
-
- public Module[] getModules() {
- Object[] values = myModules.getSelectedValues();
- if (values == null) return new Module[0];
- Module[] modules = new Module[values.length];
- for (int i = 0; i < modules.length; i++) {
- modules[i] = (Module)values[i];
- }
- return modules;
- }
-
- public void setModules(Module[] modules) {
- ArrayList allModules = new ArrayList();
- ListModel model = myModules.getModel();
- for (int i = 0; i < model.getSize(); i++) {
- allModules.add((Module)model.getElementAt(i));
- }
-
- for (int i = 0; i < modules.length; i++) {
- int idx = allModules.indexOf(modules[i]);
- myModules.getSelectionModel().addSelectionInterval(idx, idx);
- }
- }
-
- public void setModulesList(Module[] modules) {
- DefaultListModel model = new DefaultListModel();
- for (int i = 0; i < modules.length; i++) {
- model.addElement(modules[i]);
- }
- myModules.setModel(model);
- }
- }
public void disposeEditor() {
}