package codenizer.sonarqube.typescript;

public class AnalysisRunnerImpl implements AnalysisRunner {    
    public AnalysisResult[] Execute(String projectRootDirectory) {
        AnalysisResult[] result = new AnalysisResult[0];
        
       try {
           // 1) Set working directory to projectRootDirectory
           // 2) Call analyzer.js
           // 3) Parse result file
           Process p = Runtime.getRuntime().exec("node analyzer.js");
           
           p.waitFor();           
       }
       catch(Exception ex) {
           
       }
    
        return result;
    }
}
@@ -38,67 +38,225 @@
 t;%0A%0A
-public class AnalysisRunnerImpl implements AnalysisRunner %7B
+import java.io.File;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Apublic class AnalysisRunnerImpl implements AnalysisRunner %7B    %0A    private final Logger log = LoggerFactory.getLogger(this.getClass());%0A
     
@@ -549,64 +549,352 @@
     
-Process p = Runtime.getRuntime().exec(%22node analyzer.js%22
+%0A           String%5B%5D commands = new String%5B%5D %7B%0A               %22node%22,%0A               %22analyzer.js%22,%0A               %22**/*.ts%22    /* we can specify this glob because we're already in the source directory */%0A           %7D;%0A           %0A           Process p = Runtime.getRuntime().exec(commands, null /* inherit env */, new File(projectRootDirectory)
 );%0A 
@@ -914,16 +914,31 @@
         
+ int exitCode =
  p.waitF
@@ -942,16 +942,17 @@
 itFor();
+%0A
         
@@ -947,32 +947,363 @@
 ();%0A           %0A
+           if(exitCode != 0) %7B%0A               log.error(%22Running analyzer failed with exit code %22 + exitCode);%0A           %7D%0A           %0A           // Look for file in current directory%0A           String pathToResultFile = %22ts-analysis-results.json%22;%0A           %0A           result = AnalysisResultParser.FromFile(pathToResultFile);%0A
        %7D%0A       
@@ -1327,32 +1327,59 @@
 x) %7B%0A           
+log.error(ex.getMessage());
 %0A       %7D%0A    %0A 

Set working directory and command arguments