use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class TimelineFormatter method copyFile.
private static void copyFile(InputStream source, File dest) throws CucumberException {
OutputStream os = null;
try {
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = source.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
} catch (IOException e) {
throw new CucumberException("Unable to write to report file item: ", e);
} finally {
closeQuietly(os);
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class TimelineFormatter method copyReportFiles.
private void copyReportFiles() {
if (reportDir == null) {
return;
}
File outputDir = new File(reportDir.getPath());
for (String textAsset : TEXT_ASSETS) {
InputStream textAssetStream = getClass().getResourceAsStream(textAsset);
if (textAssetStream == null) {
throw new CucumberException("Couldn't find " + textAsset);
}
String fileName = new File(textAsset).getName();
copyFile(textAssetStream, new File(outputDir, fileName));
closeQuietly(textAssetStream);
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class JUnitFormatter method handleTestRunFinished.
private void handleTestRunFinished(TestRunFinished event) {
try {
Instant finished = event.getInstant();
// set up a transformer
rootElement.setAttribute("name", JUnitFormatter.class.getName());
rootElement.setAttribute("failures", String.valueOf(rootElement.getElementsByTagName("failure").getLength()));
rootElement.setAttribute("skipped", String.valueOf(rootElement.getElementsByTagName("skipped").getLength()));
rootElement.setAttribute("errors", "0");
rootElement.setAttribute("time", calculateTotalDurationString(Duration.between(started, finished)));
TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
closeQuietly(writer);
} catch (TransformerException e) {
throw new CucumberException("Error while transforming.", e);
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class JarUriFileSystemService method handleJarUriScheme.
private static CloseablePath handleJarUriScheme(URI uri) throws IOException, URISyntaxException {
String[] parts = uri.toString().split(JAR_URI_SEPARATOR);
// Regular jar schemes
if (parts.length <= 2) {
String jarUri = parts[0];
String jarPath = parts.length == 2 ? parts[1] : "/";
return open(new URI(jarUri), fileSystem -> fileSystem.getPath(jarPath));
}
// Spring boot jar scheme
String jarUri = parts[0];
String jarEntry = parts[1];
String subEntry = parts[2];
if (jarEntry.endsWith(JAR_FILE_SUFFIX)) {
throw new CucumberException(nestedJarEntriesExplanation(uri));
}
return open(new URI(jarUri), fileSystem -> fileSystem.getPath(jarEntry + subEntry));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class OptionsFileParser method parseFeatureWithLinesFile.
static Collection<FeatureWithLines> parseFeatureWithLinesFile(Path path) {
try {
List<FeatureWithLines> featurePaths = new ArrayList<>();
readAllLines(path).forEach(line -> {
Matcher matcher = RERUN_PATH_SPECIFICATION.matcher(line);
while (matcher.find()) {
featurePaths.add(FeatureWithLines.parse(matcher.group(1)));
}
});
return featurePaths;
} catch (Exception e) {
throw new CucumberException(format("Failed to parse '%s'", path), e);
}
}
Aggregations