Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of jaxb #624

Merged
merged 1 commit into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions allure-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
compile('org.apache.tika:tika-core')
compile('commons-io:commons-io')
compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
compile('org.apache.httpcomponents:httpclient')
compileOnly('org.projectlombok:lombok')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.qameta.allure.allure1;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import io.qameta.allure.Reader;
import io.qameta.allure.context.RandomUidContext;
import io.qameta.allure.core.Configuration;
Expand All @@ -26,7 +30,6 @@
import ru.yandex.qatools.allure.model.TestCaseResult;
import ru.yandex.qatools.allure.model.TestSuiteResult;

import javax.xml.bind.JAXB;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
Expand All @@ -51,6 +54,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.fasterxml.jackson.databind.MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME;
import static io.qameta.allure.entity.LabelName.ISSUE;
import static io.qameta.allure.entity.LabelName.PACKAGE;
import static io.qameta.allure.entity.LabelName.PARENT_SUITE;
Expand All @@ -68,7 +72,6 @@
import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.nullsFirst;
import static java.util.stream.Collectors.toList;
import static org.allurefw.allure1.AllureUtils.unmarshalTestSuite;

/**
* Plugin that reads results from Allure1 data format.
Expand All @@ -90,7 +93,17 @@ public class Allure1Plugin implements Reader {
public static final String ENVIRONMENT_BLOCK_NAME = "environment";
public static final String ALLURE1_RESULTS_FORMAT = "allure1";

private final ObjectMapper mapper = new ObjectMapper();
private final ObjectMapper jsonMapper = new ObjectMapper();
private final ObjectMapper xmlMapper;

public Allure1Plugin() {
final SimpleModule module = new SimpleModule()
.addDeserializer(ru.yandex.qatools.allure.model.Status.class, new StatusDeserializer());
xmlMapper = new XmlMapper()
.configure(USE_WRAPPER_NAME_AS_PROPERTY_NAME, true)
.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))
.registerModule(module);
}

@Override
public void readResults(final Configuration configuration,
Expand Down Expand Up @@ -415,8 +428,8 @@ private Stream<TestSuiteResult> jsonFiles(final Path source) {
}

private Optional<TestSuiteResult> readXmlTestSuiteFile(final Path source) {
try {
return Optional.of(unmarshalTestSuite(source));
try (InputStream is = Files.newInputStream(source)) {
return Optional.of(xmlMapper.readValue(is, TestSuiteResult.class));
} catch (IOException e) {
LOGGER.debug("Could not read result {}: {}", source, e);
}
Expand All @@ -425,7 +438,7 @@ private Optional<TestSuiteResult> readXmlTestSuiteFile(final Path source) {

private Optional<TestSuiteResult> readJsonTestSuiteFile(final Path source) {
try (InputStream is = Files.newInputStream(source)) {
return Optional.of(mapper.readValue(is, TestSuiteResult.class));
return Optional.of(jsonMapper.readValue(is, TestSuiteResult.class));
} catch (IOException e) {
LOGGER.debug("Could not read result {}: {}", source, e);
return Optional.empty();
Expand Down Expand Up @@ -489,7 +502,7 @@ private Map<String, String> processEnvironmentXml(final Path directory) {
final Map<String, String> items = new HashMap<>();
if (Files.exists(envXmlFile)) {
try (InputStream fis = Files.newInputStream(envXmlFile)) {
JAXB.unmarshal(fis, ru.yandex.qatools.commons.model.Environment.class).getParameter().forEach(p ->
xmlMapper.readValue(fis, ru.yandex.qatools.commons.model.Environment.class).getParameter().forEach(p ->
items.put(p.getKey(), p.getValue())
);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.qameta.allure.allure1;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import ru.yandex.qatools.allure.model.Status;

import java.io.IOException;
import java.util.stream.Stream;

/**
* @author charlie (Dmitry Baev).
*/
public class StatusDeserializer extends StdDeserializer<Status> {

protected StatusDeserializer() {
super(io.qameta.allure.model.Status.class);
}

@Override
public Status deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
String value = p.readValueAs(String.class);
return Stream.of(Status.values())
.filter(status -> status.value().equalsIgnoreCase(value))
.findAny()
.orElse(null);
}
}
1 change: 1 addition & 0 deletions allure-plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply from: "${gradleScriptDir}/bintray.gradle"
apply plugin: 'maven'

dependencies {
compile('javax.xml.bind:jaxb-api')
compile('com.fasterxml.jackson.core:jackson-databind')
compile('com.fasterxml.jackson.module:jackson-module-jaxb-annotations')
compile('com.vladsch.flexmark:flexmark')
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ allprojects {
dependency 'commons-io:commons-io:2.5'
dependency 'io.qameta.allure:allure-java-commons:2.0-BETA18'
dependency 'io.qameta.allure:allure2-model-api:1.0-BETA4'
dependency 'javax.xml.bind:jaxb-api:2.3.0'
dependency 'junit:junit:4.12'
dependency 'org.allurefw:allure1-model:1.0'
dependency 'org.apache.commons:commons-lang3:3.6'
Expand Down