Skip to content

Commit

Permalink
(GH-49) custom arguments in run configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Jan 11, 2021
1 parent 0a544ac commit a7c6a13
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ The full documentation of the latest release of Cake for Rider can be found at [

Files with the extension `.cake` have the Cake logo as file icons now.


#### Custom arguments in run configurations

A new setting has been added to run configuration: *Arguments*. It can be used to supply custom arguments when running that configuration.

![arguments](./images/runConfiguration-editor.png)

## Contribute

Check out the [Cake contribution guidelines](https://cakebuild.net/docs/contributing/contribution-guidelines)
Expand Down
Binary file added images/runConfiguration-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions rider/src/main/java/net/cakebuild/run/CakeConfigurationEditor.form
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.cakebuild.run.CakeConfigurationEditor">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand Down Expand Up @@ -56,9 +56,25 @@
</component>
<vspacer id="c4db2">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="66083" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Arguments"/>
</properties>
</component>
<component id="c829" class="javax.swing.JTextField" binding="argumentsField" custom-create="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.ui.components.fields.ExpandableTextField;
import net.cakebuild.shared.ui.VerbosityComboBox;
import org.jetbrains.annotations.NotNull;

Expand All @@ -15,6 +16,7 @@ public class CakeConfigurationEditor extends SettingsEditor<CakeConfiguration> {
private JTextField scriptPathField;
private JTextField taskField;
private JComboBox<String> verbosityBox;
private JTextField argumentsField;

@Override
protected void resetEditorFrom(@NotNull CakeConfiguration configuration) {
Expand All @@ -25,18 +27,20 @@ protected void resetEditorFrom(@NotNull CakeConfiguration configuration) {
scriptPathField.setText(state.getScriptPath());
taskField.setText(state.getTaskName());
((VerbosityComboBox)verbosityBox).setVerbosity(state.getVerbosity());
argumentsField.setText((state.getAdditionalArguments()));
}

@Override
protected void applyEditorTo(@NotNull CakeConfiguration configuration) throws ConfigurationException {
CakeConfigurationOptions state = configuration.getState();
if(state == null) {
throw new ConfigurationException("state is null: Can not set state.");
throw new ConfigurationException("State is null: can not set state.");
}

state.setScriptPath(scriptPathField.getText());
state.setTaskName(taskField.getText());
state.setVerbosity(((VerbosityComboBox)verbosityBox).getVerbosity());
state.setAdditionalArguments(argumentsField.getText());
}

@NotNull
Expand All @@ -47,5 +51,6 @@ protected JComponent createEditor() {

private void createUIComponents() {
verbosityBox = new VerbosityComboBox();
argumentsField = new ExpandableTextField();
}
}
14 changes: 9 additions & 5 deletions rider/src/main/kotlin/net/cakebuild/run/CakeConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.util.execution.ParametersListUtil
import net.cakebuild.settings.CakeSettings
import java.nio.file.FileSystems

Expand Down Expand Up @@ -49,15 +50,18 @@ class CakeConfiguration(project: Project, factory: CakeConfigurationFactory) :
val scriptPath = fileSystems
.getPath(project.basePath!!)
.resolve(fileSystems.getPath(options.scriptPath!!))
val arguments = mutableListOf<String>()
arguments.add(scriptPath.toString())
arguments.add("--target=${options.taskName}")
arguments.add("--verbosity=${options.verbosity}")
if (!options.additionalArguments.isNullOrEmpty()) {
arguments.addAll(ParametersListUtil.parseToArray(options.additionalArguments!!))
}
val commandLine = GeneralCommandLine()
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
.withWorkDirectory(scriptPath.parent.toString())
.withExePath(exe)
.withParameters(
scriptPath.toString(),
"--target=${options.taskName}",
"--verbosity=${options.verbosity}"
)
.withParameters(arguments)
val processHandler = ProcessHandlerFactory.getInstance().createColoredProcessHandler(commandLine)
ProcessTerminatedListener.attach(processHandler)
return processHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ class CakeConfigurationOptions : RunConfigurationOptions() {
var verbosity: String?
get() = storedVerbosity.getValue(this)
set(v) { storedVerbosity.setValue(this, v) }

private val storedAdditionalArguments: StoredProperty<String?> =
string("").provideDelegate(this, "additionalArguments")
var additionalArguments: String?
get() = storedAdditionalArguments.getValue(this)
set(v) { storedAdditionalArguments.setValue(this, v) }
}

0 comments on commit a7c6a13

Please sign in to comment.