Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ApplicationConfigurationをお手本にIDEA11風に書き直してみた。

CommonJavaRunConfigurationParametersを介さないとカバレッジ測定が有効にならないみたい。
  • Loading branch information...
commit a41ce60300dfc9054cea800b50846461bf5c7c7a 1 parent 6d5e7db
@masanobuimai authored
View
116 src/com/googlecode/intellimars/winstone/WinstoneConfiguration.java
@@ -1,5 +1,6 @@
package com.googlecode.intellimars.winstone;
+import com.intellij.execution.CommonJavaRunConfigurationParameters;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.JavaRunConfigurationExtensionManager;
@@ -14,18 +15,25 @@
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.options.SettingsEditorGroup;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.io.File;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
import java.util.ResourceBundle;
-public class WinstoneConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule> {
+public class WinstoneConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule> implements CommonJavaRunConfigurationParameters {
@NonNls
private static ResourceBundle ourBundle = ResourceBundle.getBundle("com.googlecode.intellimars.winstone.message");
private static final Logger LOGGER = Logger.getInstance("Winstone");
@@ -46,12 +54,12 @@
public String WINSTONE_PROPERTIES_FILE = "";
public String WINSTONE_JAR = "";
public String COMMONLIB_DIRECTORY = "";
- public String PROGRAM_PARAMETERS = "";
public String VM_PARAMETERS = "";
public String ALTERNATIVE_JRE_PATH = "";
public boolean ALTERNATIVE_JRE_PATH_ENABLED;
public boolean USE_TOOLS_JAR;
- public String TOOLS_JAR;
+ public String TOOLS_JAR = "";
+ public static final String WINSTONE_RUN_CLASS = "winstone.Launcher";
public WinstoneConfiguration(String name, Project project, WinstoneConfigurationType configurationType) {
@@ -59,7 +67,7 @@ public WinstoneConfiguration(String name, Project project, WinstoneConfiguration
}
public Collection<Module> getValidModules() {
- return JavaRunConfigurationModule.getModulesForClass(getProject(), "winstone.Launcher");
+ return JavaRunConfigurationModule.getModulesForClass(getProject(), WINSTONE_RUN_CLASS);
}
protected ModuleBasedConfiguration createInstance() {
@@ -107,4 +115,104 @@ public void writeExternal(Element element) throws WriteExternalException {
writeModule(element);
DefaultJDOMExternalizer.writeExternal(this, element);
}
+
+ @Override
+ public void setVMParameters(String s) {
+ VM_PARAMETERS = s;
+ }
+
+ @Override
+ public String getVMParameters() {
+ return VM_PARAMETERS;
+ }
+
+ @Override
+ public boolean isAlternativeJrePathEnabled() {
+ return ALTERNATIVE_JRE_PATH_ENABLED;
+ }
+
+ @Override
+ public void setAlternativeJrePathEnabled(boolean b) {
+ ALTERNATIVE_JRE_PATH_ENABLED = b;
+ }
+
+ @Override
+ public String getAlternativeJrePath() {
+ return ALTERNATIVE_JRE_PATH;
+ }
+
+ @Override
+ public void setAlternativeJrePath(String s) {
+ ALTERNATIVE_JRE_PATH = s;
+ }
+
+ @Override
+ public String getRunClass() {
+ return WINSTONE_RUN_CLASS;
+ }
+
+ @Override
+ public String getPackage() {
+ return "";
+ }
+
+ @Override
+ public void setProgramParameters(@Nullable String s) {
+ }
+
+ @Override
+ public String getProgramParameters() {
+ StringBuilder sb = new StringBuilder();
+ if (USE_WEB_ROOT) sb.append("--webroot=" + WEBAPP_DIRECTORY + " ");
+ if (USE_WEB_APPS) sb.append("--webappsDir=" + WEBAPP_DIRECTORY + " ");
+ if (!"".equals(CONTEXT_NAME)) sb.append("--prefix=/" + CONTEXT_NAME + " ");
+ if (!"".equals(HTTP_PORT)) sb.append("--httpPort=" + HTTP_PORT + " ");
+ if (!"".equals(AJP13_PORT)) sb.append("--ajp13Port=" + AJP13_PORT + " ");
+ if (USE_JASPER) {
+ sb.append("--useJasper=true");
+ Sdk jdk = getConfigurationModule().getModule() != null ?
+ ModuleRootManager.getInstance(getConfigurationModule().getModule()).getSdk() :
+ ProjectRootManager.getInstance(getProject()).getProjectJdk();
+ String JDK_HOME = ALTERNATIVE_JRE_PATH_ENABLED ? ALTERNATIVE_JRE_PATH : jdk.getHomePath();
+ sb.append("--javaHome=" + JDK_HOME + " ");
+ String TOOLS = USE_TOOLS_JAR ? TOOLS_JAR : JDK_HOME + "/lib/tools.jar";
+ sb.append("--toolsJar=" + TOOLS + " ");
+ }
+ sb.append("--useJNDI=" + USE_JNDI + "");
+ sb.append("--useServletReloading=" + USE_SERVLET_RELOADING + "");
+ sb.append("--directoryListings=" + USE_DIRECTORY_LISTS + "");
+ sb.append("--debug=" + DEBUG_LEVEL + "");
+ if (!"".equals(WINSTONE_PROPERTIES_FILE)) sb.append("--config=" + WINSTONE_PROPERTIES_FILE + " ");
+ if (!"".equals(COMMONLIB_DIRECTORY)) sb.append("--commonLibFolder=" + new File(COMMONLIB_DIRECTORY).getPath() + " ");
+ return sb.toString();
+ }
+
+ @Override
+ public void setWorkingDirectory(@Nullable String s) {
+ WORKING_DIRECTORY = s;
+ }
+
+ @Override
+ public String getWorkingDirectory() {
+ return WORKING_DIRECTORY;
+ }
+
+ @Override
+ public void setEnvs(@NotNull Map<String, String> stringStringMap) {
+ }
+
+ @NotNull
+ @Override
+ public Map<String, String> getEnvs() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public void setPassParentEnvs(boolean b) {
+ }
+
+ @Override
+ public boolean isPassParentEnvs() {
+ return false;
+ }
}
View
84 src/com/googlecode/intellimars/winstone/WinstoneRunnableState.java
@@ -1,16 +1,13 @@
package com.googlecode.intellimars.winstone;
-import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.execution.DefaultExecutionResult;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
import com.intellij.execution.JavaRunConfigurationExtensionManager;
import com.intellij.execution.RunConfigurationExtension;
-import com.intellij.execution.configurations.DebuggingRunnerData;
import com.intellij.execution.configurations.JavaCommandLineState;
import com.intellij.execution.configurations.JavaParameters;
-import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.configurations.RunnerSettings;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.process.OSProcessHandler;
@@ -20,19 +17,14 @@
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.ui.ConsoleView;
+import com.intellij.execution.util.JavaParametersUtil;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Key;
import java.io.File;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
public class WinstoneRunnableState extends JavaCommandLineState {
private static final Logger LOGGER = Logger.getInstance("Winstone");
@@ -83,79 +75,15 @@ protected JavaParameters createJavaParameters() throws ExecutionException {
LOGGER.info("WinstoneRunnableState.createJavaParameters");
JavaParameters javaParameters = new JavaParameters();
- // Winstoneの起動クラスを設定
- javaParameters.setMainClass("winstone.Launcher");
+ String jreHome = config.ALTERNATIVE_JRE_PATH_ENABLED ? config.ALTERNATIVE_JRE_PATH : null;
+ JavaParametersUtil.configureProject(project, javaParameters, JavaParameters.JDK_ONLY, jreHome);
+ JavaParametersUtil.configureConfiguration(javaParameters, config);
+ javaParameters.setMainClass(config.WINSTONE_RUN_CLASS);
javaParameters.getClassPath().add(new File(config.WINSTONE_JAR).getPath());
- Module module = config.getConfigurationModule().getModule();
- Sdk jdk = module != null ?
- ModuleRootManager.getInstance(module).getSdk() :
- ProjectRootManager.getInstance(project).getProjectJdk();
- javaParameters.setJdk(jdk);
-
- // よく考えてみれば,Winstoneがクラスロードするから,Winstone自身にクラスパスを設定してあげる必要はない。
-// JavaParametersUtil.configureProject(project, javaParameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS, null);
-// JavaSdkUtil.addRtJar(javaParameters.getClassPath());
- javaParameters.setWorkingDirectory(config.WORKING_DIRECTORY);
-
- ParametersList params = javaParameters.getProgramParametersList();
- if (config.USE_WEB_ROOT) params.add("--webroot=" + config.WEBAPP_DIRECTORY);
- if (config.USE_WEB_APPS) params.add("--webappsDir=" + config.WEBAPP_DIRECTORY);
- if (!"".equals(config.CONTEXT_NAME)) params.add("--prefix=/" + config.CONTEXT_NAME);
- if (!"".equals(config.HTTP_PORT)) params.add("--httpPort=" + config.HTTP_PORT);
- if (!"".equals(config.AJP13_PORT)) params.add("--ajp13Port=" + config.AJP13_PORT);
- if (config.USE_JASPER) {
- params.add("--useJasper=true");
- String JDK_HOME = jdk.getHomePath();
- params.add("--javaHome=" + JDK_HOME);
- String TOOLS_JAR = config.USE_TOOLS_JAR ? config.TOOLS_JAR : JDK_HOME + "/lib/tools.jar";
- params.add("--toolsJar=" + TOOLS_JAR);
- }
- params.add("--useJNDI=" + config.USE_JNDI);
- params.add("--useServletReloading=" + config.USE_SERVLET_RELOADING);
- params.add("--directoryListings=" + config.USE_DIRECTORY_LISTS);
- params.add("--debug=" + config.DEBUG_LEVEL);
- if (!"".equals(config.WINSTONE_PROPERTIES_FILE)) params.add("--config=" + config.WINSTONE_PROPERTIES_FILE);
- if (!"".equals(config.COMMONLIB_DIRECTORY))
- params.add("--commonLibFolder=" + new File(config.COMMONLIB_DIRECTORY).getPath());
-
-
- if (!"".equals(config.VM_PARAMETERS)) {
- ParametersList vmparams = javaParameters.getVMParametersList();
- //String vm_parameters = config.VM_PARAMETERS;
- // Need to split this string as GeneralCommandLine.appendParams()
- // quotes all params on Windows
- // See the (?=X) definition in the java.util.regex.Pattern javadoc
- vmparams.addAll(config.VM_PARAMETERS.split(" (?=-)", 0));
- }
-
- if (runnerSettings.getData() instanceof DebuggingRunnerData) {
- ParametersList vmparams = javaParameters.getVMParametersList();
- String hostname = "localhost";
- try {
- hostname = InetAddress.getLocalHost().getHostName();
- }
- catch (UnknownHostException ignore) {
- }
- DebuggingRunnerData debuggingRunnerData = (DebuggingRunnerData) runnerSettings.getData();
- String debugPort = debuggingRunnerData.getDebugPort();
- if (debugPort.length() == 0) {
- try {
- debugPort = DebuggerUtils.getInstance().findAvailableDebugAddress(true);
- }
- catch (ExecutionException e) {
- LOGGER.error(e);
- }
- debuggingRunnerData.setDebugPort(debugPort);
- }
- vmparams.add("-Xdebug");
- vmparams.add("-Xrunjdwp:transport=dt_socket,address=" + hostname + ':' + debugPort + ",suspend=y,server=n");
- }
-
// ここで RunConfigurationExtension にまわすことで,Coverageプラグインが有効なら
// カバレッジが取得できるようになる。
- RunConfigurationExtension extensions[] = Extensions.getExtensions(RunConfigurationExtension.EP_NAME);
- for (RunConfigurationExtension extension : extensions) {
+ for (RunConfigurationExtension extension : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
extension.updateJavaParameters(config, javaParameters, getRunnerSettings());
}
Please sign in to comment.
Something went wrong with that request. Please try again.