From eaf54d76738adddde20c8cd7ce11abf11755d3a0 Mon Sep 17 00:00:00 2001 From: Hans Van Akelyen Date: Mon, 16 Nov 2026 10:28:17 +0100 Subject: [PATCH] remove need to have SWT on the classpath for headless runs, fixes #9501 --- .../main/java/org/apache/hop/core/Const.java | 9 + .../hop/core/variables/VariableRegistry.java | 23 ++- .../hop/git/config/GitConfigOptionPlugin.java | 7 +- .../git/config/HeadlessReflectionTest.java | 33 ++++ .../apache/hop/lint/LinterConfigPlugin.java | 7 +- .../PipelineBeforeStartLintExtension.java | 4 +- .../WorkflowBeforeStartLintExtension.java | 4 +- .../hop/lint/HeadlessReflectionTest.java | 33 ++++ .../RunStartLintExtensionHeadlessTest.java | 75 +++++++ ...EnvironmentAfterEnabledExtensionPoint.java | 2 +- .../config/ProjectsConfigOptionPlugin.java | 8 +- .../hop/projects/util/ProjectsUtil.java | 2 +- ...EnvironmentAfterEnabledExtensionPoint.java | 2 +- .../config/HeadlessReflectionTest.java | 33 ++++ .../actions/runtests/RunPipelineTests.java | 10 +- .../hop/testing/gui/TestingGuiPlugin.java | 2 +- .../apache/hop/testing/util/DataSetConst.java | 13 ++ .../DrawTweakOnTransformExtensionPoint.java | 4 +- .../xp/PipelineGetFieldsExtensionPoint.java | 3 +- ...alidatePipelineUnitTestExtensionPoint.java | 4 +- .../xp/UnitTestLookupHeadlessTest.java | 114 +++++++++++ .../ai/config/HopAiConfigOptionPlugin.java | 155 +-------------- .../ai/config/HopAiConfigOptionWidgets.java | 186 ++++++++++++++++++ .../hop/ai/config/HeadlessReflectionTest.java | 33 ++++ .../config/HopAiConfigOptionPluginUiTest.java | 6 +- .../AwsSecretsManagerVariableResolver.java | 7 +- ...AwsSecretsManagerWidgetVisibilityTest.java | 2 +- .../resolver/aws/HeadlessReflectionTest.java | 33 ++++ .../vfs/azure/config/AzureConfigPlugin.java | 7 +- .../azure/config/HeadlessReflectionTest.java | 33 ++++ .../config/CalciteSqlFormatConfigPlugin.java | 8 +- .../config/HeadlessReflectionTest.java | 33 ++++ .../dropbox/config/DropboxConfigPlugin.java | 7 +- .../config/HeadlessReflectionTest.java | 33 ++++ .../config/GoogleDriveConfigPlugin.java | 7 +- .../gs/config/GoogleCloudConfigPlugin.java | 7 +- .../vfs/gs/config/HeadlessReflectionTest.java | 34 ++++ .../salesforceinput/SalesforceInputMeta.java | 10 - .../HeadlessReflectionTest.java | 33 ++++ .../hop/vfs/smb/metadata/SmbConnection.java | 7 +- .../vfs/smb/metadata/SmbConnectionEditor.java | 2 +- .../smb/metadata/HeadlessReflectionTest.java | 33 ++++ .../vault/BaseVaultVariableResolver.java | 9 +- .../vault/HeadlessReflectionTest.java | 33 ++++ .../vault/VaultWidgetVisibilityTest.java | 2 +- .../formula/config/FormulaConfigPlugin.java | 8 +- .../config/HeadlessReflectionTest.java | 33 ++++ .../internals/ui/i18nUtil.java | 6 +- .../HeadlessCreationTest.java | 34 ++++ .../hop/ui/hopgui/HopWebEntryPoint.java | 2 +- .../apache/hop/ui/core/dialog/BaseDialog.java | 11 +- .../ui/core/dialog/BaseDialogVariables.java | 38 ++++ .../hop/ui/core/gui/GuiCompositeWidgets.java | 41 ++++ .../apache/hop/ui/core/gui/HopNamespace.java | 2 +- .../gui/IGuiPluginModelWidgetsListener.java | 48 +++++ .../resolver/VariableResolverEditor.java | 11 +- .../config/FileValidationConfigPlugin.java | 8 +- .../file/pipeline/HopGuiPipelineGraph.java | 3 +- .../config/DebugSessionsConfigPlugin.java | 8 +- .../DrillDownRegistrationExtensionPoint.java | 2 +- ...ownWorkflowRegistrationExtensionPoint.java | 2 +- .../file/workflow/HopGuiWorkflowGraph.java | 3 +- .../tabs/ConfigPluginOptionsTab.java | 15 +- .../DatabasePerspectiveConfigPlugin.java | 8 +- .../execution/PipelineExecutionViewer.java | 3 +- .../execution/WorkflowExecutionViewer.java | 3 +- .../ExplorerPerspectiveConfigPlugin.java | 9 +- .../search/config/SearchConfigPlugin.java | 7 +- .../hopgui/welcome/WelcomeDialogOptions.java | 11 +- .../BaseDialogVariablesHeadlessTest.java | 52 +++++ .../hop/ui/hopgui/HeadlessReflectionTest.java | 45 +++++ .../tabs/ConfigPluginOptionsTabTest.java | 13 ++ .../testing/DisabledGuiWidgetsTestBase.java | 4 +- .../org/apache/hop/ui/testing/WithoutSwt.java | 94 +++++++++ 74 files changed, 1337 insertions(+), 299 deletions(-) create mode 100644 plugins/misc/git/src/test/java/org/apache/hop/git/config/HeadlessReflectionTest.java create mode 100644 plugins/misc/lint/src/test/java/org/apache/hop/lint/HeadlessReflectionTest.java create mode 100644 plugins/misc/lint/src/test/java/org/apache/hop/lint/RunStartLintExtensionHeadlessTest.java create mode 100644 plugins/misc/projects/src/test/java/org/apache/hop/projects/config/HeadlessReflectionTest.java create mode 100644 plugins/misc/testing/src/test/java/org/apache/hop/testing/xp/UnitTestLookupHeadlessTest.java create mode 100644 plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionWidgets.java create mode 100644 plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HeadlessReflectionTest.java create mode 100644 plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/HeadlessReflectionTest.java create mode 100644 plugins/tech/azure/src/test/java/org/apache/hop/vfs/azure/config/HeadlessReflectionTest.java create mode 100644 plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/HeadlessReflectionTest.java create mode 100644 plugins/tech/dropbox/src/test/java/org/apache/hop/vfs/dropbox/config/HeadlessReflectionTest.java create mode 100644 plugins/tech/google/src/test/java/org/apache/hop/vfs/gs/config/HeadlessReflectionTest.java create mode 100644 plugins/tech/salesforce/src/test/java/org/apache/hop/pipeline/transforms/salesforceinput/HeadlessReflectionTest.java create mode 100644 plugins/tech/smb/src/test/java/org/apache/hop/vfs/smb/metadata/HeadlessReflectionTest.java create mode 100644 plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/HeadlessReflectionTest.java create mode 100644 plugins/transforms/formula/src/test/java/org/apache/hop/pipeline/transforms/formula/config/HeadlessReflectionTest.java create mode 100644 plugins/transforms/languagemodelchat/src/test/java/org/apache/hop/pipeline/transforms/languagemodelchat/HeadlessCreationTest.java create mode 100644 ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialogVariables.java create mode 100644 ui/src/main/java/org/apache/hop/ui/core/gui/IGuiPluginModelWidgetsListener.java create mode 100644 ui/src/test/java/org/apache/hop/ui/core/dialog/BaseDialogVariablesHeadlessTest.java create mode 100644 ui/src/test/java/org/apache/hop/ui/hopgui/HeadlessReflectionTest.java create mode 100644 ui/src/test/java/org/apache/hop/ui/testing/WithoutSwt.java diff --git a/core/src/main/java/org/apache/hop/core/Const.java b/core/src/main/java/org/apache/hop/core/Const.java index c5b9cf61a06..a467f14645b 100644 --- a/core/src/main/java/org/apache/hop/core/Const.java +++ b/core/src/main/java/org/apache/hop/core/Const.java @@ -2004,6 +2004,15 @@ public static String getHopPlatformRuntime() { return System.getProperty(HOP_PLATFORM_RUNTIME); } + /** + * Whether this process runs Hop GUI or Hop Web, as {@link #HOP_PLATFORM_RUNTIME} tells. Code + * outside the GUI asks this before it touches a GUI class: without SWT, as in hop-run, hop-server + * or a Spark executor, merely loading one (HopGui for example) fails with a NoClassDefFoundError. + */ + public static boolean isGuiRuntime() { + return "GUI".equalsIgnoreCase(getHopPlatformRuntime()); + } + /** * Determine the quoting character depending on the OS. Often used for shell calls, gives back " * for Windows systems otherwise ' diff --git a/core/src/main/java/org/apache/hop/core/variables/VariableRegistry.java b/core/src/main/java/org/apache/hop/core/variables/VariableRegistry.java index 617f9aae057..df31b170506 100644 --- a/core/src/main/java/org/apache/hop/core/variables/VariableRegistry.java +++ b/core/src/main/java/org/apache/hop/core/variables/VariableRegistry.java @@ -79,7 +79,7 @@ public static void init() throws HopException { for (File jarFile : cache.getNativeJars()) { IndexView index = cache.getIndex(jarFile); for (AnnotationInstance info : index.getAnnotations(Variable.class)) { - register(jarFile, info.target().asField()); + registerOrSkip(jarFile, info.target().asField()); } } @@ -87,7 +87,7 @@ public static void init() throws HopException { for (File jarFile : cache.getPluginJars()) { IndexView index = cache.getIndex(jarFile); for (AnnotationInstance info : index.getAnnotations(Variable.class)) { - register(jarFile, info.target().asField()); + registerOrSkip(jarFile, info.target().asField()); } } } catch (Exception e) { @@ -95,6 +95,25 @@ public static void init() throws HopException { } } + /** + * Registers the variable, or skips it when its class can't be loaded: a class that needs a + * library this run doesn't have, SWT without a GUI for example, must not stop Hop from starting + * or keep the other variables from being registered. + */ + private static void registerOrSkip(File jarFile, FieldInfo fieldInfo) { + try { + register(jarFile, fieldInfo); + } catch (Exception | LinkageError e) { + LogChannel.GENERAL.logDetailed( + "Unable to read variable " + + fieldInfo.declaringClass().name() + + "." + + fieldInfo.name() + + ", skipping it: " + + e); + } + } + protected static void register(File jarFile, FieldInfo fieldInfo) throws ClassNotFoundException, SecurityException, diff --git a/plugins/misc/git/src/main/java/org/apache/hop/git/config/GitConfigOptionPlugin.java b/plugins/misc/git/src/main/java/org/apache/hop/git/config/GitConfigOptionPlugin.java index 228d145a79f..be6132d02d5 100644 --- a/plugins/misc/git/src/main/java/org/apache/hop/git/config/GitConfigOptionPlugin.java +++ b/plugins/misc/git/src/main/java/org/apache/hop/git/config/GitConfigOptionPlugin.java @@ -32,7 +32,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; import org.eclipse.swt.widgets.Button; @@ -49,7 +49,7 @@ ) @Getter @Setter -public class GitConfigOptionPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class GitConfigOptionPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { protected static final Class PKG = GitConfigOptionPlugin.class; private static final String WIDGET_ID_GIT_ENABLE = "10000-git-enable-plugin"; @@ -172,8 +172,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/misc/git/src/test/java/org/apache/hop/git/config/HeadlessReflectionTest.java b/plugins/misc/git/src/test/java/org/apache/hop/git/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..5b1fe92302b --- /dev/null +++ b/plugins/misc/git/src/test/java/org/apache/hop/git/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the git configuration options by reflection, also without + * SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(GitConfigOptionPlugin.class); + } +} diff --git a/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java b/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java index 081e2e5d0c7..6ab16915471 100644 --- a/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java +++ b/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java @@ -39,7 +39,7 @@ import org.apache.hop.lint.registry.RuleRegistry; import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.file.shared.HopGuiAbstractGraph; @@ -57,7 +57,7 @@ */ @ConfigPlugin(id = "linter-config", description = "Configure linter rules and settings") @GuiPlugin(description = "Linter") -public class LinterConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class LinterConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final ILogChannel log = LogChannel.GENERAL; @@ -120,8 +120,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { enableDependentWidgets(compositeWidgets); persistContents(compositeWidgets); } diff --git a/plugins/misc/lint/src/main/java/org/apache/hop/lint/PipelineBeforeStartLintExtension.java b/plugins/misc/lint/src/main/java/org/apache/hop/lint/PipelineBeforeStartLintExtension.java index 6571066a54c..c51c13ecd3a 100644 --- a/plugins/misc/lint/src/main/java/org/apache/hop/lint/PipelineBeforeStartLintExtension.java +++ b/plugins/misc/lint/src/main/java/org/apache/hop/lint/PipelineBeforeStartLintExtension.java @@ -17,6 +17,7 @@ package org.apache.hop.lint; +import org.apache.hop.core.Const; import org.apache.hop.core.exception.HopException; import org.apache.hop.core.extension.ExtensionPoint; import org.apache.hop.core.extension.IExtensionPoint; @@ -41,7 +42,8 @@ public class PipelineBeforeStartLintExtension implements IExtensionPoint public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException { try { - if (HopGui.peekInstance() == null) { + // hop-run starts a workflow with this extension point too, where touching HopGui needs SWT + if (!Const.isGuiRuntime() || HopGui.peekInstance() == null) { return; } HopGuiPipelineGraph graph = HopGui.getActivePipelineGraph(); diff --git a/plugins/misc/lint/src/main/java/org/apache/hop/lint/WorkflowBeforeStartLintExtension.java b/plugins/misc/lint/src/main/java/org/apache/hop/lint/WorkflowBeforeStartLintExtension.java index e6219788759..1c6a39036f5 100644 --- a/plugins/misc/lint/src/main/java/org/apache/hop/lint/WorkflowBeforeStartLintExtension.java +++ b/plugins/misc/lint/src/main/java/org/apache/hop/lint/WorkflowBeforeStartLintExtension.java @@ -17,6 +17,7 @@ package org.apache.hop.lint; +import org.apache.hop.core.Const; import org.apache.hop.core.exception.HopException; import org.apache.hop.core.extension.ExtensionPoint; import org.apache.hop.core.extension.IExtensionPoint; @@ -41,7 +42,8 @@ public class WorkflowBeforeStartLintExtension implements IExtensionPoint public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException { try { - if (HopGui.peekInstance() == null) { + // hop-run starts a workflow with this extension point too, where touching HopGui needs SWT + if (!Const.isGuiRuntime() || HopGui.peekInstance() == null) { return; } HopGuiWorkflowGraph graph = HopGui.getActiveWorkflowGraph(); diff --git a/plugins/misc/lint/src/test/java/org/apache/hop/lint/HeadlessReflectionTest.java b/plugins/misc/lint/src/test/java/org/apache/hop/lint/HeadlessReflectionTest.java new file mode 100644 index 00000000000..e9f353a08e3 --- /dev/null +++ b/plugins/misc/lint/src/test/java/org/apache/hop/lint/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.lint; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the lint configuration options by reflection, also without + * SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(LinterConfigPlugin.class); + } +} diff --git a/plugins/misc/lint/src/test/java/org/apache/hop/lint/RunStartLintExtensionHeadlessTest.java b/plugins/misc/lint/src/test/java/org/apache/hop/lint/RunStartLintExtensionHeadlessTest.java new file mode 100644 index 00000000000..eb778c2115f --- /dev/null +++ b/plugins/misc/lint/src/test/java/org/apache/hop/lint/RunStartLintExtensionHeadlessTest.java @@ -0,0 +1,75 @@ +/* + * 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.lint; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import java.lang.reflect.Method; +import org.apache.hop.core.Const; +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * hop-run fires the GUI's "before start" extension point for every workflow it runs. Without SWT + * the lint handlers must leave it alone: touching HopGui there fails with a NoClassDefFoundError. + */ +class RunStartLintExtensionHeadlessTest { + + private String runtime; + + @BeforeEach + void runLikeHopRun() { + runtime = System.getProperty(Const.HOP_PLATFORM_RUNTIME); + System.setProperty(Const.HOP_PLATFORM_RUNTIME, "Run"); + } + + @AfterEach + void restore() { + if (runtime == null) { + System.clearProperty(Const.HOP_PLATFORM_RUNTIME); + } else { + System.setProperty(Const.HOP_PLATFORM_RUNTIME, runtime); + } + } + + @Test + void aWorkflowStartsWithoutSwt() throws Exception { + assertRunsWithoutSwt(WorkflowBeforeStartLintExtension.class.getName()); + } + + @Test + void aPipelineStartsWithoutSwt() throws Exception { + assertRunsWithoutSwt(PipelineBeforeStartLintExtension.class.getName()); + } + + private static void assertRunsWithoutSwt(String className) throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + Class extensionClass = Class.forName(className, true, withoutSwt); + Object extension = extensionClass.getConstructor().newInstance(); + Method call = + extensionClass.getMethod( + "callExtensionPoint", + Class.forName("org.apache.hop.core.logging.ILogChannel", false, withoutSwt), + Class.forName("org.apache.hop.core.variables.IVariables", false, withoutSwt), + Object.class); + assertDoesNotThrow(() -> call.invoke(extension, null, null, null)); + } + } +} diff --git a/plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/xp/ProjectEnvironmentAfterEnabledExtensionPoint.java b/plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/xp/ProjectEnvironmentAfterEnabledExtensionPoint.java index 30a26da29c9..cec663398ec 100644 --- a/plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/xp/ProjectEnvironmentAfterEnabledExtensionPoint.java +++ b/plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/xp/ProjectEnvironmentAfterEnabledExtensionPoint.java @@ -246,7 +246,7 @@ private void runCheck(ILogChannel log, IVariables variables, AttributesContext c } static boolean isGuiRuntime() { - return "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + return Const.isGuiRuntime(); } private static void warnGui(String title, String message) { diff --git a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java index f0a7cce4da4..c5dba766091 100644 --- a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java +++ b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java @@ -37,7 +37,7 @@ import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.dialog.MessageBox; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.ComboVar; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; @@ -57,8 +57,7 @@ ) @Getter @Setter -public class ProjectsConfigOptionPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class ProjectsConfigOptionPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { protected static final Class PKG = ProjectsConfigOptionPlugin.class; @@ -339,8 +338,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/misc/projects/src/main/java/org/apache/hop/projects/util/ProjectsUtil.java b/plugins/misc/projects/src/main/java/org/apache/hop/projects/util/ProjectsUtil.java index 9249bcba4be..84805b9f72d 100644 --- a/plugins/misc/projects/src/main/java/org/apache/hop/projects/util/ProjectsUtil.java +++ b/plugins/misc/projects/src/main/java/org/apache/hop/projects/util/ProjectsUtil.java @@ -194,7 +194,7 @@ public static void enableProject( // where this info is valuable. Audit I/O must not block enabling a project (e.g. Docker audit // folder permission issues). // - if (Const.getHopPlatformRuntime() != null && Const.getHopPlatformRuntime().equals("GUI")) { + if (Const.isGuiRuntime()) { try { AuditManager.registerEvent( HopGui.DEFAULT_HOP_GUI_NAMESPACE, STRING_PROJECT_AUDIT_TYPE, projectName, "open"); diff --git a/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/ResourceProjectEnvironmentAfterEnabledExtensionPoint.java b/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/ResourceProjectEnvironmentAfterEnabledExtensionPoint.java index 1d661f31274..c16a5864814 100644 --- a/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/ResourceProjectEnvironmentAfterEnabledExtensionPoint.java +++ b/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/ResourceProjectEnvironmentAfterEnabledExtensionPoint.java @@ -88,7 +88,7 @@ public void callExtensionPoint(ILogChannel log, IVariables variables, Attributes // warn log.logError(report); - if ("GUI".equalsIgnoreCase(Const.getHopPlatformRuntime())) { + if (Const.isGuiRuntime()) { try { MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.OK | SWT.ICON_WARNING); box.setText(BaseMessages.getString(PKG, "ResourceLifecycleEnv.Check.Title")); diff --git a/plugins/misc/projects/src/test/java/org/apache/hop/projects/config/HeadlessReflectionTest.java b/plugins/misc/projects/src/test/java/org/apache/hop/projects/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..3d99b2c4013 --- /dev/null +++ b/plugins/misc/projects/src/test/java/org/apache/hop/projects/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.projects.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the projects configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(ProjectsConfigOptionPlugin.class); + } +} diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java index 5558fad26a2..cc009ef2a6a 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import lombok.Getter; import lombok.Setter; +import org.apache.hop.core.Const; import org.apache.hop.core.Result; import org.apache.hop.core.annotations.Action; import org.apache.hop.core.exception.HopException; @@ -32,6 +33,7 @@ import org.apache.hop.metadata.api.IHopMetadataSerializer; import org.apache.hop.testing.PipelineUnitTest; import org.apache.hop.testing.UnitTestResult; +import org.apache.hop.testing.util.DataSetConst; import org.apache.hop.testing.util.UnitTestUtil; import org.apache.hop.workflow.action.ActionBase; import org.apache.hop.workflow.action.IAction; @@ -165,18 +167,16 @@ public IHasFilename loadReferencedObject( throw new HopException("Unit test '" + testName.getTestName() + "' could not be found"); } - variables.setVariable( - org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME, test.getName()); + variables.setVariable(DataSetConst.VAR_UNIT_TEST_NAME, test.getName()); try { - if ("GUI".equalsIgnoreCase(org.apache.hop.core.Const.getHopPlatformRuntime())) { + if (Const.isGuiRuntime()) { Class hopGuiClass = Class.forName("org.apache.hop.ui.hopgui.HopGui"); Object hopGuiInstance = hopGuiClass.getMethod("getInstance").invoke(null); if (hopGuiInstance != null) { IVariables guiVariables = (IVariables) hopGuiClass.getMethod("getVariables").invoke(hopGuiInstance); if (guiVariables != null) { - guiVariables.setVariable( - org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME, test.getName()); + guiVariables.setVariable(DataSetConst.VAR_UNIT_TEST_NAME, test.getName()); } } } diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java index 8d23e87b09a..4b74b1e7def 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java @@ -1568,7 +1568,7 @@ private static boolean pipelineMetaMatches(PipelineMeta a, PipelineMeta b) { public static final PipelineUnitTest getCurrentUnitTest(PipelineMeta pipelineMeta) { // When rendering a pipeline on a server status page we never have a current unit test // - if (!"GUI".equalsIgnoreCase(Const.getHopPlatformRuntime())) { + if (!Const.isGuiRuntime()) { return null; } // Same rule as getPipelineGraph: never access HopGui/SWT from a worker thread (issue #7896). diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/util/DataSetConst.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/util/DataSetConst.java index 30fadc201e9..20bdb0bd57d 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/util/DataSetConst.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/util/DataSetConst.java @@ -49,6 +49,7 @@ import org.apache.hop.testing.PipelineUnitTestFieldMapping; import org.apache.hop.testing.PipelineUnitTestSetLocation; import org.apache.hop.testing.UnitTestResult; +import org.apache.hop.testing.gui.TestingGuiPlugin; import org.apache.hop.testing.xp.RowCollection; public class DataSetConst { @@ -746,4 +747,16 @@ public static PipelineTweak getTweakForDescription(String tweakDescription) { public static String[] getTweakDescriptions() { return tweakDesc; } + + /** + * The unit test active for the pipeline in Hop GUI, or null. Outside Hop GUI and Hop Web there is + * none, and this answers without loading TestingGuiPlugin, which needs SWT to load: code that + * also runs in hop-run, hop-server or on a Spark executor asks here. + */ + public static PipelineUnitTest getActiveUnitTest(PipelineMeta pipelineMeta) { + if (!Const.isGuiRuntime()) { + return null; + } + return TestingGuiPlugin.getCurrentUnitTest(pipelineMeta); + } } diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/DrawTweakOnTransformExtensionPoint.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/DrawTweakOnTransformExtensionPoint.java index a423a24e8f8..8560edb119c 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/DrawTweakOnTransformExtensionPoint.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/DrawTweakOnTransformExtensionPoint.java @@ -27,7 +27,7 @@ import org.apache.hop.pipeline.transform.TransformMeta; import org.apache.hop.testing.PipelineUnitTest; import org.apache.hop.testing.PipelineUnitTestTweak; -import org.apache.hop.testing.gui.TestingGuiPlugin; +import org.apache.hop.testing.util.DataSetConst; @ExtensionPoint( id = "DrawTweakOnTransformExtensionPoint", @@ -40,7 +40,7 @@ public class DrawTweakOnTransformExtensionPoint public void callExtensionPoint( ILogChannel log, IVariables variables, PipelinePainterExtension ext) throws HopException { TransformMeta transformMeta = ext.transformMeta; - PipelineUnitTest unitTest = TestingGuiPlugin.getCurrentUnitTest(ext.pipelineMeta); + PipelineUnitTest unitTest = DataSetConst.getActiveUnitTest(ext.pipelineMeta); if (unitTest == null) { return; } diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java index 0a95df5bcef..75bb45b86a8 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java @@ -29,7 +29,6 @@ import org.apache.hop.testing.DataSet; import org.apache.hop.testing.PipelineUnitTest; import org.apache.hop.testing.PipelineUnitTestSetLocation; -import org.apache.hop.testing.gui.TestingGuiPlugin; import org.apache.hop.testing.util.DataSetConst; @ExtensionPoint( @@ -52,7 +51,7 @@ public void callExtensionPoint( } // Check if a unit test is active in Hop GUI - PipelineUnitTest unitTest = TestingGuiPlugin.getCurrentUnitTest(pipelineMeta); + PipelineUnitTest unitTest = DataSetConst.getActiveUnitTest(pipelineMeta); if (unitTest == null) { return; } diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/ValidatePipelineUnitTestExtensionPoint.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/ValidatePipelineUnitTestExtensionPoint.java index 58cb84a3b7e..0a0dc1a7918 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/ValidatePipelineUnitTestExtensionPoint.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/ValidatePipelineUnitTestExtensionPoint.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.hop.core.Const; import org.apache.hop.core.exception.HopException; import org.apache.hop.core.extension.ExtensionPoint; import org.apache.hop.core.extension.IExtensionPoint; @@ -97,7 +98,8 @@ public void callExtensionPoint( String dontShowResults = pipeline.getVariable(DataSetConst.VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS, "N"); - if ("N".equalsIgnoreCase(dontShowResults)) { + // Only Hop GUI can show them: elsewhere touching HopGui needs SWT, and the log has them + if (Const.isGuiRuntime() && "N".equalsIgnoreCase(dontShowResults)) { final HopGui hopGui = HopGui.getInstance(); if (hopGui != null) { showUnitTestErrors(pipeline, results, hopGui); diff --git a/plugins/misc/testing/src/test/java/org/apache/hop/testing/xp/UnitTestLookupHeadlessTest.java b/plugins/misc/testing/src/test/java/org/apache/hop/testing/xp/UnitTestLookupHeadlessTest.java new file mode 100644 index 00000000000..6b272798465 --- /dev/null +++ b/plugins/misc/testing/src/test/java/org/apache/hop/testing/xp/UnitTestLookupHeadlessTest.java @@ -0,0 +1,114 @@ +/* + * 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.testing.xp; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.lang.reflect.Method; +import org.apache.hop.core.Const; +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Working out a transform's fields asks for the active unit test in every run, also in hop-run, + * hop-server and on Spark executors. Without SWT that must answer "none" without loading + * TestingGuiPlugin, which needs SWT to load. + */ +class UnitTestLookupHeadlessTest { + + private String runtime; + + @BeforeEach + void runLikeHopRun() { + runtime = System.getProperty(Const.HOP_PLATFORM_RUNTIME); + System.setProperty(Const.HOP_PLATFORM_RUNTIME, "Run"); + } + + @AfterEach + void restore() { + if (runtime == null) { + System.clearProperty(Const.HOP_PLATFORM_RUNTIME); + } else { + System.setProperty(Const.HOP_PLATFORM_RUNTIME, runtime); + } + } + + @Test + void thereIsNoActiveUnitTestWithoutAGui() throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + Class pipelineMetaClass = + Class.forName("org.apache.hop.pipeline.PipelineMeta", true, withoutSwt); + Object pipelineMeta = pipelineMetaClass.getConstructor().newInstance(); + Method lookup = + Class.forName("org.apache.hop.testing.util.DataSetConst", true, withoutSwt) + .getMethod("getActiveUnitTest", pipelineMetaClass); + assertNull(lookup.invoke(null, pipelineMeta)); + } + } + + @Test + void aTransformsFieldsAreWorkedOutWithoutSwt() throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + Class pipelineMetaClass = + Class.forName("org.apache.hop.pipeline.PipelineMeta", true, withoutSwt); + Class transformMetaClass = + Class.forName("org.apache.hop.pipeline.transform.TransformMeta", true, withoutSwt); + Class rowMetaClass = Class.forName("org.apache.hop.core.row.IRowMeta", true, withoutSwt); + Class variablesClass = + Class.forName("org.apache.hop.core.variables.IVariables", true, withoutSwt); + Class metadataClass = + Class.forName("org.apache.hop.metadata.api.IHopMetadataProvider", true, withoutSwt); + Class extensionClass = + Class.forName( + "org.apache.hop.pipeline.PipelineMeta$GetFieldsExtension", true, withoutSwt); + Object extension = + extensionClass + .getConstructor( + pipelineMetaClass, + transformMetaClass, + rowMetaClass, + String.class, + rowMetaClass.arrayType(), + transformMetaClass, + variablesClass, + metadataClass) + .newInstance( + pipelineMetaClass.getConstructor().newInstance(), + transformMetaClass.getConstructor().newInstance(), + null, + "transform", + null, + null, + null, + null); + Class xpClass = + Class.forName(PipelineGetFieldsExtensionPoint.class.getName(), true, withoutSwt); + Object xp = xpClass.getConstructor().newInstance(); + Method call = + xpClass.getMethod( + "callExtensionPoint", + Class.forName("org.apache.hop.core.logging.ILogChannel", true, withoutSwt), + variablesClass, + extensionClass); + assertDoesNotThrow(() -> call.invoke(xp, null, null, extension)); + } + } +} diff --git a/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionPlugin.java b/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionPlugin.java index facb3f08adb..3160770ad0b 100644 --- a/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionPlugin.java +++ b/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionPlugin.java @@ -18,7 +18,6 @@ package org.apache.hop.ai.config; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import lombok.Getter; import lombok.Setter; @@ -33,33 +32,17 @@ import org.apache.hop.core.gui.plugin.GuiWidgetElement; import org.apache.hop.core.gui.plugin.GuiWidgetGroupType; import org.apache.hop.core.logging.ILogChannel; -import org.apache.hop.core.logging.LogChannel; import org.apache.hop.core.util.Utils; import org.apache.hop.core.variables.IVariables; import org.apache.hop.core.vfs.HopVfs; import org.apache.hop.i18n.BaseMessages; import org.apache.hop.metadata.api.IHasHopMetadataProvider; -import org.apache.hop.metadata.api.IHopMetadataProvider; -import org.apache.hop.ui.core.PropsUi; -import org.apache.hop.ui.core.bus.HopGuiEvents; import org.apache.hop.ui.core.dialog.BaseDialog; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.GuiResource; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; -import org.apache.hop.ui.core.widget.MetaSelectionLine; -import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; -import org.apache.hop.ui.util.EnvironmentUtils; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Text; import picocli.CommandLine; @Getter @@ -72,7 +55,7 @@ configKey = HopAiConfig.HOP_CONFIG_KEY, configClass = HopAiConfig.class) @GuiPlugin(description = "i18n::HopAiConfig.Tab.Name", classLoaderGroup = "hop-ai") -public class HopAiConfigOptionPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class HopAiConfigOptionPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final Class PKG = HopAiConfigOptionPlugin.class; private static final String PARENT = ConfigPluginOptionsTab.GUI_WIDGETS_PARENT_ID; @@ -92,7 +75,7 @@ public class HopAiConfigOptionPlugin implements IConfigOptions, IGuiPluginCompos toolTip = "i18n::HopAiConfigOptionPlugin.GitWarning.Tooltip", groupType = GuiWidgetGroupType.BOXES, group = "i18n::HopAiConfigOptionPlugin.Group") - public void gitWarning(Event event) { + public void gitWarning() { // Notice text only; LINK is the widget type this form can show without a value field. } @@ -135,7 +118,7 @@ public void gitWarning(Event event) { label = "", groupType = GuiWidgetGroupType.BOXES, group = "i18n::HopAiConfigOptionPlugin.Group") - public void defaultProviderWarning(Event event) { + public void defaultProviderWarning() { // Text only, set while the default provider is not defined in the open project. } @@ -370,138 +353,16 @@ public void widgetsCreated(GuiCompositeWidgets compositeWidgets) { @Override public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { - addContextFilesHint(compositeWidgets); - alignWithProviderLine(compositeWidgets); - updateDefaultProviderWarning(compositeWidgets); - // The providers are metadata of the open project; the list follows when another one opens. - HopGui hopGui = HopGui.peekInstance(); - if (hopGui != null && hopGui.getEventsHandler() != null) { - hopGui - .getEventsHandler() - .addEventListener( - HopAiConfigOptionPlugin.class.getName() + "ProjectActivated", - e -> - hopGui - .getDisplay() - .asyncExec( - () -> reloadProviders(compositeWidgets, hopGui.getMetadataProvider())), - HopGuiEvents.ProjectActivated.name()); - } + // The widgets themselves are handled by a GUI class: this one is also used without SWT + HopAiConfigOptionWidgets.populated(compositeWidgets); } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); if (WIDGET_DEFAULT_PROVIDER.equals(widgetId)) { - updateDefaultProviderWarning(compositeWidgets); - } - } - - /** List the providers of the project that is open now, keeping the configured name. */ - static void reloadProviders( - GuiCompositeWidgets compositeWidgets, IHopMetadataProvider metadataProvider) { - if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) - instanceof MetaSelectionLine line) - || line.isDisposed()) { - return; - } - String name = HopAiConfigSingleton.getConfig().getDefaultProviderName(); - line.setMetadataProvider(metadataProvider); - try { - line.fillItems(); - } catch (HopException e) { - LogChannel.UI.logError("Unable to list the AI providers of the open project", e); - } - if (!Const.NVL(name, "").equals(Const.NVL(line.getText(), ""))) { - line.setText(Const.NVL(name, "")); - } - updateDefaultProviderWarning(compositeWidgets); - } - - /** - * The default provider is a Hop-wide setting, the providers are project metadata. Say so when the - * open project has no provider by that name: its sessions then use the provider picked last. - */ - static void updateDefaultProviderWarning(GuiCompositeWidgets compositeWidgets) { - if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER_WARNING) - instanceof Link link) - || link.isDisposed()) { - return; - } - String name = null; - if (compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) - instanceof MetaSelectionLine line) { - name = line.getText(); - if (!Utils.isEmpty(name) && Arrays.asList(line.getItems()).contains(name)) { - name = null; - } - } - String text = - Utils.isEmpty(name) - ? "" - : BaseMessages.getString( - PKG, "HopAiConfigOptionPlugin.DefaultProvider.Missing", name.replace("&", "&&")); - if (text.equals(link.getText()) && link.getVisible() == !text.isEmpty()) { - return; - } - link.setText(text); - link.setVisible(!text.isEmpty()); - if (link.getLayoutData() instanceof FormData data) { - data.height = text.isEmpty() ? 0 : SWT.DEFAULT; - } - link.getParent().layout(true, true); - } - - /** - * The text fields end where the provider field ends, before its buttons, so their variable icons - * line up with the provider's in one column. - */ - static void alignWithProviderLine(GuiCompositeWidgets compositeWidgets) { - if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) - instanceof MetaSelectionLine line) - || line.getwToolBar() == null) { - return; - } - int inset = line.getwToolBar().computeSize(SWT.DEFAULT, SWT.DEFAULT).x + PropsUi.getMargin(); - Composite parent = null; - for (String id : new String[] {WIDGET_EXTRA_CONTEXT, WIDGET_CONTEXT_FILES}) { - Control control = compositeWidgets.getWidgetsMap().get(id); - if (control != null && control.getLayoutData() instanceof FormData data) { - data.right = new FormAttachment(100, -inset); - parent = control.getParent(); - } - } - if (parent != null) { - parent.layout(true, true); - } - } - - /** - * An example of what Context files takes, in the empty field. A multi-line field on macOS shows - * no message of its own, so it is painted. - */ - static void addContextFilesHint(GuiCompositeWidgets compositeWidgets) { - Control control = compositeWidgets.getWidgetsMap().get(WIDGET_CONTEXT_FILES); - Text text = control instanceof TextVar textVar ? textVar.getTextWidget() : null; - if (text == null || text.isDisposed() || text.getData(HINT_DATA_KEY) != null) { - return; - } - text.setData(HINT_DATA_KEY, Boolean.TRUE); - String hint = BaseMessages.getString(PKG, "HopAiConfigOptionPlugin.ExtraContextFiles.Hint"); - if (EnvironmentUtils.getInstance().isWeb()) { - text.setMessage(hint); - return; + HopAiConfigOptionWidgets.updateDefaultProviderWarning(compositeWidgets); } - text.addPaintListener( - e -> { - if (text.getCharCount() > 0) { - return; - } - e.gc.setForeground(GuiResource.getInstance().getColorDarkGray()); - e.gc.drawText(hint, PropsUi.getMargin(), PropsUi.getMargin() / 2, true); - }); - text.addListener(SWT.Modify, e -> text.redraw()); } @Override diff --git a/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionWidgets.java b/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionWidgets.java new file mode 100644 index 00000000000..18b1c6f1679 --- /dev/null +++ b/plugins/tech/ai/src/main/java/org/apache/hop/ai/config/HopAiConfigOptionWidgets.java @@ -0,0 +1,186 @@ +/* + * 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.ai.config; + +import static org.apache.hop.ai.config.HopAiConfigOptionPlugin.HINT_DATA_KEY; +import static org.apache.hop.ai.config.HopAiConfigOptionPlugin.WIDGET_CONTEXT_FILES; +import static org.apache.hop.ai.config.HopAiConfigOptionPlugin.WIDGET_DEFAULT_PROVIDER; +import static org.apache.hop.ai.config.HopAiConfigOptionPlugin.WIDGET_DEFAULT_PROVIDER_WARNING; +import static org.apache.hop.ai.config.HopAiConfigOptionPlugin.WIDGET_EXTRA_CONTEXT; + +import java.util.Arrays; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.logging.LogChannel; +import org.apache.hop.core.util.Utils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.ui.core.PropsUi; +import org.apache.hop.ui.core.bus.HopGuiEvents; +import org.apache.hop.ui.core.gui.GuiCompositeWidgets; +import org.apache.hop.ui.core.gui.GuiResource; +import org.apache.hop.ui.core.widget.MetaSelectionLine; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.hopgui.HopGui; +import org.apache.hop.ui.util.EnvironmentUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Text; + +/** + * The widgets of the AI configuration options in Hop GUI. They live apart from {@link + * HopAiConfigOptionPlugin}: hop-conf and the hop command line read that class by reflection, also + * without SWT, and the lambdas here take SWT types. + */ +final class HopAiConfigOptionWidgets { + + private static final Class PKG = HopAiConfigOptionPlugin.class; + + private HopAiConfigOptionWidgets() {} + + /** The widgets have their values: set them up, and follow the project that is open. */ + static void populated(GuiCompositeWidgets compositeWidgets) { + addContextFilesHint(compositeWidgets); + alignWithProviderLine(compositeWidgets); + updateDefaultProviderWarning(compositeWidgets); + // The providers are metadata of the open project; the list follows when another one opens. + HopGui hopGui = HopGui.peekInstance(); + if (hopGui != null && hopGui.getEventsHandler() != null) { + hopGui + .getEventsHandler() + .addEventListener( + HopAiConfigOptionPlugin.class.getName() + "ProjectActivated", + e -> + hopGui + .getDisplay() + .asyncExec( + () -> reloadProviders(compositeWidgets, hopGui.getMetadataProvider())), + HopGuiEvents.ProjectActivated.name()); + } + } + + /** List the providers of the project that is open now, keeping the configured name. */ + static void reloadProviders( + GuiCompositeWidgets compositeWidgets, IHopMetadataProvider metadataProvider) { + if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) + instanceof MetaSelectionLine line) + || line.isDisposed()) { + return; + } + String name = HopAiConfigSingleton.getConfig().getDefaultProviderName(); + line.setMetadataProvider(metadataProvider); + try { + line.fillItems(); + } catch (HopException e) { + LogChannel.UI.logError("Unable to list the AI providers of the open project", e); + } + if (!Const.NVL(name, "").equals(Const.NVL(line.getText(), ""))) { + line.setText(Const.NVL(name, "")); + } + updateDefaultProviderWarning(compositeWidgets); + } + + /** + * The default provider is a Hop-wide setting, the providers are project metadata. Say so when the + * open project has no provider by that name: its sessions then use the provider picked last. + */ + static void updateDefaultProviderWarning(GuiCompositeWidgets compositeWidgets) { + if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER_WARNING) + instanceof Link link) + || link.isDisposed()) { + return; + } + String name = null; + if (compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) + instanceof MetaSelectionLine line) { + name = line.getText(); + if (!Utils.isEmpty(name) && Arrays.asList(line.getItems()).contains(name)) { + name = null; + } + } + String text = + Utils.isEmpty(name) + ? "" + : BaseMessages.getString( + PKG, "HopAiConfigOptionPlugin.DefaultProvider.Missing", name.replace("&", "&&")); + if (text.equals(link.getText()) && link.getVisible() == !text.isEmpty()) { + return; + } + link.setText(text); + link.setVisible(!text.isEmpty()); + if (link.getLayoutData() instanceof FormData data) { + data.height = text.isEmpty() ? 0 : SWT.DEFAULT; + } + link.getParent().layout(true, true); + } + + /** + * The text fields end where the provider field ends, before its buttons, so their variable icons + * line up with the provider's in one column. + */ + static void alignWithProviderLine(GuiCompositeWidgets compositeWidgets) { + if (!(compositeWidgets.getWidgetsMap().get(WIDGET_DEFAULT_PROVIDER) + instanceof MetaSelectionLine line) + || line.getwToolBar() == null) { + return; + } + int inset = line.getwToolBar().computeSize(SWT.DEFAULT, SWT.DEFAULT).x + PropsUi.getMargin(); + Composite parent = null; + for (String id : new String[] {WIDGET_EXTRA_CONTEXT, WIDGET_CONTEXT_FILES}) { + Control control = compositeWidgets.getWidgetsMap().get(id); + if (control != null && control.getLayoutData() instanceof FormData data) { + data.right = new FormAttachment(100, -inset); + parent = control.getParent(); + } + } + if (parent != null) { + parent.layout(true, true); + } + } + + /** + * An example of what Context files takes, in the empty field. A multi-line field on macOS shows + * no message of its own, so it is painted. + */ + static void addContextFilesHint(GuiCompositeWidgets compositeWidgets) { + Control control = compositeWidgets.getWidgetsMap().get(WIDGET_CONTEXT_FILES); + Text text = control instanceof TextVar textVar ? textVar.getTextWidget() : null; + if (text == null || text.isDisposed() || text.getData(HINT_DATA_KEY) != null) { + return; + } + text.setData(HINT_DATA_KEY, Boolean.TRUE); + String hint = BaseMessages.getString(PKG, "HopAiConfigOptionPlugin.ExtraContextFiles.Hint"); + if (EnvironmentUtils.getInstance().isWeb()) { + text.setMessage(hint); + return; + } + text.addPaintListener( + e -> { + if (text.getCharCount() > 0) { + return; + } + e.gc.setForeground(GuiResource.getInstance().getColorDarkGray()); + e.gc.drawText(hint, PropsUi.getMargin(), PropsUi.getMargin() / 2, true); + }); + text.addListener(SWT.Modify, e -> text.redraw()); + } +} diff --git a/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HeadlessReflectionTest.java b/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..0024dee66e7 --- /dev/null +++ b/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.ai.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the AI configuration options by reflection, also without + * SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(HopAiConfigOptionPlugin.class); + } +} diff --git a/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HopAiConfigOptionPluginUiTest.java b/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HopAiConfigOptionPluginUiTest.java index a3724af6ee4..ef40d82f06d 100644 --- a/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HopAiConfigOptionPluginUiTest.java +++ b/plugins/tech/ai/src/test/java/org/apache/hop/ai/config/HopAiConfigOptionPluginUiTest.java @@ -104,7 +104,7 @@ void aDefaultProviderTheOpenProjectDoesNotHaveIsPointedOut() throws Exception { bot -> { onUi( () -> { - HopAiConfigOptionPlugin.reloadProviders(widgets.get(), projectA); + HopAiConfigOptionWidgets.reloadProviders(widgets.get(), projectA); return null; }); MetaSelectionLine line = providerLine(widgets.get()); @@ -114,7 +114,7 @@ void aDefaultProviderTheOpenProjectDoesNotHaveIsPointedOut() throws Exception { // Another project is opened: its providers are listed, and the name it lacks is noted. onUi( () -> { - HopAiConfigOptionPlugin.reloadProviders(widgets.get(), projectB); + HopAiConfigOptionWidgets.reloadProviders(widgets.get(), projectB); return null; }); assertEquals(0, onUi(line::getItemCount)); @@ -127,7 +127,7 @@ void aDefaultProviderTheOpenProjectDoesNotHaveIsPointedOut() throws Exception { onUi( () -> { - HopAiConfigOptionPlugin.reloadProviders(widgets.get(), projectA); + HopAiConfigOptionWidgets.reloadProviders(widgets.get(), projectA); return null; }); assertFalse(onUi(() -> warning(widgets.get()).isVisible())); diff --git a/plugins/tech/aws/src/main/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerVariableResolver.java b/plugins/tech/aws/src/main/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerVariableResolver.java index 312fe560b93..78c276319ba 100644 --- a/plugins/tech/aws/src/main/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerVariableResolver.java +++ b/plugins/tech/aws/src/main/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerVariableResolver.java @@ -45,7 +45,7 @@ import org.apache.hop.metadata.api.HopMetadataProperty; import org.apache.hop.metadata.api.IHopMetadataProvider; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Control; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; @@ -85,7 +85,7 @@ documentationUrl = "/metadata-types/variable-resolver/aws-secrets-manager-variable-resolver.html") public class AwsSecretsManagerVariableResolver - implements IVariableResolver, IGuiPluginCompositeWidgetsListener { + implements IVariableResolver, IGuiPluginModelWidgetsListener { private static final String CONST_SECRET = "Secret '"; private static final String DEFAULT_VERSION_STAGE = "AWSCURRENT"; @@ -546,8 +546,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { if (ID_AUTHENTICATION_TYPE.equals(widgetId)) { hideFieldsThatDoNotApply(compositeWidgets); } diff --git a/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerWidgetVisibilityTest.java b/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerWidgetVisibilityTest.java index e935d793302..269e5e832ad 100644 --- a/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerWidgetVisibilityTest.java +++ b/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/AwsSecretsManagerWidgetVisibilityTest.java @@ -141,7 +141,7 @@ private void withWidgets( widgets.createCompositeWidgets( resolver, null, shell, VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID, null); widgets.setWidgetsContents(resolver, shell, VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID); - widgets.setWidgetsListener(resolver); + widgets.setWidgetsListener(GuiCompositeWidgets.listenerOf(resolver).orElseThrow()); resolver.widgetsPopulated(widgets); shell.layout(true, true); diff --git a/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/HeadlessReflectionTest.java b/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/HeadlessReflectionTest.java new file mode 100644 index 00000000000..97ef39b1491 --- /dev/null +++ b/plugins/tech/aws/src/test/java/org/apache/hop/core/variables/resolver/aws/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.core.variables.resolver.aws; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * Every run that loads the project's metadata reads the AWS Secrets Manager variable resolver by + * reflection, also without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(AwsSecretsManagerVariableResolver.class); + } +} diff --git a/plugins/tech/azure/src/main/java/org/apache/hop/vfs/azure/config/AzureConfigPlugin.java b/plugins/tech/azure/src/main/java/org/apache/hop/vfs/azure/config/AzureConfigPlugin.java index e4344ba7550..0131ace3e75 100644 --- a/plugins/tech/azure/src/main/java/org/apache/hop/vfs/azure/config/AzureConfigPlugin.java +++ b/plugins/tech/azure/src/main/java/org/apache/hop/vfs/azure/config/AzureConfigPlugin.java @@ -29,7 +29,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -45,7 +45,7 @@ @GuiPlugin( description = "i18n::Azure.GuiPlugin.Description" // Tab label in options dialog ) -public class AzureConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class AzureConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_AZURE_ACCOUNT = "10000-azure-account"; private static final String WIDGET_ID_AZURE_KEY = "10100-azure-key"; @@ -153,8 +153,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/tech/azure/src/test/java/org/apache/hop/vfs/azure/config/HeadlessReflectionTest.java b/plugins/tech/azure/src/test/java/org/apache/hop/vfs/azure/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..75996694c95 --- /dev/null +++ b/plugins/tech/azure/src/test/java/org/apache/hop/vfs/azure/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.vfs.azure.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the Azure configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(AzureConfigPlugin.class); + } +} diff --git a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java index d9fae5b9626..568481e6061 100644 --- a/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java +++ b/plugins/tech/calcite/src/main/java/org/apache/hop/calcite/config/CalciteSqlFormatConfigPlugin.java @@ -32,10 +32,9 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; -import org.eclipse.swt.widgets.Control; import picocli.CommandLine; /** @@ -52,7 +51,7 @@ configClass = CalciteSqlFormatConfig.class) @GuiPlugin(description = "i18n::CalciteSqlFormatConfigPlugin.Name") public class CalciteSqlFormatConfigPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { + implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final Class PKG = CalciteSqlFormatConfigPlugin.class; @@ -362,8 +361,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/HeadlessReflectionTest.java b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..a86e8afd124 --- /dev/null +++ b/plugins/tech/calcite/src/test/java/org/apache/hop/calcite/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.calcite.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the SQL format configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(CalciteSqlFormatConfigPlugin.class); + } +} diff --git a/plugins/tech/dropbox/src/main/java/org/apache/hop/vfs/dropbox/config/DropboxConfigPlugin.java b/plugins/tech/dropbox/src/main/java/org/apache/hop/vfs/dropbox/config/DropboxConfigPlugin.java index ecc5adb00b7..a043152758e 100644 --- a/plugins/tech/dropbox/src/main/java/org/apache/hop/vfs/dropbox/config/DropboxConfigPlugin.java +++ b/plugins/tech/dropbox/src/main/java/org/apache/hop/vfs/dropbox/config/DropboxConfigPlugin.java @@ -29,7 +29,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -45,7 +45,7 @@ @GuiPlugin( description = "Dropbox" // Tab label in options dialog ) -public class DropboxConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class DropboxConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_DROPBOX_ACCESS_TOKEN = "10000-dropbox-access-token"; @@ -112,8 +112,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/tech/dropbox/src/test/java/org/apache/hop/vfs/dropbox/config/HeadlessReflectionTest.java b/plugins/tech/dropbox/src/test/java/org/apache/hop/vfs/dropbox/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..cf1b447b405 --- /dev/null +++ b/plugins/tech/dropbox/src/test/java/org/apache/hop/vfs/dropbox/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.vfs.dropbox.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the Dropbox configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(DropboxConfigPlugin.class); + } +} diff --git a/plugins/tech/google/src/main/java/org/apache/hop/vfs/googledrive/config/GoogleDriveConfigPlugin.java b/plugins/tech/google/src/main/java/org/apache/hop/vfs/googledrive/config/GoogleDriveConfigPlugin.java index 88a0155ad08..e89730329ac 100644 --- a/plugins/tech/google/src/main/java/org/apache/hop/vfs/googledrive/config/GoogleDriveConfigPlugin.java +++ b/plugins/tech/google/src/main/java/org/apache/hop/vfs/googledrive/config/GoogleDriveConfigPlugin.java @@ -29,7 +29,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -45,7 +45,7 @@ @GuiPlugin( description = "i18n::GoogleDriveConfig.GuiPlugin.Description" // Tab label in options dialog ) -public class GoogleDriveConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class GoogleDriveConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_GOOGLE_DRIVE_VFS_CREDENTIALS_PATH = "10000-google-drive-vfs-credentials-path"; @@ -132,8 +132,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/tech/google/src/main/java/org/apache/hop/vfs/gs/config/GoogleCloudConfigPlugin.java b/plugins/tech/google/src/main/java/org/apache/hop/vfs/gs/config/GoogleCloudConfigPlugin.java index 8f3038bfb40..53ccf48c1f4 100644 --- a/plugins/tech/google/src/main/java/org/apache/hop/vfs/gs/config/GoogleCloudConfigPlugin.java +++ b/plugins/tech/google/src/main/java/org/apache/hop/vfs/gs/config/GoogleCloudConfigPlugin.java @@ -31,7 +31,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -50,7 +50,7 @@ @GuiPlugin( description = "i18n::GoogleCloudPlugin.GuiPlugin.Description" // Tab label in options dialog ) -public class GoogleCloudConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class GoogleCloudConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_GOOGLE_CLOUD_SERVICE_ACCOUNT_KEY_FILE = "10000-google-cloud-service-account-key-file"; @@ -379,8 +379,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/tech/google/src/test/java/org/apache/hop/vfs/gs/config/HeadlessReflectionTest.java b/plugins/tech/google/src/test/java/org/apache/hop/vfs/gs/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..7085db31559 --- /dev/null +++ b/plugins/tech/google/src/test/java/org/apache/hop/vfs/gs/config/HeadlessReflectionTest.java @@ -0,0 +1,34 @@ +/* + * 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.vfs.gs.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.apache.hop.vfs.googledrive.config.GoogleDriveConfigPlugin; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the Google configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(GoogleCloudConfigPlugin.class, GoogleDriveConfigPlugin.class); + } +} diff --git a/plugins/tech/salesforce/src/main/java/org/apache/hop/pipeline/transforms/salesforceinput/SalesforceInputMeta.java b/plugins/tech/salesforce/src/main/java/org/apache/hop/pipeline/transforms/salesforceinput/SalesforceInputMeta.java index ee66a263e67..c829b6d2c04 100644 --- a/plugins/tech/salesforce/src/main/java/org/apache/hop/pipeline/transforms/salesforceinput/SalesforceInputMeta.java +++ b/plugins/tech/salesforce/src/main/java/org/apache/hop/pipeline/transforms/salesforceinput/SalesforceInputMeta.java @@ -474,14 +474,4 @@ public void check( remarks.add(cr); } } - - public SalesforceInputDialog getDialog( - org.eclipse.swt.widgets.Shell shell, - IVariables variables, - org.apache.hop.pipeline.transform.ITransformMeta transformMeta, - PipelineMeta pipelineMeta, - String transformName) { - return new SalesforceInputDialog( - shell, variables, (SalesforceInputMeta) transformMeta, pipelineMeta); - } } diff --git a/plugins/tech/salesforce/src/test/java/org/apache/hop/pipeline/transforms/salesforceinput/HeadlessReflectionTest.java b/plugins/tech/salesforce/src/test/java/org/apache/hop/pipeline/transforms/salesforceinput/HeadlessReflectionTest.java new file mode 100644 index 00000000000..c77472bc02d --- /dev/null +++ b/plugins/tech/salesforce/src/test/java/org/apache/hop/pipeline/transforms/salesforceinput/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.pipeline.transforms.salesforceinput; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * Loading a pipeline reads its transforms' metadata by reflection, also without SWT (hop-run, + * hop-server, a Spark executor): no signature of the Salesforce input's metadata may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(SalesforceInputMeta.class); + } +} diff --git a/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnection.java b/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnection.java index 3a6107d53b4..58ae837535d 100644 --- a/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnection.java +++ b/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnection.java @@ -35,7 +35,7 @@ import org.apache.hop.metadata.api.IHopMetadata; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.ComboVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.vfs.smb.SmbAuthType; @@ -60,7 +60,7 @@ supportsGlobalReplace = true, classLoaderGroup = "vfs-smb") public class SmbConnection extends HopMetadataBase - implements Serializable, IHopMetadata, IVfsBrowseLocation, IGuiPluginCompositeWidgetsListener { + implements Serializable, IHopMetadata, IVfsBrowseLocation, IGuiPluginModelWidgetsListener { private static final long serialVersionUID = 1L; @@ -317,8 +317,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { hideCredentialsWhenGuest(compositeWidgets); } diff --git a/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnectionEditor.java b/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnectionEditor.java index efc3e3480f5..8db2400aa3a 100644 --- a/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnectionEditor.java +++ b/plugins/tech/smb/src/main/java/org/apache/hop/vfs/smb/metadata/SmbConnectionEditor.java @@ -118,7 +118,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { public void widgetModified( GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { setChanged(); - metadata.widgetModified(compositeWidgets, changedWidget, widgetId); + metadata.widgetModified(compositeWidgets, widgetId); } @Override diff --git a/plugins/tech/smb/src/test/java/org/apache/hop/vfs/smb/metadata/HeadlessReflectionTest.java b/plugins/tech/smb/src/test/java/org/apache/hop/vfs/smb/metadata/HeadlessReflectionTest.java new file mode 100644 index 00000000000..bda1eb8f9fb --- /dev/null +++ b/plugins/tech/smb/src/test/java/org/apache/hop/vfs/smb/metadata/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.vfs.smb.metadata; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * Every run that loads the project's metadata reads the SMB connection by reflection, also without + * SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(SmbConnection.class); + } +} diff --git a/plugins/tech/vault/src/main/java/org/apache/hop/core/variables/resolver/vault/BaseVaultVariableResolver.java b/plugins/tech/vault/src/main/java/org/apache/hop/core/variables/resolver/vault/BaseVaultVariableResolver.java index ff7f628e0b6..c4f22281e3f 100644 --- a/plugins/tech/vault/src/main/java/org/apache/hop/core/variables/resolver/vault/BaseVaultVariableResolver.java +++ b/plugins/tech/vault/src/main/java/org/apache/hop/core/variables/resolver/vault/BaseVaultVariableResolver.java @@ -52,7 +52,7 @@ import org.apache.hop.metadata.api.HopMetadataProperty; import org.apache.hop.metadata.api.IHopMetadataProvider; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.ComboVar; import org.apache.hop.ui.core.widget.TextVar; import org.eclipse.swt.widgets.Combo; @@ -62,7 +62,7 @@ @Getter @Setter public abstract class BaseVaultVariableResolver - implements IVariableResolver, IGuiPluginCompositeWidgetsListener { + implements IVariableResolver, IGuiPluginModelWidgetsListener { private static final String CONST_AUTH = "auth/"; static final String ID_VAULT_ADDRESS = "vaultAddress"; @@ -715,8 +715,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { if (ID_AUTHENTICATION_TYPE.equals(widgetId)) { hideFieldsThatDoNotApply(compositeWidgets); } @@ -786,7 +785,7 @@ private VaultAuthType readAuthType(GuiCompositeWidgets compositeWidgets) { } } - private static String comboText(Control control) { + private static String comboText(Object control) { if (control instanceof Combo combo) { return combo.getText(); } diff --git a/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/HeadlessReflectionTest.java b/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/HeadlessReflectionTest.java new file mode 100644 index 00000000000..3a202980dd1 --- /dev/null +++ b/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.core.variables.resolver.vault; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * Every run that loads the project's metadata reads the Vault and OpenBao variable resolvers by + * reflection, also without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(VaultVariableResolver.class, OpenBaoVariableResolver.class); + } +} diff --git a/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/VaultWidgetVisibilityTest.java b/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/VaultWidgetVisibilityTest.java index 8608d4be9ed..c52fadd48c8 100644 --- a/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/VaultWidgetVisibilityTest.java +++ b/plugins/tech/vault/src/test/java/org/apache/hop/core/variables/resolver/vault/VaultWidgetVisibilityTest.java @@ -164,7 +164,7 @@ private void withWidgets( widgets.createCompositeWidgets( resolver, null, shell, VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID, null); widgets.setWidgetsContents(resolver, shell, VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID); - widgets.setWidgetsListener(resolver); + widgets.setWidgetsListener(GuiCompositeWidgets.listenerOf(resolver).orElseThrow()); resolver.widgetsPopulated(widgets); shell.layout(true, true); diff --git a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/config/FormulaConfigPlugin.java b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/config/FormulaConfigPlugin.java index d8f3c297f19..fffca12340b 100644 --- a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/config/FormulaConfigPlugin.java +++ b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/config/FormulaConfigPlugin.java @@ -31,11 +31,10 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Control; import picocli.CommandLine; /** @@ -46,7 +45,7 @@ @Setter @ConfigPlugin(id = "FormulaConfigPlugin", description = "Formula transform options") @GuiPlugin(description = "i18n::FormulaConfigPlugin.Name") -public class FormulaConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class FormulaConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final Class PKG = FormulaConfigPlugin.class; @@ -105,8 +104,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/plugins/transforms/formula/src/test/java/org/apache/hop/pipeline/transforms/formula/config/HeadlessReflectionTest.java b/plugins/transforms/formula/src/test/java/org/apache/hop/pipeline/transforms/formula/config/HeadlessReflectionTest.java new file mode 100644 index 00000000000..f21db022c6d --- /dev/null +++ b/plugins/transforms/formula/src/test/java/org/apache/hop/pipeline/transforms/formula/config/HeadlessReflectionTest.java @@ -0,0 +1,33 @@ +/* + * 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.pipeline.transforms.formula.config; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the formula configuration options by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects(FormulaConfigPlugin.class); + } +} diff --git a/plugins/transforms/languagemodelchat/src/main/java/org/apache/hop/pipeline/transforms/languagemodelchat/internals/ui/i18nUtil.java b/plugins/transforms/languagemodelchat/src/main/java/org/apache/hop/pipeline/transforms/languagemodelchat/internals/ui/i18nUtil.java index 27c33fe9891..489de6387a5 100644 --- a/plugins/transforms/languagemodelchat/src/main/java/org/apache/hop/pipeline/transforms/languagemodelchat/internals/ui/i18nUtil.java +++ b/plugins/transforms/languagemodelchat/src/main/java/org/apache/hop/pipeline/transforms/languagemodelchat/internals/ui/i18nUtil.java @@ -19,11 +19,13 @@ import static org.apache.hop.i18n.BaseMessages.getString; -import org.apache.hop.pipeline.transforms.languagemodelchat.LanguageModelChatDialog; +import org.apache.hop.pipeline.transforms.languagemodelchat.LanguageModelChatMeta; public class i18nUtil { - private static final Class PKG = LanguageModelChatDialog.class; // For Translator + // The messages of the transform's package. Not the dialog's class: the metadata and the transform + // use these too, also without SWT, and loading the dialog needs SWT. + private static final Class PKG = LanguageModelChatMeta.class; // For Translator public static String i18n(String key) { return getString(PKG, key); diff --git a/plugins/transforms/languagemodelchat/src/test/java/org/apache/hop/pipeline/transforms/languagemodelchat/HeadlessCreationTest.java b/plugins/transforms/languagemodelchat/src/test/java/org/apache/hop/pipeline/transforms/languagemodelchat/HeadlessCreationTest.java new file mode 100644 index 00000000000..4187bc2c414 --- /dev/null +++ b/plugins/transforms/languagemodelchat/src/test/java/org/apache/hop/pipeline/transforms/languagemodelchat/HeadlessCreationTest.java @@ -0,0 +1,34 @@ +/* + * 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.pipeline.transforms.languagemodelchat; + +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * Loading or running a pipeline creates the transform's metadata, also without SWT (hop-run, + * hop-server, a Spark executor): its messages must not come through the dialog's class. + */ +class HeadlessCreationTest { + + @Test + void theMetadataIsCreatedWithoutSwt() throws Exception { + WithoutSwt.assertCreates(LanguageModelChatMeta.class); + WithoutSwt.assertReflects(LanguageModelChatMeta.class); + } +} diff --git a/rap/src/main/java/org/apache/hop/ui/hopgui/HopWebEntryPoint.java b/rap/src/main/java/org/apache/hop/ui/hopgui/HopWebEntryPoint.java index 6d1a84c15f3..0a5dfed3026 100644 --- a/rap/src/main/java/org/apache/hop/ui/hopgui/HopWebEntryPoint.java +++ b/rap/src/main/java/org/apache/hop/ui/hopgui/HopWebEntryPoint.java @@ -117,7 +117,7 @@ public class HopWebEntryPoint extends AbstractEntryPoint { @Override protected void createContents(Composite parent) { - // So drill-down and other GUI checks can use Const.getHopPlatformRuntime() from any thread + // So drill-down and other GUI checks can use Const.isGuiRuntime() from any thread System.setProperty(Const.HOP_PLATFORM_RUNTIME, "GUI"); String path = null; diff --git a/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java index 722474df1a4..b29a80e3a4d 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java +++ b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java @@ -34,8 +34,6 @@ import org.apache.hop.core.logging.LogChannel; import org.apache.hop.core.security.HopDialogEditGuard; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.core.variables.Variable; -import org.apache.hop.core.variables.VariableScope; import org.apache.hop.core.vfs.HopVfs; import org.apache.hop.i18n.BaseMessages; import org.apache.hop.ui.core.FormDataBuilder; @@ -107,12 +105,9 @@ public abstract class BaseDialog extends Dialog { private static final ThreadLocal> DIALOG_SUBJECT_STACK = ThreadLocal.withInitial(ArrayDeque::new); - @Variable( - scope = VariableScope.APPLICATION, - value = "N", - description = - "Set this value to 'Y' if you want to use the system file open/save dialog when browsing files.") - public static final String HOP_USE_NATIVE_FILE_DIALOG = "HOP_USE_NATIVE_FILE_DIALOG"; + /** See {@link BaseDialogVariables#HOP_USE_NATIVE_FILE_DIALOG}. */ + public static final String HOP_USE_NATIVE_FILE_DIALOG = + BaseDialogVariables.HOP_USE_NATIVE_FILE_DIALOG; public static final int MARGIN_SIZE = 15; public static final int LABEL_SPACING = 5; diff --git a/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialogVariables.java b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialogVariables.java new file mode 100644 index 00000000000..dec3fd9272f --- /dev/null +++ b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialogVariables.java @@ -0,0 +1,38 @@ +/* + * 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.ui.core.dialog; + +import org.apache.hop.core.variables.Variable; +import org.apache.hop.core.variables.VariableScope; + +/** + * The variables of Hop's dialogs. They live here rather than in {@link BaseDialog}: the variable + * registry loads the class that declares a variable, also in runs without a GUI, and BaseDialog + * needs SWT to load. + */ +public final class BaseDialogVariables { + + @Variable( + scope = VariableScope.APPLICATION, + value = "N", + description = + "Set this value to 'Y' if you want to use the system file open/save dialog when browsing files.") + public static final String HOP_USE_NATIVE_FILE_DIALOG = "HOP_USE_NATIVE_FILE_DIALOG"; + + private BaseDialogVariables() {} +} diff --git a/ui/src/main/java/org/apache/hop/ui/core/gui/GuiCompositeWidgets.java b/ui/src/main/java/org/apache/hop/ui/core/gui/GuiCompositeWidgets.java index 1a1e40cd44c..429d2274e66 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/gui/GuiCompositeWidgets.java +++ b/ui/src/main/java/org/apache/hop/ui/core/gui/GuiCompositeWidgets.java @@ -28,6 +28,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import lombok.Getter; @@ -1994,6 +1995,46 @@ public void setWidgetsListener(IGuiPluginCompositeWidgetsListener listener) { this.compositeWidgetsListener = listener; } + /** + * The widgets listener of a source object: the object itself when it implements {@link + * IGuiPluginCompositeWidgetsListener}, or one that passes the calls on when it implements {@link + * IGuiPluginModelWidgetsListener}, which model classes use to stay free of SWT. + * + * @param source the object the widgets show, or null + * @return its listener, or empty when it doesn't listen to its widgets + */ + public static Optional listenerOf(Object source) { + if (source instanceof IGuiPluginCompositeWidgetsListener listener) { + return Optional.of(listener); + } + if (source instanceof IGuiPluginModelWidgetsListener model) { + return Optional.of( + new IGuiPluginCompositeWidgetsListener() { + @Override + public void widgetsCreated(GuiCompositeWidgets compositeWidgets) { + model.widgetsCreated(compositeWidgets); + } + + @Override + public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { + model.widgetsPopulated(compositeWidgets); + } + + @Override + public void widgetModified( + GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + model.widgetModified(compositeWidgets, widgetId); + } + + @Override + public void persistContents(GuiCompositeWidgets compositeWidgets) { + model.persistContents(compositeWidgets); + } + }); + } + return Optional.empty(); + } + public void enableWidgets(Object sourceData, String parentGuiElementId, boolean enabled) { GuiRegistry registry = GuiRegistry.getInstance(); GuiElements guiElements = diff --git a/ui/src/main/java/org/apache/hop/ui/core/gui/HopNamespace.java b/ui/src/main/java/org/apache/hop/ui/core/gui/HopNamespace.java index 8e4c75065d3..46ad123661c 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/gui/HopNamespace.java +++ b/ui/src/main/java/org/apache/hop/ui/core/gui/HopNamespace.java @@ -93,7 +93,7 @@ public static final void setNamespace(String namespace) { * reference to {@link Display} out of the code path a headless process runs. */ private static boolean hasUserInterface() { - return "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + return Const.isGuiRuntime(); } /** The namespace of the session on this thread, or null. Only call with a user interface. */ diff --git a/ui/src/main/java/org/apache/hop/ui/core/gui/IGuiPluginModelWidgetsListener.java b/ui/src/main/java/org/apache/hop/ui/core/gui/IGuiPluginModelWidgetsListener.java new file mode 100644 index 00000000000..9f15538f3db --- /dev/null +++ b/ui/src/main/java/org/apache/hop/ui/core/gui/IGuiPluginModelWidgetsListener.java @@ -0,0 +1,48 @@ +/* + * 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.ui.core.gui; + +/** + * The callbacks of {@link IGuiPluginCompositeWidgetsListener} without SWT types, for the model + * classes whose widgets Hop builds from their annotations and that Hop also uses without a GUI: + * metadata types, configuration options, variable resolvers. Hop's serializers and command line + * options look up the methods of those classes by reflection, which needs every type in every + * method signature: one SWT type there, the Control of widgetModified for example, and without SWT + * on the class path (hop-run, hop-server, a Spark executor) the class can't be used at all. + * + *

Dialogs and other GUI classes keep implementing {@link IGuiPluginCompositeWidgetsListener}. + */ +public interface IGuiPluginModelWidgetsListener { + + /** All the widgets are created. */ + default void widgetsCreated(GuiCompositeWidgets compositeWidgets) {} + + /** All the widgets have their values, right before they're shown. */ + default void widgetsPopulated(GuiCompositeWidgets compositeWidgets) {} + + /** + * A widget was modified. + * + * @param compositeWidgets all the widgets, the changed one among them under its id + * @param widgetId the id of the changed widget + */ + default void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) {} + + /** The changed values need to be persisted. */ + default void persistContents(GuiCompositeWidgets compositeWidgets) {} +} diff --git a/ui/src/main/java/org/apache/hop/ui/core/variables/resolver/VariableResolverEditor.java b/ui/src/main/java/org/apache/hop/ui/core/variables/resolver/VariableResolverEditor.java index 4f1f910f8f5..d5e8704721e 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/variables/resolver/VariableResolverEditor.java +++ b/ui/src/main/java/org/apache/hop/ui/core/variables/resolver/VariableResolverEditor.java @@ -39,6 +39,7 @@ import org.apache.hop.ui.core.gui.GuiCompositeWidgetsAdapter; import org.apache.hop.ui.core.gui.GuiResource; import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.metadata.MetadataEditor; import org.apache.hop.ui.core.metadata.MetadataManager; import org.apache.hop.ui.core.widget.NamingSchemeTypes; @@ -264,9 +265,9 @@ private void changeResolverType() { /** * The composite has a single listener slot, which this editor needs for its own change tracking. - * Resolver plugins that implement {@link IGuiPluginCompositeWidgetsListener} -- to enable, hide - * or otherwise adjust their own widgets -- are forwarded to from here; without this their - * callbacks would never fire. + * Resolver plugins that implement {@link IGuiPluginModelWidgetsListener} (or {@link + * IGuiPluginCompositeWidgetsListener}) -- to enable, hide or otherwise adjust their own widgets + * -- are forwarded to from here; without this their callbacks would never fire. */ private IGuiPluginCompositeWidgetsListener createWidgetsListener() { return new GuiCompositeWidgetsAdapter() { @@ -301,9 +302,7 @@ private Optional pluginWidgetsListener() { if (resolver == null) { return Optional.empty(); } - return resolver.getIResolver() instanceof IGuiPluginCompositeWidgetsListener listener - ? Optional.of(listener) - : Optional.empty(); + return GuiCompositeWidgets.listenerOf(resolver.getIResolver()); } private void enableFields() { diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/config/FileValidationConfigPlugin.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/config/FileValidationConfigPlugin.java index 03f720c4c2d..9a7be5a40c2 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/config/FileValidationConfigPlugin.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/config/FileValidationConfigPlugin.java @@ -29,7 +29,7 @@ import org.apache.hop.core.variables.IVariables; import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Control; @@ -44,8 +44,7 @@ description = "Validate referenced database connections when saving a file", category = ConfigPlugin.CATEGORY_CONFIG) @GuiPlugin(description = "i18n::FileValidationConfigPlugin.Description") -public class FileValidationConfigPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class FileValidationConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { public static final String KEY_VALIDATE_DB_CONNECTIONS_ON_SAVE = "ValidateDbConnectionsOnSave"; @@ -110,8 +109,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java index 6ebd28d5fba..7aeba717119 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java @@ -5386,8 +5386,7 @@ public void paintControl(PaintEvent e) { // Do double buffering to prevent flickering on Windows // - boolean needsDoubleBuffering = - Const.isWindows() && "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + boolean needsDoubleBuffering = Const.isWindows() && Const.isGuiRuntime(); Image image = null; GC swtGc = e.gc; diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/debug/config/DebugSessionsConfigPlugin.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/debug/config/DebugSessionsConfigPlugin.java index 2cb749be452..edf5e73866c 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/debug/config/DebugSessionsConfigPlugin.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/debug/config/DebugSessionsConfigPlugin.java @@ -29,7 +29,7 @@ import org.apache.hop.pipeline.debug.DebugSessionStore; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -43,8 +43,7 @@ configKey = DebugSessionsConfig.HOP_CONFIG_KEY, configClass = DebugSessionsConfig.class) @GuiPlugin(description = "i18n::DebugSessionsConfig.GuiPlugin.Description") -public class DebugSessionsConfigPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class DebugSessionsConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_FOLDER = "10000-debug-sessions-folder"; @@ -102,8 +101,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownRegistrationExtensionPoint.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownRegistrationExtensionPoint.java index ce52d1a45ec..b97e5dd6462 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownRegistrationExtensionPoint.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownRegistrationExtensionPoint.java @@ -41,7 +41,7 @@ public class DrillDownRegistrationExtensionPoint public void callExtensionPoint( ILogChannel log, IVariables variables, IPipelineEngine pipeline) throws HopException { - if (pipeline == null || !"GUI".equalsIgnoreCase(Const.getHopPlatformRuntime())) { + if (pipeline == null || !Const.isGuiRuntime()) { return; } DrillDownGuiPlugin.registerRunningPipeline(pipeline.getLogChannelId(), pipeline); diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownWorkflowRegistrationExtensionPoint.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownWorkflowRegistrationExtensionPoint.java index 44c8e95cbaf..e5382a50ad0 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownWorkflowRegistrationExtensionPoint.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/DrillDownWorkflowRegistrationExtensionPoint.java @@ -41,7 +41,7 @@ public class DrillDownWorkflowRegistrationExtensionPoint public void callExtensionPoint( ILogChannel log, IVariables variables, IWorkflowEngine workflow) throws HopException { - if (workflow == null || !"GUI".equalsIgnoreCase(Const.getHopPlatformRuntime())) { + if (workflow == null || !Const.isGuiRuntime()) { return; } DrillDownGuiPlugin.registerRunningWorkflow(workflow.getLogChannelId(), workflow); diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java index 2812e42c60e..3b44ab50de5 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java @@ -4274,8 +4274,7 @@ public void paintControl(PaintEvent e) { // Do double buffering to prevent flickering on Windows // - boolean needsDoubleBuffering = - Const.isWindows() && "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + boolean needsDoubleBuffering = Const.isWindows() && Const.isGuiRuntime(); Image image = null; GC swtGc = e.gc; diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTab.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTab.java index 7a86244409e..dc6bee3d080 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTab.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTab.java @@ -34,7 +34,6 @@ import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; import org.apache.hop.ui.core.gui.GuiResource; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.ConfigurationPerspective; import org.eclipse.swt.SWT; @@ -150,12 +149,14 @@ public void addPluginOptionsTab(CTabFolder wTabFolder) { * widgets are enabled until the user changes something. */ static void attachWidgetsListener(GuiCompositeWidgets compositeWidgets, Object pluginSourceData) { - if (pluginSourceData instanceof IGuiPluginCompositeWidgetsListener listener) { - // This listener saves the changed values immediately, so we don't have to worry about that. - // - compositeWidgets.setWidgetsListener(listener); - listener.widgetsPopulated(compositeWidgets); - } + GuiCompositeWidgets.listenerOf(pluginSourceData) + .ifPresent( + listener -> { + // This listener saves the changed values immediately, so we don't have to worry + // about that. + compositeWidgets.setWidgetsListener(listener); + listener.widgetsPopulated(compositeWidgets); + }); } /** diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/database/config/DatabasePerspectiveConfigPlugin.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/database/config/DatabasePerspectiveConfigPlugin.java index ef7897ad599..06891c67d09 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/database/config/DatabasePerspectiveConfigPlugin.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/database/config/DatabasePerspectiveConfigPlugin.java @@ -33,10 +33,9 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; -import org.eclipse.swt.widgets.Control; import picocli.CommandLine; /** @@ -53,7 +52,7 @@ configClass = DatabasePerspectiveConfig.class) @GuiPlugin(description = "i18n::DatabasePerspectiveConfigPlugin.Name") public class DatabasePerspectiveConfigPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { + implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final Class PKG = DatabasePerspectiveConfigPlugin.class; @@ -167,8 +166,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/PipelineExecutionViewer.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/PipelineExecutionViewer.java index 364c30d82a1..538986f2131 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/PipelineExecutionViewer.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/PipelineExecutionViewer.java @@ -700,8 +700,7 @@ public void paintControl(PaintEvent e) { // Do double buffering to prevent flickering on Windows // - boolean needsDoubleBuffering = - Const.isWindows() && "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + boolean needsDoubleBuffering = Const.isWindows() && Const.isGuiRuntime(); Image image = null; GC swtGc = e.gc; diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/WorkflowExecutionViewer.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/WorkflowExecutionViewer.java index 6a953cbcc4d..f5d1ebfd938 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/WorkflowExecutionViewer.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/WorkflowExecutionViewer.java @@ -561,8 +561,7 @@ public void paintControl(PaintEvent e) { // Do double buffering to prevent flickering on Windows // - boolean needsDoubleBuffering = - Const.isWindows() && "GUI".equalsIgnoreCase(Const.getHopPlatformRuntime()); + boolean needsDoubleBuffering = Const.isWindows() && Const.isGuiRuntime(); Image image = null; GC swtGc = e.gc; diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java index 4f3aa7cde3e..995aac4fd79 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java @@ -32,7 +32,7 @@ import org.apache.hop.metadata.api.IHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.ComboVar; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; @@ -53,7 +53,7 @@ description = "Explorer Perspective" // Tab label in options dialog ) public class ExplorerPerspectiveConfigPlugin - implements IConfigOptions, IGuiPluginCompositeWidgetsListener { + implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_LAZY_LOADING_DEPTH = "10000-lazy-loading-depth"; private static final String WIDGET_ID_FILE_LOADING_MAX_SIZE = "10100-file-loading-max-size"; @@ -242,8 +242,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } @@ -352,7 +351,7 @@ public List getHelpOpenModeLabels( return labels; } - private static String readComboText(Control control) { + private static String readComboText(Object control) { if (control instanceof Combo combo) { return combo.getText(); } diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java b/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java index 470fe947e91..3fcea2e6b15 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java @@ -30,7 +30,7 @@ import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.dialog.ErrorDialog; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.core.widget.TextVar; import org.apache.hop.ui.hopgui.HopGui; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; @@ -49,7 +49,7 @@ @GuiPlugin( description = "Search" // Tab label in options dialog ) -public class SearchConfigPlugin implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class SearchConfigPlugin implements IConfigOptions, IGuiPluginModelWidgetsListener { private static final String WIDGET_ID_MIN_CONTENT_QUERY_LENGTH = "20000-search-min-content-query-length"; @@ -224,8 +224,7 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { persistContents(compositeWidgets); } diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/welcome/WelcomeDialogOptions.java b/ui/src/main/java/org/apache/hop/ui/hopgui/welcome/WelcomeDialogOptions.java index f05432917fd..01a57cf7c1a 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/welcome/WelcomeDialogOptions.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/welcome/WelcomeDialogOptions.java @@ -29,15 +29,14 @@ import org.apache.hop.core.variables.IVariables; import org.apache.hop.metadata.api.IHasHopMetadataProvider; import org.apache.hop.ui.core.gui.GuiCompositeWidgets; -import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.apache.hop.ui.hopgui.perspective.configuration.tabs.ConfigPluginOptionsTab; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Control; import picocli.CommandLine; @ConfigPlugin(id = "WelcomeDialogOption", description = "Enable or disable the welcome dialog") @GuiPlugin(description = "i18n::WelcomeDialog.Description") -public class WelcomeDialogOptions implements IConfigOptions, IGuiPluginCompositeWidgetsListener { +public class WelcomeDialogOptions implements IConfigOptions, IGuiPluginModelWidgetsListener { protected static final Class PKG = WelcomeDialogOptions.class; @CommandLine.Option( @@ -163,9 +162,9 @@ public void widgetsPopulated(GuiCompositeWidgets compositeWidgets) { } @Override - public void widgetModified( - GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { - this.welcomeDialogShowAtStartup = ((Button) changedWidget).getSelection(); + public void widgetModified(GuiCompositeWidgets compositeWidgets, String widgetId) { + this.welcomeDialogShowAtStartup = + ((Button) compositeWidgets.getWidgetsMap().get(widgetId)).getSelection(); persistContents(compositeWidgets); } diff --git a/ui/src/test/java/org/apache/hop/ui/core/dialog/BaseDialogVariablesHeadlessTest.java b/ui/src/test/java/org/apache/hop/ui/core/dialog/BaseDialogVariablesHeadlessTest.java new file mode 100644 index 00000000000..9de2d914090 --- /dev/null +++ b/ui/src/test/java/org/apache/hop/ui/core/dialog/BaseDialogVariablesHeadlessTest.java @@ -0,0 +1,52 @@ +/* + * 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.ui.core.dialog; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.lang.reflect.Field; +import org.apache.hop.core.variables.Variable; +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * The variable registry loads the class that declares a variable in every Hop process, also in runs + * without SWT: the dialog variables must load without it. + */ +class BaseDialogVariablesHeadlessTest { + + @Test + void theDialogVariablesLoadWithoutSwt() throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + Class variables = Class.forName(BaseDialogVariables.class.getName(), true, withoutSwt); + Field field = variables.getDeclaredField("HOP_USE_NATIVE_FILE_DIALOG"); + @SuppressWarnings("unchecked") + Class annotation = + (Class) Class.forName(Variable.class.getName(), true, withoutSwt); + assertNotNull(field.getAnnotation(annotation)); + assertEquals("HOP_USE_NATIVE_FILE_DIALOG", field.get(null)); + } + } + + @Test + void theDialogKeepsTheSameConstant() { + assertEquals( + BaseDialogVariables.HOP_USE_NATIVE_FILE_DIALOG, BaseDialog.HOP_USE_NATIVE_FILE_DIALOG); + } +} diff --git a/ui/src/test/java/org/apache/hop/ui/hopgui/HeadlessReflectionTest.java b/ui/src/test/java/org/apache/hop/ui/hopgui/HeadlessReflectionTest.java new file mode 100644 index 00000000000..50ff5a7f402 --- /dev/null +++ b/ui/src/test/java/org/apache/hop/ui/hopgui/HeadlessReflectionTest.java @@ -0,0 +1,45 @@ +/* + * 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.ui.hopgui; + +import org.apache.hop.ui.hopgui.file.config.FileValidationConfigPlugin; +import org.apache.hop.ui.hopgui.file.pipeline.debug.config.DebugSessionsConfigPlugin; +import org.apache.hop.ui.hopgui.perspective.database.config.DatabasePerspectiveConfigPlugin; +import org.apache.hop.ui.hopgui.perspective.explorer.config.ExplorerPerspectiveConfigPlugin; +import org.apache.hop.ui.hopgui.search.config.SearchConfigPlugin; +import org.apache.hop.ui.hopgui.welcome.WelcomeDialogOptions; +import org.apache.hop.ui.testing.WithoutSwt; +import org.junit.jupiter.api.Test; + +/** + * hop-conf and the hop command line read the configuration options of Hop GUI by reflection, also + * without SWT: no signature may need it. + */ +class HeadlessReflectionTest { + + @Test + void reflectsWithoutSwt() throws Exception { + WithoutSwt.assertReflects( + FileValidationConfigPlugin.class, + DebugSessionsConfigPlugin.class, + DatabasePerspectiveConfigPlugin.class, + ExplorerPerspectiveConfigPlugin.class, + SearchConfigPlugin.class, + WelcomeDialogOptions.class); + } +} diff --git a/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTabTest.java b/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTabTest.java index eafe2fcba78..0ecbb560e86 100644 --- a/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTabTest.java +++ b/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/configuration/tabs/ConfigPluginOptionsTabTest.java @@ -25,6 +25,7 @@ import org.apache.hop.ui.core.gui.GuiCompositeWidgets; import org.apache.hop.ui.core.gui.IGuiPluginCompositeWidgetsListener; +import org.apache.hop.ui.core.gui.IGuiPluginModelWidgetsListener; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -47,6 +48,18 @@ void aListeningPluginIsToldItsWidgetsAreFilled() { order.verify(plugin).widgetsPopulated(widgets); } + /** Plugins without SWT in their signatures listen through IGuiPluginModelWidgetsListener. */ + @Test + void aModelListenerIsToldItsWidgetsAreFilled() { + GuiCompositeWidgets widgets = mock(GuiCompositeWidgets.class); + IGuiPluginModelWidgetsListener plugin = mock(IGuiPluginModelWidgetsListener.class); + + ConfigPluginOptionsTab.attachWidgetsListener(widgets, plugin); + + verify(widgets).setWidgetsListener(any()); + verify(plugin).widgetsPopulated(widgets); + } + @Test void aPluginThatDoesNotListenIsLeftAlone() { GuiCompositeWidgets widgets = mock(GuiCompositeWidgets.class); diff --git a/ui/src/test/java/org/apache/hop/ui/testing/DisabledGuiWidgetsTestBase.java b/ui/src/test/java/org/apache/hop/ui/testing/DisabledGuiWidgetsTestBase.java index 34f25a1f56c..ea5b9248aa7 100644 --- a/ui/src/test/java/org/apache/hop/ui/testing/DisabledGuiWidgetsTestBase.java +++ b/ui/src/test/java/org/apache/hop/ui/testing/DisabledGuiWidgetsTestBase.java @@ -326,7 +326,9 @@ private void buildComposite(String className, String parentId, String disabledWi widgets.createCompositeWidgets(source, null, shell, parentId, null); widgets.setWidgetsContents(source, shell, parentId); - if (listenerFor(source) instanceof IGuiPluginCompositeWidgetsListener listener) { + IGuiPluginCompositeWidgetsListener listener = + GuiCompositeWidgets.listenerOf(listenerFor(source)).orElse(null); + if (listener != null) { widgets.setWidgetsListener(listener); listener.widgetsCreated(widgets); listener.widgetsPopulated(widgets); diff --git a/ui/src/test/java/org/apache/hop/ui/testing/WithoutSwt.java b/ui/src/test/java/org/apache/hop/ui/testing/WithoutSwt.java new file mode 100644 index 00000000000..2cdc80fb3b3 --- /dev/null +++ b/ui/src/test/java/org/apache/hop/ui/testing/WithoutSwt.java @@ -0,0 +1,94 @@ +/* + * 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.ui.testing; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + +/** + * Loads classes the way a Hop process without SWT does (hop-run, hop-server, a Spark executor): the + * test class path, hop-ui included, without SWT and JFace. + */ +public final class WithoutSwt extends URLClassLoader { + + public WithoutSwt() throws Exception { + super(classpath(), ClassLoader.getPlatformClassLoader()); + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + if (name.startsWith("org.eclipse.swt.") || name.startsWith("org.eclipse.jface.")) { + throw new ClassNotFoundException(name); + } + return super.loadClass(name, resolve); + } + + private static URL[] classpath() throws Exception { + List urls = new ArrayList<>(); + for (String entry : System.getProperty("java.class.path").split(File.pathSeparator)) { + urls.add(new File(entry).toURI().toURL()); + } + return urls.toArray(new URL[0]); + } + + /** + * Asserts that each class loads, initializes and reflects without SWT, as Hop's metadata + * serializers and command line options reflect over it: every method, field and constructor of + * the class and its superclasses. One SWT type in a signature is enough to fail that. + */ + public static void assertReflects(Class... classes) throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + for (Class c : classes) { + try { + for (Class k = Class.forName(c.getName(), true, withoutSwt); + k != null && k != Object.class; + k = k.getSuperclass()) { + k.getDeclaredMethods(); + k.getDeclaredFields(); + k.getDeclaredConstructors(); + } + } catch (LinkageError e) { + fail(c.getName() + " can't be used without SWT: " + e, e); + } + } + } + } + + /** Asserts that each class can be created with its no-argument constructor without SWT. */ + public static void assertCreates(Class... classes) throws Exception { + try (WithoutSwt withoutSwt = new WithoutSwt()) { + for (Class c : classes) { + try { + Class.forName(c.getName(), true, withoutSwt).getConstructor().newInstance(); + } catch (java.lang.reflect.InvocationTargetException e) { + if (e.getCause() instanceof LinkageError linkageError) { + fail(c.getName() + " can't be created without SWT: " + linkageError, linkageError); + } + throw e; + } catch (LinkageError e) { + fail(c.getName() + " can't be created without SWT: " + e, e); + } + } + } + } +}