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

Add scalastyle dtos #9

Merged
merged 1 commit into from
Aug 29, 2024
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package io.codety.scanner.analyzer.scalastyle.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@JacksonXmlRootElement(localName = "checkstyle")
public class ScalastyleCheckstyle {

@JacksonXmlProperty(localName = "file")
@JacksonXmlElementWrapper(useWrapping = false)
private List<ScalastyleFile> file;
private double version;

private String version;

public List<ScalastyleFile> getFile() {
return file;
Expand All @@ -14,11 +25,11 @@ public void setFile(List<ScalastyleFile> file) {
this.file = file;
}

public double getVersion() {
public String getVersion() {
return version;
}

public void setVersion(double version) {
public void setVersion(String version) {
this.version = version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.codety.scanner.analyzer.scalastyle.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScalastyleCheckstyleEntry {

@JacksonXmlProperty(isAttribute = false)
private ScalastyleCheckstyle checkstyle;

public ScalastyleCheckstyle getCheckstyle() {
return checkstyle;
}

public void setCheckstyle(ScalastyleCheckstyle checkstyle) {
this.checkstyle = checkstyle;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package io.codety.scanner.analyzer.scalastyle.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScalastyleError {
private int line;
@JacksonXmlProperty(isAttribute = true)
private Integer line;
@JacksonXmlProperty(isAttribute = true)
private String source;
@JacksonXmlProperty(isAttribute = true)
private String severity;
@JacksonXmlProperty(isAttribute = true)
private String message;
private int column;
@JacksonXmlProperty(isAttribute = true)
private Integer column;

public int getLine() {
public Integer getLine() {
return line;
}

public void setLine(int line) {
public void setLine(Integer line) {
this.line = line;
}

Expand Down Expand Up @@ -39,11 +48,11 @@ public void setMessage(String message) {
this.message = message;
}

public int getColumn() {
public Integer getColumn() {
return column;
}

public void setColumn(int column) {
public void setColumn(Integer column) {
this.column = column;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package io.codety.scanner.analyzer.scalastyle.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScalastyleFile {

@JacksonXmlElementWrapper(useWrapping = false)
private List<ScalastyleError> error;
@JacksonXmlProperty(isAttribute = true)
private String name;

public List<ScalastyleError> getError() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.codety.scanner;

import io.codety.scanner.analyzer.scalastyle.dto.ScalastyleCheckstyle;
import io.codety.scanner.analyzer.scalastyle.dto.ScalastyleError;
import io.codety.scanner.analyzer.scalastyle.dto.ScalastyleFile;
import io.codety.scanner.util.XmlFactoryUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class ScalastyleDeserializationTest {

@Test
void testDeserialize() throws IOException {
URL resource = this.getClass().getResource("/scalastyle-issue-output-example.xml");
Path path = Path.of(resource.getPath());
String s = Files.readString(path);
ScalastyleCheckstyle scalastyleCheckstyle = XmlFactoryUtil.xmlMapper.readValue(s, ScalastyleCheckstyle.class);
Assertions.assertTrue(scalastyleCheckstyle.getFile().size() == 2);
for(ScalastyleFile file : scalastyleCheckstyle.getFile()){
Assertions.assertNotNull(file.getName());
List<ScalastyleError> errors = file.getError();
Assertions.assertTrue(errors.size() > 0);
for(ScalastyleError error : errors){
Assertions.assertTrue(error.getMessage().length() > 4);
Assertions.assertTrue(error.getSource().length() > 4);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.codety.scanner.util;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public class XmlFactoryUtil {
public static final XmlMapper xmlMapper = new XmlMapper();

;
}