You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2026/05/11 13:58:45 UTC
(jena) 02/03: GH-3908: riot - flush on error and warning
This is an automated email from the ASF dual-hosted git repository.
afs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 0593354effbb20ee9494b548170737f16f8303de
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Thu May 7 19:17:12 2026 +0100
GH-3908: riot - flush on error and warning
---
apache-jena/cmd-maker | 3 +-
.../src/main/java/org/apache/jena/cmd/CmdMain.java | 1 -
jena-cmds/src/main/java/riotcmd/CmdLangParse.java | 75 +++++++++-------------
.../src/main/java/riotcmd/ErrorHandlerCLI.java | 41 ++++++++----
4 files changed, 63 insertions(+), 57 deletions(-)
diff --git a/apache-jena/cmd-maker b/apache-jena/cmd-maker
index 4c957871c2..92b497babd 100755
--- a/apache-jena/cmd-maker
+++ b/apache-jena/cmd-maker
@@ -17,7 +17,7 @@
## limitations under the License.
# Not xloader
-## xloader (forerly "TDB 1 tdbloader2") is slightly different.
+## xloader (formerly, "TDB 1 tdbloader2") is slightly different.
## The main program is not a java program
## It is split into several scripts that leverage a mixture of
## POSIX and java tools and should be maintained separately
@@ -36,7 +36,6 @@ jena.schemagen
arq.rdfdiff
arq.sparql
arq.arq
-arq.juuid
arq.rsparql
arq.rset
arq.qparse
diff --git a/jena-cmds/src/main/java/org/apache/jena/cmd/CmdMain.java b/jena-cmds/src/main/java/org/apache/jena/cmd/CmdMain.java
index 93340f4991..6279fbad2d 100644
--- a/jena-cmds/src/main/java/org/apache/jena/cmd/CmdMain.java
+++ b/jena-cmds/src/main/java/org/apache/jena/cmd/CmdMain.java
@@ -90,7 +90,6 @@ public abstract class CmdMain extends CmdGeneral
return 0;
}
-
protected abstract void exec();
protected final void mainMethod() {
diff --git a/jena-cmds/src/main/java/riotcmd/CmdLangParse.java b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
index 7f7e0f832a..8147da71b7 100644
--- a/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
+++ b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
@@ -126,27 +126,13 @@ public abstract class CmdLangParse extends CmdMain {
void postParse();
}
- protected static class ParseRecord {
- // Display name (filename as given on the command line)
- final String filename;
- // Resolved filename as a URL string.
- final String sourceURL;
- final boolean success;
- final long timeMillis;
- final long triples;
- final long quads;
- final long tuples = 0;
- final ErrorHandlerCLI errHandler;
-
- public ParseRecord(String filename, String sourceURL, boolean successful, long timeMillis, long countTriples, long countQuads,
- ErrorHandlerCLI errHandler) {
- this.filename = filename;
- this.sourceURL = sourceURL;
- this.success = successful;
- this.timeMillis = timeMillis;
- this.triples = countTriples;
- this.quads = countQuads;
- this.errHandler = errHandler;
+ protected record ParseRecord(String filename, String sourceURL, boolean success, long timeMillis,
+ long triples, long quads, long tuples, ErrorHandlerCLI errHandler) {
+ // Default tuples to 0
+ ParseRecord(String filename, String sourceURL, boolean success, long timeMillis,
+ long triples, long quads,
+ ErrorHandlerCLI errHandler) {
+ this(filename, sourceURL, success, timeMillis,triples, quads, 0L, errHandler);
}
}
@@ -364,14 +350,6 @@ public abstract class CmdLangParse extends CmdMain {
if ( passRelativeURIs )
stopOnWarnings = false;
- ErrorHandlerCLI errHandler = new ErrorHandlerCLI
- (ErrorHandlerFactory.stdLogger
- , passRelativeURIs // Silent warnings if allowing relative URIs.
- , true // Fail on error
- , stopOnWarnings // Fail on warnings
- );
- builder.errorHandler(errHandler);
-
// Make into a cmd flag. (input and output subflags?)
final boolean labelsAsGiven = false;
// NodeToLabel labels = SyntaxLabels.createNodeToLabel() ;
@@ -381,20 +359,30 @@ public abstract class CmdLangParse extends CmdMain {
builder.labelToNode(LabelToNode.createUseLabelAsGiven());
// Build parser output additions.
- StreamRDF s = parserOutputStream;
- if ( setupRDFS != null ) {
- // Remove literals as subjects
- s = RDFSFactory.removeGeneralizedRDF(s);
- // Generate RDFS (this feeds into the stream created above).
- s = RDFSFactory.streamRDFS(s, setupRDFS);
- // Parser sends data to RDFS, which goes to the filter, then to parserOutputStream
+ StreamRDFCounting parserOut;
+ {
+ StreamRDF s = parserOutputStream;
+ if ( setupRDFS != null ) {
+ // Remove literals as subjects
+ s = RDFSFactory.removeGeneralizedRDF(s);
+ // Generate RDFS (this feeds into the stream created above).
+ s = RDFSFactory.streamRDFS(s, setupRDFS);
+ // Parser sends data to RDFS, which goes to the filter, then to parserOutputStream
+ }
+ // If added here, count is quads and triples seen in the input.
+ if ( modLangParse.mergeQuads() )
+ s = new QuadsToTriples(s);
+ parserOut = StreamRDFLib.count(s);
+ s = null;
}
- // If added here, count is quads and triples seen in the input.
- if ( modLangParse.mergeQuads() )
- s = new QuadsToTriples(s);
- StreamRDFCounting parserOut = StreamRDFLib.count(s);
- s = null;
+ ErrorHandlerCLI errHandler = ErrorHandlerCLI.errorHandlerTracking(ErrorHandlerFactory.stdLogger,
+ passRelativeURIs, // Silent warnings if allowing relative URIs.
+ true, // Fail on error
+ stopOnWarnings, // Fail on warnings
+ ()->parserOut.finish() // Flush to align log messages
+ );
+ builder.errorHandler(errHandler);
boolean successful = true;
modTime.startTimer();
@@ -412,8 +400,9 @@ public abstract class CmdLangParse extends CmdMain {
successful = false;
}
parserOut.finish();
- long x = modTime.endTimer();
- ParseRecord outcome = new ParseRecord(filenameLabel, sourceURL, successful, x, parserOut.countTriples(), parserOut.countQuads(), errHandler);
+ long elapsedTime_ms = modTime.endTimer();
+ ParseRecord outcome = new ParseRecord(filenameLabel, sourceURL, successful, elapsedTime_ms,
+ parserOut.countTriples(), parserOut.countQuads(), errHandler);
return outcome;
}
diff --git a/jena-cmds/src/main/java/riotcmd/ErrorHandlerCLI.java b/jena-cmds/src/main/java/riotcmd/ErrorHandlerCLI.java
index 5b84ccb8c1..311c9115cd 100644
--- a/jena-cmds/src/main/java/riotcmd/ErrorHandlerCLI.java
+++ b/jena-cmds/src/main/java/riotcmd/ErrorHandlerCLI.java
@@ -32,21 +32,29 @@ import org.slf4j.Logger;
*/
class ErrorHandlerCLI implements ErrorHandler {
- /** Logs warnings and errors while tracking the counts of each and optionally throwing exceptions when errors and/or warnings are encounted */
- static ErrorHandlerCLI errorHandlerTracking(Logger log, boolean silentWarnings, boolean failOnError, boolean failOnWarning)
- { return new ErrorHandlerCLI(log, silentWarnings, failOnError, failOnWarning); }
+ /**
+ * Logs warnings and errors while tracking the counts of each and optionally
+ * throwing exceptions when errors and/or warnings are encountered.
+ */
+ static ErrorHandlerCLI errorHandlerTracking(Logger log, boolean silentWarnings,
+ boolean failOnError, boolean failOnWarning, Runnable onMessage) {
+ return new ErrorHandlerCLI(log, silentWarnings, failOnError, failOnWarning, onMessage);
+ }
private final Logger log ;
private final boolean silentWarnings;
private final boolean failOnError;
private final boolean failOnWarning;
- private long errorCount, warningCount;
+ private final Runnable onMessage;
+ private long errorCount = 0;
+ private long warningCount = 0;
- public ErrorHandlerCLI(Logger log, boolean silentWarnings, boolean failOnError, boolean failOnWarning) {
+ private ErrorHandlerCLI(Logger log, boolean silentWarnings, boolean failOnError, boolean failOnWarning, Runnable onMessage) {
this.log = log ;
this.silentWarnings = silentWarnings;
this.failOnError = failOnError;
this.failOnWarning = failOnWarning;
+ this.onMessage = onMessage;
}
/** report a warning */
@@ -95,21 +103,32 @@ class ErrorHandlerCLI implements ErrorHandler {
return hadErrors() || hadWarnings();
}
+ private void onLogMessage() {
+ if ( onMessage != null )
+ onMessage.run();
+ }
+
/** report a warning */
private void logWarning(String message, long line, long col) {
- if ( log != null )
- log.warn(fmtMessage(message, line, col)) ;
+ if ( log == null )
+ return;
+ onLogMessage();
+ log.warn(fmtMessage(message, line, col)) ;
}
/** report an error */
private void logError(String message, long line, long col) {
- if ( log != null )
- log.error(fmtMessage(message, line, col)) ;
+ if ( log == null )
+ return;
+ onLogMessage();
+ log.error(fmtMessage(message, line, col)) ;
}
/** report a catastrophic error */
private void logFatal(String message, long line, long col) {
- if ( log != null )
- logError(message, line, col) ;
+ if ( log == null )
+ return;
+ onLogMessage();
+ logError(message, line, col) ;
}
}