Skip to content

Commit 60cd006

Browse files
authored
Merge pull request #63 from secure-software-engineering/wip-upgrade-swan-assist
Upgrade swan-assist dependencies
2 parents 43a8eb6 + ba12464 commit 60cd006

35 files changed

+418
-327
lines changed

doc-xml-exporter-doclet/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.jsoup</groupId>
3838
<artifactId>jsoup</artifactId>
39-
<version>1.14.3</version>
39+
<version>1.15.3</version>
4040
<scope>compile</scope>
4141
</dependency>
4242
</dependencies>

swan-assist/build.gradle

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
plugins {
22
id 'java'
3-
id 'org.jetbrains.intellij' version '0.4.15'
3+
id 'org.jetbrains.intellij' version '1.8.1'
44
}
55

66
group 'de.fraunhofer'
7-
version '1.3'
8-
9-
sourceCompatibility = 1.8
7+
version '1.5'
108

9+
sourceCompatibility = JavaVersion.VERSION_11
10+
targetCompatibility = JavaVersion.VERSION_11
1111
repositories {
1212
mavenCentral()
1313
mavenLocal()
1414
}
1515

1616
dependencies {
17-
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
18-
compile group:'de.upb.cs.swt', name: 'swan_core', version: '1.5.0'
19-
compile group: 'ca.mcgill.sable', name: 'soot', version: '3.3.0'
20-
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.29'
21-
compile group: 'org.slf4j', name:'slf4j-simple', version: '1.7.29'
22-
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
17+
implementation 'com.googlecode.json-simple:json-simple:1.1'
18+
implementation 'de.fraunhofer.iem:swan:3.2.0'
19+
implementation 'ca.mcgill.sable:soot:3.3.0'
20+
implementation 'org.slf4j:slf4j-api:1.7.29'
21+
implementation 'org.slf4j:slf4j-simple:1.7.29'
22+
implementation 'org.apache.commons:commons-lang3:3.0'
23+
//implementation files('src/main/resources/Jar/swan.jar')
2324
}
2425

2526
intellij {
26-
version '2018.3.6'
27+
version = "2022.1"
28+
type = "IC"
29+
plugins = ["com.intellij.java"]
30+
2731
}
2832

2933
patchPluginXml {
30-
changeNotes "Initial release of the SWAN_Assist plugin: <br>add, delete and update methods of interest list" +
34+
changeNotes = "Initial release of the SWAN_Assist plugin: <br>add, delete and update methods of interest list" +
3135
"<br>- suggest methods" +
3236
"<br>- filter list" +
3337
"<br>- import and export configuration file"
38+
sinceBuild = "221.*"
39+
untilBuild = "222.*"
3440
}
3541

3642
runIde {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
package de.fraunhofer.iem.swan.assist.actions;
99

10-
import com.intellij.notification.Notification;
11-
import com.intellij.notification.NotificationType;
12-
import com.intellij.notification.Notifications;
10+
import com.intellij.notification.*;
1311
import com.intellij.openapi.actionSystem.AnAction;
1412
import com.intellij.openapi.actionSystem.AnActionEvent;
1513
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -31,8 +29,11 @@
3129

3230
public class ExportAction extends AnAction {
3331

32+
private static final NotificationGroup TOOL_GROUP = new NotificationGroup(Constants.PLUGIN_GROUP_DISPLAY_ID,
33+
NotificationDisplayType.TOOL_WINDOW, true);
3434
/**
3535
* Obtains list of methods and creates new JSON file in the location specified by the user.
36+
*
3637
* @param anActionEvent source event
3738
*/
3839
@Override
@@ -71,8 +72,8 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
7172
try {
7273
exportFile.writeToJsonFile(JSONFileLoader.getMethods(), filePath);
7374

74-
Notifications.Bus.notify(
75-
new Notification(Constants.PLUGIN_GROUP_DISPLAY_ID, "", JSONFileLoader.getMethods().size()+ " methods exported to: "+filePath, NotificationType.INFORMATION));
75+
Notification analysisCompleted = TOOL_GROUP.createNotification("", JSONFileLoader.getMethods().size() + " methods exported to: " + filePath, NotificationType.INFORMATION);
76+
Notifications.Bus.notify(analysisCompleted, project);
7677

7778
} catch (IOException e) {
7879
e.printStackTrace();
@@ -82,6 +83,7 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
8283

8384
/**
8485
* Controls whether the action is enabled or disabled
86+
*
8587
* @param event source event
8688
*/
8789
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public void actionPerformed(AnActionEvent anActionEvent) {
7474

7575
if(!swanParameters.get(Constants.CONFIGURATION_FILE).contentEquals(config.getProperty("swan_default_param_value"))){
7676
String outputPath = swanParameters.get(Constants.OUTPUT_DIRECTORY) + File.separator + config.getProperty("input_json_suffix");
77-
TrainingFileManager trainingFileManager = new TrainingFileManager(project);
77+
//TrainingFileManager trainingFileManager = new TrainingFileManager(project);
7878

79-
if (trainingFileManager.mergeExport(JSONFileLoader.getAllMethods(), outputPath))
80-
swanParameters.put(Constants.CONFIGURATION_FILE, outputPath);
79+
//if (trainingFileManager.mergeExport(JSONFileLoader.getAllMethods(), outputPath))
80+
// swanParameters.put(Constants.CONFIGURATION_FILE, outputPath);
8181
}
8282

8383
RunSwanAnalysisImpl processBuilder = new RunSwanAnalysisImpl(project, dialog.getParameters());

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

Lines changed: 8 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,11 @@
77

88
package de.fraunhofer.iem.swan.assist.actions;
99

10-
import com.intellij.openapi.progress.ProgressIndicator;
10+
import com.intellij.openapi.progress.PerformInBackgroundOption;
1111
import com.intellij.openapi.progress.ProgressManager;
12-
import com.intellij.openapi.progress.Task;
1312
import com.intellij.openapi.project.Project;
14-
import com.intellij.util.messages.MessageBus;
15-
import de.fraunhofer.iem.swan.Main;
16-
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
17-
import de.fraunhofer.iem.swan.assist.data.JSONFileParser;
18-
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1913
import de.fraunhofer.iem.swan.assist.util.Constants;
20-
import org.apache.commons.io.FileUtils;
21-
import org.jetbrains.annotations.NotNull;
22-
2314
import java.io.File;
24-
import java.io.IOException;
25-
import java.time.LocalDateTime;
26-
import java.time.format.DateTimeFormatter;
2715
import java.util.HashMap;
2816
import java.util.ResourceBundle;
2917

@@ -34,17 +22,19 @@ public class RunSwanAnalysisImpl {
3422

3523
private static HashMap<String, String> parameters;
3624
private Project project;
37-
private long duration;
25+
HashMap<String, String> results;
3826

3927
/**
4028
* Initializes builder.
29+
*
4130
* @param project Project on which the plugin is being used with
42-
* @param param Parameters that will be used as program arguments
31+
* @param param Parameters that will be used as program arguments
4332
*/
4433
RunSwanAnalysisImpl(Project project, HashMap<String, String> param) {
4534

4635
this.project = project;
4736
parameters = param;
37+
results = new HashMap<>();
4838
}
4939

5040
/**
@@ -56,86 +46,10 @@ public void run() {
5646

5747
File outputFolder = new File(parameters.get(Constants.OUTPUT_DIRECTORY));
5848

59-
if(!outputFolder.exists())
49+
if (!outputFolder.exists())
6050
outputFolder.mkdir();
6151

62-
/*File logFile = new File(outputFolder, currentTimestamp + parameters.get(Constants.OUTPUT_LOG));
63-
try {
64-
logFile.createNewFile();
65-
parameters.replace(Constants.OUTPUT_LOG, logFile.getPath());
66-
67-
FileOutputStream fileOutputStream = new FileOutputStream(logFile.getAbsolutePath());
68-
69-
System.setOut(new PrintStream(fileOutputStream));
70-
71-
} catch (IOException e) {
72-
e.printStackTrace();
73-
}*/
74-
75-
ProgressManager.getInstance().run(new Task.Backgroundable(project, resource.getString("Messages.Title.Progress")) {
76-
@Override
77-
public void run(@NotNull ProgressIndicator indicator) {
78-
79-
long start = System.currentTimeMillis();
80-
81-
Main.main(new String[]{parameters.get(Constants.SOURCE_DIRECTORY),
82-
parameters.get(Constants.TRAIN_DIRECTORY),
83-
parameters.get(Constants.CONFIGURATION_FILE),
84-
parameters.get(Constants.OUTPUT_DIRECTORY)});
85-
86-
duration = System.currentTimeMillis() - start;
87-
}
88-
89-
@Override
90-
public void onCancel() {
91-
super.onCancel();
92-
}
93-
94-
@Override
95-
public void onSuccess() {
96-
super.onSuccess();
97-
98-
System.out.println("FILE: "+parameters.get(Constants.OUTPUT_FILE));
99-
//Create copy of file
100-
copyFile(new File(parameters.get(Constants.OUTPUT_FILE)));
101-
102-
JSONFileParser parser = new JSONFileParser(parameters.get(Constants.OUTPUT_FILE));
103-
HashMap<String, MethodWrapper> exportedMethods = parser.parseJSONFileMap();
104-
105-
HashMap<String, String> results = new HashMap<String, String>();
106-
results.put(Constants.OUTPUT_FILE, parameters.get(Constants.OUTPUT_FILE));
107-
results.put(Constants.OUTPUT_LOG, parameters.get(Constants.OUTPUT_LOG));
108-
109-
int m = (int) (((duration / 1000) / 60) % 60);
110-
int s = (int) ((duration / 1000) % 60);
111-
112-
results.put(Constants.ANALYSIS_RESULT, exportedMethods.size() + " methods found in "+m+" mins "+s+ " secs");
113-
114-
MessageBus messageBus = project.getMessageBus();
115-
SwanNotifier publisher = messageBus.syncPublisher(SwanNotifier.END_SWAN_PROCESS_TOPIC);
116-
publisher.launchSwan(results);
117-
}
118-
});
119-
}
120-
121-
private void copyFile(File original ){
122-
123-
File copied = new File(
124-
parameters.get(Constants.OUTPUT_DIRECTORY) + File.separator +getCurrentTimestamp()+ "-config.json");
125-
try {
126-
FileUtils.copyFile(original, copied);
127-
} catch (IOException e) {
128-
e.printStackTrace();
129-
}
130-
}
131-
132-
/**
133-
* Get the timestamp in a specified format.
134-
* @return Formatted date
135-
*/
136-
private String getCurrentTimestamp() {
137-
138-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmmss");
139-
return LocalDateTime.now().format(formatter);
52+
ProgressManager.getInstance().run(new RunSwanTask(project, "Detecting SRMs", true,
53+
PerformInBackgroundOption.ALWAYS_BACKGROUND, parameters));
14054
}
14155
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package de.fraunhofer.iem.swan.assist.actions;
2+
3+
import com.intellij.openapi.progress.PerformInBackgroundOption;
4+
import com.intellij.openapi.progress.ProgressIndicator;
5+
import com.intellij.openapi.progress.Task;
6+
import com.intellij.openapi.project.Project;
7+
import com.intellij.openapi.util.NlsContexts;
8+
import com.intellij.util.messages.MessageBus;
9+
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
10+
import de.fraunhofer.iem.swan.assist.util.Constants;
11+
import de.fraunhofer.iem.swan.cli.CliRunner;
12+
import de.fraunhofer.iem.swan.cli.SwanCli;
13+
import de.fraunhofer.iem.swan.cli.SwanOptions;
14+
import de.fraunhofer.iem.swan.io.dataset.SrmList;
15+
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
16+
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
18+
19+
import java.io.File;
20+
import java.io.IOException;
21+
import java.time.LocalDateTime;
22+
import java.time.format.DateTimeFormatter;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
26+
public class RunSwanTask extends Task.Backgroundable {
27+
28+
private Project project;
29+
private HashMap<String, String> parameters;
30+
private long duration;
31+
32+
public RunSwanTask(@Nullable Project project, @NlsContexts.ProgressTitle @NotNull String title, boolean canBeCancelled, @Nullable PerformInBackgroundOption backgroundOption, HashMap<String, String> parameters) {
33+
super(project, title, canBeCancelled, backgroundOption);
34+
this.parameters = parameters;
35+
this.project = project;
36+
}
37+
38+
@Override
39+
public void run(@NotNull ProgressIndicator indicator) {
40+
41+
long start = System.currentTimeMillis();
42+
43+
indicator.setText("Configuring SWAN");
44+
SwanOptions options = new CliRunner().initializeOptions();
45+
options.setTestDataDir(parameters.get(Constants.SOURCE_DIRECTORY));
46+
options.setOutputDir(parameters.get(Constants.OUTPUT_DIRECTORY));
47+
options.setToolkit(parameters.get(Constants.TOOLKIT).toLowerCase());
48+
options.setSrmClasses(List.of("all"));
49+
options.setPhase("predict");
50+
options.setTrainDataDir("");
51+
52+
53+
indicator.setText("Running SWAN");
54+
SwanCli swan = new SwanCli();
55+
56+
try {
57+
swan.run(options);
58+
} catch (Exception e) {
59+
throw new RuntimeException(e);
60+
}
61+
62+
duration = System.currentTimeMillis() - start;
63+
int m = (int) (((duration / 1000) / 60) % 60);
64+
int s = (int) ((duration / 1000) % 60);
65+
66+
indicator.setText("Exporting SRMs");
67+
String filename = parameters.get(Constants.OUTPUT_DIRECTORY) + File.separator + "srm-" + getCurrentTimestamp() + ".json";
68+
SrmList srmList = swan.getSwanPipeline().getModelEvaluator().getPredictedSrmList();
69+
70+
try {
71+
72+
SrmListUtils.exportFile(srmList, filename);
73+
} catch (IOException e) {
74+
throw new RuntimeException(e);
75+
}
76+
77+
HashMap<String, String> results = new HashMap<>();
78+
results.put(Constants.OUTPUT_FILE, filename);
79+
results.put(Constants.OUTPUT_LOG, "");
80+
results.put(Constants.ANALYSIS_RESULT, srmList.getMethods().size() + " methods found in " + m + " mins " + s + " secs");
81+
82+
MessageBus messageBus = project.getMessageBus();
83+
SwanNotifier publisher = messageBus.syncPublisher(SwanNotifier.END_SWAN_PROCESS_TOPIC);
84+
publisher.launchSwan(results);
85+
}
86+
87+
/**
88+
* Get the timestamp in a specified format.
89+
*
90+
* @return Formatted date
91+
*/
92+
private String getCurrentTimestamp() {
93+
94+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmmss");
95+
return LocalDateTime.now().format(formatter);
96+
}
97+
98+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import de.fraunhofer.iem.swan.assist.util.Constants;
1515
import de.fraunhofer.iem.swan.assist.util.Formatter;
1616
import de.fraunhofer.iem.swan.data.Category;
17-
import javafx.util.Pair;
17+
import de.fraunhofer.iem.swan.assist.util.Pair;
1818
import org.jetbrains.annotations.NotNull;
1919
import org.jetbrains.annotations.Nullable;
2020

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import de.fraunhofer.iem.swan.assist.comm.FilterNotifier;
1717
import de.fraunhofer.iem.swan.assist.ui.MethodListTree;
1818
import icons.PluginIcons;
19-
import javafx.util.Pair;
19+
import de.fraunhofer.iem.swan.assist.util.Pair;
2020

2121
/**
2222
* Plugin action to filter method list.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import de.fraunhofer.iem.swan.assist.ui.MethodListTree;
1616
import de.fraunhofer.iem.swan.assist.util.Constants;
1717
import icons.PluginIcons;
18-
import javafx.util.Pair;
18+
import de.fraunhofer.iem.swan.assist.util.Pair;
1919
import org.jetbrains.annotations.NotNull;
2020
import org.jetbrains.annotations.Nullable;
2121

0 commit comments

Comments
 (0)