Skip to content

Commit c6b1348

Browse files
authored
Merge pull request #59 from rohithsh/wip-swan-assist-java-and-gradle-upgrade
Bump SWAN from 1.3.0 to 3.2.0
2 parents 7336158 + 814879c commit c6b1348

File tree

9 files changed

+81
-38
lines changed

9 files changed

+81
-38
lines changed

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: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
import com.intellij.openapi.project.Project;
1414
import com.intellij.util.messages.MessageBus;
1515
import de.fraunhofer.iem.swan.Main;
16+
import de.fraunhofer.iem.swan.SwanPipeline;
1617
import de.fraunhofer.iem.swan.assist.comm.SwanNotifier;
1718
import de.fraunhofer.iem.swan.assist.data.JSONFileParser;
1819
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1920
import de.fraunhofer.iem.swan.assist.util.Constants;
21+
import de.fraunhofer.iem.swan.cli.SwanOptions;
2022
import org.apache.commons.io.FileUtils;
23+
import org.jaxen.util.SingletonList;
2124
import org.jetbrains.annotations.NotNull;
2225

2326
import java.io.File;
2427
import java.io.IOException;
2528
import java.time.LocalDateTime;
2629
import java.time.format.DateTimeFormatter;
30+
import java.util.ArrayList;
2731
import java.util.HashMap;
32+
import java.util.List;
2833
import java.util.ResourceBundle;
2934

3035
/**
@@ -78,10 +83,25 @@ public void run(@NotNull ProgressIndicator indicator) {
7883

7984
long start = System.currentTimeMillis();
8085

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)});
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");
90+
91+
SwanPipeline swan = new SwanPipeline(options);
92+
try {
93+
swan.run();
94+
} catch (IOException e) {
95+
throw new RuntimeException(e);
96+
} catch (InterruptedException e) {
97+
throw new RuntimeException(e);
98+
}
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+
// });
85105

86106
duration = System.currentTimeMillis() - start;
87107
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
import com.intellij.openapi.project.Project;
1212
import com.intellij.util.messages.MessageBus;
13-
import de.fraunhofer.iem.swan.FeatureHandler;
14-
import de.fraunhofer.iem.swan.IFeature;
15-
import de.fraunhofer.iem.swan.Parser;
13+
import de.fraunhofer.iem.swan.features.code.CodeFeatureHandler;
14+
import de.fraunhofer.iem.swan.features.FeatureSet;
15+
import de.fraunhofer.iem.swan.features.code.type.IFeature;
16+
import de.fraunhofer.iem.swan.io.dataset.SrmList;
17+
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
1618
import de.fraunhofer.iem.swan.assist.comm.SuggestNotifier;
1719
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1820
import de.fraunhofer.iem.swan.assist.data.TrainingFileManager;
@@ -45,13 +47,17 @@ public void run() {
4547

4648
Map<Method, Set<IFeature>> matrix = new HashMap<Method, Set<IFeature>>();
4749
Set<Method> methods = new HashSet<Method>();
50+
try {
51+
SrmList srmList = SrmListUtils.importFile(configFilePath);
52+
methods = srmList.getMethods();
53+
} catch (Exception e){
54+
e.printStackTrace();
55+
}
4856

49-
Parser parser = new Parser(configFilePath);
50-
parser.parse(configFilePath);
51-
methods = parser.methods();
52-
53-
FeatureHandler featureHandler = new FeatureHandler(projectPath);
54-
featureHandler.initializeFeatures(0);
57+
CodeFeatureHandler featureHandler = new CodeFeatureHandler();
58+
featureHandler.initializeFeatures();
59+
/*FeatureHandler featureHandler = new FeatureHandler(projectPath);
60+
featureHandler.initializeFeatures(0);*/
5561

5662
Set<IFeature> features = featureHandler.features().get(Category.NONE);
5763

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import java.util.HashSet;
1313
import java.util.Map;
1414
import java.util.Set;
15-
import de.fraunhofer.iem.swan.IFeature;
15+
import de.fraunhofer.iem.swan.features.code.type.IFeature;
1616
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1717
import de.fraunhofer.iem.swan.data.Method;
18-
import de.fraunhofer.iem.swan.features.WeightedFeature;
18+
import de.fraunhofer.iem.swan.features.code.type.WeightedFeature;
1919

2020

2121
public class Suggester {

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/data/JSONFileParser.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import com.intellij.notification.Notification;
1111
import com.intellij.notification.NotificationType;
1212
import com.intellij.notification.Notifications;
13-
import de.fraunhofer.iem.swan.Parser;
13+
import de.fraunhofer.iem.swan.io.dataset.SrmList;
14+
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
1415
import de.fraunhofer.iem.swan.assist.util.Constants;
1516
import de.fraunhofer.iem.swan.data.Method;
1617

@@ -62,11 +63,16 @@ public void setCongFilePath(String congFilePath) {
6263
* @return HashMap of methods
6364
*/
6465
public HashMap<String, MethodWrapper> parseJSONFileMap() {
65-
66-
Parser parser = new Parser(congFilePath);
66+
try {
67+
SrmList srmList = SrmListUtils.importFile(congFilePath);
68+
return parseMethods(srmList.getMethods());
69+
} catch (Exception e){
70+
e.printStackTrace();
71+
return null;
72+
}
73+
/*Parser parser = new Parser(congFilePath);
6774
parser.parse(congFilePath);
68-
69-
return parseMethods(parser.methods());
75+
return parseMethods(parser.methods());*/
7076
}
7177

7278
/**
@@ -75,9 +81,7 @@ public HashMap<String, MethodWrapper> parseJSONFileMap() {
7581
*/
7682
public HashMap<String, MethodWrapper> parseJSONFileStream(InputStreamReader streamReader) {
7783

78-
Parser parser = new Parser();
79-
parser.parseStream(streamReader);
80-
return parseMethods(parser.methods());
84+
return null;
8185
}
8286

8387
private HashMap<String, MethodWrapper> parseMethods(Set<Method> methodsSet){

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/data/JSONWriter.java

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

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

10-
import de.fraunhofer.iem.swan.Writer;
10+
import de.fraunhofer.iem.swan.io.dataset.SrmList;
11+
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
1112
import de.fraunhofer.iem.swan.data.Method;
1213

1314
import java.io.IOException;
@@ -34,7 +35,8 @@ public void writeToJsonFile(ArrayList<MethodWrapper> methods, String outputPath)
3435
methodSet.add(method.getMethod());
3536
}
3637

37-
Writer writer = new Writer();
38-
writer.outputJSONFile(methodSet, outputPath);
38+
SrmListUtils.exportFile(new SrmList(methodSet), outputPath);
39+
// Writer writer = new Writer();
40+
// writer.outputJSONFile(methodSet, outputPath);
3941
}
4042
}

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/data/MethodWrapper.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public MethodWrapper(Method method) {
6666
public MethodWrapper(String methodName, List<String> parameters, String returnType,
6767
String className) {
6868

69-
this.method = new Method(methodName, parameters, returnType, className);
69+
this.method = new Method(methodName, parameters, returnType);
7070
status = MethodStatus.NONE;
7171

7272
}
@@ -101,9 +101,9 @@ private String trimProperty(String property) {
101101
public String getMethodName(boolean fullyQualifiedName) {
102102

103103
if (!fullyQualifiedName)
104-
return trimProperty(method.getClassName() + "." + method.getMethodName());
104+
return trimProperty(method.getClassName() + "." + method.getName());
105105
else
106-
return method.getClassName() + "." + method.getMethodName();
106+
return method.getClassName() + "." + method.getName();
107107
}
108108

109109
/**
@@ -179,7 +179,7 @@ public ArrayList<String> getCWEList() {
179179

180180
ArrayList<String> cweList = new ArrayList<String>();
181181

182-
for (Category category : method.getCategoriesTrained()) {
182+
for (Category category : method.getAllCategories()) {
183183
if (category.isCwe()) {
184184
cweList.add(category.toString());
185185
}
@@ -197,7 +197,7 @@ public ArrayList<String> getTypesList(boolean capitalize) {
197197

198198
ArrayList<String> typesList = new ArrayList<String>();
199199

200-
for (Category category : method.getCategoriesTrained()) {
200+
for (Category category : method.getAllCategories()) {
201201
if (!category.isCwe() && !capitalize) {
202202
typesList.add(category.toString());
203203
} else if (!category.isCwe())
@@ -212,7 +212,7 @@ public ArrayList<String> getTypesList(boolean capitalize) {
212212
* @return Set of Method categories
213213
*/
214214
public Set<Category> getCategories() {
215-
return method.getCategoriesTrained();
215+
return method.getAllCategories();
216216
}
217217

218218
/**
@@ -221,7 +221,18 @@ public Set<Category> getCategories() {
221221
*/
222222
public void setCategories(Set<Category> categories) {
223223

224-
method.setCategoriesTrained(categories);
224+
Set<Category> cweCategories = null;
225+
Set<Category> srmCategories = null;
226+
for(Category category: categories) {
227+
if (category.isCwe()) {
228+
cweCategories.add(category);
229+
} else if (category.isNone()) {
230+
} else {
231+
srmCategories.add(category);
232+
}
233+
}
234+
method.setSrm(srmCategories);
235+
method.setCwe(cweCategories);
225236
}
226237

227238
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public MethodPropertiesDialog(Project project, MethodWrapper method) {
4343
Object[][] values = {{resourceBundle.getString("Properties.Return"), method.getReturnType(true)},
4444
{resourceBundle.getString("Properties.Method"), method.getMethodName(true)},
4545
{resourceBundle.getString("Properties.Parameters"), StringUtils.join(method.getParameters(true), ", ") },
46-
{resourceBundle.getString("Properties.Security"), method.getMethod().getSecLevel()},
46+
//{resourceBundle.getString("Properties.Security"), method.getMethod().getSecLevel()},
4747
{resourceBundle.getString("Properties.Discovery"), method.getMethod().getDiscovery()},
4848
{resourceBundle.getString("Properties.Framework"), method.getMethod().getFramework()},
4949
{resourceBundle.getString("Properties.CWE"), StringUtils.join(method.getCWEList(), ", ")},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void navigate(MouseEvent mouseEvent, PsiElement psiElement) {
7070
}
7171

7272
@Override
73-
public void collectSlowLineMarkers(@NotNull List<PsiElement> list, @NotNull Collection<LineMarkerInfo> collection) {
73+
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> list, @NotNull Collection<? super LineMarkerInfo<?>> collection) {
7474

7575
}
7676
}

0 commit comments

Comments
 (0)