Skip to content

Commit ffea409

Browse files
committed
Add run SecuCheck action, notifier and background task
1 parent 95479b5 commit ffea409

File tree

6 files changed

+136
-14
lines changed

6 files changed

+136
-14
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package de.fraunhofer.iem.swan.assist.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.actionSystem.CommonDataKeys;
6+
import com.intellij.openapi.progress.PerformInBackgroundOption;
7+
import com.intellij.openapi.progress.ProgressManager;
8+
import com.intellij.openapi.project.Project;
9+
import de.fraunhofer.iem.swan.assist.analysis.SecucheckBackgroundTask;
10+
import de.fraunhofer.iem.swan.assist.comm.SecucheckNotifier;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
public class RunSecucheckAction extends AnAction {
14+
15+
@Override
16+
public void actionPerformed(@NotNull AnActionEvent e) {
17+
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
18+
19+
ProgressManager.getInstance().run(new SecucheckBackgroundTask(project, "Running Taint Analysis with SecuCheck", true,
20+
PerformInBackgroundOption.ALWAYS_BACKGROUND));
21+
22+
SecucheckNotifier publisher = project.getMessageBus().syncPublisher(SecucheckNotifier.START_SECUCHECK_PROCESS_TOPIC);
23+
publisher.launchSecuCheck();
24+
25+
}
26+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package de.fraunhofer.iem.swan.assist.analysis;
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.SecucheckNotifier;
10+
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
12+
13+
import java.time.LocalDateTime;
14+
import java.time.format.DateTimeFormatter;
15+
import java.util.HashMap;
16+
import java.util.concurrent.TimeUnit;
17+
18+
public class SecucheckBackgroundTask extends Task.Backgroundable {
19+
20+
private Project project;
21+
private HashMap<String, String> parameters;
22+
private long duration;
23+
24+
public SecucheckBackgroundTask(@Nullable Project project, @NlsContexts.ProgressTitle @NotNull String title, boolean canBeCancelled, @Nullable PerformInBackgroundOption backgroundOption) {
25+
super(project, title, canBeCancelled, backgroundOption);
26+
this.project = project;
27+
}
28+
29+
@Override
30+
public void run(@NotNull ProgressIndicator indicator) {
31+
32+
long start = System.currentTimeMillis();
33+
34+
//TODO add implementation to run SecuCheck
35+
indicator.setText("Generating fluentTQL Specifications");
36+
37+
indicator.setText("Configuring SecuCheck");
38+
39+
try {
40+
TimeUnit.SECONDS.sleep(2);
41+
} catch (InterruptedException e) {
42+
throw new RuntimeException(e);
43+
}
44+
indicator.setText("Configuring analysis");
45+
46+
try {
47+
TimeUnit.SECONDS.sleep(2);
48+
} catch (InterruptedException e) {
49+
throw new RuntimeException(e);
50+
}
51+
indicator.setText("Exporting analysis results");
52+
53+
MessageBus messageBus = project.getMessageBus();
54+
SecucheckNotifier publisher = messageBus.syncPublisher(SecucheckNotifier.END_SECUCHECK_PROCESS_TOPIC);
55+
publisher.launchSecuCheck();
56+
}
57+
58+
/**
59+
* Get the timestamp in a specified format.
60+
*
61+
* @return Formatted date
62+
*/
63+
private String getCurrentTimestamp() {
64+
65+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HHmmss");
66+
return LocalDateTime.now().format(formatter);
67+
}
68+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2018 Fraunhofer IEM, Paderborn, Germany.
3+
*
4+
* Contributors:
5+
* Oshando Johnson (oshando.johnson@iem.fraunhofer.de ) - initial implementation
6+
******************************************************************************/
7+
8+
package de.fraunhofer.iem.swan.assist.comm;
9+
10+
import com.intellij.util.messages.Topic;
11+
12+
import java.util.HashMap;
13+
14+
/**
15+
* Provides notifications about SWAN.
16+
*/
17+
public interface SecucheckNotifier {
18+
19+
Topic<SecucheckNotifier> START_SECUCHECK_PROCESS_TOPIC = Topic.create("Start SecuCheck", SecucheckNotifier.class);
20+
Topic<SecucheckNotifier> END_SECUCHECK_PROCESS_TOPIC = Topic.create("Stop SecuCheck", SecucheckNotifier.class);
21+
22+
/**
23+
* Provides settings used to start SWAN or to access program logs/reports.
24+
*/
25+
void launchSecuCheck();
26+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ public void launchSwan(HashMap<String, String> values) {
385385
}
386386
});
387387

388+
//Update notification button when SWAN completes running
389+
bus.connect().subscribe(SecucheckNotifier.END_SECUCHECK_PROCESS_TOPIC, new SecucheckNotifier() {
390+
@Override
391+
public void launchSecuCheck() {
392+
Notification analysisCompleted = TOOL_GROUP.createNotification("",
393+
"SecuCheck results exported to "+PropertiesComponent.getInstance(project).getValue(Constants.OUTPUT_DIRECTORY),
394+
NotificationType.INFORMATION);
395+
Notifications.Bus.notify(analysisCompleted, project);
396+
}
397+
});
398+
388399
//Notify user that Suggest method process started or that the methods were generated
389400
bus.connect().subscribe(SuggestNotifier.SUGGEST_METHOD_TOPIC, new SuggestNotifier() {
390401

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
@@ -26,6 +26,7 @@ public class Constants {
2626
public final static String TRAIN_DIRECTORY = PLUGIN_ID + "trainingPath";
2727
public final static String SOURCE_DIRECTORY = PLUGIN_ID + "projectJarFiles"; //Test Library (or the project)
2828
public final static String CONFIGURATION_FILE = PLUGIN_ID + "configurationFile";
29+
public final static String LAST_SRM_LIST = PLUGIN_ID + "lastSrmList";
2930
public final static String SWAN_SETTINGS = PLUGIN_ID + "projectConfigured";
3031
public final static String OUTPUT_DIRECTORY = PLUGIN_ID + "outputPath";
3132
public final static String OUTPUT_FILE = PLUGIN_ID + "outputFile";

swan-assist/src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<group id="SWAN_Assist.ActionBar" text="SWAN_Assist" popup="false" >
2929

3030
<action id="SWAN_Assist.LaunchSWANAction"
31-
class="de.fraunhofer.iem.swan.assist.actions.RunSwanAnalysisAction"
31+
class="de.fraunhofer.iem.swan.assist.actions.RunSwanAction"
3232
icon="AllIcons.Toolwindows.ToolWindowRun"
3333
text="Run Analysis">
3434
</action>
@@ -49,19 +49,9 @@
4949
</action>
5050
<separator/>
5151

52-
<separator/>
53-
<action id="SWAN_Assist.ImportAction" class="de.fraunhofer.iem.swan.assist.actions.ImportAction"
54-
text="Import File"
55-
icon="PluginIcons.IMPORT_ACTION"
56-
description="Import configuration file">
57-
icon="AllIcons.ToolbarDecorator.Export"
58-
</action>
59-
60-
<action id="SWAN_Assist.ExportAction"
61-
class="de.fraunhofer.iem.swan.assist.actions.ExportAction"
62-
icon="PluginIcons.EXPORT_ACTION"
63-
text="Export File"
64-
description="Export configuration file">
52+
<action id="SWAN_Assist.RunSecuCheck"
53+
class="de.fraunhofer.iem.swan.assist.actions.RunSecucheckAction"
54+
text="Run Taint Analysis"
6555
popup="true" icon="AllIcons.Actions.RunAll">
6656
</action>
6757

0 commit comments

Comments
 (0)