本文整理汇总了Java中org.sonar.api.utils.command.Command类的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于org.sonar.api.utils.command包,在下文中一共展示了Command类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyze
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
public void analyze(File configFile) throws IOException, XMLStreamException {
final Command command = Command.create(settings.getString(ColdFusionPlugin.CFLINT_JAVA));
addCflintJavaOpts(command);
command.addArgument("-jar")
.addArgument(extractCflintJar().getPath())
.addArgument("-xml")
.addArgument("-folder")
.addArgument(settings.getString("sonar.sources"))
.addArgument("-xmlfile")
.addArgument(fs.workDir() + File.separator + "cflint-result.xml")
.addArgument("-configfile")
.addArgument(configFile.getPath());
int exitCode = CommandExecutor.create().execute(command, new LogInfoStreamConsumer(), new LogErrorStreamConsumer(), Integer.MAX_VALUE);
if (exitCode != 0) {
throw new IllegalStateException("The CFLint analyzer failed with exit code: " + exitCode);
}
}
示例2: executesCommandWithCorrectArgumentsAndTimeouts
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void executesCommandWithCorrectArgumentsAndTimeouts() {
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
final ArrayList<Long> capturedTimeouts = new ArrayList<Long>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
capturedTimeouts.add((long) invocation.getArguments()[3]);
return 0;
}
};
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.executorImpl.execute(this.config, Arrays.asList(new String[] { "path/to/file", "path/to/another" }));
assertEquals(1, capturedCommands.size());
Command theCommand = capturedCommands.get(0);
long theTimeout = capturedTimeouts.get(0);
assertEquals("node path/to/tslint --format json --rules-dir path/to/rules --out path/to/temp --config path/to/config path/to/file path/to/another", theCommand.toCommandLine());
// Expect one timeout period per file processed
assertEquals(2 * 40000, theTimeout);
}
示例3: usesTypeCheckParameter_ifConfigSaysToUseTypeCheck
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void usesTypeCheckParameter_ifConfigSaysToUseTypeCheck() {
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
return 0;
}
};
this.config.setPathToTsConfig("path/to/tsconfig.json");
this.config.setShouldPerformTypeCheck(true);
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.executorImpl.execute(this.config, Arrays.asList(new String[] { "path/to/file", "path/to/another" }));
assertEquals(1, capturedCommands.size());
Command theCommand = capturedCommands.get(0);
assertEquals("node path/to/tslint --format json --rules-dir path/to/rules --out path/to/temp --config path/to/config --project path/to/tsconfig.json --type-check", theCommand.toCommandLine());
}
示例4: DoesNotAddRulesDirParameter_IfNull
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void DoesNotAddRulesDirParameter_IfNull() {
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
final ArrayList<Long> capturedTimeouts = new ArrayList<Long>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
capturedTimeouts.add((long) invocation.getArguments()[3]);
return 0;
}
};
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.config.setRulesDir(null);
this.executorImpl.execute(this.config, Arrays.asList(new String[] { "path/to/file" }));
Command theCommand = capturedCommands.get(0);
assertFalse(theCommand.toCommandLine().contains("--rules-dir"));
}
示例5: DoesNotAddRulesDirParameter_IfEmptyString
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void DoesNotAddRulesDirParameter_IfEmptyString() {
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
final ArrayList<Long> capturedTimeouts = new ArrayList<Long>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
capturedTimeouts.add((long) invocation.getArguments()[3]);
return 0;
}
};
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.config.setRulesDir("");
this.executorImpl.execute(this.config, Arrays.asList(new String[] { "path/to/file" }));
Command theCommand = capturedCommands.get(0);
assertFalse(theCommand.toCommandLine().contains("--rules-dir"));
}
示例6: addCflintJavaOpts
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
protected void addCflintJavaOpts(Command command) {
final String cflintJavaOpts = settings.getString(ColdFusionPlugin.CFLINT_JAVA_OPTS);
if (cflintJavaOpts != null) {
final String[] arguments = cflintJavaOpts.split(" ");
for (String argument : arguments) {
command.addArgument(argument);
}
}
}
示例7: getBaseCommand
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
private Command getBaseCommand(TsLintExecutorConfig config, String tempPath) {
Command command =
Command
.create(config.getPathToNode())
.addArgument(this.preparePath(config.getPathToTsLint()))
.addArgument("--format")
.addArgument("json");
String rulesDir = config.getRulesDir();
if (rulesDir != null && rulesDir.length() > 0) {
command
.addArgument("--rules-dir")
.addArgument(this.preparePath(rulesDir));
}
if (tempPath != null && tempPath.length() > 0) {
command
.addArgument("--out")
.addArgument(this.preparePath(tempPath));
}
command
.addArgument("--config")
.addArgument(this.preparePath(config.getConfigFile()));
if (config.useTsConfigInsteadOfFileList()) {
command
.addArgument("--project")
.addArgument(this.preparePath(config.getPathToTsConfig()));
}
if (config.shouldPerformTypeCheck()) {
command
.addArgument("--type-check");
}
command.setNewShell(false);
return command;
}
示例8: doesNotSendFileListToTsLint_ifConfigSaysToUseProjectFile
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void doesNotSendFileListToTsLint_ifConfigSaysToUseProjectFile() {
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
final ArrayList<Long> capturedTimeouts = new ArrayList<Long>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
capturedTimeouts.add((long) invocation.getArguments()[3]);
return 0;
}
};
this.config.setPathToTsConfig("path/to/tsconfig.json");
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.executorImpl.execute(this.config, Arrays.asList(new String[] { "path/to/file", "path/to/another" }));
assertEquals(1, capturedCommands.size());
Command theCommand = capturedCommands.get(0);
long theTimeout = capturedTimeouts.get(0);
assertEquals("node path/to/tslint --format json --rules-dir path/to/rules --out path/to/temp --config path/to/config --project path/to/tsconfig.json", theCommand.toCommandLine());
// Timeout should be just what we specified since we're not batching
assertEquals(40000, theTimeout);
}
示例9: BatchesExecutions_IfTooManyFilesForCommandLine
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
@Test
public void BatchesExecutions_IfTooManyFilesForCommandLine() {
List<String> filenames = new ArrayList<String>();
int currentLength = 0;
int standardCmdLength = "node path/to/tslint --format json --rules-dir path/to/rules --out path/to/temp --config path/to/config".length();
String firstBatch = "first batch";
while (currentLength + 12 < TsLintExecutorImpl.MAX_COMMAND_LENGTH - standardCmdLength) {
filenames.add(firstBatch);
currentLength += firstBatch.length() + 1; // 1 for the space
}
filenames.add("second batch");
final ArrayList<Command> capturedCommands = new ArrayList<Command>();
final ArrayList<Long> capturedTimeouts = new ArrayList<Long>();
Answer<Integer> captureCommand = new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
capturedCommands.add((Command) invocation.getArguments()[0]);
capturedTimeouts.add((long) invocation.getArguments()[3]);
return 0;
}
};
when(this.commandExecutor.execute(any(Command.class), any(StreamConsumer.class), any(StreamConsumer.class), any(long.class))).then(captureCommand);
this.executorImpl.execute(this.config, filenames);
assertEquals(2, capturedCommands.size());
Command theSecondCommand = capturedCommands.get(1);
assertFalse(theSecondCommand.toCommandLine().contains("first batch"));
assertTrue(theSecondCommand.toCommandLine().contains("second batch"));
}
示例10: execute
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
public void execute(String executable, String project, String solutionFile, File rulesetFile, File reportFile, int timeout) {
Command cmd = Command.create(getExecutable(executable))
.addArgument("/output=" + reportFile.getAbsolutePath())
.addArgument("/no-swea")
.addArgument("/project=" + project)
.addArgument("/profile=" + rulesetFile.getAbsolutePath())
.addArgument("/no-buildin-settings")
.addArgument(solutionFile);
int exitCode = CommandExecutor.create().execute(cmd, TimeUnit.MINUTES.toMillis(timeout));
if (exitCode != 0) {
throw new CommandException(cmd, "ReSharper execution failed with exit code: " + exitCode, null);
}
}
示例11: getCommandOutput
import org.sonar.api.utils.command.Command; //导入依赖的package包/类
private String getCommandOutput(Command thisCommand, StreamConsumer stdOutConsumer, StreamConsumer stdErrConsumer, File tslintOutputFile, Integer timeoutMs) {
this.createExecutor().execute(thisCommand, stdOutConsumer, stdErrConsumer, timeoutMs);
return getFileContent(tslintOutputFile);
}