Skip to content

Commit

Permalink
Merge pull request #142 from imas/jena4
Browse files Browse the repository at this point in the history
upgrade depends libraries (jena 4.5)
  • Loading branch information
takemikami authored May 11, 2022
2 parents c0d57f9 + bc9db80 commit 0a68a28
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- name: Prepare git
run: git config --global core.autocrlf false
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '8'
java-version: '11'
- uses: actions/setup-node@v1
with:
node-version: '12'
Expand Down
32 changes: 16 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ plugins {
id 'pmd'
id 'jacoco'
id 'com.github.johnrengelman.shadow' version '4.0.3'
id 'com.github.spotbugs' version '4.0.5'
id 'com.github.spotbugs' version '4.7.0'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.jena:jena-arq:3.4.0'
implementation 'commons-cli:commons-cli:1.4'
implementation 'org.apache.jena:jena-arq:4.5.0'
implementation 'commons-cli:commons-cli:1.5.0'
implementation 'org.jline:jline:3.21.0'
implementation 'org.yaml:snakeyaml:1.23'
implementation 'org.codehaus.groovy:groovy:3.0.0-rc-3'
implementation 'org.yaml:snakeyaml:1.30'
implementation 'org.codehaus.groovy:groovy:3.0.10'
implementation 'org.slf4j:slf4j-log4j12:1.7.25'
implementation 'org.thymeleaf:thymeleaf:3.0.11.RELEASE'
implementation 'org.thymeleaf:thymeleaf:3.0.15.RELEASE'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.2.2'
implementation 'org.reflections:reflections:0.9.11'
implementation 'org.reflections:reflections:0.10.2'
implementation 'com.github.albfernandez:juniversalchardet:2.3.0'
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.8.1'
implementation group: 'org.topbraid', name: 'shacl', version: '1.3.0'
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.12.0'
implementation 'org.topbraid:shacl:1.3.0'

compileOnly 'net.jcip:jcip-annotations:1.0'
compileOnly 'com.github.spotbugs:spotbugs:4.0.2'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.0.2'
compileOnly 'com.github.spotbugs:spotbugs:4.7.0'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.0'

testImplementation 'junit:junit:4.+'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
Expand Down Expand Up @@ -62,7 +62,7 @@ pmd {
]
}
spotbugs {
toolVersion = '4.0.2'
toolVersion = '4.2.1'
}
jacocoTestCoverageVerification {
violationRules {
Expand All @@ -75,8 +75,8 @@ jacocoTestCoverageVerification {
}
tasks.withType(Checkstyle) {
reports {
xml.enabled = false
html.enabled = true
xml.enabled(false)
html.enabled(true)
}
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
Expand Down
3 changes: 3 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
before_install:
- sdk install java 11.0.10-open
- sdk use java 11.0.10-open
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public RdflintParser build() {
if (this.lang == Lang.RDFXML) {
return new RdflintParserRdfxml(this.body, this.validators, this.base);
}
return new RdflintParserTurtle(this.body, this.validators);
return new RdflintParserTurtle(this.body, this.validators, this.base);
}

}
105 changes: 56 additions & 49 deletions src/main/java/com/github/imas/rdflint/parser/RdflintParserRdfxml.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.graph.Triple;
import org.apache.jena.irix.IRIs;
import org.apache.jena.irix.SetupJenaIRI;
import org.apache.jena.rdf.model.RDFErrorHandler;
import org.apache.jena.rdfxml.xmlinput.ALiteral;
import org.apache.jena.rdfxml.xmlinput.ARP;
Expand All @@ -35,10 +37,9 @@
import org.apache.jena.riot.RiotException;
import org.apache.jena.riot.RiotParseException;
import org.apache.jena.riot.SysRIOT;
import org.apache.jena.riot.checker.CheckerLiterals;
import org.apache.jena.riot.lang.ReaderRIOTRDFXML;
import org.apache.jena.riot.system.Checker;
import org.apache.jena.riot.system.ErrorHandler;
import org.apache.jena.riot.system.IRIResolver;
import org.apache.jena.riot.system.StreamRDF;
import org.apache.jena.riot.system.StreamRDFLib;
import org.apache.jena.sparql.util.Context;
Expand All @@ -52,16 +53,16 @@ public class RdflintParserRdfxml extends RdflintParser {

String text;
List<RdfValidator> validators;
String baseUri;
String base;

/**
* constructor.
*/
public RdflintParserRdfxml(String text, List<RdfValidator> validators, String baseUri) {
public RdflintParserRdfxml(String text, List<RdfValidator> validators, String base) {
super();
this.text = text;
this.baseUri = baseUri;
this.validators = validators;
this.base = base;
}

@Override
Expand All @@ -76,9 +77,9 @@ public void parse(Graph g, List<LintProblem> problems) {

ContentType ct = Lang.RDFXML.getContentType();
InputStream validateIn = new ByteArrayInputStream(this.text.getBytes(StandardCharsets.UTF_8));
try {
reader.read(validateIn, baseUri, ct, StreamRDFLib.graph(g), context);

try {
reader.read(validateIn, this.base, ct, StreamRDFLib.graph(g), context);
if (!parseProblemList.isEmpty()) {
problems.addAll(parseProblemList);
return;
Expand Down Expand Up @@ -107,7 +108,8 @@ public void parse(Graph g, List<LintProblem> problems) {
static class ReaderRIOTRDFXML2 // SUPPRESS CHECKSTYLE AbbreviationAsWord
extends ReaderRIOTRDFXML { // SUPPRESS CHECKSTYLE AbbreviationAsWord

List<LintProblem> diagnosticList;
private final List<RdfValidator> models;
private final List<LintProblem> diagnosticList;

public ReaderRIOTRDFXML2(ErrorHandler errorHandler, List<RdfValidator> models) {
super(errorHandler);
Expand All @@ -116,36 +118,26 @@ public ReaderRIOTRDFXML2(ErrorHandler errorHandler, List<RdfValidator> models) {
this.diagnosticList = new LinkedList<>();
}

public List<LintProblem> getDiagnosticList() {
return this.diagnosticList;
}

private ARP arp = new ARP();
private InputStream input = null; // NOPMD
private Reader reader = null; // NOPMD
private String xmlBase;
private String filename;
private StreamRDF sink;
private ErrorHandler errorHandler;
private List<RdfValidator> models;
private Context context;

public List<LintProblem> getDiagnosticList() {
return this.diagnosticList;
}

/**
* Sort out the base URI for RDF/XML parsing.
*/
private static String baseURI_RDFXML( // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
String baseIRI) { // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
if (baseIRI == null) {
return SysRIOT.chooseBaseIRI();
} else {
// This normalizes the URI.
return SysRIOT.chooseBaseIRI(baseIRI);
}
}

@Override
public void read(InputStream in, String baseURI, // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
ContentType ct, StreamRDF output, Context context) {
public void read(
InputStream in,
String baseURI, // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
ContentType ct,
StreamRDF output,
Context context) {
this.input = in;
this.xmlBase = baseURI_RDFXML(baseURI);
this.filename = baseURI;
Expand All @@ -155,8 +147,12 @@ public void read(InputStream in, String baseURI, // SUPPRESS CHECKSTYLE Abbrevia
}

@Override
public void read(Reader reader, String baseURI, // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
ContentType ct, StreamRDF output, Context context) {
public void read(
Reader reader,
String baseURI, // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
ContentType ct,
StreamRDF output,
Context context) {
this.reader = reader;
this.xmlBase = baseURI_RDFXML(baseURI);
this.filename = baseURI;
Expand All @@ -165,6 +161,9 @@ public void read(Reader reader, String baseURI, // SUPPRESS CHECKSTYLE Abbreviat
parse();
}

// RDF 1.1 is based on URIs/IRIs, where space are not allowed.
// RDF 1.0 (and RDF/XML) was based on "RDF URI References" which did allow spaces.

// Use with TDB requires this to be "true" - it is set by InitTDB.
public static boolean RiotUniformCompatibility = false; // NOPMD
// Warnings in ARP that should be errors to be compatible with
Expand All @@ -183,7 +182,8 @@ public void read(Reader reader, String baseURI, // SUPPRESS CHECKSTYLE Abbreviat
private static boolean errorForSpaceInURI = true;

// Extracted from org.apache.jena.rdfxml.xmlinput.JenaReader
private void oneProperty(ARPOptions options, // SUPPRESS CHECKSTYLE ParameterName
private void oneProperty(
ARPOptions options,
String pName, // SUPPRESS CHECKSTYLE ParameterName
Object value) {
if (!pName.startsWith("ERR_") && !pName.startsWith("IGN_") && !pName.startsWith("WARN_")) {
Expand Down Expand Up @@ -244,15 +244,15 @@ public void parse() {
}

if (JenaRuntime.isRDF11) {
arp.getOptions().setIRIFactory(IRIResolver.iriFactory());
arp.getOptions().setIRIFactory(SetupJenaIRI.iriFactory_RDFXML());
}

if (context != null) {
Map<String, Object> properties = null;
try {
@SuppressWarnings("unchecked")
Map<String, Object> p = (Map<String, Object>) (context
.get(SysRIOT.sysRdfReaderProperties));
Map<String, Object> p = (Map<String, Object>) (context.get(
SysRIOT.sysRdfReaderProperties));
properties = p;
} catch (Throwable ex) {
Log.warn(this, "Problem accessing the RDF/XML reader properties: properties ignored", ex);
Expand All @@ -269,32 +269,42 @@ public void parse() {
} else {
arp.load(input, xmlBase);
}
} catch (IOException e) {
errorHandler.error(filename + ": " + ParseException.formatMessage(e), -1, -1); // NOPMD
} catch (SAXParseException e) {
// already reported.
} catch (IOException | SAXException | RiotParseException ex) {
errorHandler.error(filename + ": " + ParseException.formatMessage(ex), // NOPMD
arp.getLocator().getLineNumber(),
arp.getLocator().getColumnNumber());
} catch (SAXException sax) {
errorHandler.error(filename + ": " + ParseException.formatMessage(sax), -1, -1); // NOPMD
}
sink.finish();
}

/**
* Sort out the base URI for RDF/XML parsing.
*/
private static String baseURI_RDFXML( // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
String baseIRI) { // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
if (baseIRI == null) {
return IRIs.getBaseStr();
} else {
return IRIs.toBase(baseIRI);
}
}

private static class HandlerSink extends ARPSaxErrorHandler implements StatementHandler,
NamespaceHandler {

private StreamRDF output;
private ErrorHandler riotErrorHandler;
private CheckerLiterals checker;
private ARP arp;
private List<RdfValidator> models;
private List<LintProblem> diagnosticList;

HandlerSink(StreamRDF output, ErrorHandler errHandler, ARP arp,
List<RdfValidator> models, List<LintProblem> diagnosticList) {
super(new ErrorHandlerBridge(errHandler));
super(new ReaderRIOTRDFXML2.ErrorHandlerBridge(errHandler));
this.output = output;
this.riotErrorHandler = errHandler;
this.checker = new CheckerLiterals(errHandler);
this.arp = arp;
this.models = models;
this.diagnosticList = diagnosticList;
Expand Down Expand Up @@ -356,10 +366,8 @@ private Node convert(AResource r) {
int i = uriStr.indexOf(' ');
String s = uriStr.substring(0, i);
String msg = String.format("Bad character in IRI (space): <%s[space]...>", s);
int line = arp.getLocator().getLineNumber();
int col = arp.getLocator().getColumnNumber();
riotErrorHandler.error(msg, line, col);// NOPMD
throw new RiotParseException(msg, line, col);
riotErrorHandler.error(msg, -1, -1);
throw new RiotParseException(msg, -1, -1);
}
}
return NodeFactory.createURI(uriStr);
Expand All @@ -379,11 +387,11 @@ private Triple convert(AResource s, AResource p, AResource o) {
}

private Triple convert(AResource s, AResource p, ALiteral o) {
Node object = convert(o);
checker.check(object,
Node literal = convert(o);
Checker.checkLiteral(literal, riotErrorHandler,
arp.getLocator().getLineNumber(),
arp.getLocator().getColumnNumber());
return Triple.create(convert(s), convert(p), object);
return Triple.create(convert(s), convert(p), literal);
}

@Override
Expand Down Expand Up @@ -431,7 +439,6 @@ private static Pair<Integer, Integer> getLineCol(Exception e) {
}
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
import org.apache.jena.irix.IRIxResolver;
import org.apache.jena.query.ARQ;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFParserRegistry;
Expand All @@ -20,7 +21,6 @@
import org.apache.jena.riot.RiotParseException;
import org.apache.jena.riot.system.ErrorHandler;
import org.apache.jena.riot.system.FactoryRDF;
import org.apache.jena.riot.system.IRIResolver;
import org.apache.jena.riot.system.ParserProfileStd;
import org.apache.jena.riot.system.PrefixMap;
import org.apache.jena.riot.system.PrefixMapFactory;
Expand All @@ -40,7 +40,7 @@ static class RdflintParseProfile extends ParserProfileStd {
List<LintProblem> diagnosticList;
List<RdfValidator> validationModels;

public RdflintParseProfile(FactoryRDF factory, ErrorHandler errorHandler, IRIResolver resolver,
public RdflintParseProfile(FactoryRDF factory, ErrorHandler errorHandler, IRIxResolver resolver,
PrefixMap prefixMap, Context context, boolean checking, boolean strictMode,
List<RdfValidator> validationModels, List<LintProblem> diagnosticList) {
super(factory, errorHandler, resolver, prefixMap, context, checking, strictMode);
Expand Down Expand Up @@ -101,14 +101,16 @@ public Node create(Node currentGraph, Token token) {

String text;
List<RdfValidator> validators;
String base;

/**
* constructor.
*/
public RdflintParserTurtle(String text, List<RdfValidator> validators) {
public RdflintParserTurtle(String text, List<RdfValidator> validators, String base) {
super();
this.text = text;
this.validators = validators;
this.base = base;
}

@Override
Expand All @@ -118,8 +120,8 @@ public void parse(Graph g, List<LintProblem> problems) {
try {
// validation
FactoryRDF factory = RiotLib.factoryRDF();
IRIResolver resolver = IRIResolver.create();
PrefixMap prefixMap = PrefixMapFactory.createForInput();
IRIxResolver resolver = IRIxResolver.create().base(this.base).build();
PrefixMap prefixMap = PrefixMapFactory.create();
Context context = new Context();
boolean checking = true;
boolean strict = false;
Expand Down
Loading

0 comments on commit 0a68a28

Please sign in to comment.