Skip to content

Commit

Permalink
(GH-31) (GH-42) added searchPaths and excludes
Browse files Browse the repository at this point in the history
a new settings page was introduced: "Search paths".
This page contains two settings: The search paths to start
the search for Cake files and excludes for paths that
should not be searched.
Default search paths is ["."], which correlates to the "old"
functionality.
Default exclude is [".*/tools/.*"] to exclude the tools
folder and thereby excluding Cake files that were
added from NuGet packages.
  • Loading branch information
nils-a committed Jan 14, 2021
1 parent 1886074 commit 6fb38b4
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 6 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,25 @@ 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)

#### Search path and excludes

The search path for where Cake files are searched to populate the Cake Tasks Window are now
configurable. Additionally excludes can be defined.

The Paths are relative to the project root and should use "/" as separator between directories.
(e.g.`../build`.) Default is `.`.

Excludes are regular expressions that each path is match against. Paths that match one of the expressions will be excluded.
Default: `.*/tools/.*`.

![Search paths settings](./images/searchPathsSettings.png)

## Contribute

Check out the [Cake contribution guidelines](https://cakebuild.net/docs/contributing/contribution-guidelines)
Expand Down
Binary file added images/searchPathsSettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions rider/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ formatting:
style:
ReturnCount:
max: 10
LoopWithTooManyJumpStatements:
maxJumpCount: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.cakebuild.settings.CakeSearchPathSettingsEditor">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="2" column-count="1" 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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="59657" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f01f4" class="javax.swing.JLabel">
<constraints border-constraint="North"/>
<properties>
<text value="Search paths"/>
</properties>
</component>
<grid id="b465e" binding="searchPathsPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<grid id="adaa6" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="333f8" class="javax.swing.JLabel">
<constraints border-constraint="North"/>
<properties>
<text value="Exclude expressions"/>
</properties>
</component>
<grid id="9dd86" binding="excludesPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.cakebuild.settings;

import net.cakebuild.settings.controls.SimpleAddEditControl;
import net.cakebuild.shared.ui.RegexCellEditor;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.util.Collection;

public class CakeSearchPathSettingsEditor {
private JPanel content;
private JPanel searchPathsPanel;
private JPanel excludesPanel;
private SimpleAddEditControl mySearchPathsPanel;
private SimpleAddEditControl myExcludesPanel;

public JPanel getContent() { return content; }

public void setScriptSearchPaths(@NotNull Collection<String> paths){
mySearchPathsPanel.setData(paths);
}

public Collection<String> getScriptSearchPaths() {
return mySearchPathsPanel.getData();
}

public void setScriptSearchIgnores(@NotNull Collection<String> expressions) {
myExcludesPanel.setData(expressions);
}

public Collection<String> getScriptSearchIgnores() {
return myExcludesPanel.getData();
}

private void createUIComponents() {
mySearchPathsPanel = new SimpleAddEditControl(new String[] { "Path" }, () -> new String[] { "" } );
searchPathsPanel = mySearchPathsPanel.getContent();

myExcludesPanel = new SimpleAddEditControl(new String[] { "Exclude Regex" }, () -> new String[] { "" });
excludesPanel = myExcludesPanel.getContent();
RegexCellEditor regexCellEditor = new RegexCellEditor();
regexCellEditor.setOnValidationError(s -> { myExcludesPanel.setValidationError(s); return null; });
regexCellEditor.setOnValidationSuccess(() -> { myExcludesPanel.setValidationError(null); return null; });
myExcludesPanel.setCellEditor(0, regexCellEditor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.cakebuild.settings.controls.SimpleAddEditControl">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" 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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="eee7b" class="javax.swing.JTable" binding="table">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<grid id="1dc84" layout-manager="GridBagLayout">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="91f3c" class="javax.swing.JButton" binding="addItem">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<icon value="general/add.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<opaque value="true"/>
<preferredSize width="30" height="30"/>
<text value=""/>
</properties>
</component>
<component id="a279" class="javax.swing.JButton" binding="removeItem">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<icon value="general/remove.png"/>
<label value=""/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
</properties>
</component>
</children>
</grid>
<component id="7e676" class="javax.swing.JLabel" binding="errorText">
<constraints>
<grid row="1" 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>
<foreground color="-65536"/>
<text value=""/>
</properties>
</component>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package net.cakebuild.settings.controls;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Supplier;

public class SimpleAddEditControl {
private JTable table;
private JButton addItem;
private JButton removeItem;
private JPanel panel;
private JLabel errorText;
private final DefaultTableModel model;

public SimpleAddEditControl(String[] headers, Supplier<String[]> newItemGenerator){
model = (DefaultTableModel) table.getModel();
for(int i = 0; i< headers.length; i++){
model.addColumn("col"+i);
}
TableColumnModel columnModel = table.getColumnModel();
for(int i = 0; i< headers.length; i++){
columnModel.getColumn(i).setHeaderValue(headers[i]);
}
table.putClientProperty("terminateEditOnFocusLost", true);
table.setCellSelectionEnabled(false);
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
table.getSelectionModel().addListSelectionListener(e -> {
int row = table.getSelectedRow();
removeItem.setEnabled(row >= 0);
});
addItem.addActionListener(e -> {
model.addRow(newItemGenerator.get());
int row = model.getRowCount()-1;
table.editCellAt(row, 0);
table.changeSelection(row, 0, false, false);
TableCellEditor editor = table.getCellEditor(row, 0);
Component textEdit = table.prepareEditor(editor, row, 0);
textEdit.requestFocus();
});
removeItem.setEnabled(false);
removeItem.addActionListener(e -> {
int row = table.getSelectedRow();
if(row < 0) {
return;
}

model.removeRow(row);
});
}

public void setCellEditor(int columnIndex, TableCellEditor cellEditor){
table.getColumnModel().getColumn(columnIndex).setCellEditor(cellEditor);
}

public Collection<String> getData() {
Collection<String> items = new HashSet<>();
int rows = model.getRowCount();
for(int i =0; i < rows; i++) {
String item = (String)model.getValueAt(i, 0);

items.add(item);
}

return items;
}

public void setData(Collection<String> data) {
while (model.getRowCount() > 0){
model.removeRow(0);
}
data.forEach(it -> model.addRow(new Object[]{ it }));
}

public void setValidationError(String error) {
if(error == null) {
errorText.setText("");
return;
}

errorText.setText(error);
}

public JPanel getContent() { return panel; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.cakebuild.settings

import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import javax.swing.JComponent

class CakeSearchPathSettingsConfigurable(private val project: Project) : Configurable {
private val editor = CakeSearchPathSettingsEditor()

override fun createComponent(): JComponent? {
return editor.content
}

override fun getDisplayName(): String {
return "Search Paths"
}

override fun apply() {
val settings = CakeSettings.getInstance(project)
settings.cakeScriptSearchPaths = editor.scriptSearchPaths.toList()
settings.cakeScriptSearchIgnores = editor.scriptSearchIgnores.toList()
}

override fun reset() {
val settings = CakeSettings.getInstance(project)
editor.scriptSearchPaths = settings.cakeScriptSearchPaths.toMutableList()
editor.scriptSearchIgnores = settings.cakeScriptSearchIgnores.toMutableList()
}

override fun isModified(): Boolean {
val settings = CakeSettings.getInstance(project)
return isModified(editor.scriptSearchPaths, settings.cakeScriptSearchPaths) ||
isModified(editor.scriptSearchIgnores, settings.cakeScriptSearchIgnores)
}

private fun isModified(left: Collection<String>, right: Collection<String>): Boolean {
if (left.size != right.size) {
return true
}

left.forEach {
if (!right.contains(it)) {
return true
}
}

return false
}
}
2 changes: 2 additions & 0 deletions rider/src/main/kotlin/net/cakebuild/settings/CakeSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CakeSettings : PersistentStateComponent<CakeSettings> {
var cakeVerbosity = "normal"
var cakeRunner = "dotnet-cake"
var cakeRunnerOverrides = mapOf(Pair("^.*windows.*$", "dotnet-cake.exe"))
var cakeScriptSearchPaths: Collection<String> = mutableListOf(".")
var cakeScriptSearchIgnores: Collection<String> = mutableListOf(".*/tools/.*")

override fun getState(): CakeSettings {
return this
Expand Down
Loading

0 comments on commit 6fb38b4

Please sign in to comment.