Skip to content

Commit 9d12f4a

Browse files
committed
Move plugin settings to configuration file
1 parent d3d64ab commit 9d12f4a

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log_suffix = _swanassist_log.txt
2+
output_dir_name = output
3+
output_json_suffix = output.json
4+
input_json_suffix = config_input.json
5+
train_dir_name = training_libs
6+
train_config_file = trainingmethods.json
7+
swan_jar_name = swan_core.jar

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/LaunchSwanAction.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88
import com.intellij.util.messages.MessageBus;
99
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
1010
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
11+
import de.fraunhofer.iem.swan.assist.data.JSONFileParser;
1112
import de.fraunhofer.iem.swan.assist.data.JSONWriter;
13+
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1214
import de.fraunhofer.iem.swan.assist.ui.dialog.SwanLauncherDialog;
15+
import de.fraunhofer.iem.swan.assist.util.Constants;
1316

17+
import java.io.File;
18+
import java.io.FileInputStream;
1419
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.util.ArrayList;
22+
import java.util.HashMap;
23+
import java.util.Objects;
24+
import java.util.Properties;
1525

1626
/**
1727
* Action to start load dialog for configuring SWAN before running.
@@ -28,20 +38,53 @@ public void actionPerformed(AnActionEvent anActionEvent) {
2838
final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);
2939
MessageBus messageBus = project.getMessageBus();
3040

31-
//Export changes to configuration files
32-
JSONWriter exportFile = new JSONWriter();
41+
Properties config = new Properties();
42+
InputStream input = null;
3343

3444
try {
35-
exportFile.writeToJsonFile(JSONFileLoader.getMethods(), JSONFileLoader.getConfigurationFile(true));
45+
input = new FileInputStream(getClass().getClassLoader().getResource("").getPath()+"config.properties");
46+
config.load(input);
3647
} catch (IOException e) {
3748
e.printStackTrace();
49+
} finally {
50+
if (input != null) {
51+
try {
52+
input.close();
53+
} catch (IOException e) {
54+
e.printStackTrace();
55+
}
56+
}
3857
}
3958

4059
//Launch Dialog
4160
SwanLauncherDialog dialog = new SwanLauncherDialog(project, true);
4261
dialog.show();
4362

44-
if (dialog.getExitCode()==DialogWrapper.OK_EXIT_CODE) {
63+
if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
64+
65+
HashMap<String, String> swanParameters = dialog.getParameters();
66+
67+
//Merge current list with training methods
68+
HashMap<String, MethodWrapper> methods = JSONFileLoader.getAllMethods();
69+
70+
//Load training methods
71+
String trainingFile = Objects.requireNonNull(getClass().getClassLoader().getResource("")).getPath() + config.getProperty("train_config_file");
72+
JSONFileParser fileParser = new JSONFileParser(trainingFile);
73+
HashMap<String, MethodWrapper> trainingMethods = fileParser.parseJSONFileMap();
74+
75+
HashMap<String, MethodWrapper> mergedMethods = new HashMap<>(methods);
76+
mergedMethods.putAll(trainingMethods);
77+
78+
//Export changes to configuration files
79+
JSONWriter exportFile = new JSONWriter();
80+
String newConfigFile = swanParameters.get(Constants.SWAN_OUTPUT_DIR) + File.separator + config.getProperty("input_json_suffix");
81+
try {
82+
exportFile.writeToJsonFile(new ArrayList<>(mergedMethods.values()), newConfigFile);
83+
} catch (IOException e) {
84+
e.printStackTrace();
85+
}
86+
87+
swanParameters.put(Constants.SWAN_CONFIG_FILE, newConfigFile);
4588

4689
SwanProcessBuilder processBuilder = new SwanProcessBuilder(project, dialog.getParameters());
4790
processBuilder.start();

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/dialog/SwanResultsDialog.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
import javax.swing.filechooser.FileSystemView;
1414
import java.awt.event.*;
1515
import java.io.File;
16+
import java.io.FileInputStream;
1617
import java.io.IOException;
18+
import java.io.InputStream;
1719
import java.nio.file.Files;
1820
import java.nio.file.Paths;
1921
import java.util.HashMap;
22+
import java.util.Properties;
23+
import java.util.ResourceBundle;
2024

2125
/**
2226
* Provides results after SWAN finishes executing.
@@ -37,7 +41,26 @@ public class SwanResultsDialog extends DialogWrapper {
3741
public SwanResultsDialog(Project project, HashMap<String, String> values) {
3842

3943
super(project);
40-
setTitle("SWAN Results");
44+
ResourceBundle resourceBundle = ResourceBundle.getBundle("dialog_messages");
45+
setTitle(resourceBundle.getString("Results.Title"));
46+
47+
Properties config = new Properties();
48+
InputStream input = null;
49+
50+
try {
51+
input = new FileInputStream(getClass().getClassLoader().getResource("").getPath() + "config.properties");
52+
config.load(input);
53+
} catch (IOException e) {
54+
e.printStackTrace();
55+
} finally {
56+
if (input != null) {
57+
try {
58+
input.close();
59+
} catch (IOException e) {
60+
e.printStackTrace();
61+
}
62+
}
63+
}
4164

4265
this.project = project;
4366

@@ -68,7 +91,7 @@ public void actionPerformed(ActionEvent actionEvent) {
6891
File selectedFile = fileChooser.getSelectedFile();
6992
String path = selectedFile.getAbsoluteFile().toString();
7093
filePath.setText(path);
71-
logPath.setText(path.replace(Constants.OUTPUT_JSON_SUFFIX, Constants.SWAN_LOG_SUFFIX));
94+
logPath.setText(path.replace(config.getProperty("output_json_suffix"), config.getProperty("log_suffix")));
7295

7396
try {
7497
logText.setText(new String(Files.readAllBytes(Paths.get(logPath.getText()))));
@@ -84,9 +107,6 @@ public void actionPerformed(ActionEvent actionEvent) {
84107
protected void doOKAction() {
85108

86109
if (isOKActionEnabled()) {
87-
MessageBus messageBus = project.getMessageBus();
88-
FileSelectedNotifier publisher = messageBus.syncPublisher(FileSelectedNotifier.UPDATED_FILE_NOTIFIER_TOPIC);
89-
publisher.notifyFileChange(filePath.getText());
90110
super.doOKAction();
91111
}
92112
}
@@ -95,7 +115,6 @@ protected void doOKAction() {
95115
@Override
96116
protected Action[] createActions() {
97117

98-
99118
return super.createActions();
100119
}
101120

swan_assist/src/de/fraunhofer/iem/swan/assist/util/Constants.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ public class Constants {
4545
public final static String SWAN_OUTPUT_LOG = "output_logs";
4646
public final static String SWAN_OUTPUT_MESSAGE = "output_message";
4747

48-
public final static String SWAN_LOG_SUFFIX = "_swanassist_log.txt";
49-
public final static String OUTPUT_DIR_NAME = "output";
50-
public final static String OUTPUT_JSON_SUFFIX = "output.json";
51-
public final static String OUTPUT_TEXT_SUFFIX = "_output.txt";
52-
53-
public final static String FILTER_CURRENT_FILE_KEY = "file";
54-
public final static String FILTER_CURRENT_FILE_VALUE = "Current Class";
55-
public final static String FILTER_CURRENT_PROJECT_KEY = "project";
56-
public final static String FILTER_CURRENT_PROJECT_VALUE = "Current Project";
57-
public final static String FILTER_CLEAR_KEY = "Clear Filters";
58-
public final static String FILTER_CLEAR_VALUE = "Clear Filters";
5948
public final static String FILTER_CWE = "CWE";
6049
public final static String FILTER_TYPE = "Type";
6150

0 commit comments

Comments
 (0)