Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuseki maintenance #2894

Merged
merged 10 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 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 @@ -76,6 +76,13 @@ public boolean hasRegistation(URI uri) {
return passwordRegistry.contains(location);
}

/**
* Remove the registration for a URI endpoint.
*/
public void unregisterUsernamePassword(String uri) {
unregisterUsernamePassword(URI.create(uri));
}

/**
* Remove the registration for a URI endpoint.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ static public void init()
initialized = true ;
registerDataset(tDataset, new DatasetAssemblerGeneral());
registerDataset(tDatasetOne, new DatasetOneAssembler());
registerDataset(tDatasetZero, new DatasetNullAssembler(tDatasetZero));
registerDataset(tDatasetSink, new DatasetNullAssembler(tDatasetSink));
registerDataset(tDatasetZero, new DatasetZeroAssembler());
registerDataset(tDatasetSink, new DatasetSinkAssembler());
registerDataset(tMemoryDataset, new InMemDatasetAssembler());
registerDataset(tDatasetTxnMem, new InMemDatasetAssembler());
registerDataset(tDatasetView, new ViewDatasetAssembler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.jena.sparql.core.assembler ;

import java.util.List ;
import java.util.Map;

import org.apache.jena.assembler.Assembler ;
import org.apache.jena.atlas.logging.Log ;
Expand All @@ -41,11 +40,6 @@ public static Resource getType() {

public DatasetAssemblerGeneral() {}

@Override
public Map<String, DatasetGraph> pool() {
return sharedDatasetPool;
}

@Override
public DatasetGraph createDataset(Assembler a, Resource root) {
// -------- Default graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.jena.sparql.core.assembler;

import java.util.List;
import java.util.Map;

import org.apache.jena.assembler.Assembler;
import org.apache.jena.assembler.exceptions.AssemblerException;
Expand Down Expand Up @@ -51,11 +50,6 @@ public static Resource getType() {

public DatasetOneAssembler() {}

@Override
public Map<String, DatasetGraph> pool() {
return sharedDatasetPool;
}

@Override
public DatasetGraph createDataset(Assembler a, Resource root) {
// Can use ja:graph or ja:defaultGraph but not both.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,29 @@

package org.apache.jena.sparql.core.assembler;

import java.util.Map;

import org.apache.jena.assembler.Assembler;
import org.apache.jena.atlas.lib.InternalErrorException;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphSink;
import org.apache.jena.sparql.core.DatasetGraphZero;

/**
* An assembler that creates datasets that do nothing, either a sink or a always empty one.
* An assembler that creates datasets that do nothing, either a sink or an always empty one.

* @see DatasetGraphSink
* @see DatasetGraphZero
*/

public class DatasetNullAssembler extends NamedDatasetAssembler {
public class DatasetSinkAssembler extends NamedDatasetAssembler {

private final Resource tDataset;
public static Resource getType() { return DatasetAssemblerVocab.tDatasetSink; }

public DatasetNullAssembler(Resource tDataset) {
this.tDataset = tDataset;
}
public DatasetSinkAssembler() {}

@Override
public DatasetGraph createDataset(Assembler a, Resource root) {
DatasetGraph dsg;
if ( DatasetAssemblerVocab.tDatasetSink.equals(tDataset) )
dsg = DatasetGraphSink.create();
else if ( DatasetAssemblerVocab.tDatasetZero.equals(tDataset) )
dsg = DatasetGraphZero.create();
else
throw new InternalErrorException();
DatasetGraph dsg = DatasetGraphSink.create();
AssemblerUtils.mergeContext(root, dsg.getContext());
return dsg;
}

@Override
public Map<String, DatasetGraph> pool() {
return sharedDatasetPool;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.sparql.core.assembler;

import org.apache.jena.assembler.Assembler;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphZero;

/**
* An assembler that creates datasets that do nothing, either a sink or an always empty one.
*
* @see DatasetGraphZero
*/

public class DatasetZeroAssembler extends NamedDatasetAssembler {

public static Resource getType() { return DatasetAssemblerVocab.tDatasetZero; }

public DatasetZeroAssembler() {}

@Override
public DatasetGraph createDataset(Assembler a, Resource root) {
DatasetGraph dsg = DatasetGraphZero.create();
AssemblerUtils.mergeContext(root, dsg.getContext());
return dsg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import static org.apache.jena.sparql.core.assembler.AssemblerUtils.loadData;
import static org.apache.jena.sparql.core.assembler.AssemblerUtils.mergeContext;

import java.util.Map;

import org.apache.jena.assembler.Assembler;
import org.apache.jena.query.Dataset;
import org.apache.jena.rdf.model.Resource;
Expand All @@ -39,11 +37,6 @@ public class InMemDatasetAssembler extends NamedDatasetAssembler {

public InMemDatasetAssembler() {}

@Override
public Map<String, DatasetGraph> pool() {
return sharedDatasetPool;
}

public static Resource getType() {
return DatasetAssemblerVocab.tMemoryDataset ;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public final DatasetGraph createNamedDataset(Assembler a, Resource root) {
return createDataset(a, root);
}

/** Shared {@link DatasetGraph} objects */
public abstract Map<String, DatasetGraph> pool();
/**
* Shared {@link DatasetGraph} objects.
* Subclasses may override for a different policy, or return null for "don't pool".
* Pools only affect {@link #createNamedDataset} and then only when {@code ja:name}
* ({@code DatasetAssemblerVocab.pDatasetName}) is present.
*/
public Map<String, DatasetGraph> pool() { return sharedDatasetPool; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.jena.sparql.core.assembler;

import java.util.Map;

import org.apache.jena.assembler.Assembler;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.sparql.core.DatasetGraph;
Expand All @@ -38,11 +36,6 @@ public class ViewDatasetAssembler extends NamedDatasetAssembler {

public ViewDatasetAssembler() {}

@Override
public Map<String, DatasetGraph> pool() {
return sharedDatasetPool;
}

@Override
public DatasetGraph createDataset(Assembler a, Resource root) {
DatasetGraph sub = createBaseDataset(root, DatasetAssemblerVocab.pDataset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ContextAccumulator {
private Context baseContext = null;

// Context when built
private Context builtContext = null;
private Context builtContext = null;

public static ContextAccumulator newBuilder() {
return new ContextAccumulator();
Expand Down Expand Up @@ -77,7 +77,7 @@ private ContextAccumulator() { }

/**
* If no explicit base, this is the default. It will be copied to isolate it at the build point.
* Default implement is to return ARQ.getContext().
* Default implementation is to return ARQ.getContext().
*/
protected Context baseContext() { return ARQ.getContext(); }

Expand Down Expand Up @@ -108,7 +108,7 @@ public ContextAccumulator context(Context context) {
*/
public Context context() {
// Freeze and return.
return getOrBuiltContext();
return getOrBuildContext();
}

/**
Expand All @@ -129,7 +129,7 @@ private void update() {
}

// Build once.
private Context getOrBuiltContext() {
private Context getOrBuildContext() {
if ( builtContext == null )
builtContext = buildProcess();
return builtContext;
Expand Down
46 changes: 46 additions & 0 deletions jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,50 @@ public static Path uniqueDerivedPath(Path path, Function<String, String> basenam
}
return null;
}

/**
* Check whether a file name points to a readable, regular file.
* Generate an exception if not.
*/
public static void checkReadableFile(String file, Function<String, RuntimeException> exceptionMaker) {
Path path = Path.of(file);
checkReadableFile(path, exceptionMaker);
}

/**
* Check whether a file path points to a readable, regular file.
* Generate an exception if not.
*/
public static void checkReadableFile(Path path, Function<String, RuntimeException> exceptionMaker) {
if ( ! Files.exists(path) )
throw exceptionMaker.apply("File not found: "+path);
if ( Files.isDirectory(path) )
throw exceptionMaker.apply("Is a directory: "+path);
if ( ! Files.isRegularFile(path) )
throw exceptionMaker.apply("Not a regular file: "+path);
if ( ! Files.isReadable(path) )
throw exceptionMaker.apply("Not readable: "+path);
}

/**
* Check whether a file path points to a readable directory.
* Generate an exception if not.
*/
public static void checkReadableDirectory(String directory, Function<String, RuntimeException> exceptionMaker) {
Path path = Path.of(directory);
checkReadableDirectory(path, exceptionMaker);
}

/**
* Check whether a file path points to a readable directory.
* Generate an exception if not.
*/
public static void checkReadableDirectory(Path path, Function<String, RuntimeException> exceptionMaker) {
if ( ! Files.exists(path) )
throw exceptionMaker.apply("File not found: "+path);
if ( ! Files.isDirectory(path) )
throw exceptionMaker.apply("Not a directory: "+path);
if ( ! Files.isReadable(path) )
throw exceptionMaker.apply("Not readable: "+path);
}
}
60 changes: 14 additions & 46 deletions jena-base/src/main/java/org/apache/jena/atlas/logging/LogCtl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
* This needs access to log4j2 binaries including log4j-core, which is encapsulated in LogCtlLog4j2.
*/
public class LogCtl {
private static final boolean hasLog4j2 = hasClass("org.apache.logging.slf4j.Log4jLoggerFactory");
private static final boolean hasLog4j1 = hasClass("org.slf4j.impl.Log4jLoggerFactory");
private static final boolean hasJUL = hasClass("org.slf4j.impl.JDK14LoggerFactory");
private static final boolean hasLog4j2 = hasClass("org.apache.logging.slf4j.Log4jLoggerFactory");
private static final boolean hasLog4j1 = hasClass("org.slf4j.impl.Log4jLoggerFactory");
// JUL always present but needs slf4j adapter.
private static final boolean hasJUL = hasClass("org.slf4j.impl.JDK14LoggerFactory");
private static final boolean hasLogback = hasClass("ch.qos.logback.core.LogbackException");
// Put per-logging system code in separate classes to avoid needing them on the classpath.

private static boolean hasClass(String className) {
Expand Down Expand Up @@ -83,67 +84,34 @@ public static String getLevel(String logger) {
String s2 = getLevelLog4j2(logger);
if ( s2 != null )
return s2;
// Always present.
String s3 = getLevelJUL(logger);
if ( s3 != null )
return s3;
return null;
}

static private String getLevelJUL(String logger) {
java.util.logging.Level level = java.util.logging.Logger.getLogger(logger).getLevel();
if ( level == null )
static private String getLevelLog4j2(String logger) {
if ( !hasLog4j2 )
return null;
if ( level == java.util.logging.Level.SEVERE )
return "ERROR";
return level.getName();
return LogCtlLog4j2.getLoggerlevel(logger);
}

static private String getLevelLog4j2(String logger) {
if ( !hasLog4j2 )
static private String getLevelJUL(String logger) {
if ( ! hasJUL )
return null;
org.apache.logging.log4j.Level level = org.apache.logging.log4j.LogManager.getLogger(logger).getLevel();
if ( level != null )
return level.toString();
return null;
return LogCtlJUL.getLevelJUL(logger);
}

private static void setLevelJUL(String logger, String levelName) {
java.util.logging.Level level = java.util.logging.Level.ALL;
if ( levelName == null )
level = null;
else if ( levelName.equalsIgnoreCase("info") )
level = java.util.logging.Level.INFO;
else if ( levelName.equalsIgnoreCase("debug") )
level = java.util.logging.Level.FINE;
else if ( levelName.equalsIgnoreCase("warn") || levelName.equalsIgnoreCase("warning") )
level = java.util.logging.Level.WARNING;
else if ( levelName.equalsIgnoreCase("error") || levelName.equalsIgnoreCase("severe") )
level = java.util.logging.Level.SEVERE;
else if ( levelName.equalsIgnoreCase("OFF") )
level = java.util.logging.Level.OFF;
java.util.logging.Logger.getLogger(logger).setLevel(level);
if ( ! hasJUL )
return ;
LogCtlJUL.setLevelJUL(logger, levelName);
}

private static void setLevelLog4j2(String logger, String levelName) {
if ( !hasLog4j2 )
return;
org.apache.logging.log4j.Level level = org.apache.logging.log4j.Level.ALL;
if ( levelName == null )
level = null;
else if ( levelName.equalsIgnoreCase("info") )
level = org.apache.logging.log4j.Level.INFO;
else if ( levelName.equalsIgnoreCase("debug") )
level = org.apache.logging.log4j.Level.DEBUG;
else if ( levelName.equalsIgnoreCase("warn") || levelName.equalsIgnoreCase("warning") )
level = org.apache.logging.log4j.Level.WARN;
else if ( levelName.equalsIgnoreCase("error") || levelName.equalsIgnoreCase("severe") )
level = org.apache.logging.log4j.Level.ERROR;
else if ( levelName.equalsIgnoreCase("fatal") )
level = org.apache.logging.log4j.Level.FATAL;
else if ( levelName.equalsIgnoreCase("OFF") )
level = org.apache.logging.log4j.Level.OFF;
LogCtlLog4j2.setLoggerlevel(logger, level);
LogCtlLog4j2.setLoggerlevel(logger, levelName);
}

/**
Expand Down
Loading
Loading