提交 e2bb0f45 编写于 作者: S serge-rider

#2202 SSH implementations moved to separate plugins


Former-commit-id: afc8b286
上级 2a8ecdc7
......@@ -126,7 +126,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.search,
org.jkiss.dbeaver.model;visibility:=reexport,
org.jkiss.utils;visibility:=reexport,
com.jcraft.jsch,
org.objectweb.asm,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.services,
......
......@@ -7,13 +7,7 @@ Bundle-Version: 1.0.0
Bundle-Release-Date: 20180319
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.jkiss.dbeaver.net.ssh.jsch.Activator
Bundle-ClassPath: .
Require-Bundle: org.eclipse.equinox.security,
org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.core.commands,
org.eclipse.core.resources,
org.jkiss.dbeaver.model;visibility:=reexport,
org.jkiss.utils;visibility:=reexport
Require-Bundle: org.jkiss.dbeaver.model,
com.jcraft.jsch
Bundle-Localization: OSGI-INF/l10n/bundle
Bundle-Vendor = JKISS
Bundle-Name = DBeaver SSH tunnels
extension-point.org.jkiss.dbeaver.net.ssh.name = SSH implementations
Bundle-Name = DBeaver SSH implementation (JSch)
......@@ -3,5 +3,8 @@
<plugin>
<extension point="org.jkiss.dbeaver.net.ssh">
<implementation id="jsch" label="JSch" class="org.jkiss.dbeaver.model.net.ssh.SSHImplementationJsch"/>
</extension>
</plugin>
......@@ -7,13 +7,7 @@ Bundle-Version: 1.0.0
Bundle-Release-Date: 20180319
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.jkiss.dbeaver.net.ssh.sshj.Activator
Bundle-ClassPath: .
Require-Bundle: org.eclipse.equinox.security,
org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.core.commands,
org.eclipse.core.resources,
org.jkiss.dbeaver.model;visibility:=reexport,
org.jkiss.utils;visibility:=reexport
Require-Bundle: org.jkiss.dbeaver.model,
com.hierynomus.sshj
Bundle-Localization: OSGI-INF/l10n/bundle
Bundle-Vendor = JKISS
Bundle-Name = DBeaver SSH tunnels
extension-point.org.jkiss.dbeaver.net.ssh.name = SSH implementations
Bundle-Name = DBeaver SSH implementation (SSHJ)
......@@ -3,5 +3,8 @@
<plugin>
<extension point="org.jkiss.dbeaver.net.ssh">
<implementation id="sshj" label="SSHJ" class="org.jkiss.dbeaver.model.net.ssh.SSHImplementationSshj"/>
</extension>
</plugin>
......@@ -25,7 +25,8 @@ import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.net.ssh.SSHConstants;
import org.jkiss.dbeaver.model.net.ssh.SSHImplType;
import org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor;
import org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationRegistry;
import org.jkiss.dbeaver.ui.IObjectPropertyConfigurator;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TextWithOpen;
......@@ -97,7 +98,7 @@ public class SSHTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBWH
tunnelImplCombo = UIUtils.createLabelCombo(advancedGroup, SSHUIMessages.model_ssh_configurator_label_implementation, SWT.DROP_DOWN | SWT.READ_ONLY);
tunnelImplCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
for (SSHImplType it : SSHImplType.values()) {
for (SSHImplementationDescriptor it : SSHImplementationRegistry.getInstance().getDescriptors()) {
tunnelImplCombo.add(it.getLabel());
}
localPortSpinner = UIUtils.createLabelSpinner(advancedGroup, SSHUIMessages.model_ssh_configurator_label_local_port, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
......@@ -139,10 +140,10 @@ public class SSHTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBWH
if (CommonUtils.isEmpty(implType)) {
tunnelImplCombo.select(0);
} else {
try {
SSHImplType it = SSHImplType.getById(implType);
tunnelImplCombo.setText(it.getLabel());
} catch (IllegalArgumentException e) {
SSHImplementationDescriptor desc = SSHImplementationRegistry.getInstance().getDescriptor(implType);
if (desc != null) {
tunnelImplCombo.setText(desc.getLabel());
} else {
tunnelImplCombo.select(0);
}
}
......@@ -181,7 +182,7 @@ public class SSHTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBWH
configuration.setSavePassword(savePasswordCheckbox.getSelection());
String implLabel = tunnelImplCombo.getText();
for (SSHImplType it : SSHImplType.values()) {
for (SSHImplementationDescriptor it : SSHImplementationRegistry.getInstance().getDescriptors()) {
if (it.getLabel().equals(implLabel)) {
properties.put(SSHConstants.PROP_IMPLEMENTATION, it.getId());
break;
......
......@@ -7,14 +7,15 @@ Bundle-Version: 1.0.0
Bundle-Release-Date: 20180319
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.jkiss.dbeaver.model.net.ssh
Export-Package: org.jkiss.dbeaver.model.net.ssh,
org.jkiss.dbeaver.model.net.ssh.registry
Bundle-ClassPath: .
Require-Bundle: org.eclipse.equinox.security,
org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.core.commands,
org.eclipse.core.resources,
org.jkiss.dbeaver.core,
org.jkiss.dbeaver.model;visibility:=reexport,
com.jcraft.jsch,
com.hierynomus.sshj
com.jcraft.jsch
Bundle-Localization: OSGI-INF/l10n/bundle
......@@ -3,7 +3,7 @@
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.application" name="Applications"/>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.net.ssh" name="Applications"/>
</appInfo>
<documentation>
Application meta info
......@@ -18,26 +18,12 @@
</annotation>
<complexType>
<sequence>
<element ref="service" minOccurs="0" maxOccurs="unbounded"/>
<element ref="implementation" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="service">
<element name="implementation">
<complexType>
<attribute name="class" type="string">
<annotation>
......@@ -45,48 +31,12 @@
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.runtime.IPluginService"/>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.model.net.ssh.SSHImplementation"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -17,11 +17,12 @@
package org.jkiss.dbeaver.model.net.ssh;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.net.DBWTunnel;
import org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor;
import org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationRegistry;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
......@@ -33,7 +34,7 @@ import java.util.Map;
*/
public class SSHTunnelImpl implements DBWTunnel {
private static final Log log = Log.getLog(SSHTunnelImpl.class);
private static final String DEF_IMPLEMENTATION = "jsch";
private SSHImplementation implementation;
......@@ -43,17 +44,17 @@ public class SSHTunnelImpl implements DBWTunnel {
{
Map<String,String> properties = configuration.getProperties();
String implId = properties.get(SSHConstants.PROP_IMPLEMENTATION);
SSHImplType implType = SSHImplType.JSCH;
if (!CommonUtils.isEmpty(implId)) {
try {
implType = SSHImplType.getById(implId);
} catch (IllegalArgumentException e) {
log.error(e);
}
if (CommonUtils.isEmpty(implId)) {
// Backward compatibility
implId = DEF_IMPLEMENTATION;
}
try {
implementation = implType.getImplClass().newInstance();
SSHImplementationDescriptor implDesc = SSHImplementationRegistry.getInstance().getDescriptor(implId);
if (implDesc == null) {
implDesc = SSHImplementationRegistry.getInstance().getDescriptor(DEF_IMPLEMENTATION);
}
implementation = implDesc.getImplClass().createInstance(SSHImplementation.class);
} catch (Throwable e) {
throw new DBException("Can't create SSH tunnel implementation", e);
}
......
......@@ -14,50 +14,52 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.net.ssh;
package org.jkiss.dbeaver.model.net.ssh.registry;
import org.jkiss.code.NotNull;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.net.ssh.SSHImplementation;
import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
/**
* SSH implementation enum
* SSHImplementationDescriptor
*/
public enum SSHImplType {
public class SSHImplementationDescriptor extends AbstractContextDescriptor
{
static final String EXTENSION_ID = "org.jkiss.dbeaver.net.ssh"; //$NON-NLS-1$
JSCH("jsch", "JSch", SSHImplementationJsch.class),
SSHJ("sshj", "SSHJ", SSHImplementationSshj.class);
private final AbstractDescriptor.ObjectType implClass;
private final String id;
private final String label;
private String id;
private String label;
private Class<? extends SSHImplementation> implClass;
SSHImplementationDescriptor(
IConfigurationElement config)
{
super(config);
SSHImplType(@NotNull String id, @NotNull String label, @NotNull Class<? extends SSHImplementation> implClass) {
this.id = id;
this.label = label;
this.implClass = implClass;
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
this.label = config.getAttribute(RegistryConstants.ATTR_LABEL);
this.implClass = new AbstractDescriptor.ObjectType(config.getAttribute(RegistryConstants.ATTR_CLASS));
}
public ObjectType getImplClass() {
return implClass;
}
@NotNull
public String getId() {
return id;
}
@NotNull
public String getLabel() {
return label;
}
@NotNull
public Class<? extends SSHImplementation> getImplClass() {
return implClass;
public SSHImplementation createImplementation()
throws DBException
{
return implClass.createInstance(SSHImplementation.class);
}
@NotNull
public static SSHImplType getById(String id) throws IllegalArgumentException {
for (SSHImplType it : values()) {
if (it.getId().equals(id)) {
return it;
}
}
throw new IllegalArgumentException("Bad SSH impl: " + id);
}
}
\ No newline at end of file
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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 org.jkiss.dbeaver.model.net.ssh.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import java.util.ArrayList;
import java.util.List;
public class SSHImplementationRegistry
{
private static SSHImplementationRegistry instance = null;
public synchronized static SSHImplementationRegistry getInstance()
{
if (instance == null) {
instance = new SSHImplementationRegistry(Platform.getExtensionRegistry());
}
return instance;
}
private final List<SSHImplementationDescriptor> descriptors = new ArrayList<>();
private SSHImplementationRegistry(IExtensionRegistry registry)
{
// Load data descriptors from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(SSHImplementationDescriptor.EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
SSHImplementationDescriptor descriptor = new SSHImplementationDescriptor(ext);
descriptors.add(descriptor);
}
}
}
public List<SSHImplementationDescriptor> getDescriptors() {
return descriptors;
}
public SSHImplementationDescriptor getDescriptor(String id) {
for (SSHImplementationDescriptor desc : descriptors) {
if (desc.getId().equals(id)) {
return desc;
}
}
return null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册