Skip to content

Commit 3a7841a

Browse files
committed
ioexception handling and formatting
1 parent 44d8c4f commit 3a7841a

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

allure-generator/src/main/java/io/qameta/allure/allure1/Allure1Plugin.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private Step convert(final Path source,
316316
//Copy test status details to each step set the same status
317317
if (Objects.equals(status, testStatus)) {
318318
current.setStatusMessage(message);
319-
current.setStatusMessage(trace);
319+
current.setStatusTrace(trace);
320320
}
321321
return current;
322322
}
@@ -580,30 +580,32 @@ private Map<String, String> processEnvironmentProperties(final Path directory) {
580580
return readEnvironmentPropertiesUtf8(envPropsFile);
581581
} catch (CharacterCodingException e) {
582582
LOGGER.error("Failed to read {} as UTF-8, falling back to ISO-8859-1", envPropsFile, e);
583+
final Map<String, String> items = new LinkedHashMap<>();
584+
try (InputStream inputStream = Files.newInputStream(envPropsFile)) {
585+
propertiesToMap(items).load(inputStream);
586+
} catch (IOException ex) {
587+
LOGGER.error("Could not read environment.properties file {}", envPropsFile, ex);
588+
}
589+
return items;
583590
} catch (IOException e) {
584-
LOGGER.error("Failed to read {} using UTF-8 path, falling back to ISO-8859-1", envPropsFile, e);
585-
}
586-
587-
final Map<String, String> items = new LinkedHashMap<>();
588-
try (InputStream inputStream = Files.newInputStream(envPropsFile)) {
589-
propertiesToMap(items).load(inputStream);
590-
} catch (IOException e) {
591-
LOGGER.error("Could not read environment.properties file " + envPropsFile, e);
591+
LOGGER.error("Could not read environment.properties file {}", envPropsFile, e);
592+
return new LinkedHashMap<>();
592593
}
593-
return items;
594594
}
595595

596596
private Map<String, String> processEnvironmentXml(final Path directory) {
597597
final Path envXmlFile = directory.resolve("environment.xml");
598598
final Map<String, String> items = new LinkedHashMap<>();
599599
if (Files.exists(envXmlFile)) {
600-
try (InputStream envXmlInputStream = Files.newInputStream(envXmlFile)) {
601-
xmlMapper.readValue(envXmlInputStream, ru.yandex.qatools.commons.model.Environment.class)
602-
.getParameter().forEach(p ->
603-
items.put(p.getKey(), p.getValue())
600+
try (InputStream envXmlInputStream =
601+
Files.newInputStream(envXmlFile)) {
602+
xmlMapper
603+
.readValue(envXmlInputStream, ru.yandex.qatools.commons.model.Environment.class)
604+
.getParameter()
605+
.forEach(p -> items.put(p.getKey(), p.getValue())
604606
);
605607
} catch (Exception e) {
606-
LOGGER.error("Could not read environment.xml file " + envXmlFile.toAbsolutePath(), e);
608+
LOGGER.error("Could not read environment.xml file {}", envXmlFile.toAbsolutePath(), e);
607609
}
608610
}
609611
return items;

allure-generator/src/test/java/io/qameta/allure/allure1/Allure1PluginTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ void shouldFallbackToIso88591WhenUtf8DecodingFails() throws Exception {
407407
);
408408

409409
assertThat(env).containsEntry("name", "café");
410+
}
410411

411412
@Test
412413
void shouldNotAllowInvalidCharactersInAttachmentSource() throws IOException {

0 commit comments

Comments
 (0)