This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
/
TsLintExecutorImpl.java
57 lines (45 loc) · 1.88 KB
/
TsLintExecutorImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.pablissimo.sonar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.command.Command;
import org.sonar.api.utils.command.CommandExecutor;
import org.sonar.api.utils.command.StreamConsumer;
public class TsLintExecutorImpl implements TsLintExecutor {
private static final Logger LOG = LoggerFactory.getLogger(TsLintExecutorImpl.class);
private StringBuilder stdOut;
private StringBuilder stdErr;
public String execute(String pathToTsLint, String configFile, String rulesDir, String file, Integer timeoutMs) {
LOG.info("TsLint executing for " + file);
Command command = Command.create("node");
command.addArgument(pathToTsLint);
command.addArgument("--format");
command.addArgument("json");
if (rulesDir != null && rulesDir.length() > 0) {
command.addArgument("--rules-dir");
command.addArgument(rulesDir);
}
command.addArgument("--config");
command.addArgument(configFile);
command.addArgument(file.trim());
command.setNewShell(false);
this.stdOut = new StringBuilder();
this.stdErr = new StringBuilder();
StreamConsumer stdOutConsumer = new StreamConsumer() {
public void consumeLine(String line) {
LOG.trace("TsLint Out: " + line);
stdOut.append(line + "\n");
}
};
StreamConsumer stdErrConsumer = new StreamConsumer() {
public void consumeLine(String line) {
LOG.error("TsLint Err: " + line);
stdErr.append(line + "\n");
}
};
this.createExecutor().execute(command, stdOutConsumer, stdErrConsumer, timeoutMs);
return stdOut.toString();
}
protected CommandExecutor createExecutor() {
return CommandExecutor.create();
}
}