From 0755c4a3d866c4affa2a9f7edd62951ad5f21450 Mon Sep 17 00:00:00 2001 From: Radek Burget Date: Tue, 25 Jul 2017 13:48:14 +0200 Subject: [PATCH 1/3] Ported from Sesame to RDF4J --- pom.xml | 64 +++++++------- vocab-builder-cli/pom.xml | 28 +++--- .../com/github/tkurz/sesame/vocab/Main.java | 16 ++-- vocab-builder-core/pom.xml | 36 ++++---- .../tkurz/sesame/vocab/VocabBuilder.java | 86 ++++++++++--------- .../vocab/test/AbstractVocabSpecificTest.java | 8 +- .../vocab/test/VocabBuilderCompileTest.java | 5 +- .../vocab/test/VocabBuilderPrefixTest.java | 5 +- .../test/VocabBuilderResourceBundleTest.java | 2 +- .../sesame/vocab/test/VocabBuilderTest.java | 53 ++++++------ .../test/VocabularyBuilderSpecialTest.java | 4 +- .../test/vocabularies/FoafVocabTest.java | 3 +- vocab-builder-maven-plugin/pom.xml | 28 +++--- .../vocab/plugin/VocabularyBuilderMojo.java | 17 ++-- 14 files changed, 179 insertions(+), 176 deletions(-) diff --git a/pom.xml b/pom.xml index b8f3e66..9731677 100644 --- a/pom.xml +++ b/pom.xml @@ -52,8 +52,8 @@ 2.3.3 UTF-8 UTF-8 - 2.7.11 - 1.7.7 + 2.2.2 + 1.7.25 @@ -68,8 +68,8 @@ maven-compiler-plugin 3.1 - 1.7 - 1.7 + 1.8 + 1.8 @@ -116,14 +116,14 @@ - org.openrdf.sesame - sesame-model - ${sesame.version} + org.eclipse.rdf4j + rdf4j-model + ${rdf4j.version} - org.openrdf.sesame - sesame-rio-api - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-api + ${rdf4j.version} commons-cli @@ -151,51 +151,51 @@ 4.3.3 - org.openrdf.sesame - sesame-rio-rdfxml - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-rdfxml + ${rdf4j.version} runtime - org.openrdf.sesame - sesame-rio-ntriples - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-ntriples + ${rdf4j.version} runtime - org.openrdf.sesame - sesame-rio-nquads - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-nquads + ${rdf4j.version} runtime - org.openrdf.sesame - sesame-rio-turtle - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-turtle + ${rdf4j.version} runtime - org.openrdf.sesame - sesame-rio-trig - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-trig + ${rdf4j.version} runtime - org.openrdf.sesame - sesame-rio-rdfjson - ${sesame.version} + org.eclipse.rdf4j + rdf4j-rio-rdfjson + ${rdf4j.version} runtime com.github.jsonld-java - jsonld-java-sesame - 0.3 + jsonld-java-tools + 0.10.0 runtime org.semarglproject - semargl-sesame - 0.6.1 + semargl-rdf4j + 0.7 runtime diff --git a/vocab-builder-cli/pom.xml b/vocab-builder-cli/pom.xml index fbf7409..ac94e3d 100644 --- a/vocab-builder-cli/pom.xml +++ b/vocab-builder-cli/pom.xml @@ -121,43 +121,43 @@ - org.openrdf.sesame - sesame-rio-rdfxml + org.eclipse.rdf4j + rdf4j-rio-rdfxml runtime - org.openrdf.sesame - sesame-rio-ntriples + org.eclipse.rdf4j + rdf4j-rio-ntriples runtime - org.openrdf.sesame - sesame-rio-nquads + org.eclipse.rdf4j + rdf4j-rio-nquads runtime - org.openrdf.sesame - sesame-rio-turtle + org.eclipse.rdf4j + rdf4j-rio-turtle runtime - org.openrdf.sesame - sesame-rio-trig + org.eclipse.rdf4j + rdf4j-rio-trig runtime - org.openrdf.sesame - sesame-rio-rdfjson + org.eclipse.rdf4j + rdf4j-rio-rdfjson runtime com.github.jsonld-java - jsonld-java-sesame + jsonld-java-tools runtime org.semarglproject - semargl-sesame + semargl-rdf4j runtime diff --git a/vocab-builder-cli/src/main/java/com/github/tkurz/sesame/vocab/Main.java b/vocab-builder-cli/src/main/java/com/github/tkurz/sesame/vocab/Main.java index bb08913..ffa5375 100644 --- a/vocab-builder-cli/src/main/java/com/github/tkurz/sesame/vocab/Main.java +++ b/vocab-builder-cli/src/main/java/com/github/tkurz/sesame/vocab/Main.java @@ -10,8 +10,11 @@ import org.apache.http.client.methods.RequestBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.rio.*; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; +import org.eclipse.rdf4j.rio.RDFParserRegistry; +import org.eclipse.rdf4j.rio.Rio; +import org.eclipse.rdf4j.rio.UnsupportedRDFormatException; import com.google.common.base.CaseFormat; @@ -67,14 +70,15 @@ public static void main(String[] args) { throw new ParseException("too many arguments"); } - RDFFormat format = Rio.getParserFormatForMIMEType(cli.getOptionValue('f', null)); + RDFFormat format = Rio.getParserFormatForMIMEType(cli.getOptionValue('f', null)).orElse(null); final VocabBuilder builder; if (input.startsWith("http://")) { URL url = new URL(input); //try to guess format - format = RDFFormat.forFileName(url.getFile()); + //format = RDFFormat.forFileName(url.getFile()); + format = Rio.getParserFormatForMIMEType(url.getFile()).orElse(null); tempFile = Files.createTempFile("vocab-builder", "." + (format != null ? format.getDefaultFileExtension() : "cache")); @@ -172,8 +176,6 @@ public static void main(String[] args) { System.err.println("Could not read input-file: " + e.getMessage()); } catch (IOException e) { System.err.println("Error during file-access: " + e.getMessage()); - } catch (GraphUtilException e) { - e.printStackTrace(); } catch (GenerationException e) { System.err.println(e.getMessage()); } finally { @@ -206,7 +208,7 @@ private static void printHelp(String error) { w.close(); } - @SuppressWarnings({"AccessStaticViaInstance", "static-access"}) + @SuppressWarnings({"static-access"}) private static Options getCliOpts() { Options o = new Options(); diff --git a/vocab-builder-core/pom.xml b/vocab-builder-core/pom.xml index 2f35156..98ca391 100644 --- a/vocab-builder-core/pom.xml +++ b/vocab-builder-core/pom.xml @@ -27,12 +27,12 @@ - org.openrdf.sesame - sesame-model + org.eclipse.rdf4j + rdf4j-model - org.openrdf.sesame - sesame-rio-api + org.eclipse.rdf4j + rdf4j-rio-api org.apache.commons @@ -59,43 +59,43 @@ test - org.openrdf.sesame - sesame-rio-rdfxml + org.eclipse.rdf4j + rdf4j-rio-rdfxml test - org.openrdf.sesame - sesame-rio-ntriples + org.eclipse.rdf4j + rdf4j-rio-ntriples test - org.openrdf.sesame - sesame-rio-nquads + org.eclipse.rdf4j + rdf4j-rio-nquads test - org.openrdf.sesame - sesame-rio-turtle + org.eclipse.rdf4j + rdf4j-rio-turtle test - org.openrdf.sesame - sesame-rio-trig + org.eclipse.rdf4j + rdf4j-rio-trig test - org.openrdf.sesame - sesame-rio-rdfjson + org.eclipse.rdf4j + rdf4j-rio-rdfjson test com.github.jsonld-java - jsonld-java-sesame + jsonld-java-tools test org.semarglproject - semargl-sesame + semargl-rdf4j test diff --git a/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java b/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java index 48185aa..ffdc385 100644 --- a/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java +++ b/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java @@ -1,18 +1,26 @@ package com.github.tkurz.sesame.vocab; import com.google.common.collect.Sets; -import info.aduna.io.MavenUtil; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; -import org.openrdf.model.*; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.model.util.GraphUtil; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.model.vocabulary.*; -import org.openrdf.rio.RDFFormat; -import org.openrdf.rio.RDFParseException; -import org.openrdf.rio.Rio; +import org.eclipse.rdf4j.common.io.MavenUtil; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Model; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.util.GraphUtil; +import org.eclipse.rdf4j.model.vocabulary.DC; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.OWL; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.vocabulary.SKOS; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; +import org.eclipse.rdf4j.rio.Rio; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,8 +50,8 @@ public class VocabBuilder { private static final Logger log = LoggerFactory.getLogger(VocabBuilder.class); - private static final URI[] COMMENT_PROPERTIES = new URI[]{RDFS.COMMENT, DCTERMS.DESCRIPTION, SKOS.DEFINITION, DC.DESCRIPTION}; - private static final URI[] LABEL_PROPERTIES = new URI[]{RDFS.LABEL, DCTERMS.TITLE, DC.TITLE, SKOS.PREF_LABEL, SKOS.ALT_LABEL}; + private static final IRI[] COMMENT_PROPERTIES = new IRI[]{RDFS.COMMENT, DCTERMS.DESCRIPTION, SKOS.DEFINITION, DC.DESCRIPTION}; + private static final IRI[] LABEL_PROPERTIES = new IRI[]{RDFS.LABEL, DCTERMS.TITLE, DC.TITLE, SKOS.PREF_LABEL, SKOS.ALT_LABEL}; private String name = null; private String prefix = null; private String packageName = null; @@ -65,7 +73,7 @@ public class VocabBuilder { * @throws RDFParseException if the format of the vocab could not be detected or is unknown. */ public VocabBuilder(String filename, String format) throws IOException, RDFParseException { - this(filename, format != null ? Rio.getParserFormatForMIMEType(format) : null); + this(filename, format != null ? Rio.getParserFormatForMIMEType(format).orElse(null) : null); } public VocabBuilder(String filename, RDFFormat format) throws IOException, RDFParseException { @@ -73,7 +81,7 @@ public VocabBuilder(String filename, RDFFormat format) throws IOException, RDFPa if (!Files.exists(file)) throw new FileNotFoundException(filename); if (format == null) { - format = Rio.getParserFormatForFileName(filename); + format = Rio.getParserFormatForFileName(filename).orElse(null); log.trace("detected input format from filename {}: {}", filename, format); } @@ -89,7 +97,7 @@ public VocabBuilder(String filename, RDFFormat format) throws IOException, RDFPa } } - public void generate(OutputStream outputStream) throws GenerationException, IOException, GraphUtilException { + public void generate(OutputStream outputStream) throws GenerationException, IOException { String cName = getName(); if (StringUtils.isBlank(cName)) { throw new GenerationException("could not detect name, please set explicitly"); @@ -100,7 +108,7 @@ public void generate(OutputStream outputStream) throws GenerationException, IOEx generate(cName, new PrintWriter(outputStream)); } - public void generate(Path output) throws IOException, GraphUtilException, GenerationException { + public void generate(Path output) throws IOException, GenerationException { final String className = output.getFileName().toString().replaceFirst("\\.java$", ""); try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(output, StandardCharsets.UTF_8))) { generate(className, out); @@ -110,7 +118,7 @@ public void generate(Path output) throws IOException, GraphUtilException, Genera /** * */ - public void generate(String className, PrintWriter out) throws IOException, GraphUtilException, GenerationException { + public void generate(String className, PrintWriter out) throws IOException, GenerationException { log.trace("classname: {}", className); if (StringUtils.isBlank(name)) { name = className; @@ -122,13 +130,13 @@ public void generate(String className, PrintWriter out) throws IOException, Grap } Pattern pattern = Pattern.compile(Pattern.quote(getPrefix()) + "(.+)"); - ConcurrentMap splitUris = new ConcurrentHashMap<>(); + ConcurrentMap splitUris = new ConcurrentHashMap<>(); for (Resource nextSubject : model.subjects()) { - if (nextSubject instanceof URI) { + if (nextSubject instanceof IRI) { Matcher matcher = pattern.matcher(nextSubject.stringValue()); if (matcher.find()) { String k = matcher.group(1); - URI putIfAbsent = splitUris.putIfAbsent(k, (URI) nextSubject); + IRI putIfAbsent = splitUris.putIfAbsent(k, (IRI) nextSubject); if (putIfAbsent != null) { log.warn("Conflicting keys found: uri={} key={} existing={}", nextSubject.stringValue(), k, putIfAbsent); @@ -144,12 +152,12 @@ public void generate(String className, PrintWriter out) throws IOException, Grap out.printf("package %s;%n%n", getPackageName()); } //imports - out.println("import org.openrdf.model.URI;"); - out.println("import org.openrdf.model.ValueFactory;"); - out.println("import org.openrdf.model.impl.ValueFactoryImpl;"); + out.println("import org.eclipse.rdf4j.model.IRI;"); + out.println("import org.eclipse.rdf4j.model.ValueFactory;"); + out.println("import org.eclipse.rdf4j.model.impl.SimpleValueFactory;"); out.println(); - final URI pfx = new URIImpl(prefix); + final IRI pfx = SimpleValueFactory.getInstance().createIRI(prefix); Literal oTitle = getFirstExistingObjectLiteral(model, pfx, getPreferredLanguage(), LABEL_PROPERTIES); Literal oDescr = getFirstExistingObjectLiteral(model, pfx, getPreferredLanguage(), COMMENT_PROPERTIES); Set oSeeAlso = model.filter(pfx, RDFS.SEEALSO, null).objects(); @@ -169,7 +177,7 @@ public void generate(String className, PrintWriter out) throws IOException, Grap if (!oSeeAlso.isEmpty()) { out.println(" *"); for (Value s : oSeeAlso) { - if (s instanceof URI) { + if (s instanceof IRI) { out.printf(" * @see %s%n", s.stringValue(), s.stringValue()); } } @@ -243,17 +251,17 @@ public void generate(String className, PrintWriter out) throws IOException, Grap String nextKey = cleanKey(doCaseFormatting(key, getConstantCase())); checkField(className, nextKey); - out.printf(getIndent(1) + "public static final URI %s;%n", nextKey); + out.printf(getIndent(1) + "public static final IRI %s;%n", nextKey); out.println(); } //static init out.println(getIndent(1) + "static {"); - out.printf(getIndent(2) + "ValueFactory factory = ValueFactoryImpl.getInstance();%n"); + out.printf(getIndent(2) + "ValueFactory factory = SimpleValueFactory.getInstance();%n"); out.println(); for (String key : keys) { String nextKey = cleanKey(doCaseFormatting(key, getConstantCase())); - out.printf(getIndent(2) + "%s = factory.createURI(%s.NAMESPACE, \"%s\");%n", nextKey, className, key); + out.printf(getIndent(2) + "%s = factory.createIRI(%s.NAMESPACE, \"%s\");%n", nextKey, className, key); } out.println(getIndent(1) + "}"); out.println(); @@ -297,13 +305,13 @@ public void generateResourceBundle(String baseName, Path bundleDir) throws Gener public HashMap generateResourceBundle(String baseName) throws GenerationException { Pattern pattern = Pattern.compile(Pattern.quote(getPrefix()) + "(.+)"); - HashMap splitUris = new HashMap<>(); + HashMap splitUris = new HashMap<>(); for (Resource nextSubject : model.subjects()) { - if (nextSubject instanceof URI) { + if (nextSubject instanceof IRI) { Matcher matcher = pattern.matcher(nextSubject.stringValue()); if (matcher.find()) { String k = matcher.group(1); - splitUris.put(k, (URI) nextSubject); + splitUris.put(k, (IRI) nextSubject); } } } @@ -316,14 +324,14 @@ public HashMap generateResourceBundle(String baseName) throw // Default we have for sure bundles.put(baseName, new Properties()); for (String key : keys) { - final URI resource = splitUris.get(key); + final IRI resource = splitUris.get(key); String nextKey = cleanKey(doCaseFormatting(key, getConstantCase())); - for (URI p : LABEL_PROPERTIES) { + for (IRI p : LABEL_PROPERTIES) { for (Value v : GraphUtil.getObjects(model, resource, p)) { if (v instanceof Literal) { final Literal lit = (Literal) v; - final String lang = lit.getLanguage(); + final String lang = lit.getLanguage().orElse(null); final Properties bundle; if (lang == null) { bundle = bundles.get(baseName); @@ -341,11 +349,11 @@ public HashMap generateResourceBundle(String baseName) throw } } - for (URI p : COMMENT_PROPERTIES) { + for (IRI p : COMMENT_PROPERTIES) { for (Value v : GraphUtil.getObjects(model, resource, p)) { if (v instanceof Literal) { final Literal lit = (Literal) v; - final String lang = lit.getLanguage(); + final String lang = lit.getLanguage().orElse(null); final Properties bundle; if (lang == null) { bundle = bundles.get(baseName); @@ -387,8 +395,8 @@ private String getIndent(int level) { return StringUtils.repeat(getIndent(), level); } - private Literal getFirstExistingObjectLiteral(Model model, Resource subject, String lang, URI... predicates) throws GraphUtilException { - for (URI predicate : predicates) { + private Literal getFirstExistingObjectLiteral(Model model, Resource subject, String lang, IRI... predicates) { + for (IRI predicate : predicates) { Literal literal = getOptionalObjectLiteral(model, subject, predicate, lang); if (literal != null) { return literal; @@ -398,7 +406,7 @@ private Literal getFirstExistingObjectLiteral(Model model, Resource subject, Str } private Literal getOptionalObjectLiteral(Model model, Resource subject, - URI predicate, String lang) { + IRI predicate, String lang) { Set objects = GraphUtil.getObjects(model, subject, predicate); Literal result = null; @@ -406,7 +414,7 @@ private Literal getOptionalObjectLiteral(Model model, Resource subject, for (Value nextValue : objects) { if (nextValue instanceof Literal) { final Literal literal = (Literal) nextValue; - if (result == null || (lang != null && lang.equals(literal.getLanguage()))) { + if (result == null || (lang != null && lang.equals(literal.getLanguage().orElse(null)))) { result = literal; } } diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/AbstractVocabSpecificTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/AbstractVocabSpecificTest.java index 31c4f64..2490271 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/AbstractVocabSpecificTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/AbstractVocabSpecificTest.java @@ -4,14 +4,13 @@ import com.github.tkurz.sesame.vocab.GenerationException; import com.github.tkurz.sesame.vocab.VocabBuilder; import org.apache.commons.io.FileUtils; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.rio.RDFFormat; -import org.openrdf.rio.RDFParseException; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; @@ -42,10 +41,7 @@ public void setUp() throws IOException { Assert.fail("Could not generate vocab " + e.getMessage()); } catch (RDFParseException e) { Assert.fail("Could not parse test-file: " + e.getMessage()); - } catch (GraphUtilException e) { - Assert.fail("Could not read vocabulary: " + e.getMessage()); } - } protected abstract InputStream getInputStream(); diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderCompileTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderCompileTest.java index 9a86cd1..bced9d2 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderCompileTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderCompileTest.java @@ -4,13 +4,12 @@ import com.github.tkurz.sesame.vocab.GenerationException; import com.github.tkurz.sesame.vocab.VocabBuilder; import org.apache.commons.io.FileUtils; +import org.eclipse.rdf4j.rio.RDFParseException; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.rio.RDFParseException; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; @@ -41,8 +40,6 @@ public void setUp() throws IOException { Assert.fail("Could not generate vocab " + e.getMessage()); } catch (RDFParseException e) { Assert.fail("Could not parse test-file: " + e.getMessage()); - } catch (GraphUtilException e) { - Assert.fail("Could not read vocabulary: " + e.getMessage()); } } diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderPrefixTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderPrefixTest.java index 5a3be78..c32dcd8 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderPrefixTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderPrefixTest.java @@ -3,12 +3,11 @@ import com.github.tkurz.sesame.vocab.GenerationException; import com.github.tkurz.sesame.vocab.VocabBuilder; +import org.eclipse.rdf4j.rio.RDFParseException; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.rio.RDFParseException; import java.io.File; import java.io.IOException; @@ -59,8 +58,6 @@ public void testVocabBuilder() throws IOException { Assert.fail("Could not generate vocab " + e.getMessage()); } catch (RDFParseException e) { Assert.fail("Could not parse test-file: " + e.getMessage()); - } catch (GraphUtilException e) { - Assert.fail("Could not read vocabulary: " + e.getMessage()); } } diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderResourceBundleTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderResourceBundleTest.java index fe24166..8e35b8f 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderResourceBundleTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderResourceBundleTest.java @@ -3,13 +3,13 @@ import com.github.tkurz.sesame.vocab.GenerationException; import com.github.tkurz.sesame.vocab.VocabBuilder; import org.apache.commons.io.FileUtils; +import org.eclipse.rdf4j.rio.RDFParseException; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.openrdf.rio.RDFParseException; import java.io.BufferedReader; import java.io.File; diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderTest.java index 0c6a6bf..d1ad3ab 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabBuilderTest.java @@ -5,6 +5,22 @@ import com.github.tkurz.sesame.vocab.VocabBuilder; import com.google.common.base.CaseFormat; + +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Model; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.LinkedHashModel; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.OWL; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.vocabulary.SKOS; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParserRegistry; +import org.eclipse.rdf4j.rio.Rio; +import org.eclipse.rdf4j.rio.UnsupportedRDFormatException; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -13,17 +29,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.openrdf.model.Literal; -import org.openrdf.model.Model; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.LinkedHashModel; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.*; -import org.openrdf.rio.RDFFormat; -import org.openrdf.rio.RDFParserRegistry; -import org.openrdf.rio.Rio; -import org.openrdf.rio.UnsupportedRDFormatException; import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -68,15 +73,15 @@ public static Collection data() { private Path testDir; - private URI testOntologyUri; + private IRI testOntologyUri; - private URI testProperty1; + private IRI testProperty1; - private URI testProperty2; + private IRI testProperty2; - private URI testProperty3; + private IRI testProperty3; - private URI testProperty4; + private IRI testProperty4; private Literal testProperty1Description; @@ -100,14 +105,14 @@ public VocabBuilderTest(RDFFormat format) { public void setUp() throws Exception { testDir = tempDir.newFolder("vocabbuildertest").toPath(); - ValueFactory vf = ValueFactoryImpl.getInstance(); + ValueFactory vf = SimpleValueFactory.getInstance(); String ns = "http://example.com/ns/ontology#"; - testOntologyUri = vf.createURI(ns); - testProperty1 = vf.createURI(ns, "property1"); - testProperty2 = vf.createURI(ns, "property_2"); - testProperty3 = vf.createURI(ns, "property-3"); - testProperty4 = vf.createURI(ns, "propertyLocalised4"); + testOntologyUri = vf.createIRI(ns); + testProperty1 = vf.createIRI(ns, "property1"); + testProperty2 = vf.createIRI(ns, "property_2"); + testProperty3 = vf.createIRI(ns, "property-3"); + testProperty4 = vf.createIRI(ns, "propertyLocalised4"); testProperty1Description = vf.createLiteral("property 1 description"); testProperty2Description = vf.createLiteral("property 2 description"); testProperty3Description = vf.createLiteral("property 3 description"); @@ -184,7 +189,7 @@ public final void testUpperUnderscoreCase() throws Exception { Files.copy(javaFilePath, out); String result = new String(out.toByteArray(), StandardCharsets.UTF_8); assertTrue("Did not find expected key case", result.contains("PROPERTY_LOCALISED4 = ")); - assertTrue("Did not find original URI", result.contains("\"propertyLocalised4\"")); + assertTrue("Did not find original IRI", result.contains("\"propertyLocalised4\"")); } /** @@ -207,7 +212,7 @@ public final void testNoExplicitCase() throws Exception { Files.copy(javaFilePath, out); String result = new String(out.toByteArray(), StandardCharsets.UTF_8); assertTrue("Did not find expected key case", result.contains("propertyLocalised4 = ")); - assertTrue("Did not find original URI", result.contains("\"propertyLocalised4\"")); + assertTrue("Did not find original IRI", result.contains("\"propertyLocalised4\"")); } } diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabularyBuilderSpecialTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabularyBuilderSpecialTest.java index 8606f91..576543e 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabularyBuilderSpecialTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/VocabularyBuilderSpecialTest.java @@ -54,8 +54,8 @@ public final void testReservedWordsHandling() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Files.copy(javaFilePath, out); String result = new String(out.toByteArray(), StandardCharsets.UTF_8); - assertTrue(result.contains("public static final URI hasTarget")); - assertTrue(result.contains("public static final URI _default")); + assertTrue(result.contains("public static final IRI hasTarget")); + assertTrue(result.contains("public static final IRI _default")); } } diff --git a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/vocabularies/FoafVocabTest.java b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/vocabularies/FoafVocabTest.java index cfec067..4e9471a 100644 --- a/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/vocabularies/FoafVocabTest.java +++ b/vocab-builder-core/src/test/java/com/github/tkurz/sesame/vocab/test/vocabularies/FoafVocabTest.java @@ -1,8 +1,9 @@ package com.github.tkurz.sesame.vocab.test.vocabularies; import com.github.tkurz.sesame.vocab.test.AbstractVocabSpecificTest; + +import org.eclipse.rdf4j.rio.RDFFormat; import org.junit.Assume; -import org.openrdf.rio.RDFFormat; import java.io.IOException; import java.io.InputStream; diff --git a/vocab-builder-maven-plugin/pom.xml b/vocab-builder-maven-plugin/pom.xml index 72a9159..8a70df3 100644 --- a/vocab-builder-maven-plugin/pom.xml +++ b/vocab-builder-maven-plugin/pom.xml @@ -90,43 +90,43 @@ - org.openrdf.sesame - sesame-rio-rdfxml + org.eclipse.rdf4j + rdf4j-rio-rdfxml runtime - org.openrdf.sesame - sesame-rio-ntriples + org.eclipse.rdf4j + rdf4j-rio-ntriples runtime - org.openrdf.sesame - sesame-rio-nquads + org.eclipse.rdf4j + rdf4j-rio-nquads runtime - org.openrdf.sesame - sesame-rio-turtle + org.eclipse.rdf4j + rdf4j-rio-turtle runtime - org.openrdf.sesame - sesame-rio-trig + org.eclipse.rdf4j + rdf4j-rio-trig runtime - org.openrdf.sesame - sesame-rio-rdfjson + org.eclipse.rdf4j + rdf4j-rio-rdfjson runtime com.github.jsonld-java - jsonld-java-sesame + jsonld-java-tools runtime org.semarglproject - semargl-sesame + semargl-rdf4j runtime diff --git a/vocab-builder-maven-plugin/src/main/java/com/github/tkurz/sesame/vocab/plugin/VocabularyBuilderMojo.java b/vocab-builder-maven-plugin/src/main/java/com/github/tkurz/sesame/vocab/plugin/VocabularyBuilderMojo.java index 53e861e..555123a 100644 --- a/vocab-builder-maven-plugin/src/main/java/com/github/tkurz/sesame/vocab/plugin/VocabularyBuilderMojo.java +++ b/vocab-builder-maven-plugin/src/main/java/com/github/tkurz/sesame/vocab/plugin/VocabularyBuilderMojo.java @@ -24,11 +24,10 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.*; import org.apache.maven.project.MavenProject; -import org.openrdf.model.util.GraphUtilException; -import org.openrdf.rio.RDFFormat; -import org.openrdf.rio.RDFParseException; -import org.openrdf.rio.RDFParserRegistry; -import org.openrdf.rio.Rio; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; +import org.eclipse.rdf4j.rio.RDFParserRegistry; +import org.eclipse.rdf4j.rio.Rio; import org.slf4j.impl.StaticLoggerBinder; import org.sonatype.plexus.build.incremental.BuildContext; @@ -151,12 +150,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (mime == null) { if (vocab.getUrl() != null) { - RDFFormat guess = Rio.getParserFormatForFileName(vocab.getUrl().toString()); + RDFFormat guess = Rio.getParserFormatForFileName(vocab.getUrl().toString()).orElse(null); if (guess != null) { mime = guess.getDefaultMIMEType(); } } else if (vocab.getFile() != null) { - RDFFormat guess = Rio.getParserFormatForFileName(vocab.getFile().toString()); + RDFFormat guess = Rio.getParserFormatForFileName(vocab.getFile().toString()).orElse(null); if (guess != null) { mime = guess.getDefaultMIMEType(); } @@ -297,8 +296,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } catch (RDFParseException e) { throw new MojoFailureException(String.format("Could not parse vocabulary %s: %s", displayName, e.getMessage())); - } catch (GraphUtilException e) { - throw new MojoExecutionException("Internal Mojo Error", e); } catch (GenerationException e) { throw new MojoFailureException(String.format("Could not generate vocabulary %s: %s", displayName, e.getMessage())); } catch (URISyntaxException e) { @@ -346,7 +343,7 @@ public File handleResponse(HttpResponse response) throws IOException { log.debug("Using mime-type from response-header: " + mime); } - final RDFFormat format = Rio.getParserFormatForMIMEType(mime); + final RDFFormat format = Rio.getParserFormatForMIMEType(mime).orElse(null); final String fName; if (format == null) { fName = displayName + ".cache"; From 29ee4b1f1f2d1bf0d331792c38d9c89978a96414 Mon Sep 17 00:00:00 2001 From: Radek Burget Date: Wed, 26 Jul 2017 13:23:02 +0200 Subject: [PATCH 2/3] Update plugin version in pom --- vocab-builder-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vocab-builder-maven-plugin/pom.xml b/vocab-builder-maven-plugin/pom.xml index 8a70df3..68af69b 100644 --- a/vocab-builder-maven-plugin/pom.xml +++ b/vocab-builder-maven-plugin/pom.xml @@ -20,7 +20,7 @@ org.apache.maven.plugins maven-plugin-plugin - 3.2 + 3.5 vocab-builder From 425c42558e726c7e50697e6f6e8979fa2f6d734b Mon Sep 17 00:00:00 2001 From: Radek Burget Date: Wed, 26 Jul 2017 15:55:40 +0200 Subject: [PATCH 3/3] Deprecated functions replaced --- .../java/com/github/tkurz/sesame/vocab/VocabBuilder.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java b/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java index ffdc385..d334db5 100644 --- a/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java +++ b/vocab-builder-core/src/main/java/com/github/tkurz/sesame/vocab/VocabBuilder.java @@ -11,7 +11,6 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import org.eclipse.rdf4j.model.util.GraphUtil; import org.eclipse.rdf4j.model.vocabulary.DC; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.OWL; @@ -328,7 +327,7 @@ public HashMap generateResourceBundle(String baseName) throw String nextKey = cleanKey(doCaseFormatting(key, getConstantCase())); for (IRI p : LABEL_PROPERTIES) { - for (Value v : GraphUtil.getObjects(model, resource, p)) { + for (Value v : model.filter(resource, p, null).objects()) { if (v instanceof Literal) { final Literal lit = (Literal) v; final String lang = lit.getLanguage().orElse(null); @@ -350,7 +349,7 @@ public HashMap generateResourceBundle(String baseName) throw } for (IRI p : COMMENT_PROPERTIES) { - for (Value v : GraphUtil.getObjects(model, resource, p)) { + for (Value v : model.filter(resource, p, null).objects()) { if (v instanceof Literal) { final Literal lit = (Literal) v; final String lang = lit.getLanguage().orElse(null); @@ -407,7 +406,7 @@ private Literal getFirstExistingObjectLiteral(Model model, Resource subject, Str private Literal getOptionalObjectLiteral(Model model, Resource subject, IRI predicate, String lang) { - Set objects = GraphUtil.getObjects(model, subject, predicate); + Set objects = model.filter(subject, predicate, null).objects(); Literal result = null;