This is an automated email from the ASF dual-hosted git repository.
mattcasters pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 12091d70c8 Fixes #8669 : Make the file explorer git actions work again
(#8672)
12091d70c8 is described below
commit 12091d70c884de3e3f8f91fab8954d8dcd9b1ff2
Author: Bart Maertens <[email protected]>
AuthorDate: Thu Oct 1 11:36:05 2026 +0200
Fixes #8669 : Make the file explorer git actions work again (#8672)
#8108 made GitGuiPlugin's UIGit handle per session. The root changed
callback sets it on the session singleton, but toolbar and menu items are
dispatched to a separate instance the GuiRegistry builds itself, where it
stayed null and every action returned on its null check. Register the singleton
with the GuiRegistry for the explorer toolbar, context menu and status toolbar.
---
.../main/java/org/apache/hop/git/GitGuiPlugin.java | 40 +++++++++++
.../apache/hop/git/GitGuiPluginDispatchTest.java | 80 ++++++++++++++++++++++
2 files changed, 120 insertions(+)
diff --git
a/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
b/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
index 54e79a9eb3..c250c88d04 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
@@ -37,6 +37,7 @@ import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.exception.HopFileException;
import org.apache.hop.core.exception.HopRuntimeException;
import org.apache.hop.core.gui.plugin.GuiPlugin;
+import org.apache.hop.core.gui.plugin.GuiRegistry;
import org.apache.hop.core.gui.plugin.callback.GuiCallback;
import org.apache.hop.core.gui.plugin.menu.GuiMenuElement;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement;
@@ -59,6 +60,7 @@ import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
import org.apache.hop.ui.core.dialog.EnterStringDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
+import org.apache.hop.ui.core.gui.BaseGuiWidgets;
import org.apache.hop.ui.core.gui.GuiMenuWidgets;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.core.gui.GuiToolbarWidgets;
@@ -183,9 +185,46 @@ public class GitGuiPlugin
});
}
+ // Toolbar and menu items are dispatched to a separate instance: hand the
registry this one,
+ // which holds the repository.
+ //
+ registerAsGuiPluginObjects();
+
enableButtons();
}
+ /**
+ * Register this instance for the toolbars and menus which dispatch git
actions. A
+ * {@code @GuiToolbarElement} or {@code @GuiMenuElement} method goes to
whatever {@link
+ * BaseGuiWidgets} finds in the {@link GuiRegistry}, or to a fresh instance
with no repository
+ * when it finds none. Rebuilt widgets get a new instance id, so this is
repeated whenever the
+ * repository changes.
+ */
+ private void registerAsGuiPluginObjects() {
+ ExplorerPerspective explorerPerspective =
ExplorerPerspective.getInstance();
+ if (explorerPerspective != null) {
+ registerAsGuiPluginObject(explorerPerspective.getToolBarWidgets());
+ registerAsGuiPluginObject(explorerPerspective.getMenuWidgets());
+ }
+ HopGui hopGui = HopGui.peekInstance();
+ if (hopGui != null) {
+ registerAsGuiPluginObject(hopGui.getStatusToolbarWidgets());
+ }
+ }
+
+ private void registerAsGuiPluginObject(BaseGuiWidgets widgets) {
+ HopGui hopGui = HopGui.peekInstance();
+ if (hopGui == null || widgets == null || widgets.getInstanceId() == null) {
+ return;
+ }
+ registerAsGuiPluginObject(hopGui.getId(), widgets.getInstanceId());
+ }
+
+ /* package */ void registerAsGuiPluginObject(String hopGuiId, String
instanceId) {
+ GuiRegistry.getInstance()
+ .registerGuiPluginObject(hopGuiId, GitGuiPlugin.class.getName(),
instanceId, this);
+ }
+
private void refreshGitPerspective(boolean refreshAll) {
GitPerspective gitPerspective = GitPerspective.getInstance();
if (gitPerspective != null && gitPerspective.isInitialized()) {
@@ -939,6 +978,7 @@ public class GitGuiPlugin
}
}
refreshChangedFiles();
+ registerAsGuiPluginObjects();
enableButtons();
// Refresh Git perspectives when a project is activated
diff --git
a/plugins/misc/git/src/test/java/org/apache/hop/git/GitGuiPluginDispatchTest.java
b/plugins/misc/git/src/test/java/org/apache/hop/git/GitGuiPluginDispatchTest.java
new file mode 100644
index 0000000000..d2460a2360
--- /dev/null
+++
b/plugins/misc/git/src/test/java/org/apache/hop/git/GitGuiPluginDispatchTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.hop.git;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import org.apache.hop.core.gui.plugin.GuiRegistry;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The explorer toolbar and context menu reach {@link GitGuiPlugin} through
the {@link GuiRegistry},
+ * which builds an instance of its own - one with no repository - when the
registry has none for
+ * those widgets. These tests cover the registration which prevents that.
+ */
+class GitGuiPluginDispatchTest {
+
+ /** The lookup BaseGuiWidgets performs before it falls back to constructing
an instance. */
+ private static Object lookup(String hopGuiId, String instanceId) {
+ return GuiRegistry.getInstance()
+ .findGuiPluginObject(hopGuiId, GitGuiPlugin.class.getName(),
instanceId);
+ }
+
+ @Test
+ void widgetLookupFindsTheInstanceHoldingTheRepository() {
+ GitGuiPlugin plugin = new GitGuiPlugin();
+ String hopGuiId = "GitGuiPluginDispatchTest-gui";
+ String instanceId = "GitGuiPluginDispatchTest-toolbar";
+
+ plugin.registerAsGuiPluginObject(hopGuiId, instanceId);
+
+ assertSame(
+ plugin,
+ lookup(hopGuiId, instanceId),
+ "Toolbar and menu items must be dispatched to the instance which owns
the UIGit handle, "
+ + "not to one the GuiRegistry builds for itself");
+ }
+
+ @Test
+ void eachSetOfWidgetsNeedsItsOwnRegistration() {
+ GitGuiPlugin plugin = new GitGuiPlugin();
+ String hopGuiId = "GitGuiPluginDispatchTest-gui-2";
+
+ plugin.registerAsGuiPluginObject(hopGuiId,
"GitGuiPluginDispatchTest-toolbar-2");
+
+ // The explorer toolbar, the explorer context menu and the status toolbar
each get a random
+ // instance id, so registering one of them says nothing about the others.
+ assertNull(
+ lookup(hopGuiId, "GitGuiPluginDispatchTest-menu-2"),
+ "An unregistered set of widgets falls back to a fresh instance with no
repository");
+ }
+
+ @Test
+ void registrationsOfDifferentSessionsDoNotOverlap() {
+ GitGuiPlugin first = new GitGuiPlugin();
+ GitGuiPlugin second = new GitGuiPlugin();
+ String instanceId = "GitGuiPluginDispatchTest-shared-toolbar";
+
+ first.registerAsGuiPluginObject("GitGuiPluginDispatchTest-session-a",
instanceId);
+ second.registerAsGuiPluginObject("GitGuiPluginDispatchTest-session-b",
instanceId);
+
+ assertSame(first, lookup("GitGuiPluginDispatchTest-session-a",
instanceId));
+ assertSame(second, lookup("GitGuiPluginDispatchTest-session-b",
instanceId));
+ }
+}