Skip to content

Commit 9f743b9

Browse files
committed
Bump SWAN from 1.3.0 to 3.2.0
1 parent c6b1348 commit 9f743b9

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

swan-assist/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515

1616
dependencies {
1717
implementation 'com.googlecode.json-simple:json-simple:1.1'
18-
implementation 'de.upb.cs.swt:swan_core:1.3.0'
18+
implementation 'de.fraunhofer.iem:swan:3.2.0'
1919
implementation 'ca.mcgill.sable:soot:3.3.0'
2020
implementation 'org.slf4j:slf4j-api:1.7.29'
2121
implementation 'org.slf4j:slf4j-simple:1.7.29'

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

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
import com.intellij.openapi.progress.Task;
1313
import com.intellij.openapi.project.Project;
1414
import com.intellij.util.messages.MessageBus;
15-
import de.fraunhofer.iem.swan.Main;
16-
import de.fraunhofer.iem.swan.SwanPipeline;
1715
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
18-
import de.fraunhofer.iem.swan.assist.data.JSONFileParser;
19-
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
2016
import de.fraunhofer.iem.swan.assist.util.Constants;
17+
import de.fraunhofer.iem.swan.cli.CliRunner;
18+
import de.fraunhofer.iem.swan.cli.SwanCli;
2119
import de.fraunhofer.iem.swan.cli.SwanOptions;
20+
import de.fraunhofer.iem.swan.io.dataset.SrmList;
21+
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
2222
import org.apache.commons.io.FileUtils;
23-
import org.jaxen.util.SingletonList;
2423
import org.jetbrains.annotations.NotNull;
2524

2625
import java.io.File;
2726
import java.io.IOException;
2827
import java.time.LocalDateTime;
2928
import java.time.format.DateTimeFormatter;
30-
import java.util.ArrayList;
3129
import java.util.HashMap;
32-
import java.util.List;
3330
import java.util.ResourceBundle;
3431

3532
/**
@@ -40,11 +37,13 @@ public class RunSwanAnalysisImpl {
4037
private static HashMap<String, String> parameters;
4138
private Project project;
4239
private long duration;
40+
private SwanCli swan;
4341

4442
/**
4543
* Initializes builder.
44+
*
4645
* @param project Project on which the plugin is being used with
47-
* @param param Parameters that will be used as program arguments
46+
* @param param Parameters that will be used as program arguments
4847
*/
4948
RunSwanAnalysisImpl(Project project, HashMap<String, String> param) {
5049

@@ -61,7 +60,7 @@ public void run() {
6160

6261
File outputFolder = new File(parameters.get(Constants.OUTPUT_DIRECTORY));
6362

64-
if(!outputFolder.exists())
63+
if (!outputFolder.exists())
6564
outputFolder.mkdir();
6665

6766
/*File logFile = new File(outputFolder, currentTimestamp + parameters.get(Constants.OUTPUT_LOG));
@@ -83,27 +82,23 @@ public void run(@NotNull ProgressIndicator indicator) {
8382

8483
long start = System.currentTimeMillis();
8584

86-
SwanOptions options = new SwanOptions("", "", "",
87-
"/Users/rohith/Desktop/Work",
88-
new SingletonList("code"), "meka", new SingletonList("all"), new SingletonList("all"), false
89-
, true, 10, 0.7, "validate");
85+
SwanOptions options = new CliRunner().initializeOptions();
86+
options.setTestDataDir(parameters.get(Constants.SOURCE_DIRECTORY));
87+
options.setOutputDir( parameters.get(Constants.OUTPUT_DIRECTORY));
88+
options.setToolkit("meka");
89+
options.setPhase("predict");
90+
options.setTrainDataDir("");
9091

91-
SwanPipeline swan = new SwanPipeline(options);
92+
93+
swan = new SwanCli();
9294
try {
93-
swan.run();
94-
} catch (IOException e) {
95+
swan.run(options);
96+
} catch (IOException | InterruptedException e) {
9597
throw new RuntimeException(e);
96-
} catch (InterruptedException e) {
98+
} catch (Exception e) {
9799
throw new RuntimeException(e);
98100
}
99-
100-
101-
// Main.main(new String[]{parameters.get(Constants.SOURCE_DIRECTORY),
102-
// parameters.get(Constants.TRAIN_DIRECTORY),
103-
// parameters.get(Constants.CONFIGURATION_FILE),
104-
// });
105-
106-
duration = System.currentTimeMillis() - start;
101+
duration = System.currentTimeMillis() - start;
107102
}
108103

109104
@Override
@@ -115,21 +110,32 @@ public void onCancel() {
115110
public void onSuccess() {
116111
super.onSuccess();
117112

118-
System.out.println("FILE: "+parameters.get(Constants.OUTPUT_FILE));
113+
114+
SrmList srmList = swan.getSwanPipeline().getModelEvaluator().getPredictedSrmList();
115+
116+
String filename = parameters.get(Constants.OUTPUT_DIRECTORY) + File.separator + "srm-" + getCurrentTimestamp() + ".json";
117+
118+
try {
119+
SrmListUtils.exportFile(srmList, filename);
120+
} catch (IOException e) {
121+
throw new RuntimeException(e);
122+
}
123+
124+
119125
//Create copy of file
120-
copyFile(new File(parameters.get(Constants.OUTPUT_FILE)));
126+
/*copyFile(new File(parameters.get(Constants.OUTPUT_FILE)));
121127
122128
JSONFileParser parser = new JSONFileParser(parameters.get(Constants.OUTPUT_FILE));
123-
HashMap<String, MethodWrapper> exportedMethods = parser.parseJSONFileMap();
129+
HashMap<String, MethodWrapper> exportedMethods = parser.parseJSONFileMap();*/
124130

125131
HashMap<String, String> results = new HashMap<String, String>();
126-
results.put(Constants.OUTPUT_FILE, parameters.get(Constants.OUTPUT_FILE));
127-
results.put(Constants.OUTPUT_LOG, parameters.get(Constants.OUTPUT_LOG));
132+
results.put(Constants.OUTPUT_FILE, filename);
133+
results.put(Constants.OUTPUT_LOG, "");
128134

129135
int m = (int) (((duration / 1000) / 60) % 60);
130136
int s = (int) ((duration / 1000) % 60);
131137

132-
results.put(Constants.ANALYSIS_RESULT, exportedMethods.size() + " methods found in "+m+" mins "+s+ " secs");
138+
results.put(Constants.ANALYSIS_RESULT, srmList.getMethods().size() + " methods found in " + m + " mins " + s + " secs");
133139

134140
MessageBus messageBus = project.getMessageBus();
135141
SwanNotifier publisher = messageBus.syncPublisher(SwanNotifier.END_SWAN_PROCESS_TOPIC);
@@ -138,10 +144,10 @@ public void onSuccess() {
138144
});
139145
}
140146

141-
private void copyFile(File original ){
147+
private void copyFile(File original) {
142148

143149
File copied = new File(
144-
parameters.get(Constants.OUTPUT_DIRECTORY) + File.separator +getCurrentTimestamp()+ "-config.json");
150+
parameters.get(Constants.OUTPUT_DIRECTORY) + File.separator + getCurrentTimestamp() + "-config.json");
145151
try {
146152
FileUtils.copyFile(original, copied);
147153
} catch (IOException e) {
@@ -151,6 +157,7 @@ private void copyFile(File original ){
151157

152158
/**
153159
* Get the timestamp in a specified format.
160+
*
154161
* @return Formatted date
155162
*/
156163
private String getCurrentTimestamp() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ private void loadMethods() {
558558

559559
if (methods.size() > 0) {
560560

561-
DefaultMutableTreeNode root = new DefaultMutableTreeNode("<html><b>Classified Methods</b> <font color='gray'>[<i>" + JSONFileLoader.getConfigurationFile(false) + "</i>]</font></html>");
561+
DefaultMutableTreeNode root = new DefaultMutableTreeNode("<html><b>SRMs</b> <font color='gray'>[<i>" + JSONFileLoader.getConfigurationFile(false) + "</i>]</font></html>");
562562

563563
int methodCount = 0;
564564
int totalMethods = 0;
@@ -581,7 +581,7 @@ private void loadMethods() {
581581
String pattern = "###,###";
582582
DecimalFormat decimalFormat = new DecimalFormat(pattern);
583583

584-
root.setUserObject("<html><b>Classified Methods</b> <font color='gray'>(" + decimalFormat.format(totalMethods) + " in "+ decimalFormat.format(methods.size())+" classes)</font></html>");
584+
root.setUserObject("<html><b>SRMs</b> <font color='gray'>(" + decimalFormat.format(totalMethods) + " in "+ decimalFormat.format(methods.size())+" classes)</font></html>");
585585

586586
treeModel.setRoot(root);
587587
TREE_EXPANDED = false;

0 commit comments

Comments
 (0)