* .ngrinder.model.User, org.ngrinder.model.IFileEntry, boolean,
* java.lang.String)
*/
@Override
public String validate(User user, IFileEntry scriptIEntry, boolean useScriptInSVN, String hostString) {
FileEntry scriptEntry = cast(scriptIEntry);
try {
checkNotNull(scriptEntry, "scriptEntity should be not null");
checkNotEmpty(scriptEntry.getPath(), "scriptEntity path should be provided");
if (!useScriptInSVN) {
checkNotEmpty(scriptEntry.getContent(), "scriptEntity content should be provided");
}
checkNotNull(user, "user should be provided");
// String result = checkSyntaxErrors(scriptEntry.getContent());
ScriptHandler handler = scriptHandlerFactory.getHandler(scriptEntry);
if (config.getControllerProperties().getPropertyBoolean(PROP_CONTROLLER_VALIDATION_SYNTAX_CHECK)) {
String result = handler.checkSyntaxErrors(scriptEntry.getPath(), scriptEntry.getContent());
LOGGER.info("Perform Syntax Check by {} for {}", user.getUserId(), scriptEntry.getPath());
if (result != null) {
return result;
}
}
File scriptDirectory = config.getHome().getScriptDirectory(user);
FileUtils.deleteDirectory(scriptDirectory);
Preconditions.checkTrue(scriptDirectory.mkdirs(), "Script directory {} creation is failed.");
ProcessingResultPrintStream processingResult = new ProcessingResultPrintStream(new ByteArrayOutputStream());
handler.prepareDist(0L, user, scriptEntry, scriptDirectory, config.getControllerProperties(), processingResult);
if (!processingResult.isSuccess()) {
return new String(processingResult.getLogByteArray());
}
File scriptFile = new File(scriptDirectory, FilenameUtils.getName(scriptEntry.getPath()));
if (useScriptInSVN) {
fileEntryService.writeContentTo(user, scriptEntry.getPath(), scriptDirectory);
} else {
FileUtils.writeStringToFile(scriptFile, scriptEntry.getContent(),
StringUtils.defaultIfBlank(scriptEntry.getEncoding(), "UTF-8"));
}
File doValidate = localScriptTestDriveService.doValidate(scriptDirectory, scriptFile, new Condition(),
config.isSecurityEnabled(), hostString, getTimeout());
List<String> readLines = FileUtils.readLines(doValidate);
StringBuilder output = new StringBuilder();