diff --git a/src/com/goide/runconfig/GoRunConfigurationBase.java b/src/com/goide/runconfig/GoRunConfigurationBase.java index 9702121b31..cbf3afad4a 100644 --- a/src/com/goide/runconfig/GoRunConfigurationBase.java +++ b/src/com/goide/runconfig/GoRunConfigurationBase.java @@ -48,6 +48,7 @@ public abstract class GoRunConfigurationBase myCustomEnvironment = ContainerUtil.newHashMap(); @@ -194,4 +195,14 @@ public String getWorkingDirectory() { public void setWorkingDirectory(@NotNull String workingDirectory) { myWorkingDirectory = workingDirectory; } + + @NotNull + public String getFilePath() { + return myFilePath; + } + + public void setFilePath(@NotNull String filePath) { + myFilePath = filePath; + } + } diff --git a/src/com/goide/runconfig/GoRunConfigurationProducerBase.java b/src/com/goide/runconfig/GoRunConfigurationProducerBase.java index 34edde6f12..fcf259e9ee 100644 --- a/src/com/goide/runconfig/GoRunConfigurationProducerBase.java +++ b/src/com/goide/runconfig/GoRunConfigurationProducerBase.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class GoRunConfigurationProducerBase extends RunConfigurationProducer implements Cloneable { +public class GoRunConfigurationProducerBase extends RunConfigurationProducer implements Cloneable { protected GoRunConfigurationProducerBase(@NotNull ConfigurationType configurationType) { super(configurationType); } diff --git a/src/com/goide/runconfig/GoRunConfigurationWithMain.java b/src/com/goide/runconfig/GoRunConfigurationWithMain.java index bba9aaf9db..5b228a09fa 100644 --- a/src/com/goide/runconfig/GoRunConfigurationWithMain.java +++ b/src/com/goide/runconfig/GoRunConfigurationWithMain.java @@ -38,11 +38,9 @@ public abstract class GoRunConfigurationWithMain extends GoRunConfigurationBase { private static final String FILE_PATH_NAME = "file_path"; - @NotNull private String myFilePath = ""; - public GoRunConfigurationWithMain(String name, GoModuleBasedConfiguration configurationModule, ConfigurationFactory factory) { super(name, configurationModule, factory); - myFilePath = getWorkingDirectory(); + setFilePath(getWorkingDirectory()); } @Override @@ -50,15 +48,15 @@ public void readExternal(@NotNull Element element) throws InvalidDataException { super.readExternal(element); String filePathValue = JDOMExternalizerUtil.getFirstChildValueAttribute(element, FILE_PATH_NAME); if (filePathValue != null) { - myFilePath = filePathValue; + setFilePath(filePathValue); } } @Override public void writeExternal(Element element) throws WriteExternalException { super.writeExternal(element); - if (StringUtil.isNotEmpty(myFilePath)) { - JDOMExternalizerUtil.addElementWithValueAttribute(element, FILE_PATH_NAME, myFilePath); + if (StringUtil.isNotEmpty(getFilePath())) { + JDOMExternalizerUtil.addElementWithValueAttribute(element, FILE_PATH_NAME, getFilePath()); } } @@ -83,12 +81,4 @@ public void checkConfiguration() throws RuntimeConfigurationException { } } - @NotNull - public String getFilePath() { - return myFilePath; - } - - public void setFilePath(@NotNull String filePath) { - myFilePath = filePath; - } } diff --git a/src/com/goide/runconfig/application/GoApplicationConfiguration.java b/src/com/goide/runconfig/application/GoApplicationRunConfiguration.java similarity index 75% rename from src/com/goide/runconfig/application/GoApplicationConfiguration.java rename to src/com/goide/runconfig/application/GoApplicationRunConfiguration.java index 3efdbdfb3d..94ed69c58d 100644 --- a/src/com/goide/runconfig/application/GoApplicationConfiguration.java +++ b/src/com/goide/runconfig/application/GoApplicationRunConfiguration.java @@ -17,8 +17,8 @@ package com.goide.runconfig.application; import com.goide.runconfig.GoModuleBasedConfiguration; -import com.goide.runconfig.GoRunConfigurationWithMain; -import com.goide.runconfig.ui.GoRunConfigurationEditorForm; +import com.goide.runconfig.GoRunConfigurationBase; +import com.goide.runconfig.ui.GoApplicationRunConfigurationEditorForm; import com.intellij.execution.configurations.ConfigurationType; import com.intellij.execution.configurations.ModuleBasedConfiguration; import com.intellij.execution.configurations.RunConfiguration; @@ -28,21 +28,21 @@ import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; -public class GoApplicationConfiguration extends GoRunConfigurationWithMain { - public GoApplicationConfiguration(Project project, String name, @NotNull ConfigurationType configurationType) { +public class GoApplicationRunConfiguration extends GoRunConfigurationBase { + public GoApplicationRunConfiguration(Project project, String name, @NotNull ConfigurationType configurationType) { super(name, new GoModuleBasedConfiguration(project), configurationType.getConfigurationFactories()[0]); } @NotNull @Override protected ModuleBasedConfiguration createInstance() { - return new GoApplicationConfiguration(getProject(), getName(), GoApplicationRunConfigurationType.getInstance()); + return new GoApplicationRunConfiguration(getProject(), getName(), GoApplicationRunConfigurationType.getInstance()); } @NotNull @Override public SettingsEditor getConfigurationEditor() { - return new GoRunConfigurationEditorForm(getProject()); + return new GoApplicationRunConfigurationEditorForm(getProject()); } @NotNull diff --git a/src/com/goide/runconfig/application/GoApplicationRunConfigurationProducer.java b/src/com/goide/runconfig/application/GoApplicationRunConfigurationProducer.java index 3b3857b1be..448efc7604 100644 --- a/src/com/goide/runconfig/application/GoApplicationRunConfigurationProducer.java +++ b/src/com/goide/runconfig/application/GoApplicationRunConfigurationProducer.java @@ -18,7 +18,7 @@ import com.goide.runconfig.GoRunConfigurationProducerBase; -public class GoApplicationRunConfigurationProducer extends GoRunConfigurationProducerBase implements Cloneable { +public class GoApplicationRunConfigurationProducer extends GoRunConfigurationProducerBase implements Cloneable { public GoApplicationRunConfigurationProducer() { super(GoApplicationRunConfigurationType.getInstance()); } diff --git a/src/com/goide/runconfig/application/GoApplicationRunConfigurationType.java b/src/com/goide/runconfig/application/GoApplicationRunConfigurationType.java index 64e13732cf..8528e10a8f 100644 --- a/src/com/goide/runconfig/application/GoApplicationRunConfigurationType.java +++ b/src/com/goide/runconfig/application/GoApplicationRunConfigurationType.java @@ -30,7 +30,7 @@ public GoApplicationRunConfigurationType() { addFactory(new GoConfigurationFactoryBase(this) { @NotNull public RunConfiguration createTemplateConfiguration(Project project) { - return new GoApplicationConfiguration(project, "Go", getInstance()); + return new GoApplicationRunConfiguration(project, "Go", getInstance()); } }); } diff --git a/src/com/goide/runconfig/application/GoApplicationRunningState.java b/src/com/goide/runconfig/application/GoApplicationRunningState.java index 4e84ddbda2..9cd8905090 100644 --- a/src/com/goide/runconfig/application/GoApplicationRunningState.java +++ b/src/com/goide/runconfig/application/GoApplicationRunningState.java @@ -24,17 +24,19 @@ import com.intellij.execution.process.ProcessOutput; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -public class GoApplicationRunningState extends GoRunningState { +public class GoApplicationRunningState extends GoRunningState { private File myTempFile; public GoApplicationRunningState(@NotNull ExecutionEnvironment env, @NotNull Module module, - @NotNull GoApplicationConfiguration configuration) { + @NotNull GoApplicationRunConfiguration configuration) { super(env, module, configuration); } @@ -52,12 +54,13 @@ protected ProcessHandler startProcess() throws ExecutionException { } try { ProcessOutput processOutput = new ProcessOutput(); + VirtualFile[] sourceRoots = ModuleRootManager.getInstance(myModule).getSourceRoots(false); //Eventually to support multiple module dependencies boolean success = GoExecutor.in(myModule) - .addParameters("build", "-o", myTempFile.getAbsolutePath(), myConfiguration.getFilePath()) + .addParameters("build", "-o", myTempFile.getAbsolutePath()) + .withWorkDirectory(sourceRoots[0].getCanonicalPath()) .withProcessOutput(processOutput) .showOutputOnError() .execute(); - if (!success) { throw new ExecutionException("Build failure. `go build` is finished with exit code " + processOutput.getExitCode()); } diff --git a/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.form b/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.form new file mode 100644 index 0000000000..c6fd2c93f6 --- /dev/null +++ b/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.form @@ -0,0 +1,23 @@ + +
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.java b/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.java new file mode 100644 index 0000000000..e9d97b7925 --- /dev/null +++ b/src/com/goide/runconfig/ui/GoApplicationRunConfigurationEditorForm.java @@ -0,0 +1,57 @@ +/* + * Copyright 2013-2014 Sergey Ignatov, Alexander Zolotov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.goide.runconfig.ui; + +import com.goide.runconfig.application.GoApplicationRunConfiguration; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +public class GoApplicationRunConfigurationEditorForm extends SettingsEditor { + private JPanel myComponent; + private GoCommonSettingsPanel myCommonSettingsPanel; + + + public GoApplicationRunConfigurationEditorForm(@NotNull final Project project) { + super(null); + myCommonSettingsPanel.init(project); + } + + @Override + protected void resetEditorFrom(@NotNull GoApplicationRunConfiguration configuration) { + myCommonSettingsPanel.resetEditorFrom(configuration); + } + + @Override + protected void applyEditorTo(@NotNull GoApplicationRunConfiguration configuration) throws ConfigurationException { + myCommonSettingsPanel.applyEditorTo(configuration); + } + + @NotNull + @Override + protected JComponent createEditor() { + return myComponent; + } + + @Override + protected void disposeEditor() { + myComponent.setVisible(false); + } +}