Skip to content

Commit 6f48b2f

Browse files
committed
support variable replacement in library path
1 parent ebee73e commit 6f48b2f

File tree

6 files changed

+103
-19
lines changed

6 files changed

+103
-19
lines changed

META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin version="2">
22
<id>com.millennialmedia.intellibot</id>
33
<name>[email protected]</name>
4-
<version>0.10.143.396</version>
4+
<version>0.10.143.397</version>
55
<vendor email="[email protected]" url="http://www.millennialmedia.com">Millennial Media</vendor>
66

77
<depends>com.intellij.modules.lang</depends>

intellibot.jar

1.71 KB
Binary file not shown.
Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.millennialmedia.intellibot.ide.config.RobotConfiguration">
3-
<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">
3+
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="539" height="283"/>
6+
<xy x="20" y="20" width="561" height="352"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
1010
<children>
11-
<grid id="62c2a" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
11+
<grid id="62c2a" layout-manager="GridLayoutManager" row-count="10" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1212
<margin top="0" left="0" bottom="0" right="0"/>
1313
<constraints>
14-
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
14+
<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"/>
1515
</constraints>
1616
<properties/>
1717
<border type="none"/>
1818
<children>
1919
<component id="39b74" class="javax.swing.JCheckBox" binding="allowGlobalVariables">
2020
<constraints>
21-
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
21+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
2222
</constraints>
2323
<properties>
2424
<text value="Allow Global Variables (performance concern)"/>
2525
</properties>
2626
</component>
2727
<component id="34fab" class="javax.swing.JCheckBox" binding="enableDebug">
2828
<constraints>
29-
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
29+
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
3030
</constraints>
3131
<properties>
3232
<text value="Enable Debug Trace"/>
3333
</properties>
3434
</component>
3535
<component id="f8258" class="javax.swing.JCheckBox" binding="capitalizeKeywords">
3636
<constraints>
37-
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
37+
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
3838
</constraints>
3939
<properties>
4040
<text value="Capitalize Keywords"/>
4141
</properties>
4242
</component>
4343
<component id="37b5e" class="javax.swing.JCheckBox" binding="inlineVariableSearch">
4444
<constraints>
45-
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
45+
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
4646
</constraints>
4747
<properties>
4848
<text value="Inline Variable Keyword Search (performance concern)"/>
4949
</properties>
5050
</component>
5151
<component id="c6ab4" class="javax.swing.JCheckBox" binding="stripVariableInLibraryPath">
5252
<constraints>
53-
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
53+
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
5454
</constraints>
5555
<properties>
5656
<text value="Strip Variable in library path (${name}/ to be name/)"/>
5757
</properties>
5858
</component>
5959
<component id="3203a" class="javax.swing.JCheckBox" binding="loadProjectDefaultVariable">
6060
<constraints>
61-
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
61+
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
6262
</constraints>
6363
<properties>
6464
<text value="Load Variables in Project Default Resource (&lt;root&gt;/_ProjectDefaultResource_.robot)"/>
6565
</properties>
6666
</component>
6767
<component id="9e9b0" class="javax.swing.JCheckBox" binding="searchChildKeywords">
6868
<constraints>
69-
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
69+
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
7070
</constraints>
7171
<properties>
7272
<text value="Search Keywords in Sub-packages (e.g. SeleniumLibrary)"/>
@@ -82,7 +82,7 @@
8282
</component>
8383
<component id="1f6de" class="javax.swing.JSpinner" binding="maxTransitiveDepth">
8484
<constraints>
85-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
85+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
8686
<maximum-size width="100" height="-1"/>
8787
</grid>
8888
</constraints>
@@ -96,13 +96,46 @@
9696
<text value="Expand Adjacent 2 or 3 Spaces to 4 Spaces When Type"/>
9797
</properties>
9898
</component>
99+
<vspacer id="d1a6b">
100+
<constraints>
101+
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
102+
</constraints>
103+
</vspacer>
99104
</children>
100105
</grid>
101-
<vspacer id="5915a">
106+
<grid id="e2c3b" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
107+
<margin top="0" left="0" bottom="0" right="0"/>
102108
<constraints>
103-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
109+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
104110
</constraints>
105-
</vspacer>
111+
<properties/>
112+
<border type="none" title="Variables"/>
113+
<children>
114+
<scrollpane id="e6756">
115+
<constraints>
116+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
117+
</constraints>
118+
<properties/>
119+
<border type="none"/>
120+
<children>
121+
<component id="edea2" class="javax.swing.JTextArea" binding="predefineVaraibles">
122+
<constraints/>
123+
<properties>
124+
<margin top="5" left="5" bottom="5" right="5"/>
125+
</properties>
126+
</component>
127+
</children>
128+
</scrollpane>
129+
<component id="bf96" class="javax.swing.JLabel">
130+
<constraints>
131+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
132+
</constraints>
133+
<properties>
134+
<text value="Define value for variables used in library and resource path, format: ${var}=value, one per line)"/>
135+
</properties>
136+
</component>
137+
</children>
138+
</grid>
106139
</children>
107140
</grid>
108141
</form>

src/com/millennialmedia/intellibot/ide/config/RobotConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class RobotConfiguration implements SearchableConfigurable, Configurable.
2929
private JCheckBox loadProjectDefaultVariable;
3030
private JSpinner maxTransitiveDepth;
3131
private JCheckBox expandSuperSpaces;
32+
private JTextArea predefineVaraibles;
3233

3334
public RobotConfiguration(@NotNull Project project) {
3435
this.provider = RobotOptionsProvider.getInstance(project);
@@ -75,7 +76,8 @@ public boolean isModified() {
7576
this.provider.searchChildKeywords() != this.searchChildKeywords.isSelected() ||
7677
this.provider.loadProjectDefaultVariable() != this.loadProjectDefaultVariable.isSelected() ||
7778
this.provider.maxTransitiveDepth() != (int) this.maxTransitiveDepth.getValue() ||
78-
this.provider.expandSuperSpaces() != this.expandSuperSpaces.isSelected();
79+
this.provider.expandSuperSpaces() != this.expandSuperSpaces.isSelected() ||
80+
! this.provider.predefinedVariables().equals(this.predefineVaraibles.getText());
7981
}
8082

8183
@Override
@@ -92,6 +94,7 @@ public void apply() throws ConfigurationException {
9294
} catch (Exception ignore) {}
9395
this.provider.setMaxTransitiveDepth((int)this.maxTransitiveDepth.getValue());
9496
this.provider.setExpandSuperSpaces(this.expandSuperSpaces.isSelected());
97+
this.provider.setPredefinedVariables(this.predefineVaraibles.getText());
9598
}
9699

97100
@Override
@@ -105,6 +108,7 @@ public void reset() {
105108
this.loadProjectDefaultVariable.setSelected(this.provider.loadProjectDefaultVariable());
106109
this.maxTransitiveDepth.setValue(this.provider.maxTransitiveDepth());
107110
this.expandSuperSpaces.setSelected(this.provider.expandSuperSpaces());
111+
this.predefineVaraibles.setText(this.provider.predefinedVariables());
108112
}
109113

110114
@Override

src/com/millennialmedia/intellibot/ide/config/RobotOptionsProvider.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.millennialmedia.intellibot.ide.config;
22

3-
import com.intellij.notification.NotificationDisplayType;
4-
import com.intellij.notification.NotificationsConfiguration;
3+
import com.intellij.notification.*;
54
import com.intellij.openapi.components.*;
65
import com.intellij.openapi.project.Project;
76
import org.jetbrains.annotations.Nullable;
87

8+
import java.util.Hashtable;
9+
import java.util.Map;
10+
911
/**
1012
* @author mrubino
1113
* @since 2014-06-26
@@ -32,6 +34,7 @@ public static class State {
3234
public boolean loadProjectDefaultVariable = false;
3335
public int maxTransitiveDepth = 99;
3436
public boolean expandSuperSpaces = true;
37+
public String predefinedVariables = "";
3538
}
3639

3740
private State state = new State();
@@ -57,8 +60,12 @@ public void loadState(State state) {
5760
this.state.loadProjectDefaultVariable = state.loadProjectDefaultVariable;
5861
this.state.maxTransitiveDepth = state.maxTransitiveDepth;
5962
this.state.expandSuperSpaces = state.expandSuperSpaces;
63+
this.state.predefinedVariables = state.predefinedVariables;
64+
setPredefinedVaraibleTable();
6065
}
6166

67+
private final Hashtable<String, String> predefinedVaraibleTable = new Hashtable<String, String>();
68+
6269
public boolean isDebug() {
6370
return this.state.debug;
6471
}
@@ -131,4 +138,40 @@ public void setExpandSuperSpaces(boolean expandSuperSpaces) {
131138
this.state.expandSuperSpaces = expandSuperSpaces;
132139
}
133140

141+
public String predefinedVariables() { return this.state.predefinedVariables; }
142+
143+
public synchronized void setPredefinedVariables(String predefinedVariables) {
144+
this.state.predefinedVariables = predefinedVariables;
145+
setPredefinedVaraibleTable();
146+
}
147+
148+
//private static final com.intellij.openapi.diagnostic.Logger LOGGER = com.intellij.openapi.diagnostic.Logger.getInstance(RobotOptionsProvider.class);
149+
//private static final com.intellij.openapi.diagnostic.Logger LOGGER = com.intellij.openapi.diagnostic.Logger.getInstance("#intellibot.RobotOptionsProvider");
150+
151+
private synchronized void setPredefinedVaraibleTable() {
152+
predefinedVaraibleTable.clear();
153+
String[] lines = this.state.predefinedVariables.split("\n", 0);
154+
for (String line: lines) {
155+
if (line.isEmpty()) {
156+
continue;
157+
}
158+
String[] words = line.split("=", 2);
159+
if (words.length != 2) {
160+
continue;
161+
}
162+
predefinedVaraibleTable.put(words[0].trim(), words[1].trim());
163+
}
164+
if (isDebug()) {
165+
String message = "[RobotOptionsProvider] Variables:\n";
166+
for (Map.Entry<String, String> entry : getPredefinedVaraibleTable().entrySet()) {
167+
message += entry.getKey() + ": " + entry.getValue() + "\n";
168+
169+
}
170+
Notifications.Bus.notify(new Notification("intellibot.debug", "Debug", message, NotificationType.INFORMATION));
171+
}
172+
}
173+
174+
public Hashtable<String, String> getPredefinedVaraibleTable() {
175+
return this.predefinedVaraibleTable;
176+
}
134177
}

src/com/millennialmedia/intellibot/psi/ref/RobotFileManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Collection;
2020
import java.util.List;
21+
import java.util.Map;
2122

2223
/**
2324
* This handles finding Robot files or python classes/files.
@@ -271,6 +272,9 @@ private static boolean acceptablePath(@NotNull String path, @Nullable PsiFile fi
271272

272273
@NotNull
273274
private static String[] getFilename(@NotNull String path, @NotNull String suffix, @NotNull Project project) {
275+
for (Map.Entry<String, String> entry : RobotOptionsProvider.getInstance(project).getPredefinedVaraibleTable().entrySet()) {
276+
path = path.replace(entry.getKey(), entry.getValue());
277+
}
274278
// support either / or ${/}
275279
String[] pathElements = path.split("(\\$\\{)?/(})?");
276280
String result;

0 commit comments

Comments
 (0)