1212import com .intellij .openapi .progress .Task ;
1313import com .intellij .openapi .project .Project ;
1414import com .intellij .util .messages .MessageBus ;
15- import de .fraunhofer .iem .swan .Main ;
16- import de .fraunhofer .iem .swan .SwanPipeline ;
1715import 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 ;
2016import de .fraunhofer .iem .swan .assist .util .Constants ;
17+ import de .fraunhofer .iem .swan .cli .CliRunner ;
18+ import de .fraunhofer .iem .swan .cli .SwanCli ;
2119import de .fraunhofer .iem .swan .cli .SwanOptions ;
20+ import de .fraunhofer .iem .swan .io .dataset .SrmList ;
21+ import de .fraunhofer .iem .swan .io .dataset .SrmListUtils ;
2222import org .apache .commons .io .FileUtils ;
23- import org .jaxen .util .SingletonList ;
2423import org .jetbrains .annotations .NotNull ;
2524
2625import java .io .File ;
2726import java .io .IOException ;
2827import java .time .LocalDateTime ;
2928import java .time .format .DateTimeFormatter ;
30- import java .util .ArrayList ;
3129import java .util .HashMap ;
32- import java .util .List ;
3330import 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 () {
0 commit comments