diff --git a/build.gradle b/build.gradle index 379fe31..9d3b235 100644 --- a/build.gradle +++ b/build.gradle @@ -1,192 +1,34 @@ - plugins { - id "org.sonarqube" version "2.8" + id "de.marcphilipp.nexus-publish" version "0.4.0" id "io.codearte.nexus-staging" version "0.21.1" - id "com.github.spotbugs" version "2.0.1" id "org.xbib.gradle.plugin.asciidoctor" version "1.5.6.0.1" } +wrapper { + gradleVersion = "${rootProject.property('gradle.wrapper.version')}" + distributionType = Wrapper.DistributionType.ALL +} + +ext { + user = 'xbib' + name = 'content' + description = 'Content processing library for Java' + inceptionYear = '2016' + url = 'https://github.com/' + user + '/' + name + scmUrl = 'https://github.com/' + user + '/' + name + scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' + scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git' + issueManagementSystem = 'Github' + issueManagementUrl = ext.scmUrl + '/issues' + licenseName = 'The Apache License, Version 2.0' + licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' +} + subprojects { - - apply plugin: 'java' - apply plugin: 'maven' - apply plugin: 'pmd' - apply plugin: 'checkstyle' - apply plugin: 'com.github.spotbugs' - apply plugin: 'org.xbib.gradle.plugin.asciidoctor' - - repositories { - mavenCentral() - } - - configurations { - asciidoclet - } - - dependencies { - testCompile "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}" - testCompile "org.junit.jupiter:junit-jupiter-params:${project.property('junit.version')}" - testCompile "org.junit.jupiter:junit-jupiter-engine:${project.property('junit.version')}" - testCompile "org.junit.vintage:junit-vintage-engine:${project.property('junit.version')}" - testCompile "junit:junit:${project.property('junit4.version')}" - asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}" - } - - compileJava { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:all" - } - - jar { - manifest { - attributes('Implementation-Version': project.version) - } - } - - test { - useJUnitPlatform() - failFast = false - testLogging { - events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED' - } - afterSuite { desc, result -> - if (!desc.parent) { - println "\nTest result: ${result.resultType}" - println "Test summary: ${result.testCount} tests, " + - "${result.successfulTestCount} succeeded, " + - "${result.failedTestCount} failed, " + - "${result.skippedTestCount} skipped" - } - } - } - - clean { - delete 'out' - } - - task sourcesJar(type: Jar, dependsOn: classes) { - classifier 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar, dependsOn: javadoc) { - classifier 'javadoc' - } - - artifacts { - archives sourcesJar, javadocJar - } - - tasks.withType(Checkstyle) { - ignoreFailures = true - reports { - xml.enabled = true - html.enabled = true - } - } - spotbugs { - effort = "max" - reportLevel = "low" - //includeFilter = file("findbugs-exclude.xml") - } - - tasks.withType(com.github.spotbugs.SpotBugsTask) { - ignoreFailures = true - reports { - xml.enabled = false - html.enabled = true - } - } - - tasks.withType(Pmd) { - ignoreFailures = true - reports { - xml.enabled = true - html.enabled = true - } - } - - checkstyle { - configFile = rootProject.file('config/checkstyle/checkstyle.xml') - ignoreFailures = true - showViolations = true - } - - sonarqube { - properties { - property "sonar.projectName", "${project.group} ${project.name}" - property "sonar.sourceEncoding", "UTF-8" - property "sonar.tests", "src/test/java" - property "sonar.scm.provider", "git" - property "sonar.junit.reportsPath", "build/test-results/test/" - } - } - - ext { - projectDescription = 'Content processing library for Java' - scmUrl = 'https://github.com/xbib/content' - scmConnection = 'scm:git:git://github.com/xbib/content.git' - scmDeveloperConnection = 'scm:git:git://github.com/xbib/content.git' - } - - task sonatypeUpload(type: Upload, dependsOn: build) { - group = 'publish' - configuration = configurations.archives - uploadDescriptor = true - repositories { - if (project.hasProperty('ossrhUsername')) { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - repository(url: uri(ossrhReleaseUrl)) { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - snapshotRepository(url: uri(ossrhSnapshotUrl)) { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - pom.project { - groupId project.group - artifactId project.name - version project.version - name project.name - description projectDescription - packaging 'jar' - inceptionYear '2016' - url scmUrl - organization { - name 'xbib' - url 'http://xbib.org' - } - developers { - developer { - id 'xbib' - name 'Jörg Prante' - email 'joergprante@gmail.com' - url 'https://github.com/jprante' - } - } - scm { - url scmUrl - connection scmConnection - developerConnection scmDeveloperConnection - } - licenses { - license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - } - } - } - } - } -} - -nexusStaging { - packageGroup = "org.xbib" - //stagingProfileId = "org.xbib" + apply plugin: 'java-library' + apply from: rootProject.file('gradle/ide/idea.gradle') + apply from: rootProject.file('gradle/compile/java.gradle') + apply from: rootProject.file('gradle/test/junit5.gradle') + apply from: rootProject.file('gradle/publishing/publication.gradle') } +apply from: rootProject.file('gradle/publishing/sonatype.gradle') diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 52fe33c..773fc1a 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -73,7 +73,6 @@ page at http://checkstyle.sourceforge.net/config.html --> - diff --git a/content-core/build.gradle b/content-core/build.gradle index 0d26d6f..62cdcc6 100644 --- a/content-core/build.gradle +++ b/content-core/build.gradle @@ -1,3 +1,3 @@ dependencies { - compile "com.fasterxml.jackson.core:jackson-core:${project.property('jackson.version')}" + api "com.fasterxml.jackson.core:jackson-core:${project.property('jackson.version')}" } diff --git a/content-core/src/main/java/module-info.java b/content-core/src/main/java/module-info.java new file mode 100644 index 0000000..c29c994 --- /dev/null +++ b/content-core/src/main/java/module-info.java @@ -0,0 +1,14 @@ +module org.xbib.content.core { + exports org.xbib.content; + exports org.xbib.content.io; + exports org.xbib.content.json; + exports org.xbib.content.settings; + exports org.xbib.content.util.geo; + exports org.xbib.content.util.unit; + requires com.fasterxml.jackson.core; + provides org.xbib.content.XContent with + org.xbib.content.json.JsonXContent; + provides org.xbib.content.settings.SettingsLoader with + org.xbib.content.settings.PropertiesSettingsLoader, + org.xbib.content.json.JsonSettingsLoader; +} diff --git a/content-core/src/test/java/org/xbib/content/XContentBuilderTest.java b/content-core/src/test/java/org/xbib/content/XContentBuilderTest.java index 7a2ed07..c8f72f0 100644 --- a/content-core/src/test/java/org/xbib/content/XContentBuilderTest.java +++ b/content-core/src/test/java/org/xbib/content/XContentBuilderTest.java @@ -1,9 +1,10 @@ package org.xbib.content; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.xbib.content.json.JsonXContent.contentBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.json.JsonXContent; import java.io.IOException; @@ -16,7 +17,7 @@ import java.util.Map; /** * */ -public class XContentBuilderTest extends Assert { +public class XContentBuilderTest { @Test public void testCopy() throws IOException { @@ -141,10 +142,11 @@ public class XContentBuilderTest extends Assert { assertEquals(map.toString(), "{value=4AC3B67267}"); } - @Test(expected = NullPointerException.class) - public void testNullKey() throws IOException { - XContentBuilder builder = contentBuilder(); - builder.field((String) null); + @Test + public void testNullKey() { + assertThrows(NullPointerException.class, () -> { + XContentBuilder builder = contentBuilder(); + builder.field((String) null); + }); } - } diff --git a/content-core/src/test/java/org/xbib/content/settings/SettingsTest.java b/content-core/src/test/java/org/xbib/content/settings/SettingsTest.java index c087b4c..6df296b 100644 --- a/content-core/src/test/java/org/xbib/content/settings/SettingsTest.java +++ b/content-core/src/test/java/org/xbib/content/settings/SettingsTest.java @@ -1,7 +1,9 @@ package org.xbib.content.settings; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; import org.xbib.content.XContentHelper; import org.xbib.content.io.BytesArray; import org.xbib.content.io.BytesReference; @@ -24,7 +26,7 @@ import java.util.concurrent.TimeUnit; /** * */ -public class SettingsTest extends Assert { +public class SettingsTest { @Test public void testEmpty() { diff --git a/content-csv/src/main/java/module-info.java b/content-csv/src/main/java/module-info.java new file mode 100644 index 0000000..ffa9849 --- /dev/null +++ b/content-csv/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module org.xbib.content.csv { + exports org.xbib.content.csv; +} diff --git a/content-csv/src/main/java/org/xbib/content/csv/CSVParser.java b/content-csv/src/main/java/org/xbib/content/csv/CSVParser.java index 9b1a0e7..3f0427e 100644 --- a/content-csv/src/main/java/org/xbib/content/csv/CSVParser.java +++ b/content-csv/src/main/java/org/xbib/content/csv/CSVParser.java @@ -6,16 +6,12 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class CSVParser { - private static final Logger logger = Logger.getLogger(CSVParser.class.getName()); - private final CSVLexer lexer; private final List row; @@ -43,7 +39,7 @@ public class CSVParser { } public Iterator> iterator() { - return new Iterator>() { + return new Iterator<>() { private List current; private List getNextRow() throws IOException { @@ -56,7 +52,6 @@ public class CSVParser { try { current = getNextRow(); } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); throw new NoSuchElementException(e.getMessage()); } } diff --git a/content-csv/src/test/java/org/xbib/content/csv/CSVGeneratorTest.java b/content-csv/src/test/java/org/xbib/content/csv/CSVGeneratorTest.java index 6f6d639..ed0e325 100644 --- a/content-csv/src/test/java/org/xbib/content/csv/CSVGeneratorTest.java +++ b/content-csv/src/test/java/org/xbib/content/csv/CSVGeneratorTest.java @@ -1,7 +1,6 @@ package org.xbib.content.csv; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; diff --git a/content-csv/src/test/java/org/xbib/content/csv/CSVParserTest.java b/content-csv/src/test/java/org/xbib/content/csv/CSVParserTest.java index 8b47c8e..48246ee 100644 --- a/content-csv/src/test/java/org/xbib/content/csv/CSVParserTest.java +++ b/content-csv/src/test/java/org/xbib/content/csv/CSVParserTest.java @@ -1,27 +1,20 @@ package org.xbib.content.csv; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.text.MessageFormat; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class CSVParserTest { - private static final Logger logger = Logger.getLogger(CSVParserTest.class.getName()); - @Test public void testCommaSeparated() throws IOException { InputStream in = getClass().getResourceAsStream("test.csv"); @@ -31,7 +24,6 @@ public class CSVParserTest { Iterator> it = csvParser.iterator(); while (it.hasNext()) { List row = it.next(); - //logger.log(Level.INFO, MessageFormat.format("count={0} row={1}", count, row)); count++; } } @@ -47,7 +39,6 @@ public class CSVParserTest { Iterator> it = csvParser.iterator(); while (it.hasNext()) { List row = it.next(); - //logger.log(Level.INFO, MessageFormat.format("count={0} row={1}", count, row)); count++; } } diff --git a/content-csv/src/test/java/org/xbib/content/csv/TSVParserTest.java b/content-csv/src/test/java/org/xbib/content/csv/TSVParserTest.java index 02808d9..6746178 100644 --- a/content-csv/src/test/java/org/xbib/content/csv/TSVParserTest.java +++ b/content-csv/src/test/java/org/xbib/content/csv/TSVParserTest.java @@ -1,11 +1,11 @@ package org.xbib.content.csv; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; /** * @@ -15,7 +15,7 @@ public class TSVParserTest { @Test public void testTabSeparated() throws IOException { InputStream in = getClass().getResourceAsStream("2076831-X-web.txt"); - InputStreamReader r = new InputStreamReader(in, "UTF-8"); + InputStreamReader r = new InputStreamReader(in, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(r); // skip 3 lines reader.readLine(); @@ -24,7 +24,6 @@ public class TSVParserTest { String line; while ((line = reader.readLine()) != null) { String[] s = line.split("\\t"); - //logger.info("len={} line={}", s.length, Arrays.asList(s)); int i = 0; String sigel = i < s.length ? s[i++] : ""; String isil = i < s.length ? s[i++] : ""; @@ -40,8 +39,6 @@ public class TSVParserTest { String lastVolume = i < s.length ? s[i++] : ""; String lastIssue = i < s.length ? s[i++] : ""; String movingWall = i < s.length ? s[i] : ""; - //logger.info("lastDate={}", lastDate); } - } } diff --git a/content-csv/src/test/resources/log4j2.xml b/content-csv/src/test/resources/log4j2-test.xml similarity index 100% rename from content-csv/src/test/resources/log4j2.xml rename to content-csv/src/test/resources/log4j2-test.xml diff --git a/content-json/build.gradle b/content-json/build.gradle index 7af65c1..0b1fcf4 100644 --- a/content-json/build.gradle +++ b/content-json/build.gradle @@ -1,10 +1,9 @@ dependencies { - compile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" - testCompile("junit:junit:${project.property('junit4.version')}") { + api "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" + testImplementation("junit:junit:${project.property('junit4.version')}") { exclude group: 'org.hamcrest' } - testCompile("org.mockito:mockito-core:${project.property('mockito.version')}") { + testImplementation("org.mockito:mockito-core:${project.property('mockito.version')}") { exclude group: 'org.hamcrest' } - testCompile "org.hamcrest:hamcrest-library:${project.property('hamcrest.version')}" } diff --git a/content-json/src/main/java/module-info.java b/content-json/src/main/java/module-info.java new file mode 100644 index 0000000..0611013 --- /dev/null +++ b/content-json/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module org.xbib.content.json { + exports org.xbib.content.json.diff; + exports org.xbib.content.json.jackson; + exports org.xbib.content.json.mergepatch; + exports org.xbib.content.json.patch; + exports org.xbib.content.json.pointer; + requires com.fasterxml.jackson.databind; +} diff --git a/content-language/src/main/java/module-info.java b/content-language/src/main/java/module-info.java new file mode 100644 index 0000000..e4a3ef7 --- /dev/null +++ b/content-language/src/main/java/module-info.java @@ -0,0 +1,4 @@ +module org.xbib.content.language { + exports org.xbib.content.language; + exports org.xbib.content.language.enums; +} diff --git a/content-rdf/build.gradle b/content-rdf/build.gradle index f11f23c..1649a2b 100644 --- a/content-rdf/build.gradle +++ b/content-rdf/build.gradle @@ -1,3 +1,5 @@ dependencies { - compile project(':content-xml') + implementation project(':content-core') + implementation project(':content-resource') + implementation project(':content-xml') } diff --git a/content-rdf/src/main/java/module-info.java b/content-rdf/src/main/java/module-info.java new file mode 100644 index 0000000..73edb1b --- /dev/null +++ b/content-rdf/src/main/java/module-info.java @@ -0,0 +1,17 @@ +module org.xbib.content.rdf { + exports org.xbib.content.rdf; + exports org.xbib.content.rdf.internal; + exports org.xbib.content.rdf.io.json; + exports org.xbib.content.rdf.io.nquads; + exports org.xbib.content.rdf.io.ntriple; + exports org.xbib.content.rdf.io.rdfxml; + exports org.xbib.content.rdf.io.sink; + exports org.xbib.content.rdf.io.source; + exports org.xbib.content.rdf.io.turtle; + exports org.xbib.content.rdf.io.xml; + exports org.xbib.content.rdf.util; + requires org.xbib.content.core; + requires org.xbib.content.resource; + requires org.xbib.content.xml; + requires java.xml; +} diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultRdfGraph.java b/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultRdfGraph.java index 9aff712..a4e64fd 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultRdfGraph.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultRdfGraph.java @@ -13,19 +13,15 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class DefaultRdfGraph implements RdfGraph { - private static final Logger logger = Logger.getLogger(DefaultRdfGraph.class.getName()); - private RdfGraphParams params = DefaultRdfGraphParams.DEFAULT_PARAMS; - private Map resources = new LinkedHashMap<>(); + private final Map resources = new LinkedHashMap<>(); @Override public Iterator getResources() { @@ -151,8 +147,6 @@ public class DefaultRdfGraph implements RdfGraph { if (r != null) { list.add(new DefaultTriple(resource1, pred, r.id())); list.addAll(unfold(r)); - } else { - logger.log(Level.SEVERE, "huh? {}", resource1.id()); } } else { list.addAll(unfold(resource1)); diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultResource.java b/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultResource.java index 708884a..ee5210a 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultResource.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/internal/DefaultResource.java @@ -18,7 +18,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -27,8 +26,9 @@ import java.util.stream.Collectors; public class DefaultResource implements Resource, Comparable, XSDResourceIdentifiers { static final String GENID = "genid"; + static final String PLACEHOLDER = "_:"; - private static final Logger logger = Logger.getLogger(DefaultResource.class.getName()); + private static final String UNDERSCORE = "_"; private final MultiMap attributes; @@ -164,7 +164,6 @@ public class DefaultResource implements Resource, Comparable, XSDResou return child.add(triple); } else { // nothing found, continue with a new resource with new subject - logger.info("nothing found!!! my ID is " + id()); return new DefaultResource(otherId).add(triple); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentGenerator.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentGenerator.java index acd3062..5b8e840 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentGenerator.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentGenerator.java @@ -15,15 +15,12 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class JsonContentGenerator implements RdfContentGenerator, Flushable { - private static final Logger logger = Logger.getLogger(JsonContentGenerator.class.getName()); private final Writer writer; private boolean nsWritten; @@ -54,16 +51,12 @@ public class JsonContentGenerator implements RdfContentGenerator, Flushable { - private static final Logger logger = Logger.getLogger(NTripleContentGenerator.class.getName()); - private static final char LF = '\n'; private final Writer writer; @@ -95,13 +91,9 @@ public class NTripleContentGenerator @Override public NTripleContentGenerator receive(Resource resource) throws IOException { - resource.triples().forEach(t -> { - try { - writer.write(writeStatement(t)); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); - } - }); + for (Triple t : resource.triples()) { + writer.write(writeStatement(t)); + } return this; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java index 03baf55..1ef35f0 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java @@ -5,16 +5,12 @@ import org.xbib.content.rdf.io.sink.TripleSink; import java.io.IOException; import java.util.BitSet; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Implementation of streaming NTriples parser. */ public final class NTriplesParser implements CharSink { - private static final Logger logger = Logger.getLogger(NTriplesParser.class.getName()); - private static final short PARSING_OUTSIDE = 0; private static final short PARSING_URI = 1; private static final short PARSING_BNODE = 2; @@ -118,7 +114,7 @@ public final class NTriplesParser implements CharSink { parsingState = PARSING_OUTSIDE; processOutsideChar(buffer, pos); } else { - logger.log(Level.SEVERE, "unexpected character '" + buffer[pos] + "' after literal"); + throw new IOException("unexpected character '" + buffer[pos] + "' after literal"); } } else if (parsingState == PARSING_LITERAL_TYPE) { processLiteralTypeChar(buffer, pos); @@ -159,7 +155,7 @@ public final class NTriplesParser implements CharSink { } else if (type.startsWith("^^<") && type.charAt(type.length() - 2) == '>') { onTypedLiteral(literalObj, type.substring(3, type.length() - 2 - trimSize)); } else { - logger.log(Level.SEVERE, "literal type '" + type + "' can not be parsed"); + throw new IOException("literal type '" + type + "' can not be parsed"); } parsingState = PARSING_OUTSIDE; if (trimSize > 0) { @@ -190,7 +186,7 @@ public final class NTriplesParser implements CharSink { break; default: if (!WHITESPACE.get(buffer[pos])) { - logger.log(Level.SEVERE, "unexpected character '" + buffer[pos] + "'"); + throw new IOException("unexpected character '" + buffer[pos] + "'"); } } } @@ -199,13 +195,13 @@ public final class NTriplesParser implements CharSink { if (waitingForSentenceEnd) { waitingForSentenceEnd = false; } else { - logger.log(Level.SEVERE, "unexpected end of sentence"); + throw new IOException("unexpected end of sentence"); } } private void onNonLiteral(String uri) throws IOException { if (waitingForSentenceEnd) { - logger.log(Level.SEVERE, "endStream of sentence expected"); + throw new IOException("endStream of sentence expected"); } if (subj == null) { subj = uri; @@ -220,9 +216,9 @@ public final class NTriplesParser implements CharSink { private void onPlainLiteral(String value, String lang) throws IOException { if (subj == null || pred == null) { if (waitingForSentenceEnd) { - logger.log(Level.SEVERE, "end of sentence expected"); + throw new IOException("end of sentence expected"); } else { - logger.log(Level.SEVERE, "literal is not an object"); + throw new IOException("literal is not an object"); } } sink.addPlainLiteral(subj, pred, value, lang); @@ -232,9 +228,9 @@ public final class NTriplesParser implements CharSink { private void onTypedLiteral(String value, String type) throws IOException { if (subj == null || pred == null) { if (waitingForSentenceEnd) { - logger.log(Level.SEVERE, "end of sentence expected"); + throw new IOException("end of sentence expected"); } else { - logger.log(Level.SEVERE, "literal is not an object"); + throw new IOException("literal is not an object"); } } sink.addTypedLiteral(subj, pred, value, type); @@ -281,7 +277,7 @@ public final class NTriplesParser implements CharSink { @Override public void endStream() throws IOException { if (tokenStartPos != -1 || waitingForSentenceEnd) { - logger.log(Level.SEVERE, "unexpected end of stream"); + throw new IOException("unexpected end of stream"); } sink.endStream(); } @@ -331,7 +327,7 @@ public final class NTriplesParser implements CharSink { case 'U': int sequenceLength = ch == 'u' ? 4 : 8; if (i + sequenceLength >= limit) { - logger.log(Level.SEVERE, "error parsing escape sequence '\\" + ch + "'"); + throw new IOException("error parsing escape sequence '\\" + ch + "'"); } String code = str.substring(i + 1, i + 1 + sequenceLength); i += sequenceLength; @@ -340,7 +336,7 @@ public final class NTriplesParser implements CharSink { int value = Integer.parseInt(code, 16); result.append((char) value); } catch (NumberFormatException nfe) { - logger.log(Level.SEVERE, "error parsing escape sequence '\\" + ch + "'"); + throw new IOException("error parsing escape sequence '\\" + ch + "'"); } break; default: diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesSerializer.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesSerializer.java index 8aeb242..b819bf8 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesSerializer.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesSerializer.java @@ -6,8 +6,6 @@ import org.xbib.content.rdf.io.sink.TripleSink; import java.io.IOException; import java.util.BitSet; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Implementation of {@link org.xbib.content.rdf.io.sink.TripleSink} which serializes triples to @@ -17,7 +15,6 @@ public class NTriplesSerializer implements TripleSink, RDF { protected static final String DOT_EOL = ".\n"; protected static final char SPACE = ' '; - private static final Logger logger = Logger.getLogger(NTriplesSerializer.class.getName()); private static final char QUOTE = '"'; private static final char URI_START = '<'; private static final char URI_END = '>'; @@ -118,7 +115,7 @@ public class NTriplesSerializer implements TripleSink, RDF { return str; } StringBuilder result = new StringBuilder(limit); - result.append(str.substring(0, pos)); + result.append(str, 0, pos); for (; pos < limit; pos++) { char ch = str.charAt(pos); if (ch < 0x80) { @@ -151,41 +148,29 @@ public class NTriplesSerializer implements TripleSink, RDF { } @Override - public void addNonLiteral(String subj, String pred, String obj) { - try { - startTriple(subj, pred); - serializeBnodeOrUri(obj); - sink.process(DOT_EOL); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); - } + public void addNonLiteral(String subj, String pred, String obj) throws IOException { + startTriple(subj, pred); + serializeBnodeOrUri(obj); + sink.process(DOT_EOL); } @Override - public void addPlainLiteral(String subj, String pred, String content, String lang) { - try { - startTriple(subj, pred); - addContent(content); - if (lang != null) { - sink.process('@').process(lang); - } - sink.process(SPACE).process(DOT_EOL); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + public void addPlainLiteral(String subj, String pred, String content, String lang) throws IOException { + startTriple(subj, pred); + addContent(content); + if (lang != null) { + sink.process('@').process(lang); } + sink.process(SPACE).process(DOT_EOL); } @Override - public void addTypedLiteral(String subj, String pred, String content, String type) { - try { - startTriple(subj, pred); - addContent(content); - sink.process("^^"); - serializeUri(type); - sink.process(DOT_EOL); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); - } + public void addTypedLiteral(String subj, String pred, String content, String type) throws IOException { + startTriple(subj, pred); + addContent(content); + sink.process("^^"); + serializeUri(type); + sink.process(DOT_EOL); } @Override diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentGenerator.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentGenerator.java index 60d3db2..55f15e8 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentGenerator.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentGenerator.java @@ -18,16 +18,12 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * RDF/XML writer. */ public class RdfXmlContentGenerator implements RdfContentGenerator, Flushable, RdfConstants { - private static final Logger logger = Logger.getLogger(RdfXmlContentGenerator.class.getName()); - private final Writer writer; private boolean writingStarted; @@ -119,7 +115,9 @@ public class RdfXmlContentGenerator implements RdfContentGenerator"); - writeNewLine(); - lastWrittenSubject = subj; - } - writer.write("\t"); - writeStartOfStartTag(predNamespace, predLocalName); - if (obj instanceof Resource) { - Resource objRes = (Resource) obj; - if (objRes.isEmbedded()) { - writeAttribute(NS_URI, "nodeID", objRes.id().toString()); - } else { - writeAttribute(NS_URI, "resource", objRes.id().toString()); - } - writer.write("/>"); - } else if (obj instanceof Literal) { - Literal l = (Literal) obj; - if (l.lang() != null) { - writeAttribute("xml:lang", l.lang()); - } - boolean isXMLLiteral = false; - IRI datatype = l.type(); - if (datatype != null) { - isXMLLiteral = datatype.equals(RDF_XMLLITERAL); - if (isXMLLiteral) { - writeAttribute(NS_URI, "parseType", "Literal"); - } else { - writeAttribute(NS_URI, "datatype", datatype.toString()); - } - } - writer.write(">"); - if (isXMLLiteral) { - writer.write(obj.toString()); - } else { - writer.write(escapeCharacterData(obj.toString())); - } - writeEndTag(predNamespace, predLocalName); - } - writeNewLine(); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + private RdfXmlContentGenerator writeTriple(Triple triple) throws IOException { + if (!writingStarted) { + throw new IOException("document writing has not yet been started"); } + Resource subj = triple.subject(); + IRI pred = triple.predicate(); + Node obj = triple.object(); + String predString = pred.toString(); + int predSplitIdx = findURISplitIndex(predString); + if (predSplitIdx == -1) { + throw new IOException("unable to create XML namespace-qualified name for predicate: " + predString); + } + String predNamespace = predString.substring(0, predSplitIdx); + String predLocalName = predString.substring(predSplitIdx); + if (!headerWritten) { + writeHeader(); + } + if (!subj.equals(lastWrittenSubject)) { + flushPendingStatements(); + writeNewLine(); + writeStartOfStartTag(NS_URI, "Description"); + if (subj.isEmbedded()) { + writeAttribute(NS_URI, "nodeID", subj.toString()); + } else { + writeAttribute(NS_URI, "about", subj.toString()); + } + writer.write(">"); + writeNewLine(); + lastWrittenSubject = subj; + } + writer.write("\t"); + writeStartOfStartTag(predNamespace, predLocalName); + if (obj instanceof Resource) { + Resource objRes = (Resource) obj; + if (objRes.isEmbedded()) { + writeAttribute(NS_URI, "nodeID", objRes.id().toString()); + } else { + writeAttribute(NS_URI, "resource", objRes.id().toString()); + } + writer.write("/>"); + } else if (obj instanceof Literal) { + Literal l = (Literal) obj; + if (l.lang() != null) { + writeAttribute("xml:lang", l.lang()); + } + boolean isXMLLiteral = false; + IRI datatype = l.type(); + if (datatype != null) { + isXMLLiteral = datatype.equals(RDF_XMLLITERAL); + if (isXMLLiteral) { + writeAttribute(NS_URI, "parseType", "Literal"); + } else { + writeAttribute(NS_URI, "datatype", datatype.toString()); + } + } + writer.write(">"); + if (isXMLLiteral) { + writer.write(obj.toString()); + } else { + writer.write(escapeCharacterData(obj.toString())); + } + writeEndTag(predNamespace, predLocalName); + } + writeNewLine(); return this; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java index 41e56ef..c0ed15b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java @@ -16,8 +16,8 @@ import org.xbib.content.rdf.internal.DefaultLiteral; import org.xbib.content.rdf.internal.DefaultTriple; import org.xbib.content.rdf.io.xml.XmlHandler; import org.xbib.content.resource.IRI; -import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRISyntaxException; +import org.xbib.content.resource.NamespaceContext; import org.xbib.content.resource.Node; import org.xbib.content.xml.util.XMLUtil; import org.xml.sax.Attributes; @@ -38,8 +38,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -56,8 +54,6 @@ import javax.xml.parsers.SAXParserFactory; */ public class RdfXmlContentParser implements RdfConstants, RdfContentParser { - private static final Logger logger = Logger.getLogger(RdfXmlContentParser.class.getName()); - private final Reader reader; private final Resource resource = new DefaultAnonymousResource(); @@ -245,7 +241,6 @@ public class RdfXmlContentParser implements RdfConst try { uri = IRI.create(uriString); } catch (IRISyntaxException e) { - logger.log(Level.FINE, e.getMessage(), e); // illegal URI, try repair uri = IRI.create(uriString .replace(" ", "%20") @@ -418,18 +413,18 @@ public class RdfXmlContentParser implements RdfConst private StringBuilder xmlLiteral = null; - private IRINamespaceContext namespaceContext; + private NamespaceContext namespaceContext; private int literalLevel = 0; // level in XMLLiteral @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { this.namespaceContext = namespaceContext; return this; } @Override - public IRINamespaceContext getNamespaceContext() { + public NamespaceContext getNamespaceContext() { return namespaceContext; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/QuadSink.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/QuadSink.java index f80b0cd..8396b07 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/QuadSink.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/QuadSink.java @@ -1,5 +1,7 @@ package org.xbib.content.rdf.io.sink; +import java.io.IOException; + /** * Interface for quad consuming. */ @@ -12,8 +14,9 @@ public interface QuadSink extends TripleSink { * @param pred predicate's IRI * @param obj object's IRI or BNode name * @param graph graph's IRI + * @throws IOException if handling of triple fails */ - void addNonLiteral(String subj, String pred, String obj, String graph); + void addNonLiteral(String subj, String pred, String obj, String graph) throws IOException; /** * Callback for handling triples with plain literal objects. @@ -23,8 +26,9 @@ public interface QuadSink extends TripleSink { * @param content unescaped string representation of content * @param lang content's lang, can be null if no language specified * @param graph graph's IRI + * @throws IOException if handling of triple fails */ - void addPlainLiteral(String subj, String pred, String content, String lang, String graph); + void addPlainLiteral(String subj, String pred, String content, String lang, String graph) throws IOException; /** * Callback for handling triples with typed literal objects. @@ -34,7 +38,8 @@ public interface QuadSink extends TripleSink { * @param content unescaped string representation of content * @param type literal datatype's IRI * @param graph graph's IRI + * @throws IOException if handling of triple fails */ - void addTypedLiteral(String subj, String pred, String content, String type, String graph); + void addTypedLiteral(String subj, String pred, String content, String type, String graph) throws IOException; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/RdfContentBuilderSink.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/RdfContentBuilderSink.java index bff46c9..dae5b88 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/RdfContentBuilderSink.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/RdfContentBuilderSink.java @@ -13,16 +13,13 @@ import org.xbib.content.rdf.internal.DefaultTriple; import org.xbib.content.resource.IRI; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.Iterator; /** * */ public class RdfContentBuilderSink implements QuadSink { - private static final Logger logger = Logger.getLogger(RdfContentBuilderSink.class.getName()); - private final RdfGraph graph; private final RdfContentBuilderProvider provider; @@ -34,81 +31,57 @@ public class RdfContentBuilderSink implements QuadSink { } @Override - public void addNonLiteral(String subj, String pred, String obj) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Resource o = DefaultResource.create(graph.getParams().getNamespaceContext(), obj); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addNonLiteral(String subj, String pred, String obj) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Resource o = DefaultResource.create(graph.getParams().getNamespaceContext(), obj); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override - public void addNonLiteral(String subj, String pred, String obj, String graphIRI) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Resource o = DefaultResource.create(graph.getParams().getNamespaceContext(), obj); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addNonLiteral(String subj, String pred, String obj, String graphIRI) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Resource o = DefaultResource.create(graph.getParams().getNamespaceContext(), obj); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override - public void addPlainLiteral(String subj, String pred, String content, String lang) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Literal o = new DefaultLiteral(content).lang(lang); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addPlainLiteral(String subj, String pred, String content, String lang) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Literal o = new DefaultLiteral(content).lang(lang); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override - public void addPlainLiteral(String subj, String pred, String content, String lang, String graphIRI) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Literal o = new DefaultLiteral(content).lang(lang); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addPlainLiteral(String subj, String pred, String content, String lang, String graphIRI) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Literal o = new DefaultLiteral(content).lang(lang); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override - public void addTypedLiteral(String subj, String pred, String content, String type) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Literal o = new DefaultLiteral(content).type(IRI.create(type)); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addTypedLiteral(String subj, String pred, String content, String type) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Literal o = new DefaultLiteral(content).type(IRI.create(type)); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override - public void addTypedLiteral(String subj, String pred, String content, String type, String graphIRI) { - try { - Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); - IRI p = IRI.create(pred); - Literal o = new DefaultLiteral(content).type(IRI.create(type)); - Triple t = new DefaultTriple(s, p, o); - graph.receive(t); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + public void addTypedLiteral(String subj, String pred, String content, String type, String graphIRI) throws IOException { + Resource s = DefaultResource.create(graph.getParams().getNamespaceContext(), subj); + IRI p = IRI.create(pred); + Literal o = new DefaultLiteral(content).type(IRI.create(type)); + Triple t = new DefaultTriple(s, p, o); + graph.receive(t); } @Override @@ -125,22 +98,16 @@ public class RdfContentBuilderSink implements QuadSink { public void endStream() throws IOException { if (graph.getResources() != null) { if (provider != null) { - graph.getResources().forEachRemaining(resource -> { + Iterator iterator = graph.getResources(); + while (iterator.hasNext()) { + Resource resource = iterator.next(); RdfContentBuilder rdfContentBuilder; - try { rdfContentBuilder = provider.newContentBuilder(); rdfContentBuilder.startStream(); rdfContentBuilder.receive(resource); rdfContentBuilder.endStream(); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - }); - } else { - logger.log(Level.WARNING, "no RDF content builder provider"); + } } - } else { - logger.log(Level.WARNING, "no graph resources"); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/TripleSink.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/TripleSink.java index b9b0869..b71fd8b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/TripleSink.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/sink/TripleSink.java @@ -1,5 +1,7 @@ package org.xbib.content.rdf.io.sink; +import java.io.IOException; + /** * Interface for triple consuming. */ @@ -11,8 +13,9 @@ public interface TripleSink extends Sink { * @param subj subject's IRI or BNode name * @param pred predicate's IRI * @param obj object's IRI or BNode name + * @throws IOException if handling of triple fails */ - void addNonLiteral(String subj, String pred, String obj); + void addNonLiteral(String subj, String pred, String obj) throws IOException; /** * Callback for handling triples with plain literal objects. @@ -21,8 +24,9 @@ public interface TripleSink extends Sink { * @param pred predicate's IRI * @param content unescaped string representation of content * @param lang content's lang, can be null if no language specified + * @throws IOException if handling of triple fails */ - void addPlainLiteral(String subj, String pred, String content, String lang); + void addPlainLiteral(String subj, String pred, String content, String lang) throws IOException; /** * Callback for handling triples with typed literal objects. @@ -31,7 +35,7 @@ public interface TripleSink extends Sink { * @param pred predicate's IRI * @param content unescaped string representation of content * @param type literal datatype's IRI + * @throws IOException if handling of triple fails */ - void addTypedLiteral(String subj, String pred, String content, String type); - + void addTypedLiteral(String subj, String pred, String content, String type) throws IOException; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentGenerator.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentGenerator.java index 5ab1bff..bfa7ba2 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentGenerator.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentGenerator.java @@ -19,16 +19,12 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class TurtleContentGenerator implements RdfContentGenerator, Flushable { - private static final Logger logger = Logger.getLogger(TurtleContentGenerator.class.getName()); - private static final char LF = '\n'; private static final char TAB = '\t'; private static final String TYPE = RdfConstants.NS_URI + "type"; @@ -43,15 +39,15 @@ public class TurtleContentGenerator implements RdfContentGenerator embedded; + private final LinkedList embedded; - private LinkedList triples; + private final LinkedList triples; private Triple triple; private boolean nsWritten; - private StringBuilder sb; + private final StringBuilder sb; private Resource resource; @@ -117,13 +113,9 @@ public class TurtleContentGenerator implements RdfContentGenerator receive(Resource resource) throws IOException { - resource.triples().forEach(t -> { - try { + for (Triple t : resource.triples()) { writeTriple(t); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); - } - }); + } while (!embedded.isEmpty()) { closeEmbeddedResource(); } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java index 61d11d9..aa42d88 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java @@ -16,8 +16,9 @@ import org.xbib.content.rdf.internal.DefaultLiteral; import org.xbib.content.rdf.internal.DefaultResource; import org.xbib.content.rdf.internal.DefaultTriple; import org.xbib.content.resource.IRI; +import org.xbib.content.resource.NamespaceContext; import org.xbib.content.resource.Node; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.xml.XmlNamespaceContext; import java.io.EOFException; import java.io.IOException; @@ -29,8 +30,6 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.LinkedList; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Turtle - Terse RDF Triple Parser. @@ -41,8 +40,6 @@ import java.util.logging.Logger; */ public class TurtleContentParser implements RdfContentParser { - private static final Logger logger = Logger.getLogger(TurtleContentParser.class.getName()); - private final Resource resource = new DefaultAnonymousResource(); private final HashMap bnodes = new HashMap<>(); @@ -93,7 +90,7 @@ public class TurtleContentParser implements RdfConte /** * The namespace context. */ - private XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + private NamespaceContext context; public TurtleContentParser(InputStream in) throws IOException { this(new InputStreamReader(in, StandardCharsets.UTF_8)); @@ -101,6 +98,7 @@ public class TurtleContentParser implements RdfConte public TurtleContentParser(Reader reader) { this.reader = new PushbackReader(reader, 2); + this.context = XmlNamespaceContext.newInstance(); } public static String decode(String s, String encoding) throws UnsupportedEncodingException { @@ -154,7 +152,7 @@ public class TurtleContentParser implements RdfConte return this; } - public TurtleContentParser context(XmlNamespaceContext context) { + public TurtleContentParser context(NamespaceContext context) { this.context = context; return this; } @@ -781,7 +779,7 @@ public class TurtleContentParser implements RdfConte if ((char) ch != v) { String message = (subject != null ? subject : "") + " unexpected character: '" + (char) ch + "' expected: '" + v + "'"; - logger.log(Level.WARNING, message); + throw new IOException(message); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleSerializer.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleSerializer.java index bb20939..13b9205 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleSerializer.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleSerializer.java @@ -8,8 +8,6 @@ import java.io.IOException; import java.util.HashSet; import java.util.LinkedList; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Implementation of {@link org.xbib.content.rdf.io.sink.TripleSink} which serializes triples to {@link @@ -18,8 +16,6 @@ import java.util.logging.Logger; */ public final class TurtleSerializer implements TripleSink, RDF { - private static final Logger logger = Logger.getLogger(TurtleSerializer.class.getName()); - private static final String DOT_EOL = " .\n"; private static final String COMMA_EOL = " ,\n"; private static final String SEMICOLON_EOL = " ;\n"; @@ -58,47 +54,35 @@ public final class TurtleSerializer implements TripleSink, RDF { } @Override - public void addNonLiteral(String subj, String pred, String obj) { - try { - startTriple(subj, pred); - if (obj.startsWith(BNODE_PREFIX)) { - if (!namedBnodes.contains(obj) && obj.endsWith(SHORTENABLE_BNODE_SUFFIX)) { - openBnode(obj); - } else { - sink.process(obj); - } + public void addNonLiteral(String subj, String pred, String obj) throws IOException { + startTriple(subj, pred); + if (obj.startsWith(BNODE_PREFIX)) { + if (!namedBnodes.contains(obj) && obj.endsWith(SHORTENABLE_BNODE_SUFFIX)) { + openBnode(obj); } else { - serializeUri(obj); + sink.process(obj); } - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + } else { + serializeUri(obj); } } @Override - public void addPlainLiteral(String subj, String pred, String content, String lang) { - try { - startTriple(subj, pred); - addContent(content); - if (lang != null) { - sink.process('@').process(lang); - } - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + public void addPlainLiteral(String subj, String pred, String content, String lang) throws IOException { + startTriple(subj, pred); + addContent(content); + if (lang != null) { + sink.process('@').process(lang); } } @Override - public void addTypedLiteral(String subj, String pred, String content, String type) { - try { - startTriple(subj, pred); - addContent(content); - sink.process("^^"); - serializeUri(type); - } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); - } - } + public void addTypedLiteral(String subj, String pred, String content, String type) throws IOException { + startTriple(subj, pred); + addContent(content); + sink.process("^^"); + serializeUri(type); +} @Override public void startStream() throws IOException { diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlHandler.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlHandler.java index bfe3cf5..18ff041 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlHandler.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlHandler.java @@ -2,7 +2,7 @@ package org.xbib.content.rdf.io.xml; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.RdfContentParams; -import org.xbib.content.resource.IRINamespaceContext; +import org.xbib.content.resource.NamespaceContext; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; @@ -15,9 +15,9 @@ import org.xml.sax.ErrorHandler; public interface XmlHandler

extends EntityResolver, DTDHandler, ContentHandler, ErrorHandler { - IRINamespaceContext getNamespaceContext(); + NamespaceContext getNamespaceContext(); - XmlHandler

setNamespaceContext(IRINamespaceContext namespaceContext); + XmlHandler

setNamespaceContext(NamespaceContext namespaceContext); XmlHandler

setDefaultNamespace(String prefix, String uri); diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/IRINamespaceCompactionTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/IRINamespaceCompactionTest.java index 86c2cb4..632f14b 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/IRINamespaceCompactionTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/IRINamespaceCompactionTest.java @@ -1,14 +1,14 @@ package org.xbib.content.rdf; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRINamespaceContext; /** * */ -public class IRINamespaceCompactionTest extends Assert { +public class IRINamespaceCompactionTest { @Test public void testCompaction() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/IRITest.java b/content-rdf/src/test/java/org/xbib/content/rdf/IRITest.java index a461d92..ed961ed 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/IRITest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/IRITest.java @@ -1,27 +1,32 @@ package org.xbib.content.rdf; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRISyntaxException; /** * */ -public class IRITest extends Assert { +public class IRITest { @Test public void testJsonLd() { IRI iri = IRI.create("@context"); - assertEquals(null, iri.getScheme()); + assertNull(iri.getScheme()); assertEquals("@context", iri.getSchemeSpecificPart()); } - @Test(expected = IRISyntaxException.class) + @Test public void testIllegalBlankNodeIRI() { - IRI iri = IRI.create("_:a1"); - assertEquals("_", iri.getScheme()); - assertEquals("a1", iri.getSchemeSpecificPart()); + Assertions.assertThrows(IRISyntaxException.class, () -> { + IRI iri = IRI.create("_:a1"); + assertEquals("_", iri.getScheme()); + assertEquals("a1", iri.getSchemeSpecificPart()); + + }); } @Test diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/RdfXContentGeneratorTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/RdfXContentGeneratorTest.java index 2fb50d5..d325a63 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/RdfXContentGeneratorTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/RdfXContentGeneratorTest.java @@ -1,9 +1,9 @@ package org.xbib.content.rdf; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.xbib.content.rdf.RdfXContentFactory.rdfXContentBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.internal.DefaultLiteral; import org.xbib.content.rdf.internal.DefaultResource; import org.xbib.content.resource.IRI; @@ -11,7 +11,7 @@ import org.xbib.content.resource.IRI; /** * */ -public class RdfXContentGeneratorTest extends Assert { +public class RdfXContentGeneratorTest { @Test public void testContentBuilder() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/RouteRdfXContentBuilderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/RouteRdfXContentBuilderTest.java index ec47dec..3ddb2a7 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/RouteRdfXContentBuilderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/RouteRdfXContentBuilderTest.java @@ -1,13 +1,14 @@ package org.xbib.content.rdf; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.xbib.content.rdf.RdfXContentFactory.routeRdfXContentBuilder; +import static org.xbib.content.rdf.StreamTester.assertStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.internal.DefaultLiteral; import org.xbib.content.rdf.internal.DefaultResource; import org.xbib.content.rdf.io.rdfxml.RdfXmlContentParser; import org.xbib.content.resource.IRI; -import org.xbib.helper.StreamTester; import java.io.IOException; import java.io.InputStream; @@ -18,7 +19,7 @@ import java.nio.charset.StandardCharsets; /** * */ -public class RouteRdfXContentBuilderTest extends StreamTester { +public class RouteRdfXContentBuilderTest { @Test public void testRoute() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/helper/StreamTester.java b/content-rdf/src/test/java/org/xbib/content/rdf/StreamTester.java similarity index 65% rename from content-rdf/src/test/java/org/xbib/helper/StreamTester.java rename to content-rdf/src/test/java/org/xbib/content/rdf/StreamTester.java index 37295ee..34509e7 100644 --- a/content-rdf/src/test/java/org/xbib/helper/StreamTester.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/StreamTester.java @@ -1,26 +1,26 @@ -package org.xbib.helper; - -import org.junit.Assert; +package org.xbib.content.rdf; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.InputStream; import java.io.Reader; /** * */ -public class StreamTester extends Assert { +public class StreamTester { - protected static void assertStream(InputStream expected, InputStream actual) { + public static void assertStream(InputStream expected, InputStream actual) { int offset = 0; try { while (true) { final int exp = expected.read(); if (exp == -1) { - assertEquals("Expecting end of actual stream at offset " + offset, -1, actual.read()); + assertEquals(-1, actual.read()); break; } else { final int act = actual.read(); - assertEquals("Expecting same data at offset " + offset, exp, act); + assertEquals(exp, act); } offset++; } @@ -37,11 +37,11 @@ public class StreamTester extends Assert { while (true) { final int exp = expected.read(); if (exp == -1) { - assertEquals("Expecting end of actual stream at offset " + offset, -1, actual.read()); + assertEquals(-1, actual.read(), "Expecting end of actual stream at offset " + offset); break; } else { final int act = actual.read(); - assertEquals("Expecting same data at offset " + offset, exp, act); + assertEquals(exp, act, "Expecting same data at offset " + offset); } offset++; } diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/internal/BlankNodeTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/internal/BlankNodeTest.java index 8f12119..1cf6258 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/internal/BlankNodeTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/internal/BlankNodeTest.java @@ -1,7 +1,7 @@ package org.xbib.content.rdf.internal; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.Resource; import org.xbib.content.rdf.Triple; import org.xbib.content.resource.IRI; @@ -11,7 +11,7 @@ import java.util.Iterator; /** * */ -public class BlankNodeTest extends Assert { +public class BlankNodeTest { @Test public void testBlankNodeRenumbering() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/internal/LiteralTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/internal/LiteralTest.java index ada8126..2fdbd04 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/internal/LiteralTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/internal/LiteralTest.java @@ -1,13 +1,13 @@ package org.xbib.content.rdf.internal; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.resource.IRI; /** * */ -public class LiteralTest extends Assert { +public class LiteralTest { @Test public void testLiteral() { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/internal/ResourceTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/internal/ResourceTest.java index 4912264..26fe152 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/internal/ResourceTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/internal/ResourceTest.java @@ -1,9 +1,11 @@ package org.xbib.content.rdf.internal; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.Literal; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.Resource; @@ -19,16 +21,16 @@ import java.util.Iterator; /** * */ -public class ResourceTest extends Assert { +public class ResourceTest { @Test public void deleted() throws Exception { Resource r = new DefaultAnonymousResource(); - assertEquals(r.isDeleted(), false); + assertFalse(r.isDeleted()); r.setDeleted(true); - assertEquals(r.isDeleted(), true); + assertTrue(r.isDeleted()); r.setDeleted(false); - assertEquals(r.isDeleted(), false); + assertFalse(r.isDeleted()); } @Test @@ -44,7 +46,7 @@ public class ResourceTest extends Assert { @Test public void testEmptyResources() throws Exception { Resource r = new DefaultResource(IRI.create("urn:root")); - assertEquals(r.isEmpty(), true); + assertTrue(r.isEmpty()); assertEquals(r.toString(), "urn:root"); } @@ -52,14 +54,14 @@ public class ResourceTest extends Assert { public void testEmptyProperty() throws Exception { Resource r = new DefaultResource(IRI.create("urn:root")); r.add("urn:property", (String) null); - assertEquals(r.isEmpty(), true); + assertTrue(r.isEmpty()); } @Test public void testStringLiteral() throws Exception { Resource r = new DefaultResource(IRI.create("urn:root")); r.add("urn:property", "Hello World"); - assertEquals(r.isEmpty(), false); + assertFalse(r.isEmpty()); assertEquals(r.triples().get(0).object().toString(), "Hello World"); } @@ -68,7 +70,7 @@ public class ResourceTest extends Assert { Resource r = new DefaultResource(IRI.create("urn:root")); DefaultLiteral literal = new DefaultLiteral(123).type(Literal.INT); r.add("urn:property", literal); - assertEquals(r.isEmpty(), false); + assertFalse(r.isEmpty()); assertEquals(r.triples().get(0).object().toString(), "123^^xsd:int"); } diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/internal/TripleTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/internal/TripleTest.java index 564a25c..ad8dc38 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/internal/TripleTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/internal/TripleTest.java @@ -1,7 +1,7 @@ package org.xbib.content.rdf.internal; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.Resource; import org.xbib.content.resource.IRI; import org.xbib.content.resource.Node; @@ -9,7 +9,7 @@ import org.xbib.content.resource.Node; /** * */ -public class TripleTest extends Assert { +public class TripleTest { @Test public void testSimpleTriple() { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java index af6d505..76daeb3 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java @@ -2,12 +2,13 @@ package org.xbib.content.rdf.io.json; import static org.xbib.content.rdf.RdfContentFactory.jsonBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.io.xml.XmlHandler; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.resource.NamespaceContext; +import org.xbib.content.rdf.StreamTester; import java.io.IOException; import java.io.InputStream; @@ -55,7 +56,7 @@ public class JsonReaderTest extends StreamTester { } @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { return this; } diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java index 98b15fc..faf37ec 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java @@ -2,9 +2,9 @@ package org.xbib.content.rdf.io.ntriple; import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.IOException; import java.io.InputStream; diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleTest.java index 38bce65..ff79f14 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleTest.java @@ -1,9 +1,10 @@ package org.xbib.content.rdf.io.ntriple; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.Resource; import org.xbib.content.rdf.XSDResourceIdentifiers; @@ -14,7 +15,7 @@ import org.xbib.content.resource.IRI; /** * */ -public class NTripleTest extends Assert { +public class NTripleTest { @Test public void testNTripleBuilder() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/EuropeanaEDMReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/EuropeanaEDMReaderTest.java index ebd7260..487e396 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/EuropeanaEDMReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/EuropeanaEDMReaderTest.java @@ -2,8 +2,7 @@ package org.xbib.content.rdf.io.rdfxml; import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContent; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.Resource; @@ -11,12 +10,11 @@ import org.xbib.content.rdf.Triple; import org.xbib.content.rdf.internal.DefaultLiteral; import org.xbib.content.rdf.internal.DefaultRdfGraph; import org.xbib.content.rdf.internal.DefaultTriple; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.rdf.io.ntriple.NTripleContent; import org.xbib.content.rdf.io.ntriple.NTripleContentParams; import org.xbib.content.resource.IRI; import org.xbib.content.resource.Node; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.IOException; import java.io.InputStream; @@ -25,14 +23,12 @@ import java.util.Iterator; /** * */ -@Category(IOTests.class) public class EuropeanaEDMReaderTest extends StreamTester { private static final IRI GEO_LAT = IRI.create("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); private static final IRI GEO_LON = IRI.create("http://www.w3.org/2003/01/geo/wgs84_pos#long"); private static final IRI location = IRI.create("location"); - @SuppressWarnings("unchecked") @Test public void testEuropeana() throws Exception { String filename = "oai_edm.xml"; @@ -56,7 +52,7 @@ public class EuropeanaEDMReaderTest extends StreamTester { builder.streamInput()); } - private class GeoJSONFilter extends RdfContentBuilder { + private static class GeoJSONFilter extends RdfContentBuilder { DefaultRdfGraph graph; diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/GNDRdfXmlReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/GNDRdfXmlReaderTest.java index 9f026a1..beceeec 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/GNDRdfXmlReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/GNDRdfXmlReaderTest.java @@ -2,28 +2,22 @@ package org.xbib.content.rdf.io.rdfxml; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentFactory; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.rdf.io.ntriple.NTripleContentParams; import org.xbib.content.rdf.io.turtle.TurtleContentParams; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; -import java.util.logging.Logger; /** * */ -@Category(IOTests.class) public class GNDRdfXmlReaderTest extends StreamTester { - private static final Logger logger = Logger.getLogger(GNDRdfXmlReaderTest.class.getName()); - @Test public void testGNDfromRdfXmltoTurtle() throws Exception { String filename = "GND.rdf"; diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/RdfXmlReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/RdfXmlReaderTest.java index 1e77f0d..fc20063 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/RdfXmlReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/RdfXmlReaderTest.java @@ -2,28 +2,22 @@ package org.xbib.content.rdf.io.rdfxml; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.internal.DefaultAnonymousResource; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.rdf.io.turtle.TurtleContentParams; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; import java.nio.charset.StandardCharsets; -import java.util.logging.Logger; /** * */ -@Category(IOTests.class) public class RdfXmlReaderTest extends StreamTester { - private static final Logger logger = Logger.getLogger(RdfXmlReaderTest.class.getName()); - @Test public void testReader() throws Exception { String filename = "118540238.xml"; diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/VIAFRdfXmlReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/VIAFRdfXmlReaderTest.java index 523894e..6d478f5 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/VIAFRdfXmlReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/rdfxml/VIAFRdfXmlReaderTest.java @@ -2,12 +2,10 @@ package org.xbib.content.rdf.io.rdfxml; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.xbib.content.rdf.io.IOTests; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.io.turtle.TurtleContentParams; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.IOException; import java.io.InputStream; @@ -17,7 +15,6 @@ import java.io.StringReader; /** * */ -@Category(IOTests.class) public class VIAFRdfXmlReaderTest extends StreamTester { @Test diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java index 5220125..6c269be 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java @@ -1,22 +1,18 @@ package org.xbib.content.rdf.io.turtle; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentFactory; import org.xbib.content.resource.IRI; -import org.xbib.helper.StreamTester; +import org.xbib.content.rdf.StreamTester; import java.io.InputStream; import java.text.MessageFormat; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class TurtleConformanceTest extends StreamTester { - private static final Logger logger = Logger.getLogger(TurtleConformanceTest.class.getName()); - @Test public void conformance() throws Exception { for (int n = 0; n < 30; n++) { @@ -26,10 +22,9 @@ public class TurtleConformanceTest extends StreamTester { .setBaseIRI(IRI.create("http://example/base/")); turtleParser.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder); turtleParser.setRdfContentBuilderHandler(b -> { - logger.log(Level.INFO, MessageFormat.format("turtle test {0}", b.string())); + //logger.log(Level.INFO, MessageFormat.format("turtle test {0}", b.string())); }); turtleParser.parse(); } } - } diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java index 4295ea2..7de319f 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java @@ -1,17 +1,17 @@ package org.xbib.content.rdf.io.turtle; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.RdfContentFactory; import org.xbib.content.rdf.Resource; import org.xbib.content.rdf.internal.DefaultResource; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.resource.NamespaceContext; +import org.xbib.content.rdf.StreamTester; import java.io.BufferedReader; import java.io.InputStream; @@ -21,12 +21,11 @@ import java.nio.charset.StandardCharsets; /** * */ -@Category(IOTests.class) public class TurtleTest extends StreamTester { @Test public void testTurtleGND() throws Exception { - IRINamespaceContext context = IRINamespaceContext.newInstance(); + NamespaceContext context = IRINamespaceContext.newInstance(); context.addNamespace("gnd", "http://d-nb.info/gnd/"); InputStream in = getClass().getResourceAsStream("GND.ttl"); TurtleContentParser reader = new TurtleContentParser(in) diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/OAITest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/OAITest.java index 634356d..f6ed259 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/OAITest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/OAITest.java @@ -2,21 +2,18 @@ package org.xbib.content.rdf.io.xml; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.rdf.io.turtle.TurtleContentParams; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.resource.NamespaceContext; +import org.xbib.content.rdf.StreamTester; import org.xbib.net.PercentEncoders; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; @@ -25,10 +22,7 @@ import javax.xml.namespace.QName; */ public class OAITest extends StreamTester { - private static final Logger logger = Logger.getLogger(OAITest.class.getName()); - @Test - @Category(IOTests.class) public void testOAIListRecordsToTurtle() throws Exception { String filename = "oai-listrecords.xml"; InputStream in = getClass().getResourceAsStream(filename); @@ -38,7 +32,7 @@ public class OAITest extends StreamTester { IRINamespaceContext context = IRINamespaceContext.newInstance(); XmlContentParams params = new XmlContentParams(context); - XmlHandler xmlHandler = new AbstractXmlResourceHandler(params) { + XmlHandler xmlHandler = new AbstractXmlResourceHandler<>(params) { @Override public boolean isResourceDelimiter(QName name) { @@ -53,7 +47,7 @@ public class OAITest extends StreamTester { getResource().setId(IRI.create("id:" + PercentEncoders.getRegNameEncoder(StandardCharsets.UTF_8).encode(value))); } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + // ignore } } } @@ -64,7 +58,7 @@ public class OAITest extends StreamTester { } @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { return this; } diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlReaderTest.java index b28da42..df2b81c 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlReaderTest.java @@ -1,21 +1,21 @@ package org.xbib.content.rdf.io.xml; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.Resource; import org.xbib.content.rdf.Triple; import org.xbib.content.rdf.internal.DefaultAnonymousResource; import org.xbib.content.rdf.internal.DefaultResource; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.rdf.io.ntriple.NTripleContent; import org.xbib.content.rdf.io.ntriple.NTripleContentParams; import org.xbib.content.rdf.io.turtle.TurtleContentParams; import org.xbib.content.resource.IRI; import org.xbib.content.resource.IRINamespaceContext; -import org.xbib.helper.StreamTester; +import org.xbib.content.resource.NamespaceContext; +import org.xbib.content.rdf.StreamTester; import org.xbib.net.PercentEncoders; import java.io.IOException; @@ -23,19 +23,14 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; /** * */ -@Category(IOTests.class) public class XmlReaderTest extends StreamTester { - private static final Logger logger = Logger.getLogger(XmlReaderTest.class.getName()); - @Test public void testOAIDC() throws Exception { String filename = "oro-eprint-25656.xml"; @@ -49,7 +44,7 @@ public class XmlReaderTest extends StreamTester { namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/"); XmlContentParams params = new XmlContentParams(namespaceContext); - XmlHandler xmlHandler = new AbstractXmlResourceHandler(params) { + XmlHandler xmlHandler = new AbstractXmlResourceHandler<>(params) { @Override public boolean isResourceDelimiter(QName name) { @@ -64,7 +59,7 @@ public class XmlReaderTest extends StreamTester { getResource().setId(IRI.create("id:" + PercentEncoders.getRegNameEncoder(StandardCharsets.UTF_8).encode(value))); } catch (IOException e) { - logger.log(Level.FINE, e.getMessage(), e); + // swallow } } } @@ -76,7 +71,7 @@ public class XmlReaderTest extends StreamTester { } @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { return this; } @@ -104,7 +99,7 @@ public class XmlReaderTest extends StreamTester { } IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(); XmlContentParams params = new XmlContentParams(namespaceContext); - AbstractXmlHandler xmlHandler = new AbstractXmlResourceHandler(params) { + AbstractXmlHandler xmlHandler = new AbstractXmlResourceHandler<>(params) { @Override public boolean isResourceDelimiter(QName name) { @@ -122,7 +117,7 @@ public class XmlReaderTest extends StreamTester { } @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { return this; } @@ -153,7 +148,7 @@ public class XmlReaderTest extends StreamTester { } IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(); XmlContentParams params = new XmlContentParams(namespaceContext); - AbstractXmlHandler xmlHandler = new AbstractXmlResourceHandler(params) { + AbstractXmlHandler xmlHandler = new AbstractXmlResourceHandler<>(params) { @Override public boolean isResourceDelimiter(QName name) { return false; @@ -170,7 +165,7 @@ public class XmlReaderTest extends StreamTester { } @Override - public XmlHandler setNamespaceContext(IRINamespaceContext namespaceContext) { + public XmlHandler setNamespaceContext(NamespaceContext namespaceContext) { return this; } @@ -194,7 +189,7 @@ public class XmlReaderTest extends StreamTester { ); } - private class MyBuilder extends RdfContentBuilder { + private static class MyBuilder extends RdfContentBuilder { final List triples = new LinkedList<>(); diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlResourceWriterTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlResourceWriterTest.java index 0f7afdd..615920f 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlResourceWriterTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/xml/XmlResourceWriterTest.java @@ -1,22 +1,19 @@ package org.xbib.content.rdf.io.xml; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.xbib.content.rdf.RdfContentFactory.xmlBuilder; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.Resource; import org.xbib.content.rdf.internal.DefaultAnonymousResource; import org.xbib.content.rdf.internal.DefaultResource; -import org.xbib.content.rdf.io.IOTests; import org.xbib.content.resource.IRI; /** * */ -@Category(IOTests.class) -public class XmlResourceWriterTest extends Assert { +public class XmlResourceWriterTest { @Test public void testXMLResourceWriter() throws Exception { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java index 249ed57..fd04e66 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java @@ -1,10 +1,8 @@ package org.xbib.content.rdf.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; import java.util.Arrays; /** diff --git a/content-rdf/src/test/java/org/xbib/helper/package-info.java b/content-rdf/src/test/java/org/xbib/helper/package-info.java deleted file mode 100644 index bc4f6a8..0000000 --- a/content-rdf/src/test/java/org/xbib/helper/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Classes for helpting the testing of RDF content. - */ -package org.xbib.helper; diff --git a/content-resource/build.gradle b/content-resource/build.gradle index 3a626c6..a9255cd 100644 --- a/content-resource/build.gradle +++ b/content-resource/build.gradle @@ -1,4 +1,4 @@ dependencies { - compile "org.xbib:net-url:${project.property('xbib-net.version')}" - testCompile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" + api "org.xbib:net-url:${project.property('xbib.net.version')}" + testImplementation "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" } \ No newline at end of file diff --git a/content-resource/src/main/java/module-info.java b/content-resource/src/main/java/module-info.java new file mode 100644 index 0000000..77b1593 --- /dev/null +++ b/content-resource/src/main/java/module-info.java @@ -0,0 +1,5 @@ +module org.xbib.content.resource { + exports org.xbib.content.resource; + exports org.xbib.content.resource.text; + requires org.xbib.net.url; +} \ No newline at end of file diff --git a/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java b/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java index a32d13d..ed1f0a0 100644 --- a/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java +++ b/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java @@ -1,36 +1,39 @@ package org.xbib.content.resource; import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; /** * */ -public final class IRINamespaceContext extends XmlNamespaceContext { +public final class IRINamespaceContext implements NamespaceContext { - /** - * Share namespace.properties with {@link XmlNamespaceContext}. - */ private static final String DEFAULT_RESOURCE = - XmlNamespaceContext.class.getPackage().getName().replace('.', '/') + '/' + "namespace"; + IRINamespaceContext.class.getPackage().getName().replace('.', '/') + '/' + "namespace"; private static IRINamespaceContext instance; private static final IRINamespaceContext DEFAULT_CONTEXT = newInstance(DEFAULT_RESOURCE); + // sort namespace by length in descending order, useful for compacting prefix + private final SortedMap namespaces; + + private final SortedMap> prefixes; + + protected final Object lock; + private List sortedNamespacesByPrefixLength; - private IRINamespaceContext() { - super(); - } - - private IRINamespaceContext(ResourceBundle bundle) { - super(bundle); - } public static IRINamespaceContext getInstance() { return DEFAULT_CONTEXT; @@ -55,9 +58,36 @@ public final class IRINamespaceContext extends XmlNamespaceContext { return new IRINamespaceContext(); } + protected IRINamespaceContext() { + this.namespaces = new TreeMap<>(); + this.prefixes = new TreeMap<>(); + this.lock = new Object(); + } + + private IRINamespaceContext(ResourceBundle bundle) { + this(); + Enumeration en = bundle.getKeys(); + while (en.hasMoreElements()) { + String prefix = en.nextElement(); + String namespace = bundle.getString(prefix); + addNamespace(prefix, namespace); + } + } + @Override public void addNamespace(String prefix, String namespace) { - super.addNamespace(prefix, namespace); + if (prefix != null && namespace != null) { + synchronized (lock) { + namespaces.put(prefix, namespace); + if (prefixes.containsKey(namespace)) { + prefixes.get(namespace).add(prefix); + } else { + Set set = new HashSet<>(); + set.add(prefix); + prefixes.put(namespace, set); + } + } + } synchronized (lock) { sortedNamespacesByPrefixLength = new ArrayList<>(getNamespaces().values()); // sort from longest to shortest prefix for successful matching @@ -71,7 +101,7 @@ public final class IRINamespaceContext extends XmlNamespaceContext { public IRINamespaceContext add(Map map) { for (Map.Entry e : map.entrySet()) { - super.addNamespace(e.getKey(), e.getValue()); + addNamespace(e.getKey(), e.getValue()); } synchronized (lock) { sortedNamespacesByPrefixLength = new ArrayList<>(getNamespaces().values()); @@ -131,4 +161,37 @@ public final class IRINamespaceContext extends XmlNamespaceContext { public String getPrefix(IRI uri) { return getNamespaceURI(uri.getScheme()) != null ? uri.getScheme() : getPrefix(uri.toString()); } + + @Override + public SortedMap getNamespaces() { + return namespaces; + } + + @Override + public String getNamespaceURI(String prefix) { + if (prefix == null) { + return null; + } + return namespaces.getOrDefault(prefix, null); + } + + @Override + public String getPrefix(String namespaceURI) { + Iterator it = getPrefixes(namespaceURI); + return it != null && it.hasNext() ? it.next() : null; + } + + @Override + public Iterator getPrefixes(String namespace) { + if (namespace == null) { + throw new IllegalArgumentException("namespace URI cannot be null"); + } + return prefixes.containsKey(namespace) ? + prefixes.get(namespace).iterator() : null; + } + + @Override + public String toString() { + return namespaces.toString(); + } } diff --git a/content-resource/src/main/java/org/xbib/content/resource/NamespaceContext.java b/content-resource/src/main/java/org/xbib/content/resource/NamespaceContext.java new file mode 100644 index 0000000..976aeb1 --- /dev/null +++ b/content-resource/src/main/java/org/xbib/content/resource/NamespaceContext.java @@ -0,0 +1,17 @@ +package org.xbib.content.resource; + +import java.util.Iterator; +import java.util.SortedMap; + +public interface NamespaceContext { + + String getNamespaceURI(String prefix); + + String getPrefix(String namespaceURI); + + Iterator getPrefixes(String namespaceURI); + + SortedMap getNamespaces(); + + void addNamespace(String prefix, String namespace); +} diff --git a/content-smile/build.gradle b/content-smile/build.gradle index df5ed6f..6b4f9af 100644 --- a/content-smile/build.gradle +++ b/content-smile/build.gradle @@ -1,4 +1,4 @@ dependencies { - compile project(':content-core') - compile "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${project.property('jackson.version')}" + implementation project(':content-core') + api "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${project.property('jackson.version')}" } diff --git a/content-smile/src/main/java/module-info.java b/content-smile/src/main/java/module-info.java new file mode 100644 index 0000000..953910f --- /dev/null +++ b/content-smile/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module org.xbib.content.smile { + exports org.xbib.content.smile; + requires org.xbib.content.core; + requires com.fasterxml.jackson.dataformat.smile; + provides org.xbib.content.XContent with + org.xbib.content.smile.SmileXContent; +} diff --git a/content-xml/build.gradle b/content-xml/build.gradle index d618b1d..07f88f6 100644 --- a/content-xml/build.gradle +++ b/content-xml/build.gradle @@ -1,7 +1,6 @@ dependencies { - compile project(':content-core') - compile project(':content-resource') - compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${project.property('jackson.version')}" - compile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson-databind.version')}" - compile "com.fasterxml.woodstox:woodstox-core:${project.property('woodstox.version')}" + implementation project(':content-core') + implementation project(':content-resource') + api "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${project.property('jackson.version')}" + implementation "com.fasterxml.woodstox:woodstox-core:${project.property('woodstox.version')}" } diff --git a/content-xml/src/main/java/module-info.java b/content-xml/src/main/java/module-info.java new file mode 100644 index 0000000..fae3918 --- /dev/null +++ b/content-xml/src/main/java/module-info.java @@ -0,0 +1,15 @@ +module org.xbib.content.xml { + exports org.xbib.content.xml; + exports org.xbib.content.xml.json; + exports org.xbib.content.xml.json.events; + exports org.xbib.content.xml.stream; + exports org.xbib.content.xml.transform; + exports org.xbib.content.xml.util; + requires java.xml; + requires org.xbib.content.core; + requires org.xbib.content.resource; + requires com.fasterxml.jackson.core; + requires com.fasterxml.jackson.dataformat.xml; + provides org.xbib.content.XContent with + org.xbib.content.xml.XmlXContent; +} diff --git a/content-resource/src/main/java/org/xbib/content/resource/XmlNamespaceContext.java b/content-xml/src/main/java/org/xbib/content/xml/XmlNamespaceContext.java similarity index 74% rename from content-resource/src/main/java/org/xbib/content/resource/XmlNamespaceContext.java rename to content-xml/src/main/java/org/xbib/content/xml/XmlNamespaceContext.java index 24394ec..0d57f32 100644 --- a/content-resource/src/main/java/org/xbib/content/resource/XmlNamespaceContext.java +++ b/content-xml/src/main/java/org/xbib/content/xml/XmlNamespaceContext.java @@ -1,4 +1,4 @@ -package org.xbib.content.resource; +package org.xbib.content.xml; import java.util.Enumeration; import java.util.HashSet; @@ -15,12 +15,7 @@ import javax.xml.namespace.NamespaceContext; /** * Contains a simple context for XML namespaces. */ -public class XmlNamespaceContext implements NamespaceContext { - - private static final String DEFAULT_RESOURCE = - XmlNamespaceContext.class.getPackage().getName().replace('.', '/') + '/' + "namespace"; - - private static final XmlNamespaceContext DEFAULT_CONTEXT = newDefaultInstance(); +public class XmlNamespaceContext implements NamespaceContext, org.xbib.content.resource.NamespaceContext { // sort namespace by length in descending order, useful for compacting prefix private final SortedMap namespaces; @@ -45,10 +40,6 @@ public class XmlNamespaceContext implements NamespaceContext { } } - public static XmlNamespaceContext getInstance() { - return DEFAULT_CONTEXT; - } - /** * Empty namespace context. * @@ -58,22 +49,10 @@ public class XmlNamespaceContext implements NamespaceContext { return new XmlNamespaceContext(); } - public static XmlNamespaceContext newDefaultInstance() { - return newInstance(DEFAULT_RESOURCE); - } - - /** - * Use thread context class laoder to instantiate a namespace context. - * @param bundleName the resource bundle name - * @return XML namespace context - */ - public static XmlNamespaceContext newInstance(String bundleName) { - return newInstance(bundleName, Locale.getDefault(), Thread.currentThread().getContextClassLoader()); - } - public static XmlNamespaceContext newInstance(String bundleName, Locale locale, ClassLoader classLoader) { try { - return new XmlNamespaceContext(ResourceBundle.getBundle(bundleName, locale, classLoader)); + ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, classLoader); + return new XmlNamespaceContext(bundle); } catch (MissingResourceException e) { return new XmlNamespaceContext(); } diff --git a/content-xml/src/main/java/org/xbib/content/xml/XmlXContentGenerator.java b/content-xml/src/main/java/org/xbib/content/xml/XmlXContentGenerator.java index f2bd16a..b8c53d9 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/XmlXContentGenerator.java +++ b/content-xml/src/main/java/org/xbib/content/xml/XmlXContentGenerator.java @@ -17,8 +17,6 @@ import java.io.IOException; import java.io.OutputStream; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; @@ -29,8 +27,6 @@ import javax.xml.stream.XMLStreamException; */ public class XmlXContentGenerator extends AbstractXContentGenerator { - private static final Logger logger = Logger.getLogger(XmlXContentGenerator.class.getName()); - private final XmlXContentGeneratorDelegate delegate; private XmlXParams params; @@ -50,7 +46,7 @@ public class XmlXContentGenerator extends AbstractXContentGenerator { return params; } - public XmlXContentGenerator setParams(XmlXParams params) { + public XmlXContentGenerator setParams(XmlXParams params) throws IOException { delegate.setParams(params); return this; } @@ -138,12 +134,12 @@ public class XmlXContentGenerator extends AbstractXContentGenerator { this.params = params; } - public void setParams(XmlXParams params) { + public void setParams(XmlXParams params) throws IOException { this.params = params; try { generator.getStaxWriter().setPrefix(params.getRoot().getPrefix(), params.getRoot().getNamespaceURI()); } catch (XMLStreamException e) { - logger.log(Level.SEVERE, e.getMessage(), e); + throw new IOException(e); } } @@ -183,7 +179,7 @@ public class XmlXContentGenerator extends AbstractXContentGenerator { generator.getStaxWriter().writeNamespace(prefix, uri); } } catch (XMLStreamException e) { - logger.log(Level.SEVERE, e.getMessage(), e); + throw new IOException(e); } rootUsed = true; } diff --git a/content-xml/src/main/java/org/xbib/content/xml/XmlXParams.java b/content-xml/src/main/java/org/xbib/content/xml/XmlXParams.java index 92829e3..4f125b7 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/XmlXParams.java +++ b/content-xml/src/main/java/org/xbib/content/xml/XmlXParams.java @@ -2,10 +2,6 @@ package org.xbib.content.xml; import com.fasterxml.jackson.dataformat.xml.XmlFactory; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; -import org.xbib.content.resource.XmlNamespaceContext; - -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; @@ -16,8 +12,6 @@ import javax.xml.stream.XMLOutputFactory; */ public class XmlXParams { - private static final Logger logger = Logger.getLogger(XmlXParams.class.getName()); - private static final XmlXParams DEFAULT_PARAMS = new XmlXParams(new QName("root"), XmlNamespaceContext.newInstance(), @@ -69,35 +63,23 @@ public class XmlXParams { // load from service factories in META-INF/services // default impl is "com.sun.xml.internal.stream.XMLInputFactoryImpl" XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - try { - inputFactory.setProperty("javax.xml.stream.isNamespaceAware", Boolean.TRUE); - inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE); - inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.TRUE); - inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE); - inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + inputFactory.setProperty("javax.xml.stream.isNamespaceAware", Boolean.TRUE); + inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE); + inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.TRUE); + inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE); + inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); return inputFactory; } protected static XMLOutputFactory createXMLOutputFactory() { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - try { - outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE); return outputFactory; } protected static XmlFactory createXmlFactory(XMLInputFactory inputFactory, XMLOutputFactory outputFactory) { XmlFactory xmlFactory = new XmlFactory(inputFactory, outputFactory); - try { - xmlFactory.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + xmlFactory.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true); return xmlFactory; } diff --git a/content-xml/src/main/java/org/xbib/content/xml/json/JsonSaxAdapter.java b/content-xml/src/main/java/org/xbib/content/xml/json/JsonSaxAdapter.java index fc91d6f..553e183 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/json/JsonSaxAdapter.java +++ b/content-xml/src/main/java/org/xbib/content/xml/json/JsonSaxAdapter.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.resource.NamespaceContext; import org.xbib.content.xml.util.ToQName; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; @@ -51,7 +51,7 @@ public class JsonSaxAdapter { private QName root = new QName("root"); - private XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + private NamespaceContext context; public JsonSaxAdapter(Reader reader, ContentHandler contentHandler) throws IOException { this(factory.createParser(reader), contentHandler); @@ -68,7 +68,7 @@ public class JsonSaxAdapter { return this; } - public JsonSaxAdapter context(XmlNamespaceContext context) { + public JsonSaxAdapter context(NamespaceContext context) { this.context = context; return this; } @@ -163,7 +163,7 @@ public class JsonSaxAdapter { qname.getLocalPart(), qname.getPrefix() + ":" + qname.getLocalPart()); } - private void writeNamespaceDeclarations(XmlNamespaceContext context) throws SAXException { + private void writeNamespaceDeclarations(NamespaceContext context) throws SAXException { Set keys = new TreeSet<>(context.getNamespaces().keySet()); if (root != null && !keys.contains(root.getPrefix())) { contentHandler.startPrefixMapping(root.getPrefix(), root.getNamespaceURI()); diff --git a/content-xml/src/main/java/org/xbib/content/xml/json/JsonStylesheet.java b/content-xml/src/main/java/org/xbib/content/xml/json/JsonStylesheet.java index 604564e..3630d1f 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/json/JsonStylesheet.java +++ b/content-xml/src/main/java/org/xbib/content/xml/json/JsonStylesheet.java @@ -1,6 +1,6 @@ package org.xbib.content.xml.json; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.xml.XmlNamespaceContext; import org.xbib.content.xml.transform.StylesheetTransformer; import org.xml.sax.InputSource; @@ -9,6 +9,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import javax.xml.namespace.QName; @@ -24,7 +25,7 @@ public class JsonStylesheet { private QName root = new QName("root"); - private XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + private XmlNamespaceContext context; private StylesheetTransformer transformer; @@ -51,7 +52,7 @@ public class JsonStylesheet { } public JsonStylesheet transform(InputStream in, OutputStream out) throws IOException { - return transform(in, new OutputStreamWriter(out, "UTF-8")); + return transform(in, new OutputStreamWriter(out, StandardCharsets.UTF_8)); } public JsonStylesheet transform(InputStream in, Writer out) throws IOException { @@ -78,7 +79,7 @@ public class JsonStylesheet { } public JsonStylesheet toXML(InputStream in, OutputStream out) throws IOException { - return toXML(in, new OutputStreamWriter(out, "UTF-8")); + return toXML(in, new OutputStreamWriter(out, StandardCharsets.UTF_8)); } public JsonStylesheet toXML(InputStream in, Writer out) throws IOException { diff --git a/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlReader.java b/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlReader.java index d3fe5bd..5910757 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlReader.java +++ b/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlReader.java @@ -1,6 +1,6 @@ package org.xbib.content.xml.json; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.xml.XmlNamespaceContext; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; @@ -33,9 +33,9 @@ public class JsonXmlReader implements XMLReader { private QName root = new QName("root"); - private XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + private XmlNamespaceContext context; - private Map map = new HashMap<>(); + private final Map map; private ContentHandler contentHandler; @@ -45,6 +45,10 @@ public class JsonXmlReader implements XMLReader { private ErrorHandler errorHandler; + public JsonXmlReader() { + this.map = new HashMap<>(); + } + public JsonXmlReader root(QName root) { this.root = root; return this; diff --git a/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlStreamer.java b/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlStreamer.java index 9889e93..a1a1baf 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlStreamer.java +++ b/content-xml/src/main/java/org/xbib/content/xml/json/JsonXmlStreamer.java @@ -4,7 +4,8 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.resource.NamespaceContext; +import org.xbib.content.xml.XmlNamespaceContext; import org.xbib.content.xml.util.ToQName; import java.io.IOException; @@ -39,12 +40,12 @@ public class JsonXmlStreamer { private QName root; - private XmlNamespaceContext context; + private NamespaceContext context; - private Deque elements; + private final Deque elements; public JsonXmlStreamer() { - context = XmlNamespaceContext.newDefaultInstance(); + context = XmlNamespaceContext.newInstance(); root = new QName("root"); eventFactory = XMLEventFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); @@ -58,7 +59,7 @@ public class JsonXmlStreamer { return this; } - public JsonXmlStreamer context(XmlNamespaceContext context) { + public JsonXmlStreamer context(NamespaceContext context) { this.context = context; return this; } diff --git a/content-xml/src/main/java/org/xbib/content/xml/stream/AbstractXMLEvent.java b/content-xml/src/main/java/org/xbib/content/xml/stream/AbstractXMLEvent.java index 01d5fcf..c41731a 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/stream/AbstractXMLEvent.java +++ b/content-xml/src/main/java/org/xbib/content/xml/stream/AbstractXMLEvent.java @@ -1,8 +1,6 @@ package org.xbib.content.xml.stream; import java.io.StringWriter; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; import javax.xml.stream.Location; @@ -17,8 +15,6 @@ import javax.xml.stream.events.XMLEvent; */ public abstract class AbstractXMLEvent implements XMLEvent { - private static final Logger logger = Logger.getLogger(AbstractXMLEvent.class.getName()); - /** * The event location. */ @@ -115,7 +111,7 @@ public abstract class AbstractXMLEvent implements XMLEvent { try { this.writeAsEncodedUnicode(writer); } catch (XMLStreamException e) { - logger.log(Level.WARNING, e.getMessage(), e); + // ignore } return writer.toString(); } diff --git a/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLEventWriter.java b/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLEventWriter.java index 7f52d55..9f13cfb 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLEventWriter.java +++ b/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLEventWriter.java @@ -3,8 +3,6 @@ package org.xbib.content.xml.stream; import java.io.IOException; import java.io.Writer; import java.util.Arrays; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import javax.xml.stream.XMLEventWriter; @@ -42,8 +40,6 @@ import javax.xml.stream.events.XMLEvent; */ public class IndentingXMLEventWriter extends EventWriterDelegate implements Indentation { - private static final Logger logger = Logger.getLogger(IndentingXMLEventWriter.class.getName()); - private static final int WROTE_MARKUP = 1; private static final int WROTE_DATA = 2; /** @@ -153,7 +149,7 @@ public class IndentingXMLEventWriter extends EventWriterDelegate implements Inde try { newLineEvent.write(out, depth - 1); } catch (Exception e) { - logger.log(Level.FINE, e.getMessage(), e); + // swallow } } } diff --git a/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLStreamWriter.java b/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLStreamWriter.java index 12f1a91..8264acb 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLStreamWriter.java +++ b/content-xml/src/main/java/org/xbib/content/xml/stream/IndentingXMLStreamWriter.java @@ -1,8 +1,5 @@ package org.xbib.content.xml.stream; -import java.util.logging.Level; -import java.util.logging.Logger; - import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -35,8 +32,6 @@ import javax.xml.stream.XMLStreamWriter; */ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements Indentation { - private static final Logger logger = Logger.getLogger(IndentingXMLStreamWriter.class.getName()); - private static final int WROTE_MARKUP = 1; private static final int WROTE_DATA = 2; /** @@ -254,7 +249,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In try { writeNewLine(depth - 1); } catch (XMLStreamException e) { - logger.log(Level.FINE, e.getMessage(), e); + // swallow } } } @@ -270,7 +265,7 @@ public class IndentingXMLStreamWriter extends StreamWriterDelegate implements In try { writeNewLine(0); } catch (XMLStreamException e) { - logger.log(Level.FINE, e.getMessage(), e); + // swallow } } stack[depth] = 0; // start fresh diff --git a/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventXMLReader.java b/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventXMLReader.java index 2f5f598..319cc4f 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventXMLReader.java +++ b/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventXMLReader.java @@ -5,8 +5,6 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.util.Iterator; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; @@ -32,8 +30,6 @@ import javax.xml.stream.events.XMLEvent; */ public class StaxEventXMLReader extends AbstractStaxXMLReader { - private static final Logger logger = Logger.getLogger(StaxEventXMLReader.class.getName()); - private final XMLEventReader reader; /** @@ -52,7 +48,6 @@ public class StaxEventXMLReader extends AbstractStaxXMLReader { throw new IllegalStateException("XMLEventReader not at start of document or element"); } } catch (XMLStreamException ex) { - logger.log(Level.FINE, ex.getMessage(), ex); throw new IllegalStateException("Could not read first element: " + ex.getMessage()); } this.reader = reader; diff --git a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetErrorListener.java b/content-xml/src/main/java/org/xbib/content/xml/transform/DefaultStylesheetErrorListener.java similarity index 59% rename from content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetErrorListener.java rename to content-xml/src/main/java/org/xbib/content/xml/transform/DefaultStylesheetErrorListener.java index 4a103b5..9cbe665 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetErrorListener.java +++ b/content-xml/src/main/java/org/xbib/content/xml/transform/DefaultStylesheetErrorListener.java @@ -1,26 +1,21 @@ package org.xbib.content.xml.transform; -import java.util.logging.Level; -import java.util.logging.Logger; - import javax.xml.transform.ErrorListener; import javax.xml.transform.TransformerException; /** * An {@link javax.xml.transform.ErrorListener} that reacts to errors when parsing (compiling) the stylesheet. */ -public final class StylesheetErrorListener implements ErrorListener { - - private static final Logger logger = Logger.getLogger(StylesheetErrorListener.class.getName()); +public class DefaultStylesheetErrorListener implements ErrorListener { @Override public void warning(TransformerException e) throws TransformerException { - logger.log(Level.WARNING, "warning (recoverable): " + e.getMessage(), e); + //logger.log(Level.WARNING, "warning (recoverable): " + e.getMessage(), e); } @Override public void error(TransformerException e) throws TransformerException { - logger.log(Level.WARNING, "error (recoverable): " + e.getMessage(), e); + //logger.log(Level.WARNING, "error (recoverable): " + e.getMessage(), e); } /** @@ -28,7 +23,7 @@ public final class StylesheetErrorListener implements ErrorListener { */ @Override public void fatalError(TransformerException e) throws TransformerException { - logger.log(Level.WARNING, "fatal error: " + e.getMessage(), e); + //logger.log(Level.WARNING, "fatal error: " + e.getMessage(), e); throw e; } } diff --git a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetPool.java b/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetPool.java index fe324af..9b9d622 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetPool.java +++ b/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetPool.java @@ -3,8 +3,6 @@ package org.xbib.content.xml.transform; import java.text.MessageFormat; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.transform.Source; import javax.xml.transform.Templates; @@ -18,8 +16,6 @@ import javax.xml.transform.stream.StreamSource; */ public final class StylesheetPool { - private static final Logger logger = Logger.getLogger(StylesheetPool.class.getName()); - /** * A map of precompiled stylesheets ({@link javax.xml.transform.Templates} objects). */ @@ -61,8 +57,6 @@ public final class StylesheetPool { String systemId = source.getSystemId(); Templates template = stylesheets.get(systemId); if (template == null) { - logger.log(Level.FINE, MessageFormat.format("new source={0} {1}", - source.getSystemId(), source.getClass().getName())); template = transformerFactory.newTemplates(source); stylesheets.put(systemId, template); } diff --git a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetTransformer.java b/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetTransformer.java index b809be3..4ae867e 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetTransformer.java +++ b/content-xml/src/main/java/org/xbib/content/xml/transform/StylesheetTransformer.java @@ -51,7 +51,7 @@ public class StylesheetTransformer implements Closeable { if (transformerFactory == null) { transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance(); } - transformerFactory.setErrorListener(new StylesheetErrorListener()); + transformerFactory.setErrorListener(new DefaultStylesheetErrorListener()); setResolver(path == null ? new TransformerURIResolver() : new TransformerURIResolver(path)); return this; } diff --git a/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerErrorListener.java b/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerErrorListener.java index af96912..d641d0a 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerErrorListener.java +++ b/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerErrorListener.java @@ -1,8 +1,5 @@ package org.xbib.content.xml.transform; -import java.util.logging.Level; -import java.util.logging.Logger; - import javax.xml.transform.ErrorListener; import javax.xml.transform.TransformerException; @@ -12,8 +9,6 @@ import javax.xml.transform.TransformerException; */ public final class TransformerErrorListener implements ErrorListener { - private static final Logger logger = Logger.getLogger(TransformerErrorListener.class.getName()); - /** * We store the exception internally as a workaround to xalan, which reports * {@link javax.xml.transform.TransformerException} as {@link RuntimeException} (wrapped). @@ -25,7 +20,7 @@ public final class TransformerErrorListener implements ErrorListener { */ @Override public void warning(TransformerException e) throws TransformerException { - logger.log(Level.WARNING, "Warning (recoverable): " + e.getMessage(), e); + //logger.log(Level.WARNING, "Warning (recoverable): " + e.getMessage(), e); } /* @@ -33,7 +28,7 @@ public final class TransformerErrorListener implements ErrorListener { */ @Override public void error(TransformerException e) throws TransformerException { - logger.log(Level.WARNING, "Error (recoverable): " + e.getMessage(), e); + //logger.log(Level.WARNING, "Error (recoverable): " + e.getMessage(), e); } /** @@ -41,7 +36,7 @@ public final class TransformerErrorListener implements ErrorListener { */ @Override public void fatalError(TransformerException e) throws TransformerException { - logger.log(Level.SEVERE, "Fatal error: " + e.getMessage(), e); + //logger.log(Level.SEVERE, "Fatal error: " + e.getMessage(), e); this.exception = e; throw e; } diff --git a/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerURIResolver.java b/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerURIResolver.java index 477b3f9..947ceb5 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerURIResolver.java +++ b/content-xml/src/main/java/org/xbib/content/xml/transform/TransformerURIResolver.java @@ -14,8 +14,6 @@ import java.net.URL; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -30,8 +28,6 @@ import javax.xml.transform.sax.SAXSource; */ public class TransformerURIResolver implements URIResolver, Closeable { - private static final Logger logger = Logger.getLogger(TransformerURIResolver.class.getName()); - private List inputStreams = new LinkedList<>(); private List bases = new LinkedList<>(); @@ -78,7 +74,7 @@ public class TransformerURIResolver implements URIResolver, Closeable { try { in = url.openStream(); } catch (IOException e) { - logger.log(Level.WARNING, "error while opening stream", e); + // ignore } } if (in == null) { diff --git a/content-xml/src/main/java/org/xbib/content/xml/util/ToQName.java b/content-xml/src/main/java/org/xbib/content/xml/util/ToQName.java index 1b8eb8b..b84d27b 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/util/ToQName.java +++ b/content-xml/src/main/java/org/xbib/content/xml/util/ToQName.java @@ -1,6 +1,6 @@ package org.xbib.content.xml.util; -import javax.xml.namespace.NamespaceContext; +import org.xbib.content.resource.NamespaceContext; import javax.xml.namespace.QName; /** diff --git a/content-xml/src/test/java/org/xbib/content/xml/XContentXmlBuilderTest.java b/content-xml/src/test/java/org/xbib/content/xml/XContentXmlBuilderTest.java index a052a55..fe4420c 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/XContentXmlBuilderTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/XContentXmlBuilderTest.java @@ -1,10 +1,9 @@ package org.xbib.content.xml; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.XContentBuilder; import org.xbib.content.XContentHelper; -import org.xbib.content.resource.XmlNamespaceContext; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -15,7 +14,7 @@ import javax.xml.namespace.QName; /** * */ -public class XContentXmlBuilderTest extends Assert { +public class XContentXmlBuilderTest { @Test public void testConstructorForServiceLoader() { @@ -124,7 +123,7 @@ public class XContentXmlBuilderTest extends Assert { @Test public void testParseJson() throws Exception { - XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + XmlNamespaceContext context = XmlNamespaceContext.newInstance(); context.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/"); context.addNamespace("xbib", "http://xbib.org/"); context.addNamespace("abc", "http://localhost/"); diff --git a/content-xml/src/test/java/org/xbib/content/xml/XmlNamespaceContextTest.java b/content-xml/src/test/java/org/xbib/content/xml/XmlNamespaceContextTest.java index c96966f..dc37b6f 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/XmlNamespaceContextTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/XmlNamespaceContextTest.java @@ -1,10 +1,10 @@ package org.xbib.content.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; import org.xbib.content.XContentBuilder; -import org.xbib.content.resource.XmlNamespaceContext; +import org.xbib.content.xml.transform.StylesheetTransformer; +import java.util.Locale; import javax.xml.namespace.QName; /** @@ -15,14 +15,14 @@ public class XmlNamespaceContextTest { @Test public void testDefaultNamespace() { XmlNamespaceContext context = XmlNamespaceContext.newInstance(); - assertTrue(context.getNamespaces().size() == 0); - context = XmlNamespaceContext.newDefaultInstance(); - assertTrue(context.getNamespaces().size() > 0); + assertEquals(0, context.getNamespaces().size()); } @Test public void testDefaultNamespaces() throws Exception { - XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + XmlNamespaceContext context = + XmlNamespaceContext.newInstance("org/xbib/content/resource/namespace", + Locale.getDefault(), StylesheetTransformer.class.getClassLoader()); XmlXParams params = new XmlXParams(context); XContentBuilder builder = XmlXContent.contentBuilder(params); builder.startObject() diff --git a/content-xml/src/test/java/org/xbib/content/xml/json/Json2XmlTest.java b/content-xml/src/test/java/org/xbib/content/xml/json/Json2XmlTest.java index 50d99be..e9a1d6b 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/json/Json2XmlTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/json/Json2XmlTest.java @@ -1,7 +1,7 @@ package org.xbib.content.xml.json; -import org.junit.Test; -import org.xbib.content.resource.XmlNamespaceContext; +import org.junit.jupiter.api.Test; +import org.xbib.content.xml.XmlNamespaceContext; import org.xml.sax.InputSource; import java.io.File; import java.io.FileOutputStream; @@ -12,6 +12,7 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.util.Locale; import javax.xml.namespace.QName; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; @@ -70,7 +71,7 @@ public class Json2XmlTest { private Writer getOutput(String path) throws IOException { File file = File.createTempFile(path, ".dat"); - return new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); + return new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); } private QName root() { @@ -78,12 +79,14 @@ public class Json2XmlTest { } private XmlNamespaceContext context() { - XmlNamespaceContext nsContext = XmlNamespaceContext.newDefaultInstance(); - nsContext.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/"); - nsContext.addNamespace("xbib", "http://xbib.org/"); - nsContext.addNamespace("abc", "http://localhost/"); - nsContext.addNamespace("lia", "http://xbib.org/namespaces/lia/"); - return nsContext; + XmlNamespaceContext context = + XmlNamespaceContext.newInstance("org/xbib/content/resource/namespace", + Locale.getDefault(), Json2XmlTest.class.getClassLoader()); + context.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/"); + context.addNamespace("xbib", "http://xbib.org/"); + context.addNamespace("abc", "http://localhost/"); + context.addNamespace("lia", "http://xbib.org/namespaces/lia/"); + return context; } } diff --git a/content-xml/src/test/java/org/xbib/content/xml/json/StylesheetTransformerTest.java b/content-xml/src/test/java/org/xbib/content/xml/json/StylesheetTransformerTest.java index ac47637..6942179 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/json/StylesheetTransformerTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/json/StylesheetTransformerTest.java @@ -1,13 +1,14 @@ package org.xbib.content.xml.json; -import org.junit.Test; -import org.xbib.content.resource.XmlNamespaceContext; +import org.junit.jupiter.api.Test; +import org.xbib.content.xml.XmlNamespaceContext; import org.xbib.content.xml.transform.StylesheetTransformer; import org.xml.sax.InputSource; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.util.Locale; import javax.xml.namespace.QName; import javax.xml.transform.sax.SAXSource; @@ -18,7 +19,9 @@ public class StylesheetTransformerTest { private final QName root = new QName("http://example.org", "result", "ex"); - private final XmlNamespaceContext context = XmlNamespaceContext.newDefaultInstance(); + private final XmlNamespaceContext context = + XmlNamespaceContext.newInstance("org/xbib/content/resource/namespace", + Locale.getDefault(), StylesheetTransformer.class.getClassLoader()); @Test public void testJsonAsXML() throws Exception { diff --git a/content-xml/src/test/java/org/xbib/content/xml/util/SaxEventConsumerTest.java b/content-xml/src/test/java/org/xbib/content/xml/util/SaxEventConsumerTest.java index 69eaf1c..d64a36c 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/util/SaxEventConsumerTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/util/SaxEventConsumerTest.java @@ -1,6 +1,6 @@ package org.xbib.content.xml.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.content.xml.stream.SaxEventConsumer; import org.xml.sax.helpers.DefaultHandler; import java.util.LinkedList; diff --git a/content-xml/src/test/java/org/xbib/content/xml/util/XMLUtilTest.java b/content-xml/src/test/java/org/xbib/content/xml/util/XMLUtilTest.java index 84ba2be..45206a0 100644 --- a/content-xml/src/test/java/org/xbib/content/xml/util/XMLUtilTest.java +++ b/content-xml/src/test/java/org/xbib/content/xml/util/XMLUtilTest.java @@ -1,12 +1,12 @@ package org.xbib.content.xml.util; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; /** * */ -public class XMLUtilTest extends Assert { +public class XMLUtilTest { @Test public void testWhitespaceCleaner() { diff --git a/content-yaml/build.gradle b/content-yaml/build.gradle index 4daf6d8..3bc02b3 100644 --- a/content-yaml/build.gradle +++ b/content-yaml/build.gradle @@ -1,4 +1,4 @@ dependencies { - compile project(':content-core') - compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${project.property('jackson.version')}" -} \ No newline at end of file + api project(':content-core') + api "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${project.property('jackson.version')}" +} diff --git a/content-yaml/src/main/java/module-info.java b/content-yaml/src/main/java/module-info.java new file mode 100644 index 0000000..e8dcf14 --- /dev/null +++ b/content-yaml/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module org.xbib.content.yaml { + exports org.xbib.content.yaml; + requires org.xbib.content.core; + requires com.fasterxml.jackson.dataformat.yaml; + provides org.xbib.content.XContent with + org.xbib.content.yaml.YamlXContent; + provides org.xbib.content.settings.SettingsLoader with + org.xbib.content.yaml.YamlSettingsLoader; +} diff --git a/gradle.properties b/gradle.properties index a06606b..a86e661 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,12 @@ group = org.xbib name = content -version = 2.1.0 +version = 2.2.0 -xbib-net.version = 2.0.3 +gradle.wrapper.version = 6.4.1 +xbib.net.version = 2.0.4 jackson.version = 2.9.10 -jackson-databind.version = 2.9.10.1 -woodstox.version = 6.0.2 - -# test -junit.version = 5.6.2 -junit4.version = 4.13 -hamcrest.version = 2.2 +jackson.databind.version = 2.9.10.1 +woodstox.version = 6.2.1 mockito.version = 3.1.0 - -# doc +junit4.version = 4.13 asciidoclet.version = 1.5.6 diff --git a/gradle/compile/java.gradle b/gradle/compile/java.gradle new file mode 100644 index 0000000..7b1e601 --- /dev/null +++ b/gradle/compile/java.gradle @@ -0,0 +1,35 @@ + +apply plugin: 'java-library' + +java { + modularity.inferModulePath.set(true) +} + +compileJava { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +compileTestJava { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +jar { + manifest { + attributes('Implementation-Version': project.version) + } +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier 'javadoc' +} + +artifacts { + archives sourcesJar, javadocJar +} diff --git a/gradle/documentation/asciidoc.gradle b/gradle/documentation/asciidoc.gradle new file mode 100644 index 0000000..34ace12 --- /dev/null +++ b/gradle/documentation/asciidoc.gradle @@ -0,0 +1,36 @@ +apply plugin: 'org.xbib.gradle.plugin.asciidoctor' + +configurations { + asciidoclet +} + +dependencies { + asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}" +} + +subprojects { + + /*javadoc { + options.docletpath = configurations.asciidoclet.files.asType(List) + options.doclet = 'org.asciidoctor.Asciidoclet' + //options.overview = "src/docs/asciidoclet/overview.adoc" + options.addStringOption "-base-dir", "${projectDir}" + options.addStringOption "-attribute", + "name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}" + configure(options) { + noTimestamp = true + } +}*/ + + asciidoctor { + attributes 'source-highlighter': 'coderay', + toc: 'left', + doctype: 'book', + icons: 'font', + encoding: 'utf-8', + sectlink: true, + sectanchors: true, + linkattrs: true, + imagesdir: 'img' + } +} \ No newline at end of file diff --git a/gradle/ide/idea.gradle b/gradle/ide/idea.gradle new file mode 100644 index 0000000..64e2167 --- /dev/null +++ b/gradle/ide/idea.gradle @@ -0,0 +1,13 @@ +apply plugin: 'idea' + +idea { + module { + outputDir file('build/classes/java/main') + testOutputDir file('build/classes/java/test') + } +} + +if (project.convention.findPlugin(JavaPluginConvention)) { + //sourceSets.main.output.classesDirs = file("build/classes/java/main") + //sourceSets.test.output.classesDirs = file("build/classes/java/test") +} diff --git a/gradle/publishing/publication.gradle b/gradle/publishing/publication.gradle new file mode 100644 index 0000000..c35fcb9 --- /dev/null +++ b/gradle/publishing/publication.gradle @@ -0,0 +1,64 @@ + +apply plugin: "de.marcphilipp.nexus-publish" + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + pom { + name = project.name + description = rootProject.ext.description + url = rootProject.ext.url + inceptionYear = rootProject.ext.inceptionYear + packaging = 'jar' + organization { + name = 'xbib' + url = 'https://xbib.org' + } + developers { + developer { + id = 'jprante' + name = 'Jörg Prante' + email = 'joergprante@gmail.com' + url = 'https://github.com/jprante' + } + } + scm { + url = rootProject.ext.scmUrl + connection = rootProject.ext.scmConnection + developerConnection = rootProject.ext.scmDeveloperConnection + } + issueManagement { + system = rootProject.ext.issueManagementSystem + url = rootProject.ext.issueManagementUrl + } + licenses { + license { + name = rootProject.ext.licenseName + url = rootProject.ext.licenseUrl + distribution = 'repo' + } + } + } + } + } +} + +if (project.hasProperty("signing.keyId")) { + apply plugin: 'signing' + signing { + sign publishing.publications.mavenJava + } +} + +nexusPublishing { + repositories { + sonatype { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + packageGroup = "org.xbib" + } + } +} diff --git a/gradle/publishing/sonatype.gradle b/gradle/publishing/sonatype.gradle new file mode 100644 index 0000000..e1813f3 --- /dev/null +++ b/gradle/publishing/sonatype.gradle @@ -0,0 +1,11 @@ + +if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { + + apply plugin: 'io.codearte.nexus-staging' + + nexusStaging { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + packageGroup = "org.xbib" + } +} diff --git a/gradle/test/junit5.gradle b/gradle/test/junit5.gradle new file mode 100644 index 0000000..cfef972 --- /dev/null +++ b/gradle/test/junit5.gradle @@ -0,0 +1,27 @@ + +def junitVersion = project.hasProperty('junit.version')?project.property('junit.version'):'5.6.2' +def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.version'):'2.2' + +dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" + testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" +} + +test { + useJUnitPlatform() + failFast = true + testLogging { + events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED' + } + afterSuite { desc, result -> + if (!desc.parent) { + println "\nTest result: ${result.resultType}" + println "Test summary: ${result.testCount} tests, " + + "${result.successfulTestCount} succeeded, " + + "${result.failedTestCount} failed, " + + "${result.skippedTestCount} skipped" + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf..62d4c05 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c4388a..21e622d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 83f2acf..fbd7c51 100755 --- a/gradlew +++ b/gradlew @@ -82,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -129,6 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -154,19 +156,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a1..a9f778a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%* set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%