Skip to content
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
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/arq/cmdline/CmdARQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import org.apache.jena.atlas.lib.Lib;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.query.ARQ;
import org.apache.jena.sys.JenaSystem;

public abstract class CmdARQ extends CmdGeneral {
public abstract class CmdARQ extends CmdMain {
static {
JenaSystem.init();
}
Expand Down
12 changes: 7 additions & 5 deletions jena-cmds/src/main/java/arq/cmdline/CmdARQ_SSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@
/** Root of read an SSE file and do something */
public abstract class CmdARQ_SSE extends CmdARQ
{
protected ModItem modItem = new ModItem() ;
protected ModItem modItem = new ModItem() ;

public CmdARQ_SSE(String[] argv)
{
super(argv) ;
super.addModule(modItem) ;
}

@Override
protected String getSummary() { return getCommandName()+" [--file<file> | string]" ; }
protected String getSummary() {
return getCommandName() + " [--file<file> | string]";
}

@Override
final protected void exec()
{
Item item = modItem.getItem() ;
exec(item) ;
}

protected abstract void exec(Item item) ;
}
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/arq/qparse.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ protected void processModulesAndArgs() {
printQuery = true;
}

static String usage = qparse.class.getName() + " [--in syntax] [--out syntax] [--print=FORM] [\"query\"] | --query <file>";
static String usageArgs = "[--in syntax] [--out syntax] [--print=FORM] [\"query\"] | --query <file>";

@Override
protected String getSummary() {
return usage;
return getCommandName()+" "+usageArgs;
}

static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
Expand Down
9 changes: 5 additions & 4 deletions jena-cmds/src/main/java/org/apache/jena/cmd/CmdArgModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class CmdArgModule extends CmdMain
public abstract class CmdArgModule extends CmdLineArgs
{
private List<ArgModuleGeneral> modules = new ArrayList<>();

Expand All @@ -34,9 +34,9 @@ protected void addModule(ArgModuleGeneral argModule) {
}

@Override
final public void process() {
public void process() {
super.process();
forEach((controller, module) -> module.processArgs(controller));
forEach((cmdArgModule, module) -> module.processArgs(cmdArgModule));
processModulesAndArgs();
}

Expand All @@ -48,7 +48,8 @@ private void forEach(Action action) {
}
}

@FunctionalInterface
interface Action {
public void action(CmdArgModule controller, ArgModuleGeneral module);
public void action(CmdArgModule cmdArgModule, ArgModuleGeneral module);
}
}
22 changes: 12 additions & 10 deletions jena-cmds/src/main/java/org/apache/jena/cmd/CmdGeneral.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.io.PrintStream;
import org.apache.jena.atlas.io.IndentedWriter;
// Added usage + some common flags
// This is the usual starting point for any sub
// This is the starting point for argument processing.

public abstract class CmdGeneral extends CmdArgModule
{
Expand All @@ -40,9 +40,9 @@ public void addModule(ArgModuleGeneral argModule) {
argModule.registerWith(this);
}

protected boolean isVerbose() { return modGeneral.verbose; }
protected boolean isQuiet() { return modGeneral.quiet; }
protected boolean isDebug() { return modGeneral.debug; }
public boolean isVerbose() { return modGeneral.verbose; }
public boolean isQuiet() { return modGeneral.quiet; }
public boolean isDebug() { return modGeneral.debug; }
protected boolean help() { return modGeneral.help; }

final public void printHelp() {
Expand All @@ -56,9 +56,16 @@ protected void processModulesAndArgs() {
modVersion.printVersionAndExit();
}

public void add(ArgDecl argDecl, String argName, String msg) {
add(argDecl);
getUsage().addUsage(argName, msg);
}

private Usage usage = new Usage();
protected String cmdName = null;

protected String getCommandName() { return null; }
protected abstract String getSummary();

public void usage() { usage(System.err); }

public void usage(PrintStream pStr) {
Expand All @@ -67,10 +74,5 @@ public void usage(PrintStream pStr) {
usage.output(out);
}

public void add(ArgDecl argDecl, String argName, String msg) {
add(argDecl);
getUsage().addUsage(argName, msg);
}

public Usage getUsage() { return usage; }
}
8 changes: 8 additions & 0 deletions jena-cmds/src/main/java/org/apache/jena/cmd/CmdLineArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public CmdLineArgs(String[] args) {
super(args);
}

public void cmdError(String msg) { cmdError(msg, true);}

public void cmdError(String msg, boolean exit) {
System.err.println(msg);
if ( exit )
throw new TerminationException(5);
}

private boolean processedArgs = false;

// Setup:
Expand Down
37 changes: 18 additions & 19 deletions jena-cmds/src/main/java/org/apache/jena/cmd/CmdMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@
package org.apache.jena.cmd;

import org.apache.jena.atlas.logging.LogCtl;
/** Adds main()-like methods
*

/**
* Adds main()-like methods to argument processing.
* <p>
* Use this class for commands that follow the common pattern of processing arguments
* and then executing with no additional intermediate steps.
* <p>
* Usage:
* new YourCommand(args).mainAndExit()
* which never returns and routes thing to System.exit.
* or call
* new YourCommand(args).mainMethod()
* which should not call System.exit anywhere */
* <pre>new YourCommand(args).mainAndExit()</pre>
* which never returns and routes to System.exit. or call
* <pre>new YourCommand(args).mainMethod()</pre>
*
* which should not call {@code System.exit} anywhere.
*/

public abstract class CmdMain extends CmdLineArgs
public abstract class CmdMain extends CmdGeneral
{
// Do this very early so it happens before anything else
// gets a chance to create a logger.
static { LogCtl.setLogging(); }

public CmdMain(String[] args) {
protected CmdMain(String[] args) {
super(args);
}

Expand Down Expand Up @@ -81,18 +87,11 @@ public int mainRun(boolean exitOnSuccess, boolean exitOnFailure) {
return 0;
}

protected final void mainMethod() {
process();
exec();
}

protected abstract void exec();
protected abstract String getCommandName();
public void cmdError(String msg) { cmdError(msg, true);}

public void cmdError(String msg, boolean exit) {
System.err.println(msg);
if ( exit )
throw new TerminationException(5);
protected final void mainMethod() {
process();
exec();
}
}
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/rdfpatch/CmdRDFPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.apache.jena.atlas.io.IO;
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.sys.JenaSystem;

/** Abstract base class to work on patch files given on the command line */
public abstract class CmdRDFPatch extends CmdGeneral {
public abstract class CmdRDFPatch extends CmdMain {
static {
LogCtl.setLogging();
JenaSystem.init();
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/riotcmd/CmdLangParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.irix.IRIException;
import org.apache.jena.irix.IRIs;
import org.apache.jena.irix.IRIxResolver;
Expand All @@ -54,7 +54,7 @@
import org.apache.jena.sys.JenaSystem;

/** Common framework for running RIOT parsers */
public abstract class CmdLangParse extends CmdGeneral {
public abstract class CmdLangParse extends CmdMain {
static {
JenaSystem.init();
}
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/riotcmd/infer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.jena.atlas.io.IO ;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.graph.Graph;
import org.apache.jena.rdfs.RDFSFactory;
import org.apache.jena.riot.Lang ;
Expand Down Expand Up @@ -78,7 +78,7 @@
* owl:inverseOf
* owl:TransitiveProperty
*/
public class infer extends CmdGeneral
public class infer extends CmdMain
{
static final ArgDecl argRDFS = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
private Graph vocab ;
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/shacl/shacl_parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.graph.Graph;
import org.apache.jena.irix.IRIException;
import org.apache.jena.irix.IRIs;
Expand All @@ -49,7 +49,7 @@
* <p>
* Usage: <code>shacl parse FILE</code>
*/
public class shacl_parse extends CmdGeneral {
public class shacl_parse extends CmdMain {
static {
LogCtl.setLogging();
JenaSystem.init();
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/shacl/shacl_validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
Expand All @@ -39,7 +39,7 @@
* <p>
* Usage: <code>shacl validate [--text] --shapes SHAPES --data DATA</code>
*/
public class shacl_validate extends CmdGeneral {
public class shacl_validate extends CmdMain {

static {
LogCtl.setLogging();
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/shex/shex_parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.riot.RiotException;
import org.apache.jena.shex.Shex;
import org.apache.jena.shex.ShexSchema;
Expand All @@ -42,7 +42,7 @@
* <p>
* Usage: <code>shex parse FILE</code>
*/
public class shex_parse extends CmdGeneral {
public class shex_parse extends CmdMain {
static {
LogCtl.setLogging();
JenaSystem.init();
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/shex/shex_validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
Expand All @@ -37,7 +37,7 @@
* <p>
* Usage: <code>shex validate [--text] --shapes SHAPES --data DATA</code>
*/
public class shex_validate extends CmdGeneral {
public class shex_validate extends CmdMain {

static {
LogCtl.setLogging();
Expand Down
4 changes: 2 additions & 2 deletions jena-cmds/src/main/java/tdb/xloader/CmdNodeTableBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.sys.JenaSystem;
Expand All @@ -36,7 +36,7 @@
import tdb.cmdline.CmdTDB;

/** Build node table - write triples/quads as text file */
public class CmdNodeTableBuilder extends CmdGeneral
public class CmdNodeTableBuilder extends CmdMain
{
static {
LogCtl.setLogging();
Expand Down
7 changes: 2 additions & 5 deletions jena-cmds/src/main/java/tdb2/xloader/AbstractCmdxLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.cmd.CmdMain;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.tdb2.xloader.XLoaderFiles;

/**
* Base class for TDB xloaders commands for java steps in the load process.
* All steps accept all the same arguments, even if they are not applicable to the stage.
*/
abstract class AbstractCmdxLoad extends CmdGeneral {
abstract class AbstractCmdxLoad extends CmdMain {
static {
JenaSystem.init();
LogCtl.setLog4j2();
Expand Down Expand Up @@ -79,9 +79,6 @@ protected AbstractCmdxLoad(String stageName, String[] argv) {

protected abstract void setCmdArgs();

@Override
protected abstract String getSummary();

protected String getArgsSummary() {
return "--loc=DIR --tmpdir=DIR";
}
Expand Down
Loading
Loading