From 1037f9308afa300a04cb1f8622ba18d168275956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 6 Feb 2018 23:31:56 +0100 Subject: [PATCH] prepare for build under Java 9 --- build.gradle | 9 +++++--- content-json/build.gradle | 6 +++--- .../content/json/pointer/TreePointerTest.java | 2 +- .../rdf/io/rdfxml/RdfXmlContentParser.java | 17 ++++++++++----- .../rdf/io/source/StreamProcessor.java | 4 ++-- .../xbib/content/rdf/io/source/XmlSource.java | 20 +++++++++++------- .../content/rdf/io/xml/XmlContentParser.java | 16 ++++++++------ .../rdf/io/rdfxml/EuropeanaEDMReaderTest.java | 1 + .../xml/stream/StaxEventContentHandler.java | 6 +++--- .../xml/transform/TransformerURIResolver.java | 12 ++++++++--- gradle.properties | 8 +++++-- gradle/publish.gradle | 4 +++- gradle/wrapper/gradle-wrapper.jar | Bin 54333 -> 54333 bytes gradle/wrapper/gradle-wrapper.properties | 4 ++-- 14 files changed, 70 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index c1f8bfc..5519727 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id "org.sonarqube" version "2.6.1" id "io.codearte.nexus-staging" version "0.11.0" - id "org.xbib.gradle.plugin.asciidoctor" version "1.5.4.1.0" + id "org.xbib.gradle.plugin.asciidoctor" version "1.5.6.0.1" } printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGroovy: %s\nGradle: %s\n" + @@ -42,8 +42,8 @@ allprojects { } dependencies { - testCompile 'junit:junit:4.12' - wagon 'org.apache.maven.wagon:wagon-ssh:3.0.0' + testCompile "junit:junit:${project.property('junit.version')}" + wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}" } sourceCompatibility = JavaVersion.VERSION_1_8 @@ -75,12 +75,15 @@ allprojects { classifier 'sources' from sourceSets.main.allSource } + task javadocJar(type: Jar, dependsOn: javadoc) { classifier 'javadoc' } + artifacts { archives sourcesJar, javadocJar } + if (project.hasProperty('signing.keyId')) { signing { sign configurations.archives diff --git a/content-json/build.gradle b/content-json/build.gradle index 8ec155f..43cc0ff 100644 --- a/content-json/build.gradle +++ b/content-json/build.gradle @@ -1,10 +1,10 @@ dependencies { compile "com.fasterxml.jackson.core:jackson-databind:${project.property('jackson.version')}" - testCompile('junit:junit:4.12') { + testCompile("junit:junit:${project.property('junit.version')}") { exclude group: 'org.hamcrest' } - testCompile('org.mockito:mockito-core:1.9.5') { + testCompile("org.mockito:mockito-core:${project.property('mockito.version')}") { exclude group: 'org.hamcrest' } - testCompile 'org.hamcrest:hamcrest-all:1.3' + testCompile "org.hamcrest:hamcrest-all:${project.property('hamcrest.version')}" } diff --git a/content-json/src/test/java/org/xbib/content/json/pointer/TreePointerTest.java b/content-json/src/test/java/org/xbib/content/json/pointer/TreePointerTest.java index 1ed76f2..482547f 100644 --- a/content-json/src/test/java/org/xbib/content/json/pointer/TreePointerTest.java +++ b/content-json/src/test/java/org/xbib/content/json/pointer/TreePointerTest.java @@ -1,6 +1,6 @@ package org.xbib.content.json.pointer; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.only; 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 a489fa7..41e56ef 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 @@ -25,7 +25,6 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.helpers.XMLReaderFactory; import java.io.IOException; import java.io.InputStream; @@ -41,6 +40,9 @@ 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; /** * RdfXmlParser is an admittedly convoluted hand-coded SAX parser for RDF/XML. @@ -71,7 +73,7 @@ public class RdfXmlContentParser implements RdfConst // counter for blank node generation private int bn = 0; - public RdfXmlContentParser(InputStream in) throws IOException { + public RdfXmlContentParser(InputStream in) { this(new InputStreamReader(in, StandardCharsets.UTF_8)); } @@ -98,14 +100,19 @@ public class RdfXmlContentParser implements RdfConst public RdfXmlContentParser parse() throws IOException { try { parse(new InputSource(reader)); - } catch (SAXException ex) { + } catch (SAXException | ParserConfigurationException ex) { throw new IOException(ex); } return this; } - public RdfXmlContentParser parse(InputSource source) throws IOException, SAXException { - parse(XMLReaderFactory.createXMLReader(), source); + public RdfXmlContentParser parse(InputSource source) throws IOException, SAXException, ParserConfigurationException { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + SAXParser parser = factory.newSAXParser(); + XMLReader xmlReader = parser.getXMLReader(); + parse(xmlReader, source); return this; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/source/StreamProcessor.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/source/StreamProcessor.java index 4627439..49671b8 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/source/StreamProcessor.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/source/StreamProcessor.java @@ -6,6 +6,7 @@ import org.xbib.content.rdf.io.sink.XmlSink; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -58,8 +59,7 @@ public final class StreamProcessor extends BaseStreamProcessor { source.process(reader, mimeType, baseUri); } - public void setReader(XMLReader xmlReader) throws SAXException { + public void setReader(XMLReader xmlReader) throws SAXException, ParserConfigurationException { ((XmlSource) source).setXmlReader(xmlReader); } - } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/source/XmlSource.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/source/XmlSource.java index 9a05b35..a965878 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/source/XmlSource.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/source/XmlSource.java @@ -4,13 +4,15 @@ import org.xbib.content.rdf.io.sink.XmlSink; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; final class XmlSource extends AbstractSource { @@ -20,17 +22,19 @@ final class XmlSource extends AbstractSource { super(sink); } - public static XMLReader getDefaultXmlReader() throws SAXException { - XMLReader result = XMLReaderFactory.createXMLReader(); - result.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); - return result; + public static XMLReader getDefaultXmlReader() throws SAXException, ParserConfigurationException { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + SAXParser parser = factory.newSAXParser(); + return parser.getXMLReader(); } @Override public void process(Reader reader, String mimeType, String baseUri) throws IOException { try { initXmlReader(); - } catch (SAXException e) { + } catch (SAXException | ParserConfigurationException e) { throw new IOException("can not instantinate XMLReader", e); } try { @@ -53,7 +57,7 @@ final class XmlSource extends AbstractSource { } } - private void initXmlReader() throws SAXException { + private void initXmlReader() throws SAXException, ParserConfigurationException { if (xmlReader == null) { xmlReader = getDefaultXmlReader(); } @@ -61,7 +65,7 @@ final class XmlSource extends AbstractSource { xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", sink); } - public void setXmlReader(XMLReader xmlReader) throws SAXException { + public void setXmlReader(XMLReader xmlReader) throws SAXException, ParserConfigurationException { if (xmlReader == null) { this.xmlReader = getDefaultXmlReader(); } else { diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java index ec5cc1d..1fc3e82 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java @@ -9,13 +9,15 @@ import org.xbib.content.rdf.util.NormalizeEolFilter; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; /** * An XML reader for parsing XML into triples. @@ -33,7 +35,7 @@ public class XmlContentParser

implements RdfContentP private boolean validate = false; - public XmlContentParser(InputStream in) throws IOException { + public XmlContentParser(InputStream in) { this(new InputStreamReader(in, StandardCharsets.UTF_8)); } @@ -73,9 +75,13 @@ public class XmlContentParser

implements RdfContentP @Override public XmlContentParser

parse() throws IOException { try { - XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + SAXParser parser = factory.newSAXParser(); + XMLReader xmlReader = parser.getXMLReader(); parse(xmlReader, new InputSource(reader)); - } catch (SAXException ex) { + } catch (SAXException | ParserConfigurationException ex) { throw new IOException(ex); } return this; @@ -88,8 +94,6 @@ public class XmlContentParser

implements RdfContentP } reader.setContentHandler(handler); } - reader.setFeature("http://xml.org/sax/features/namespaces", namespaces); - reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", validate); reader.parse(source); return this; } 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 dcddb48..ebd7260 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 @@ -51,6 +51,7 @@ public class EuropeanaEDMReaderTest extends StreamTester { Resource resource = resourceIterator.next(); builder.receive(resource); } + //System.err.println(builder.string()); assertStream(getClass().getResource("edm.nt").openStream(), builder.streamInput()); } diff --git a/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventContentHandler.java b/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventContentHandler.java index 4c3f98c..acd0b2a 100644 --- a/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventContentHandler.java +++ b/content-xml/src/main/java/org/xbib/content/xml/stream/StaxEventContentHandler.java @@ -70,14 +70,14 @@ public class StaxEventContentHandler extends AbstractStaxContentHandler { @Override protected void startElementInternal(QName name, Attributes atts, SimpleNamespaceContext namespaceContext) throws XMLStreamException { - List attributes = getAttributes(atts); - List namespaces = createNamespaces(namespaceContext); + List attributes = getAttributes(atts); + List namespaces = createNamespaces(namespaceContext); consumeEvent(eventFactory.createStartElement(name, attributes.iterator(), namespaces.iterator())); } @Override protected void endElementInternal(QName name, SimpleNamespaceContext namespaceContext) throws XMLStreamException { - List namespaces = createNamespaces(namespaceContext); + List namespaces = createNamespaces(namespaceContext); consumeEvent(eventFactory.createEndElement(name, namespaces.iterator())); } 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 63e918e..477b3f9 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 @@ -3,7 +3,6 @@ package org.xbib.content.xml.transform; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; import java.io.Closeable; import java.io.IOException; @@ -18,6 +17,9 @@ import java.util.List; 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; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; @@ -107,12 +109,16 @@ public class TransformerURIResolver implements URIResolver, Closeable { throw new TransformerException("href could not be resolved: " + href); } try { - XMLReader reader = XMLReaderFactory.createXMLReader(); + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); inputStreams.add(in); SAXSource source = new SAXSource(reader, new InputSource(in)); source.setSystemId(systemId); return source; - } catch (SAXException e) { + } catch (SAXException | ParserConfigurationException e) { throw new TransformerException("no XML reader for SAX source in URI resolving for:" + href, e); } } diff --git a/gradle.properties b/gradle.properties index b9f2211..bb7c8e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,10 @@ group = org.xbib name = content -version = 1.2.4 +version = 1.3.0 -jackson.version = 2.8.11 xbib-net.version = 1.0.0 +jackson.version = 2.8.11 +junit.version = 4.12 +hamcrest.version = 1.3 +mockito.version = 2.13.0 +wagon.version = 3.0.0 diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 05d7199..7bf8ad6 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,12 +1,13 @@ task xbibUpload(type: Upload, dependsOn: build) { + group = 'publish' configuration = configurations.archives uploadDescriptor = true repositories { if (project.hasProperty('xbibUsername')) { mavenDeployer { configuration = configurations.wagon - repository(url: uri('sftp://xbib.org/repository')) { + repository(url: uri(project.property('xbibUrl'))) { authentication(userName: xbibUsername, privateKey: xbibPrivateKey) } } @@ -15,6 +16,7 @@ task xbibUpload(type: Upload, dependsOn: build) { } task sonatypeUpload(type: Upload, dependsOn: build) { + group = 'publish' configuration = configurations.archives uploadDescriptor = true repositories { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 99340b4ad18d3c7e764794d300ffd35017036793..c44b679acd3f794ddbb3aa5e919244914911014a 100644 GIT binary patch delta 67 zcmdnHf_d)><_YF3^<10PCt62xypsG>^s$JMVS?1gZT}APTs3B42=Hd-&|;n)KKZ~Q Tf3UjE!iVn(uz-cWUiJV0iuD?> delta 67 zcmdnHf_d)><_YF3rx}klPPC5Xcp>?z=wlHh!vv{~+x{KoxoFJ75a7+uA)6T)Hu=CI Tf3UjE!iVn(uz-cWUiJV0zM~v6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eea9141..6e8d417 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Jan 27 20:21:20 CET 2018 +#Tue Feb 06 23:13:29 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip