diff --git a/deploy/scripts/run-server.sh b/deploy/scripts/run-server.sh index 426693ded8..8b67c5ca96 100755 --- a/deploy/scripts/run-server.sh +++ b/deploy/scripts/run-server.sh @@ -36,5 +36,6 @@ exec java ${JAVA_OPTS} \ -jar ${launcherJar} \ -product io.cloudbeaver.product.ce.product \ -web-config conf/cloudbeaver.conf \ + ${CLI_OPTS} \ -nl en \ -registryMultiLanguage diff --git a/deploy/scripts/server-cli.sh b/deploy/scripts/server-cli.sh new file mode 100755 index 0000000000..8738ca3638 --- /dev/null +++ b/deploy/scripts/server-cli.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -Eeo pipefail +CLI_OPTS="$@" +if [[ $# -eq 0 ]] ; + then + CLI_OPTS='-help' +fi +source run-server.sh \ No newline at end of file diff --git a/server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF b/server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF index 7c3231aca5..c1d2fb5624 100644 --- a/server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF +++ b/server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Bundle-ActivationPolicy: lazy Bundle-ClassPath: . Require-Bundle: org.jkiss.dbeaver.data.gis;visibility:=reexport, org.jkiss.dbeaver.model;visibility:=reexport, + org.jkiss.dbeaver.model.cli;visibility:=reexport, org.jkiss.dbeaver.model.sm;visibility:=reexport, org.jkiss.dbeaver.model.event;visibility:=reexport, org.jkiss.dbeaver.model.nio;visibility:=reexport, @@ -29,6 +30,7 @@ Export-Package: io.cloudbeaver, io.cloudbeaver.model, io.cloudbeaver.model.app, io.cloudbeaver.model.config, + io.cloudbeaver.model.cli, io.cloudbeaver.model.events, io.cloudbeaver.model.fs, io.cloudbeaver.model.log, diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseServletApplication.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseServletApplication.java index 308666b074..7e415cc7f6 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseServletApplication.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseServletApplication.java @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.app; +import io.cloudbeaver.model.cli.CloudBeaverInstanceServer; import io.cloudbeaver.model.log.SLF4JLogHandler; import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplicationContext; @@ -27,6 +28,7 @@ import org.jkiss.dbeaver.model.DBFileController; import org.jkiss.dbeaver.model.app.DBPWorkspace; import org.jkiss.dbeaver.model.auth.SMCredentialsProvider; import org.jkiss.dbeaver.model.auth.SMSessionContext; +import org.jkiss.dbeaver.model.cli.ApplicationInstanceController; import org.jkiss.dbeaver.model.data.json.JSONUtils; import org.jkiss.dbeaver.model.impl.app.ApplicationRegistry; import org.jkiss.dbeaver.model.impl.app.BaseApplicationImpl; @@ -57,7 +59,7 @@ public abstract class BaseServletApplication extends BaseApplicationImpl impleme private static final Log log = Log.getLog(BaseServletApplication.class); private String instanceId; - + private CloudBeaverInstanceServer instanceServer; @Override public RMController createResourceController( @NotNull SMCredentialsProvider credentialsProvider, @@ -200,6 +202,11 @@ public abstract class BaseServletApplication extends BaseApplicationImpl impleme public Object start(IApplicationContext context) { initializeApplicationServices(); try { + try { + this.instanceServer = new CloudBeaverInstanceServer(); + } catch (Exception e) { + log.error("Error initializing instance server", e); + } startServer(); } catch (Exception e) { log.error(e.getMessage(), e); @@ -266,4 +273,10 @@ public abstract class BaseServletApplication extends BaseApplicationImpl impleme log.error("Failed close " + name, e); } } + + @Nullable + @Override + public ApplicationInstanceController getInstanceServer() { + return instanceServer; + } } diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverCommandLine.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverCommandLine.java new file mode 100644 index 0000000000..177f711a3a --- /dev/null +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverCommandLine.java @@ -0,0 +1,35 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2025 DBeaver Corp and others + * + * Licensed 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 io.cloudbeaver.model.cli; + +import org.jkiss.dbeaver.model.cli.ApplicationCommandLine; +import org.jkiss.dbeaver.model.cli.ApplicationInstanceController; + +public class CloudBeaverCommandLine extends ApplicationCommandLine { + private static CloudBeaverCommandLine INSTANCE = null; + + private CloudBeaverCommandLine() { + super(); + } + + public synchronized static CloudBeaverCommandLine getInstance() { + if (INSTANCE == null) { + INSTANCE = new CloudBeaverCommandLine(); + } + return INSTANCE; + } +} diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverInstanceServer.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverInstanceServer.java new file mode 100644 index 0000000000..701f591e49 --- /dev/null +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/cli/CloudBeaverInstanceServer.java @@ -0,0 +1,46 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2025 DBeaver Corp and others + * + * Licensed 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 io.cloudbeaver.model.cli; + +import org.apache.commons.cli.CommandLine; +import org.jkiss.code.NotNull; +import org.jkiss.dbeaver.model.cli.ApplicationInstanceController; +import org.jkiss.dbeaver.model.cli.ApplicationInstanceServer; +import org.jkiss.dbeaver.model.cli.CmdProcessResult; + +import java.io.IOException; + +public class CloudBeaverInstanceServer extends ApplicationInstanceServer { + public CloudBeaverInstanceServer() throws IOException { + super(ApplicationInstanceController.class); + } + + @NotNull + @Override + public CmdProcessResult handleCommandLine(@NotNull String[] args) { + CommandLine cmd = CloudBeaverCommandLine.getInstance().getCommandLine(args); + try { + return CloudBeaverCommandLine.getInstance().executeCommandLineCommands( + cmd, + this, + false + ); + } catch (Exception e) { + return new CmdProcessResult(CmdProcessResult.PostAction.ERROR, "Error executing command: " + e.getMessage()); + } + } +}