Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/src/main/java/org/apache/hop/core/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,41 @@ 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());
}
}

// Search annotation in plugins
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) {
LogChannel.GENERAL.logDetailed("Unable to find variable definitions", e);
}
}

/**
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +42,8 @@ public class PipelineBeforeStartLintExtension implements IExtensionPoint<Object>
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +42,8 @@ public class WorkflowBeforeStartLintExtension implements IExtensionPoint<Object>
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading
Loading