Skip to content

Commit 79f6b73

Browse files
committed
WIP: SQLDEV-2076 Command line connection processing added
1 parent 4d916a6 commit 79f6b73

File tree

14 files changed

+517
-23
lines changed

14 files changed

+517
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.class
33
*.jar
44
classes/
5+
built/
56
.*

sqldeveloper/extension/.classpath

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/built/gen-src"/>
4-
<classpathentry kind="src" path="java/InsertTemplateAction/built/gen-src"/>
5-
<classpathentry kind="src" path="java/InsertTemplateAction/src"/>
6-
<classpathentry kind="src" path="java/ContextMenuAction/built/gen-src"/>
7-
<classpathentry kind="src" path="java/ContextMenuAction/src"/>
8-
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/src"/>
9-
<classpathentry kind="src" path="java/DumpObjectTypesAction/src"/>
10-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
11-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/FXDiagram 0.35.0-SNAPSHOT"/>
12-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/KIELER KLay Layouters v. 2015.02"/>
13-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 19.2"/>
14-
<classpathentry kind="output" path="built/classes"/>
15-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/built/gen-src"/>
4+
<classpathentry kind="src" path="java/ConnectionHelper/built/gen-src"/>
5+
<classpathentry kind="src" path="java/InsertTemplateAction/built/gen-src"/>
6+
<classpathentry kind="src" path="java/InsertTemplateAction/src"/>
7+
<classpathentry kind="src" path="java/ContextMenuAction/built/gen-src"/>
8+
<classpathentry kind="src" path="java/ContextMenuAction/src"/>
9+
<classpathentry kind="src" output="java/DependencyExample/built/classes" path="java/DependencyExample/src"/>
10+
<classpathentry kind="src" path="java/DumpObjectTypesAction/src"/>
11+
<classpathentry kind="src" path="java/ConnectionHelper/src"/>
12+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
13+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/FXDiagram 0.35.0-SNAPSHOT"/>
14+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/KIELER KLay Layouters v. 2015.02"/>
15+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SQLDeveloper 20.1"/>
16+
<classpathentry kind="output" path="built/classes"/>
17+
</classpath>

sqldeveloper/extension/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Depending on requirements, this can be done in either XML or java and deployed b
66

77
### New
88

9-
* [XML Based Favorites Example](xml/favorites)
9+
* [Connection Helper](java/ConnectionHelper) - Accept connection info from the command line (and maybe on a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html))
1010

11+
* Added resource reference for Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
1112

12-
* [Example Update Center](https://github.com/bjeffrie/sqldev-update-center) (external) with pre-built cfu bundles for these examples.
1313

1414
### Contents
1515

@@ -19,8 +19,19 @@ Depending on requirements, this can be done in either XML or java and deployed b
1919
* ["Simple" User Extensions (XML)](xml)
2020

2121

22+
* [XML Based Favorites Example](xml/favorites)
23+
24+
2225
* [Standard Extensions (java)](java)
2326

2427

2528
* [Check For Updates (cfu)](cfu)
26-
29+
30+
31+
### External Resources
32+
Please note these are links to external resources. They are not supplied or supported by Oracle.
33+
34+
* [Example Update Center](https://github.com/bjeffrie/sqldev-update-center) (external) with pre-built cfu bundles for these examples.
35+
36+
* Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
37+

sqldeveloper/extension/java/ConnectionHelper/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ Where:
2222

2323
### TODO
2424
* Preference page _(May need/want preference page as a load trigger hook)_
25-
* CheckBox: Accept connection info on command line [false]
26-
* CheckBox: Persist command line connections [false]
25+
* Labelled sub-panel: Command Line
26+
* CheckBox: Accept connection info on command line [false]
27+
* CheckBox: Persist command line connections [false]
2728
* [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
2829
* Preference page
29-
* NumericSpinner: Listener port [4444]
30-
* CheckBox: Autostart server
31-
* Button: Start now
30+
* Labelled sub-panel: External Connection Server
31+
* NumericSpinner: Listener port [4444]
32+
* CheckBox: Persist external connections [false]
33+
* CheckBox: Autostart server
34+
* Button: Start now
3235
* Simple client test app for [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
3336

3437

38+
[//]: # (https://github.com/PhilippSalvisberg/sqldev)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extension.id=oracle.db.example.sqldeveloper.extension.connectionHelper
2+
extension.name=Connection Helper
3+
extension.descr=Example to accept connection info from the command line (or via a SocketServer?)
4+
extension.version=20.1.0
5+
extension.resources=oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelperResources
6+
7+
extension.lib=external:$oracle.fcp.home$/sqldeveloper/extensions/${extension.id}/lib
8+
osgi.bundle.classpath=.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="windows-1252" ?>
2+
<project name="ConnectionHelper" default="_deploy">
3+
<!-- imports -->
4+
<import file="../../buildtools/ant/build.xml" />
5+
6+
<!-- bundle dependencies -->
7+
<property name="osgi.required.bundles"
8+
value="${osgi.bundle.default.dependencies},${osgi.bundle.sqldev},${osgi.bundle.utils-nodeps},${osgi.bundle.utils},oracle.sqldeveloper.extras" />
9+
10+
<!-- classpath declarations -->
11+
<path id="local.classpath">
12+
<path refid="oracle.sqldeveloper.utils-nodeps"/>
13+
<path refid="oracle.sqldeveloper.utils"/>
14+
<path refid="oracle.sqldeveloper" />
15+
<pathelement location="${sqldev.extensions}/oracle.sqldeveloper.extras.jar" />
16+
</path>
17+
18+
<!-- local targets -->
19+
20+
<!-- target overrides -->
21+
<!-- Build structure from ../../buildtools/ant/build.xml < targets.xml -->
22+
23+
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<extension xmlns="http://jcp.org/jsr/198/extension-manifest"
19+
id="@@extension.id@@" version="@@extension.version@@.@@extension.build@@"
20+
esdk-version="1.0"
21+
rsbundle-class="@@extension.resources@@">
22+
23+
<name>@@extension.name@@</name>
24+
<owner>@@extension.owner@@ @@extension.owner.url@@</owner>
25+
26+
<!--
27+
<feature-category xmlns="http://xmlns.oracle.com/ide/extension" id="example-category">
28+
<name>${CATEGORY_NAME}</name>
29+
<description>${CATEGORY_DESCRIPTION}</description>
30+
</feature-category>
31+
Duplicate category definitions cause a severe error to be logged.
32+
Only way around it from the outside I can think of is an extension just to add
33+
the category and all the others dependent on it.
34+
The pre-defined ones are:
35+
{db-category=Database, ide-category=IDE, db-migrations-category=Database Migrations,
36+
database-category=Database Development, java-se-category=Java SE,
37+
vcs-category=Version Control, xml-category=XML}
38+
and example-category=Examples, if you've installed the XMLPackedExample
39+
Not supplying a category or giving a non-existent one will just show the extension
40+
at the root of the features tree.
41+
-->
42+
<feature id="@@extension.id@@" xmlns="http://xmlns.oracle.com/ide/extension">
43+
<category-id>db-category</category-id>
44+
<name>@@extension.name@@</name>
45+
<description>@@extension.descr@@</description>
46+
<type>
47+
<service can-user-disable="true" reload-if-used="true"/>
48+
</type>
49+
</feature>
50+
<trigger-hooks xmlns="http://xmlns.oracle.com/ide/extension">
51+
<triggers xmlns:c="http://xmlns.oracle.com/ide/customization">
52+
<settings-ui-hook>
53+
<page id="CONNECTION_HELPER_PREFERENCES_PAGE_ID" parent-idref="/preferences">
54+
<label>${CONNECTION_HELPER_PREFERENCES_TITLE}</label>
55+
<traversable-class>oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelperPreferencePanel</traversable-class>
56+
</page>
57+
</settings-ui-hook>
58+
</triggers>
59+
</trigger-hooks>
60+
<hooks>
61+
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
62+
<addins>
63+
<addin>oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelperAddin</addin>
64+
</addins>
65+
</jdeveloper-hook>
66+
</hooks>
67+
68+
</extension>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelperResources
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oracle.db.example.sqldeveloper.extension.connectionHelper;
4+
5+
import java.util.regex.Matcher;
6+
import java.util.regex.Pattern;
7+
8+
import oracle.dbtools.raptor.standalone.connection.ConnectionUtils;
9+
import oracle.ide.Ide;
10+
import oracle.ide.cmd.ExitCommand;
11+
import oracle.ide.cmd.ShutdownHook;
12+
13+
/**
14+
* ConnectionHelper - Where the 'do the work' stuff lives
15+
*
16+
* @author <a href="mailto:brian.jeffries@oracle.com?subject=oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelper">Brian Jeffries</a>
17+
* @since SQL Developer 20.1
18+
*/
19+
public class ConnectionHelper {
20+
21+
private static boolean processedCommandLineArgs;
22+
23+
public static void processCommandLineArgs() {
24+
// if (!processedCommandLineArgs) {
25+
String[] args = Ide.getIdeArgs().getArgs();
26+
for (String arg : args) {
27+
System.out.println(arg);
28+
ConnectionHelper.processPotentialConnectionArgument(arg);
29+
}
30+
processedCommandLineArgs = true;
31+
// }
32+
}
33+
34+
// -system_DB120101=system/dbtools@llg00hon.uk.oracle.com:1521/DB12201
35+
// -sysdba_DB120101=sys/dbtools@llg00hon.uk.oracle.com:1521/DB12201#SYSDBA
36+
// TODO? Look up valid character requirements for each group
37+
// format = -conName=user[/[pw]]@host:port(:sid|/svc)[#role]
38+
// 1 2 4 5 6 8 9 11
39+
private static final String conRegex = "-(.*)=([^\\/]*)(\\/([^@]*))?@([^:]*):([^:]*)(:([a-zA-Z0-9_]*)|\\/([a-zA-Z0-9_]*))(#([a-zA-Z0-9_]*))?"; //$NON-NLS-1$
40+
private static final Pattern conArg = Pattern.compile(conRegex);
41+
public static void processPotentialConnectionArgument(String arg) {
42+
Matcher m = conArg.matcher(arg);
43+
if (m.matches()) {
44+
String connName = m.group(1);
45+
String userName = m.group(2);
46+
String password = m.group(4);
47+
String host = m.group(5);
48+
String port = m.group(6);
49+
String sid = m.group(8);
50+
String service = m.group(9);
51+
String role = m.group(11);
52+
String folder = ConnectionHelperPreferenceModel.getInstance().isPersistCommandLineConnections()
53+
? ConnectionHelperResources.getString(ConnectionHelperResources.PERSISTENT)
54+
: ConnectionHelperResources.getString(ConnectionHelperResources.TRANSIENT);
55+
56+
57+
ConnectionUtils.addConnection(connName, userName, password, sid, host, port, false/*osAuth*/, service, role, folder);
58+
final String fqName = ConnectionUtils.getFqConnectionName(connName);
59+
ConnectionUtils.connect(fqName);
60+
61+
if (!ConnectionHelperPreferenceModel.getInstance().isPersistCommandLineConnections()) {
62+
ExitCommand.addShutdownHook(new ShutdownHook() {
63+
@Override
64+
public boolean canShutdown() {
65+
return true;
66+
}
67+
@Override
68+
public void shutdown() {
69+
ConnectionUtils.closeAndDeleteConnection(fqName);
70+
}
71+
});
72+
}
73+
}
74+
}
75+
76+
// TODO Refactor to handle request from server
77+
public static void processPotentialConnectionRequest(String arg) {
78+
79+
}
80+
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oracle.db.example.sqldeveloper.extension.connectionHelper;
4+
5+
import oracle.dbtools.util.Logger;
6+
import oracle.ide.Addin;
7+
import oracle.ide.Ide;
8+
import oracle.ide.IdeEvent;
9+
import oracle.ide.IdeListener;
10+
11+
/**
12+
* ConnectionHelperAddin
13+
*
14+
* @author <a href="mailto:brian.jeffries@oracle.com?subject=oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelperAddin">Brian Jeffries</a>
15+
* @since SQL Developer 20.1
16+
*/
17+
public class ConnectionHelperAddin implements Addin {
18+
19+
/* (non-Javadoc)
20+
* @see oracle.ide.Addin#initialize()
21+
*/
22+
@Override
23+
public void initialize() {
24+
Logger.info(getClass(), "Initialize"); // TODO REMOVE
25+
addIdeListener(); // Don't do any checking now, need system initialized first.
26+
}
27+
28+
@SuppressWarnings("deprecation")
29+
private void addIdeListener() {
30+
Ide.addIdeListener(new IdeListener() {
31+
32+
@Override
33+
public void mainWindowOpened(IdeEvent e) {
34+
if (ConnectionHelperPreferenceModel.getInstance().isAcceptCommandLineConnections()) {
35+
ConnectionHelper.processCommandLineArgs();
36+
}
37+
}
38+
39+
@Override
40+
public void addinsLoaded(IdeEvent e) {} // No longer fired see IdeEvent.IDE_ADDINS_LOADED
41+
@Override
42+
public void mainWindowClosing(IdeEvent e) {} // Don't care
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)