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 2021/05/05 07:51:36 UTC
[jena] branch main updated: JENA-2102: Explicitly initialize map
for injected commands
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 155af2a JENA-2102: Explicitly initialize map for injected commands
new cb1def6 Merge pull request #998 from afs/jena2102-cmd-init
155af2a is described below
commit 155af2a8eb82854b1f839b287bfb55eb11587020
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Tue May 4 10:17:04 2021 +0100
JENA-2102: Explicitly initialize map for injected commands
---
.../src/main/java/org/apache/jena/cmd/Cmds.java | 10 +++++-
.../main/java/org/apache/jena/cmd/InitCmds.java | 37 ++++++++++++++++++++++
.../org.apache.jena.sys.JenaSubsystemLifecycle | 1 +
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/jena-cmds/src/main/java/org/apache/jena/cmd/Cmds.java b/jena-cmds/src/main/java/org/apache/jena/cmd/Cmds.java
index b53f56f..5e206c1 100644
--- a/jena-cmds/src/main/java/org/apache/jena/cmd/Cmds.java
+++ b/jena-cmds/src/main/java/org/apache/jena/cmd/Cmds.java
@@ -32,7 +32,15 @@ public class Cmds {
static { JenaSystem.init(); }
- private static Map<String, Consumer<String[]>> cmds = new HashMap<>();
+ private static Map<String, Consumer<String[]>> cmds;
+
+ // Initialize via JenaSubsystemLifecycle and not rely on class initialization.
+ static void init() {
+ // Initialization should be minimal, just enough to allow modules to register commands.
+ // We may be inside some other place where JenaSystem.init() was called.
+ if ( cmds != null )
+ cmds = new HashMap<>();
+ }
public static void injectCmd(String name, Consumer<String[]> main) {
cmds.put(name, main);
diff --git a/jena-cmds/src/main/java/org/apache/jena/cmd/InitCmds.java b/jena-cmds/src/main/java/org/apache/jena/cmd/InitCmds.java
new file mode 100644
index 0000000..d0cf7f8
--- /dev/null
+++ b/jena-cmds/src/main/java/org/apache/jena/cmd/InitCmds.java
@@ -0,0 +1,37 @@
+/*
+ * 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.cmd;
+
+import org.apache.jena.sys.JenaSubsystemLifecycle;
+
+public class InitCmds implements JenaSubsystemLifecycle {
+
+ @Override
+ public void start() {
+ Cmds.init();
+ }
+
+ @Override
+ public void stop() {}
+
+ @Override
+ public int level() {
+ return 15;
+ }
+}
diff --git a/jena-cmds/src/main/resources/META-INF/services/org.apache.jena.sys.JenaSubsystemLifecycle b/jena-cmds/src/main/resources/META-INF/services/org.apache.jena.sys.JenaSubsystemLifecycle
new file mode 100644
index 0000000..f26ab98
--- /dev/null
+++ b/jena-cmds/src/main/resources/META-INF/services/org.apache.jena.sys.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.cmd.InitCmds