55import api .messages .params .AnalyzeParams ;
66import api .messages .params .Params ;
77import com .ibm .wala .classLoader .Module ;
8+ import goblintserver .GoblintConfWatcher ;
89import goblintserver .GoblintServer ;
910import gobpie .GobPieConfiguration ;
1011import gobpie .GobPieException ;
2021import org .zeroturnaround .exec .InvalidExitValueException ;
2122import org .zeroturnaround .exec .ProcessExecutor ;
2223import org .zeroturnaround .exec .ProcessResult ;
23- import org .zeroturnaround .process .UnixProcess ;
24- import util .FileWatcher ;
2524
2625import java .io .File ;
2726import java .io .IOException ;
28- import java .nio .file .Path ;
2927import java .util .ArrayList ;
3028import java .util .Arrays ;
3129import java .util .Collection ;
5149
5250public class GoblintAnalysis implements ServerAnalysis {
5351
54- private final static int SIGINT = 2 ;
55-
5652 private final MagpieServer magpieServer ;
5753 private final GoblintServer goblintServer ;
5854 private final GoblintService goblintService ;
5955 private final GobPieConfiguration gobpieConfiguration ;
60- private final FileWatcher goblintConfWatcher ;
61-
62- private static boolean configValid = false ;
56+ private final GoblintConfWatcher goblintConfWatcher ;
6357 private static Future <?> lastAnalysisTask = null ;
6458
6559 private final Logger log = LogManager .getLogger (GoblintAnalysis .class );
6660
6761
68- public GoblintAnalysis (MagpieServer magpieServer , GoblintServer goblintServer , GoblintService goblintService , GobPieConfiguration gobpieConfiguration ) {
62+ public GoblintAnalysis (MagpieServer magpieServer , GoblintServer goblintServer , GoblintService goblintService , GobPieConfiguration gobpieConfiguration , GoblintConfWatcher goblintConfWatcher ) {
6963 this .magpieServer = magpieServer ;
7064 this .goblintServer = goblintServer ;
7165 this .goblintService = goblintService ;
7266 this .gobpieConfiguration = gobpieConfiguration ;
73- this .goblintConfWatcher = new FileWatcher ( Path . of ( gobpieConfiguration . getGoblintConf ())) ;
67+ this .goblintConfWatcher = goblintConfWatcher ;
7468 }
7569
7670
@@ -100,7 +94,7 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
10094 return ;
10195 }
10296
103- if (!goblintServer .getGoblintRunProcess (). getProcess (). isAlive ()) {
97+ if (!goblintServer .isAlive ()) {
10498 // Goblint server has crashed. Exit GobPie because without the server no analysis is possible.
10599 magpieServer .exit ();
106100 return ;
@@ -109,16 +103,14 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
109103 if (lastAnalysisTask != null && !lastAnalysisTask .isDone ()) {
110104 lastAnalysisTask .cancel (true );
111105 try {
112- abortAnalysis ();
106+ goblintServer . abortAnalysis ();
113107 log .info ("--------------- This analysis has been aborted -------------" );
114108 } catch (IOException e ) {
115109 log .error ("Aborting analysis failed." );
116110 }
117111 }
118112
119- refreshGoblintConfig ();
120-
121- if (!configValid ) {
113+ if (!goblintConfWatcher .refreshGoblintConfig ()) {
122114 return ;
123115 }
124116
@@ -144,40 +136,6 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
144136 }
145137
146138
147- /**
148- * Aborts the previous running analysis by sending a SIGINT signal to Goblint.
149- */
150- private void abortAnalysis () throws IOException {
151- Process goblintProcess = goblintServer .getGoblintRunProcess ().getProcess ();
152- int pid = Math .toIntExact (goblintProcess .pid ());
153- UnixProcess unixProcess = new UnixProcess (pid );
154- unixProcess .kill (SIGINT );
155- }
156-
157-
158- /**
159- * Reloads Goblint config if it has been changed or is currently invalid.
160- */
161- private void refreshGoblintConfig () {
162- if (goblintConfWatcher .checkModified () || !configValid ) {
163- configValid = goblintService .reset_config ()
164- .thenCompose (_res ->
165- goblintService .read_config (new Params (new File (gobpieConfiguration .getGoblintConf ()).getAbsolutePath ())))
166- .handle ((_res , ex ) -> {
167- if (ex != null ) {
168- Throwable cause = ex instanceof CompletionException ? ex .getCause () : ex ;
169- String msg = "Goblint was unable to successfully read the new configuration: " + cause .getMessage ();
170- magpieServer .forwardMessageToClient (new MessageParams (MessageType .Error , msg ));
171- log .error (msg );
172- return false ;
173- }
174- return true ;
175- })
176- .join ();
177- }
178- }
179-
180-
181139 /**
182140 * The method that is triggered before each analysis.
183141 * <p>
0 commit comments