Skip to content

Commit

Permalink
Adjust command line args via customizer
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Dec 26, 2024
1 parent c795587 commit 3b88681
Show file tree
Hide file tree
Showing 26 changed files with 326 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static void delete(File f, boolean reportExistsAfter) {

/**
* Delete all files in a directory.
* Does not recurse in the direction.
* Does nothing if the path name does not exist or is not a directory.
*
* @param dir
Expand All @@ -84,7 +85,7 @@ public static void clearAll(String d) {
clearAll(new File(d)) ;
}

/** Delete all files and directories (recursively) in a directory */
/** Delete all files and directories (recursively) in a directory; does not delete the directory argument. */
public static void clearAll(File d) {
if ( ! d.exists() )
return ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ public static void initConsts() {}
public static final String attrNameRegistry = "org.apache.jena.fuseki:DataAccessPointRegistry";
public static final String attrOperationRegistry = "org.apache.jena.fuseki:OperationRegistry";
public static final String attrAuthorizationService = "org.apache.jena.fuseki:AuthorizationService";
// The Fuseki Server
public static final String attrFusekiServer = "org.apache.jena.fuseki:Server";
// The FusekiServerCtl object for the admin area; may be null
public static final String attrFusekiServerCtl = "org.apache.jena.fuseki:ServerCtl";
public static final String attrMetricsProvider = "org.apache.jena.fuseki:MetricsProvider";

public static void setVerbose(ServletContext cxt, boolean verbose) {
Expand Down
16 changes: 16 additions & 0 deletions jena-fuseki2/jena-fuseki-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,24 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-cmds</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Add for runtime in jena-fuseki-server -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-ui</artifactId>
<version>5.3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- Add in jena-fuseki-server
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-text</artifactId>
<version>${project.version}</version>
</dependency>
-->

<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.jena.fuseki.server.FusekiCoreInfo;
import org.slf4j.Logger;

public class FusekiMainInfo {
public class FusekiInfo {

/** Details of the code version. */
public static void logCode(Logger log) {
Expand All @@ -31,8 +31,8 @@ public static void logCode(Logger log) {

/** Log server details. */
public static void logServer(Logger log, FusekiServer server, boolean verbose) {
FusekiMainInfo.logServerConnections(log, server);
FusekiMainInfo.logServerDatasets(log, server, verbose);
FusekiInfo.logServerConnections(log, server);
FusekiInfo.logServerDatasets(log, server, verbose);
if ( server.getStaticContentDir() != null )
FmtLog.info(log, "Static files: %s", server.getStaticContentDir());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.jena.cmd.*;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.main.FusekiMainInfo;
import org.apache.jena.fuseki.main.FusekiInfo;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.sys.FusekiModules;
import org.apache.jena.fuseki.main.sys.FusekiServerArgsCustomiser;
Expand All @@ -56,6 +56,17 @@
import org.slf4j.Logger;

public class FusekiMain extends CmdARQ {

// Need to pass to mods?
// Add "setup" call.
public enum Mode {
// Command setup, no admin
PLAIN,
// + Admin + Validators + metrics + ...
GENERAL
}


/** Default HTTP port when running from the command line. */
public static int defaultPort = 3030;
/** Default HTTPS port when running from the command line. */
Expand Down Expand Up @@ -97,8 +108,8 @@ public class FusekiMain extends CmdARQ {
private static ArgDecl argWithMetrics = new ArgDecl(ArgDecl.NoValue, "withMetrics", "metrics");
private static ArgDecl argWithCompact = new ArgDecl(ArgDecl.NoValue, "withCompact", "compact");

// // Use modules found by the ServiceLoader.
// private static ArgDecl argEnableModules = new ArgDecl(ArgDecl.HasValue, "modules", "fuseki-modules");
// Use modules found by the ServiceLoader. Currently, no-op.
private static ArgDecl argEnableModules = new ArgDecl(ArgDecl.HasValue, "modules", "fuseki-modules");

private static ArgDecl argAuth = new ArgDecl(ArgDecl.HasValue, "auth");

Expand Down Expand Up @@ -196,6 +207,20 @@ public static void addCustomiser(FusekiServerArgsCustomiser customiser) {
ArgCustomizers.addCustomiser(customiser);
}

/**
* Registers CLI customisers.
* <p>
* CLI customisers can add one/more custom arguments into the Fuseki Server CLI arguments and then can apply those
* to the Fuseki server being built during the processing of {@link #processModulesAndArgs()}. This allows for
* custom arguments that directly affect how the Fuseki server is built to be created.
* </p>
* @see #addCustomiser(FusekiServerArgsCustomiser)
*/
public static void addCustomisers(FusekiModules customiserSet) {
Objects.requireNonNull(customiserSet);
customiserSet.forEach(customiser->ArgCustomizers.addCustomiser(customiser));
}

/**
* Resets any previously registered CLI customisers
*/
Expand Down Expand Up @@ -306,7 +331,7 @@ private void argumentsSetup() {
add(argWithMetrics, "--metrics", "Enable /$/metrics");
add(argWithCompact, "--compact", "Enable /$/compact/*");

//add(argEnableModules, "--modules=true|false", "Enable Fuseki modules");
add(argEnableModules, "--modules=true|false", "Enable Fuseki autoloaded modules");

super.modVersion.addClass("Fuseki", Fuseki.class);

Expand Down Expand Up @@ -578,9 +603,9 @@ private void processStdArguments(Logger log) {
// Allows for external setting of serverArgs.fusekiModules
if ( serverArgs.fusekiModules == null ) {
// Get modules from system-wide setup.
// This (Fuseki 5.3.0- defaults to an empty set of modules.
// boolean withModules = hasValueOfTrue(argEnableModules);
serverArgs.fusekiModules = FusekiModules.getSystemModules();
boolean withModules = hasValueOfTrue(argEnableModules);
if ( withModules )
serverArgs.fusekiModules = FusekiModules.getSystemModules();
}

if ( contains(argCORS) ) {
Expand Down Expand Up @@ -630,7 +655,7 @@ protected void exec() {
// Check for command line or config setup.
try {
Logger log = Fuseki.serverLog;
FusekiMainInfo.logServerCode(log);
FusekiInfo.logServerCode(log);
FusekiServer server = makeServer(serverArgs);
infoCmd(server, log);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.apache.jena.fuseki.main.cmds;

import org.apache.jena.fuseki.mod.FusekiModServer;
import org.apache.jena.fuseki.mod.FusekiServerRunner;
import org.apache.jena.fuseki.system.FusekiLogging;

/** Fuseki command that runs a Fuseki server with the admin UI.
Expand All @@ -45,7 +45,7 @@ public class FusekiServerCmd {
* syntax but not start it.
*/
static public void main(String... args) {
FusekiModServer.runAsync(args).join();
FusekiServerRunner.runAsync(args).join();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ServerArgs {
public boolean verboseLogging = false;

/**
* FusekiModules to use during the server build *
* FusekiModules to use during the server build
* Command line customisers are handled separately by FusekiMain.
*/
public FusekiModules fusekiModules = null;
Expand All @@ -75,7 +75,7 @@ public class ServerArgs {
public String serverConfigFile = null;
public Model serverConfigModel = null;

/** Allow no datasets without it being an error. This is not an argument. */
/** Allow no datasets without it being an error. This is not a command argument. */
public boolean allowEmpty = false;
public SetupType setup = SetupType.UNSET;
/** Start without a dataset or configuration (this is {@code --empty}) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ else if ( WebContent.isMultiPartForm(ct) )
FmtLog.warn(action.log, "Inconsistent names: datasetPath = %s; DataAccessPoint name = %s", datasetPath, dataAccessPoint);
succeeded = true;
action.getDataAccessPointRegistry().register(dataAccessPoint);

// Add to metrics
MetricsProvider metricProvider = action.getMetricsProvider();
if ( metricProvider != null )
Expand Down Expand Up @@ -418,7 +418,14 @@ private static void assemblerFromForm(HttpAction action, StreamRDF dest) {
params.put(Template.NAME, dbName.substring(1));
else
params.put(Template.NAME, dbName);
FusekiServerCtl.addGlobals(params);

FusekiServerCtl serverCtl = FusekiServerCtl.get(action.getServletContext());
if ( serverCtl != null )
serverCtl.addGlobals(params);
else {
ServletOps.errorOccurred("No admin area");
// No return.
}

//action.log.info(format("[%d] Create database : name = %s, type = %s", action.id, dbName, dbType ));

Expand All @@ -429,7 +436,7 @@ private static void assemblerFromForm(HttpAction action, StreamRDF dest) {
ServletOps.errorBadRequest(format("dbType can be only one of %s", keys));
}

String instance = TemplateFunctions.templateFile(template, params, Lang.TTL);
String instance = TemplateFunctions.templateFile(serverCtl.getFusekiBase(), template, params, Lang.TTL);
RDFParser.create().source(new StringReader(instance)).base("http://base/").lang(Lang.TTL).parse(dest);
}

Expand Down
Loading

0 comments on commit 3b88681

Please sign in to comment.