Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/

# Eclipse
.classpath
Expand Down
Empty file added .mvn/jvm.maven
Empty file.
Empty file added .mvn/maven.config
Empty file.
1 change: 1 addition & 0 deletions build-files/rat-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

## Maven
**/target/**/*
**/.mvn/**/*

## Misc
archive.md
Expand Down
8 changes: 6 additions & 2 deletions jena-arq/src/main/java/org/apache/jena/http/auth/AuthEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public class AuthEnv {
private AuthEnv() { }

/** Register (username, password) information for a URI endpoint. */
public void registerUsernamePassword(URI uri, String user, String password) {
public void registerUsernamePassword(String uri, String username, String password) {
registerUsernamePassword(URI.create(uri), username, password);
}
/** Register (username, password) information for a URI endpoint. */
public void registerUsernamePassword(URI uri, String username, String password) {
AuthDomain domain = new AuthDomain(uri);
passwordRegistry.put(domain, new PasswordRecord(user, password));
passwordRegistry.put(domain, new PasswordRecord(username, password));
// Remove any existing registration for this URI,
// but not registrations with this URI as prefix.
// unregisterUsernamePassword() removes registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,25 @@ public Y context(Context context) {
if ( context == null )
return thisBuilder();
ensureContext();
this.context.putAll(context);
this.context.setAll(context);
return thisBuilder();
}

public Y set(Symbol symbol, Object value) {
ensureContext();
this.context.put(symbol, value);
this.context.set(symbol, value);
return thisBuilder();
}

public Y set(Symbol symbol, boolean value) {
ensureContext();
this.context.put(symbol, value);
this.context.set(symbol, value);
return thisBuilder();
}

private void ensureContext() {
if ( context == null )
context = new Context();
context = Context.create();
}

private void ensureUpdateRequest() {
Expand Down
5 changes: 5 additions & 0 deletions jena-arq/src/main/java/org/apache/jena/query/ARQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,11 @@ public static void enableOptimizer(Context context, boolean state) {
*/
public static final String systemPropertyScripting = "jena:scripting";

/**
* Context symbol for the script function allow list
*/
public static final Symbol symCustomFunctionScriptAllowList = ScriptLangSymbols.scriptAllowList;

/**
* Context symbol for JavaScript functions as a string value which is evaluated.
* {@code arq:js-functions}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private static Query toQuery(Element pattern) {
private static Plan makePlan(Query query, DatasetGraph dataset, Binding input, Context context)
{
if ( context == null )
context = new Context(ARQ.getContext());
context = ARQ.getContext().copy();
if ( input == null )
input = BindingRoot.create();
QueryEngineFactory f = QueryEngineRegistry.findFactory(query, dataset, context);
Expand Down
6 changes: 6 additions & 0 deletions jena-arq/src/main/java/org/apache/jena/riot/RDFFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class RDFFormat {
public static final RDFFormatVariant BLOCKS = new RDFFormatVariant("blocks") ;
/** Print out one per line */
public static final RDFFormatVariant FLAT = new RDFFormatVariant("flat") ;
/** Print with fixed indentation width and linebreaks after each sequence element */
public static final RDFFormatVariant LONG = new RDFFormatVariant("long") ;

/** Use ASCII output (N-triples, N-Quads) */
public static final RDFFormatVariant ASCII = new RDFFormatVariant("ascii") ;
Expand All @@ -51,6 +53,8 @@ public class RDFFormat {
public static final RDFFormat TURTLE_BLOCKS = new RDFFormat(Lang.TURTLE, BLOCKS) ;
/** Turtle - one line per triple */
public static final RDFFormat TURTLE_FLAT = new RDFFormat(Lang.TURTLE, FLAT) ;
/** Turtle - with fixed indentation width and linebreaks after each sequence element */
public static final RDFFormat TURTLE_LONG = new RDFFormat(Lang.TURTLE, LONG) ;

/** N-Triples in UTF-8 */
public static final RDFFormat NTRIPLES_UTF8 = new RDFFormat(Lang.NTRIPLES, UTF8) ;
Expand Down Expand Up @@ -78,6 +82,8 @@ public class RDFFormat {
public static final RDFFormat TRIG_BLOCKS = new RDFFormat(Lang.TRIG, BLOCKS) ;
/** TriG - one line per triple */
public static final RDFFormat TRIG_FLAT = new RDFFormat(Lang.TRIG, FLAT) ;
/** TriG - with fixed indentation width and linebreaks after each sequence element */
public static final RDFFormat TRIG_LONG = new RDFFormat(Lang.TRIG, LONG) ;

/** SHACL Compact Syntax */
public static final RDFFormat SHACLC = new RDFFormat(Lang.SHACLC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private static WriterGraphRIOTFactory createWriterGraphFactory() {
return new TurtleWriterBlocks() ;
if ( Objects.equals(RDFFormat.TURTLE_FLAT, serialization) )
return new TurtleWriterFlat() ;
if ( Objects.equals(RDFFormat.TURTLE_LONG, serialization) )
return new TurtleWriterLong() ;

if ( Objects.equals(RDFFormat.NTRIPLES_UTF8, serialization) )
return new NTriplesWriter() ;
Expand Down Expand Up @@ -97,6 +99,8 @@ private static WriterDatasetRIOTFactory createWriterDatasetFactory() {
return new TriGWriterBlocks() ;
if ( Objects.equals(RDFFormat.TRIG_FLAT, serialization) )
return new TriGWriterFlat() ;
if ( Objects.equals(RDFFormat.TRIG_LONG, serialization) )
return new TriGWriterLong() ;
if ( Objects.equals(RDFFormat.NQUADS_UTF8, serialization) )
return new NQuadsWriter() ;
if ( Objects.equals(RDFFormat.NQUADS_ASCII, serialization) )
Expand Down Expand Up @@ -159,6 +163,7 @@ public static void init() {}
register(RDFFormat.TURTLE_PRETTY, wgfactory) ;
register(RDFFormat.TURTLE_BLOCKS, wgfactory) ;
register(RDFFormat.TURTLE_FLAT, wgfactory) ;
register(RDFFormat.TURTLE_LONG, wgfactory) ;

register(RDFFormat.NTRIPLES, wgfactory) ;
register(RDFFormat.NTRIPLES_ASCII, wgfactory) ;
Expand Down Expand Up @@ -213,6 +218,7 @@ public static void init() {}
register(RDFFormat.TRIG_PRETTY, wgfactory) ;
register(RDFFormat.TRIG_BLOCKS, wgfactory) ;
register(RDFFormat.TRIG_FLAT, wgfactory) ;
register(RDFFormat.TRIG_LONG, wgfactory) ;

register(RDFFormat.NQUADS, wgfactory) ;
register(RDFFormat.NQUADS_ASCII, wgfactory) ;
Expand Down
6 changes: 6 additions & 0 deletions jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ public static String getBuildDate() {
* not output BASE even when given.
*/
public static final Symbol symTurtleOmitBase = SystemARQ.allocSymbol(TURTLE_SYMBOL_BASE, "omitBase");


/**
* Printing style. Whether to use a "wide" or "long" indentation style.
*/
public static final Symbol symTurtleIndentStyle = SystemARQ.allocSymbol(TURTLE_SYMBOL_BASE, "indentStyle");
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
package org.apache.jena.riot.lang;

import java.util.UUID;
import java.util.concurrent.Callable;

import org.apache.commons.codec.digest.MurmurHash3;
import org.apache.jena.atlas.lib.*;
import org.apache.jena.ext.com.google.common.hash.Hashing;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;

Expand All @@ -46,8 +44,8 @@
public class BlankNodeAllocatorHash implements BlankNodeAllocator {

private static int CacheSize = 1000;
private byte[] seedBytes = null;
private byte[] counterBytes = new byte[10];
private byte[] seedBytes = null;
private byte[] counterBytes = new byte[10];
private Cache<String, Node> cache = null;
private long counter = 0;

Expand All @@ -60,16 +58,16 @@ public BlankNodeAllocatorHash() {
* Gets a fresh seed value
* <p>
* Note that this is called almost immediately by the constructor
* and on this initial call you will not yet have access to any
* and on this initial call you will not yet have access to any
* implementation specific information used to select the seed.
* </p>
* <p>
* Implementations <strong>must</strong> return a non-null value
* so if you can't decide a seed prior to seeing your derived
* implementations constructor inputs you should return a temporary
* fake value initially. You can then call {@link #reset()} in your
* fake value initially. You can then call {@link #reset()} in your
* own constructor after you've taken the necessary steps that allow
* you to decide how to generate your own seed.
* you to decide how to generate your own seed.
* </p>
* @return Seed value
*/
Expand All @@ -95,8 +93,7 @@ public void reset() {

@Override
public Node alloc(String label) {
Callable<Node> getter = ()->alloc(Bytes.string2bytes(label));
Node n = cache.getOrFill(label, getter);
Node n = cache.get(label, (x)->alloc(Bytes.string2bytes(x)));
return n;
}

Expand All @@ -116,37 +113,17 @@ private Node alloc(byte[] labelBytes) {
byte[] input = new byte[seedBytes.length+labelBytes.length];
System.arraycopy(seedBytes, 0, input, 0, seedBytes.length);
System.arraycopy(labelBytes, 0, input, seedBytes.length, labelBytes.length);

// Apache Common Codec or Guava.
// The 2 versions of the code below should produce the same hex strings.
//
// The main difference from our perspective is that the Guava version
// returns a byte[]. Hashes are not "large numbers" - they are bit patterns --
// but it does create and use internal Java objects.
//

// We need to be careful about byte order. The long[] returned by
// MurmurHash3 (Apache Commons) needs to be stringified as "low bytes first"
// which is the reverse of %d-formatting for a long which is
// which is the reverse of %d-formatting for a long which is
// "high byte first" (in a left-to-right writing system).
//
// For byte output compatibility with byte[] from Guava,
// need to reverse the bytes of the longs so that it prints "low to high"
// Java works in big-endian -- high bytes first.

String hexString;
if ( true ) {
long[] x = MurmurHash3.hash128x64(input);
// dev: String xs = String.format("%016x%016x", Long.reverseBytes(x[0]), Long.reverseBytes(x[1]));
char[] chars = new char[32];
longAsHexLC(x[0], chars, 0);
longAsHexLC(x[1], chars, 16);
hexString = new String(chars);
} else {
// Guava. Several objects created.
// Using MurmurHash3.DEFAULT_SEED (which is 104729) makes it agree with Apache Commons Codec value.
byte[] bytes = Hashing.murmur3_128(MurmurHash3.DEFAULT_SEED).hashBytes(input).asBytes();
hexString = Bytes.asHexLC(bytes);
}
long[] x = MurmurHash3.hash128x64(input);
// dev: String xs = String.format("%016x%016x", Long.reverseBytes(x[0]), Long.reverseBytes(x[1]));
char[] chars = new char[32];
longAsHexLC(x[0], chars, 0);
longAsHexLC(x[1], chars, 16);
String hexString = new String(chars);
return NodeFactory.createBlankNode(hexString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@

package org.apache.jena.riot.system;

import java.util.concurrent.ExecutionException ;

import org.apache.jena.ext.com.google.common.cache.Cache ;
import org.apache.jena.atlas.lib.Cache;
import org.apache.jena.atlas.lib.CacheFactory;
import org.apache.jena.atlas.lib.cache.CacheInfo ;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.xsd.XSDDatatype ;
import org.apache.jena.ext.com.google.common.cache.CacheBuilder ;
import org.apache.jena.ext.com.google.common.cache.CacheStats ;
import org.apache.jena.graph.Node ;
import org.apache.jena.riot.RiotException ;
import org.apache.jena.riot.lang.LabelToNode ;
import org.apache.jena.sparql.graph.NodeConst ;

/** Adds some caching of created nodes - the caching is tuned to RIOT parser usage */
public class FactoryRDFCaching extends FactoryRDFStd {
public static final int DftNodeCacheSize = 5000 ;

// Control the setup - for one thread; start size = 50% of full size, no stats
private final int cacheSize ;
private final Cache<String, Node> cache ;

public FactoryRDFCaching() {
Expand All @@ -44,26 +41,17 @@ public FactoryRDFCaching() {

public FactoryRDFCaching(int cacheSize, LabelToNode labelMapping) {
super(labelMapping) ;
cache = setCache(cacheSize) ;
this.cacheSize = cacheSize;
this.cache = setCache(cacheSize) ;
}

private Cache<String, Node> setCache(int cacheSize) {
return CacheBuilder.newBuilder()
.maximumSize(cacheSize)
.initialCapacity(cacheSize/2)
//.recordStats()
.concurrencyLevel(1)
.build() ;
return CacheFactory.createCache(cacheSize);
}

@Override
public Node createURI(String uriStr) {
try {
return cache.get(uriStr, ()->RiotLib.createIRIorBNode(uriStr)) ;
}
catch (ExecutionException e) {
throw new RiotException("Execution exception filling cache <"+uriStr+">", e) ;
}
return cache.get(uriStr, RiotLib::createIRIorBNode);
}

// A few constants
Expand Down Expand Up @@ -95,17 +83,7 @@ public Node createStringLiteral(String lexical) {
return super.createStringLiteral(lexical) ;
}

// The cache is not reset. It can be carried across parser runs.
// @Override
// public void reset() {
// super.reset();
// }

public CacheInfo stats() {
CacheStats stats = cache.stats() ;
if ( stats.missCount() == 0 && stats.hitCount() == 0 )
// Stats not enabled - all counts zero.
return null ;
return new CacheInfo(DftNodeCacheSize, stats) ;
return cache.stats();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void doChecking(IRIx irix, String uriStr, long line, long col) {
if ( irix instanceof IRIProviderJenaIRI.IRIxJena )
iri = (IRI)irix.getImpl();
else
iri = iriCache.getOrFill(uriStr, () -> SetupJenaIRI.iriCheckerFactory().create(uriStr));
iri = iriCache.get(uriStr, x -> SetupJenaIRI.iriCheckerFactory().create(x));
Checker.iriViolations(iri, errorHandler, false, true, line, col);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jena.riot.writer;

enum IndentStyle {
WIDE, LONG ;
public static IndentStyle create(String label) {
String s = label.toLowerCase() ;
switch(s) {
case "wide":
return IndentStyle.WIDE ;
case "long":
return IndentStyle.LONG ;
}
return null;
}
}
Loading