diff --git a/plugins/org.jkiss.dbeaver.core.application/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.core.application/META-INF/MANIFEST.MF index 78f3477f38a8250b9cc1e3b8a8c9fbca10cbbeb9..81be43cdae64b0eefece614b284411bab9b46a5f 100644 --- a/plugins/org.jkiss.dbeaver.core.application/META-INF/MANIFEST.MF +++ b/plugins/org.jkiss.dbeaver.core.application/META-INF/MANIFEST.MF @@ -24,4 +24,5 @@ Require-Bundle: org.jkiss.dbeaver.core, org.eclipse.e4.ui.css.core, org.eclipse.e4.ui.css.swt, org.eclipse.e4.ui.workbench.renderers.swt, - org.w3c.css.sac + org.w3c.css.sac, + org.apache.commons.cli diff --git a/plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/DBeaverApplication.java b/plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/DBeaverApplication.java index d85266d4b7b2156eb3a64b9426c72743362f074c..f9d97f2b4eefefbc823688370241bf9594b73f1d 100644 --- a/plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/DBeaverApplication.java +++ b/plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/DBeaverApplication.java @@ -17,6 +17,7 @@ */ package org.jkiss.dbeaver.core.application; +import org.apache.commons.cli.*; import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -28,11 +29,17 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PlatformUI; +import org.jkiss.code.Nullable; import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.core.DBeaverCore; +import org.jkiss.utils.ArrayUtils; import java.io.File; import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; /** * This class controls all aspects of the application's execution @@ -42,9 +49,6 @@ public class DBeaverApplication implements IApplication private static final Log log = Log.getLog(DBeaverApplication.class); public static final String DBEAVER_DEFAULT_DIR = ".dbeaver"; //$NON-NLS-1$ - /* (non-Javadoc) - * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) - */ @Override public Object start(IApplicationContext context) { @@ -53,7 +57,6 @@ public class DBeaverApplication implements IApplication Location instanceLoc = Platform.getInstanceLocation(); String defaultHomePath = getDefaultWorkspaceLocation().getAbsolutePath(); try { - URL defaultHomeURL = new URL( "file", //$NON-NLS-1$ null, @@ -62,6 +65,9 @@ public class DBeaverApplication implements IApplication Shell shell = null; while (keepTrying) { if (!instanceLoc.set(defaultHomeURL, true)) { + if (handleCommandLine(instanceLoc)) { + return IApplication.EXIT_OK; + } // Can't lock specified path if (shell == null) { shell = new Shell(display, SWT.ON_TOP); @@ -125,6 +131,44 @@ public class DBeaverApplication implements IApplication } } + private boolean handleCommandLine(Location instanceLoc) { + CommandLine commandLine = getCommandLine(); + if (commandLine == null) { + return false; + } + String[] files = commandLine.getOptionValues(DBeaverCommandLine.PARAM_FILE); + String[] fileArgs = commandLine.getArgs(); + if (!ArrayUtils.isEmpty(files) || !ArrayUtils.isEmpty(fileArgs)) { + List fileNames = new ArrayList<>(); + if (!ArrayUtils.isEmpty(files)) { + Collections.addAll(fileNames, files); + } + if (!ArrayUtils.isEmpty(fileArgs)) { + Collections.addAll(fileNames, fileArgs); + } + return true; + } + if (commandLine.hasOption(DBeaverCommandLine.PARAM_STOP)) { + return true; + } + if (commandLine.hasOption(DBeaverCommandLine.PARAM_THREAD_DUMP)) { + return true; + } + if (commandLine.hasOption(DBeaverCommandLine.PARAM_HELP)) { + HelpFormatter helpFormatter = new HelpFormatter(); + helpFormatter.setWidth(120); + helpFormatter.setOptionComparator(new Comparator