Skip to content

Commit 54587d8

Browse files
authored
Merge pull request #60 from rohithsh/wip-swan-assist-java-and-gradle-upgrade
Update dialog to run analysis
2 parents 9f743b9 + 7e5ae13 commit 54587d8

File tree

7 files changed

+85
-73
lines changed

7 files changed

+85
-73
lines changed

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/actions/RunSwanAnalysisImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void run(@NotNull ProgressIndicator indicator) {
8585
SwanOptions options = new CliRunner().initializeOptions();
8686
options.setTestDataDir(parameters.get(Constants.SOURCE_DIRECTORY));
8787
options.setOutputDir( parameters.get(Constants.OUTPUT_DIRECTORY));
88-
options.setToolkit("meka");
88+
options.setToolkit(parameters.get(Constants.TOOLKIT).toLowerCase());
8989
options.setPhase("predict");
9090
options.setTrainDataDir("");
9191

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/ui/dialog/RunAnalysisDialog.form

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.fraunhofer.iem.swan.assist.ui.dialog.RunAnalysisDialog">
3-
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="7" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
66
<xy x="48" y="141" width="603" height="328"/>
@@ -16,7 +16,9 @@
1616
<constraints>
1717
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
1818
</constraints>
19-
<properties/>
19+
<properties>
20+
<enabled value="true"/>
21+
</properties>
2022
<border type="none"/>
2123
<children>
2224
<component id="998b" class="javax.swing.JLabel">
@@ -35,52 +37,10 @@
3537
</component>
3638
</children>
3739
</grid>
38-
<component id="26fcc" class="javax.swing.JCheckBox" binding="configurationPathCheckbox">
39-
<constraints>
40-
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
41-
</constraints>
42-
<properties>
43-
<text resource-bundle="dialog_messages" key="Launcher.Checkbox.ConfigurationFile"/>
44-
</properties>
45-
</component>
46-
<grid id="2dc06" binding="configurationFilePanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
47-
<margin top="0" left="0" bottom="0" right="0"/>
48-
<constraints>
49-
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
50-
</constraints>
51-
<properties/>
52-
<border type="none"/>
53-
<children>
54-
<component id="2a3cb" class="javax.swing.JLabel">
55-
<constraints>
56-
<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"/>
57-
</constraints>
58-
<properties>
59-
<text resource-bundle="dialog_messages" key="Launcher.ConfigurationFile"/>
60-
</properties>
61-
</component>
62-
<component id="47199" class="javax.swing.JTextField" binding="configFileTextbox">
63-
<constraints>
64-
<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">
65-
<preferred-size width="150" height="-1"/>
66-
</grid>
67-
</constraints>
68-
<properties/>
69-
</component>
70-
<component id="a19ba" class="javax.swing.JButton" binding="configButton">
71-
<constraints>
72-
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
73-
</constraints>
74-
<properties>
75-
<text value="..."/>
76-
</properties>
77-
</component>
78-
</children>
79-
</grid>
8040
<grid id="d5fbf" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
8141
<margin top="0" left="0" bottom="0" right="0"/>
8242
<constraints>
83-
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
43+
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
8444
</constraints>
8545
<properties/>
8646
<border type="none"/>
@@ -147,7 +107,7 @@
147107
</grid>
148108
<component id="b260" class="javax.swing.JCheckBox" binding="trainingPathCheckbox">
149109
<constraints>
150-
<grid row="4" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
110+
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
151111
</constraints>
152112
<properties>
153113
<selected value="false"/>
@@ -157,7 +117,7 @@
157117
<grid id="1ffb" binding="trainingPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
158118
<margin top="0" left="0" bottom="0" right="0"/>
159119
<constraints>
160-
<grid row="5" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
120+
<grid row="4" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
161121
</constraints>
162122
<properties/>
163123
<border type="none"/>
@@ -188,6 +148,47 @@
188148
</component>
189149
</children>
190150
</grid>
151+
<grid id="7ce0b" binding="toolkitPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
152+
<margin top="0" left="0" bottom="0" right="0"/>
153+
<constraints>
154+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
155+
</constraints>
156+
<properties/>
157+
<border type="none"/>
158+
<children>
159+
<component id="c3485" class="javax.swing.JLabel">
160+
<constraints>
161+
<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"/>
162+
</constraints>
163+
<properties>
164+
<text resource-bundle="dialog_messages" key="Launcher.Toolkit"/>
165+
</properties>
166+
</component>
167+
<component id="d7cdd" class="javax.swing.JRadioButton" binding="WEKARadioButton" default-binding="true">
168+
<constraints>
169+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
170+
</constraints>
171+
<properties>
172+
<selected value="true"/>
173+
<text resource-bundle="dialog_messages" key="Launcher.wekaRadioButton"/>
174+
</properties>
175+
</component>
176+
<component id="7d7a5" class="javax.swing.JRadioButton" binding="MEKARadioButton" default-binding="true">
177+
<constraints>
178+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
179+
</constraints>
180+
<properties>
181+
<text resource-bundle="dialog_messages" key="Launcher.mekaRadioButton"/>
182+
</properties>
183+
</component>
184+
</children>
185+
</grid>
191186
</children>
192187
</grid>
188+
<buttonGroups>
189+
<group name="toolkit">
190+
<member id="d7cdd"/>
191+
<member id="7d7a5"/>
192+
</group>
193+
</buttonGroups>
193194
</form>

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/ui/dialog/RunAnalysisDialog.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ public class RunAnalysisDialog extends DialogWrapper {
4545
private JButton trainButton;
4646
private JPanel trainingPanel;
4747
private JCheckBox trainingPathCheckbox;
48-
private JCheckBox configurationPathCheckbox;
49-
private JTextField configFileTextbox;
50-
private JButton configButton;
51-
private JPanel configurationFilePanel;
48+
private JRadioButton WEKARadioButton;
49+
private JRadioButton MEKARadioButton;
50+
private JPanel toolkitPanel;
5251
private HashMap<String, String> parameters = new HashMap<String, String>();
5352
private ResourceBundle resourceBundle;
5453
private Properties config;
@@ -88,13 +87,13 @@ public RunAnalysisDialog(Project project, boolean modal) {
8887
File configurationFile = new File(JSONFileLoader.getConfigurationFile(true));
8988

9089
//Use value for source path, if available. Otherwise set the default path
91-
if (!PropertiesComponent.getInstance(project).isValueSet(Constants.SOURCE_DIRECTORY))
92-
sourceDirTextbox.setText(project.getBasePath());
90+
if (PropertiesComponent.getInstance(project).isValueSet(Constants.SOURCE_DIRECTORY))
91+
sourceDirTextbox.setText(project.getBasePath()+"/target");
9392
else
9493
sourceDirTextbox.setText(PropertiesComponent.getInstance(project).getValue(Constants.SOURCE_DIRECTORY));
9594

9695
//Use value for the output path, if available. Otherwise set the default path
97-
if (!PropertiesComponent.getInstance(project).isValueSet(Constants.OUTPUT_DIRECTORY))
96+
if (PropertiesComponent.getInstance(project).isValueSet(Constants.OUTPUT_DIRECTORY))
9897
outputDir.setText(project.getBasePath() + File.separator + config.getProperty("output_dir_name"));
9998
else
10099
outputDir.setText(PropertiesComponent.getInstance(project).getValue(Constants.OUTPUT_DIRECTORY));
@@ -107,20 +106,20 @@ public RunAnalysisDialog(Project project, boolean modal) {
107106
}
108107

109108
//Set value for using configuration file
110-
configurationPathCheckbox.setSelected(PropertiesComponent.getInstance(project).getBoolean(Constants.PROJECT_CONFIGURATION_FILE, false));
111-
112-
for (Component component : configurationFilePanel.getComponents()) {
113-
component.setEnabled(configurationPathCheckbox.isSelected());
114-
}
109+
// configurationPathCheckbox.setSelected(PropertiesComponent.getInstance(project).getBoolean(Constants.PROJECT_CONFIGURATION_FILE, false));
110+
//
111+
// for (Component component : configurationFilePanel.getComponents()) {
112+
// component.setEnabled(configurationPathCheckbox.isSelected());
113+
// }
115114

116115

117116
if (PropertiesComponent.getInstance(project).isValueSet(Constants.TRAIN_DIRECTORY)) {
118117
trainingTextbox.setText(PropertiesComponent.getInstance(project).getValue(Constants.TRAIN_DIRECTORY));
119118
}
120119

121-
if (PropertiesComponent.getInstance(project).isValueSet(Constants.CONFIGURATION_FILE)) {
122-
configFileTextbox.setText(PropertiesComponent.getInstance(project).getValue(Constants.CONFIGURATION_FILE));
123-
}
120+
// if (PropertiesComponent.getInstance(project).isValueSet(Constants.CONFIGURATION_FILE)) {
121+
// configFileTextbox.setText(PropertiesComponent.getInstance(project).getValue(Constants.CONFIGURATION_FILE));
122+
// }
124123

125124
init();
126125
/*
@@ -140,7 +139,7 @@ public void actionPerformed(ActionEvent e) {
140139
}
141140
});
142141

143-
configurationPathCheckbox.addActionListener(new ActionListener() {
142+
/*configurationPathCheckbox.addActionListener(new ActionListener() {
144143
@Override
145144
public void actionPerformed(ActionEvent e) {
146145
@@ -150,7 +149,7 @@ public void actionPerformed(ActionEvent e) {
150149
component.setEnabled(configurationPathCheckbox.isSelected());
151150
}
152151
}
153-
});
152+
}); */
154153

155154
sourceBtn.addActionListener(new ActionListener() {
156155
@Override
@@ -176,13 +175,13 @@ public void actionPerformed(ActionEvent e) {
176175
}
177176
});
178177

179-
configButton.addActionListener(new ActionListener() {
178+
/*configButton.addActionListener(new ActionListener() {
180179
@Override
181180
public void actionPerformed(ActionEvent e) {
182181
183182
configFileTextbox.setText(fileSelector(JFileChooser.FILES_ONLY, configFileTextbox.getText()));
184183
}
185-
});
184+
});*/
186185
}
187186

188187
@Override
@@ -221,11 +220,17 @@ private void setParameters() {
221220
}
222221

223222
//Check if option to use default configuration file is selected
224-
if (configurationPathCheckbox.isSelected()) {
223+
/* if (configurationPathCheckbox.isSelected()) {
225224
parameters.put(Constants.CONFIGURATION_FILE, configFileTextbox.getText());
226-
} else
227-
parameters.put(Constants.CONFIGURATION_FILE, config.getProperty("swan_default_param_value"));
228-
225+
} else */
226+
//set the configuration file to default
227+
parameters.put(Constants.CONFIGURATION_FILE, config.getProperty("swan_default_param_value"));
228+
229+
if(!MEKARadioButton.isSelected()){
230+
parameters.put(Constants.TOOLKIT, MEKARadioButton.getText());
231+
}else{
232+
parameters.put(Constants.TOOLKIT, WEKARadioButton.getText());
233+
}
229234
parameters.put(Constants.SOURCE_DIRECTORY, sourceDirTextbox.getText());
230235
parameters.put(Constants.OUTPUT_DIRECTORY, outputDir.getText());
231236
parameters.put(Constants.OUTPUT_LOG, config.getProperty("log_suffix"));

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/util/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Constants {
3232
public final static String ANALYSIS_RESULT = PLUGIN_ID + "analysisResult";
3333
public final static String TRAIN_FILE_SUGGESTED = PLUGIN_ID + "file_suggested_methods";
3434

35+
public final static String TOOLKIT = "toolkit";
3536
public final static String DEFAULT_TRAINING_PATH = PLUGIN_ID + "defaultTrainingPath";
3637
public final static String PROJECT_CONFIGURATION_FILE = PLUGIN_ID + "defaultConfigurationFile";
3738

swan-assist/src/main/java/icons/IconUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import de.fraunhofer.iem.swan.data.Constants;
1212
import org.apache.commons.lang3.StringUtils;
1313
import javax.swing.*;
14+
import java.net.URL;
1415
import java.util.ArrayList;
1516
import java.util.Collections;
1617

swan-assist/src/main/resources/config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
log_suffix = _swanassist_log.txt
2-
output_dir_name = swan-assist
2+
output_dir_name = out
33
output_json_suffix = swan_assist_results.json
44
input_json_suffix = config_input.json
55
train_config_file = trainingmethods.json

swan-assist/src/main/resources/dialog_messages.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MethodDialog.SelectedCategory = Selected Categories
1717
#Dialog for running SWAN
1818
Launcher.Title=Run Analysis
1919
Launcher.ProjectCheckBox = General Options
20-
Launcher.Project = Project JAR(s)
20+
Launcher.Project = Project
2121
Launcher.AdvancedOptionsCheckBox = Advanced Options
2222
Launcher.Output = Output Path
2323
Launcher.TrainingJars = Training JARs
@@ -116,4 +116,8 @@ CWE601.FullName= URL Redirection to Untrusted Site ('Open Redirect')
116116
CWE862.FullName= Missing Authorization
117117
CWE863.FullName= Incorrect Authorization
118118

119+
Launcher.Toolkit=Toolkit
120+
Launcher.mekaRadioButton=MEKA
121+
Launcher.wekaRadioButton=WEKA
122+
119123

0 commit comments

Comments
 (0)