提交 153cde55 编写于 作者: J jurgen

Maven dependencies model

Former-commit-id: d8db2561
上级 68e0dfb7
......@@ -18,7 +18,7 @@
package org.jkiss.dbeaver.registry;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.utils.CommonUtils;
import java.io.File;
......@@ -43,8 +43,8 @@ public class DriverClassLoader extends URLClassLoader
protected String findLibrary(String libname)
{
String nativeName = System.mapLibraryName(libname);
for (DriverFileDescriptor driverFile : driver.getDriverFiles()) {
if (driverFile.getType() == DBPDriverFile.FileType.lib && driverFile.matchesCurrentPlatform()) {
for (DriverLibraryDescriptor driverFile : driver.getDriverLibraries()) {
if (driverFile.getType() == DBPDriverLibrary.FileType.lib && driverFile.matchesCurrentPlatform()) {
final File localFile = driverFile.getLocalFile();
if (localFile != null && localFile.exists()) {
final String fileName = localFile.getName();
......
......@@ -102,8 +102,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
private boolean disabled;
private final List<String> clientHomeIds = new ArrayList<String>();
private final List<DriverFileSource> fileSources = new ArrayList<DriverFileSource>();
private final List<DriverFileDescriptor> files = new ArrayList<DriverFileDescriptor>();
private final List<DriverFileDescriptor> origFiles = new ArrayList<DriverFileDescriptor>();
private final List<DriverLibraryDescriptor> files = new ArrayList<DriverLibraryDescriptor>();
private final List<DriverLibraryDescriptor> origFiles = new ArrayList<DriverLibraryDescriptor>();
private final List<DriverPathDescriptor> pathList = new ArrayList<DriverPathDescriptor>();
private final List<DBPPropertyDescriptor> connectionPropertyDescriptors = new ArrayList<DBPPropertyDescriptor>();
private final List<OSDescriptor> supportedSystems = new ArrayList<OSDescriptor>();
......@@ -170,7 +170,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.isLoaded = false;
for (IConfigurationElement lib : config.getChildren(RegistryConstants.TAG_FILE)) {
this.files.add(new DriverFileDescriptor(this, lib));
this.files.add(new DriverLibraryDescriptor(this, lib));
}
this.origFiles.addAll(this.files);
......@@ -430,7 +430,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
private boolean hasValidLibraries()
{
for (DriverFileDescriptor lib : files) {
for (DriverLibraryDescriptor lib : files) {
File file = lib.getLocalFile();
if (file != null && file.exists()) {
return true;
......@@ -635,14 +635,14 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@NotNull
@Override
public Collection<DriverFileDescriptor> getDriverFiles()
public Collection<DriverLibraryDescriptor> getDriverLibraries()
{
return files;
}
public DriverFileDescriptor getDriverFile(String path)
public DriverLibraryDescriptor getDriverFile(String path)
{
for (DriverFileDescriptor lib : files) {
for (DriverLibraryDescriptor lib : files) {
if (lib.getPath().equals(path)) {
return lib;
}
......@@ -650,19 +650,19 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return null;
}
public DriverFileDescriptor addDriverFile(String path, DBPDriverFile.FileType fileType)
public DriverLibraryDescriptor addDriverFile(String path, DBPDriverLibrary.FileType fileType)
{
for (DriverFileDescriptor lib : files) {
for (DriverLibraryDescriptor lib : files) {
if (lib.getPath().equals(path)) {
return lib;
}
}
DriverFileDescriptor lib = new DriverFileDescriptor(this, fileType, path);
DriverLibraryDescriptor lib = new DriverLibraryDescriptor(this, fileType, path);
addDriverFile(lib);
return lib;
}
public boolean addDriverFile(DriverFileDescriptor descriptor)
public boolean addDriverFile(DriverLibraryDescriptor descriptor)
{
resetDriverInstance();
if (!files.contains(descriptor)) {
......@@ -672,7 +672,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return false;
}
public boolean removeDriverFile(DriverFileDescriptor lib)
public boolean removeDriverFile(DriverLibraryDescriptor lib)
{
resetDriverInstance();
if (!lib.isCustom()) {
......@@ -798,8 +798,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
public String getLicense()
{
for (DriverFileDescriptor file : files) {
if (file.getType() == DBPDriverFile.FileType.license) {
for (DriverLibraryDescriptor file : files) {
if (file.getType() == DBPDriverLibrary.FileType.license) {
final File licenseFile = file.getLocalFile();
if (licenseFile != null && licenseFile.exists()) {
try {
......@@ -875,8 +875,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
List<URL> libraryURLs = new ArrayList<URL>();
// Load libraries
for (DriverFileDescriptor file : files) {
if (file.isDisabled() || file.getType() != DBPDriverFile.FileType.jar) {
for (DriverLibraryDescriptor file : files) {
if (file.isDisabled() || file.getType() != DBPDriverLibrary.FileType.jar) {
continue;
}
File localFile = file.getLocalFile();
......@@ -902,7 +902,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@Override
public void validateFilesPresence(final DBRRunnableContext runnableContext)
{
for (DriverFileDescriptor file : files) {
for (DriverLibraryDescriptor file : files) {
if (file.isCustom()) {
File localFile = file.getLocalFile();
if (localFile != null && localFile.exists()) {
......@@ -912,8 +912,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
final List<DriverFileDescriptor> downloadCandidates = new ArrayList<DriverFileDescriptor>();
for (DriverFileDescriptor file : files) {
final List<DriverLibraryDescriptor> downloadCandidates = new ArrayList<DriverLibraryDescriptor>();
for (DriverLibraryDescriptor file : files) {
if (file.isDisabled() || !file.isDownloadable()) {
// Nothing we can do about it
continue;
......@@ -938,16 +938,11 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
@Override
public void updateFiles(DBRRunnableContext runnableContext) {
}
public boolean acceptDriverLicenses(DBRRunnableContext runnableContext)
{
// User must accept all licenses before actual drivers download
for (final DriverFileDescriptor file : getDriverFiles()) {
if (file.getType() == DBPDriverFile.FileType.license) {
for (final DriverLibraryDescriptor file : getDriverLibraries()) {
if (file.getType() == DBPDriverLibrary.FileType.license) {
final File libraryFile = file.getLocalFile();
if (libraryFile == null || !libraryFile.exists()) {
try {
......@@ -1019,7 +1014,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return origSampleURL;
}
public List<DriverFileDescriptor> getOrigFiles()
public List<DriverLibraryDescriptor> getOrigFiles()
{
return origFiles;
}
......@@ -1059,7 +1054,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
// Libraries
for (DriverFileDescriptor lib : this.getDriverFiles()) {
for (DriverLibraryDescriptor lib : this.getDriverLibraries()) {
if ((export && !lib.isDisabled()) || lib.isCustom() || lib.isDisabled()) {
xml.startElement(RegistryConstants.TAG_LIBRARY);
xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
......@@ -1231,20 +1226,20 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
log.warn("File outside of driver");
return;
}
DBPDriverFile.FileType type;
DBPDriverLibrary.FileType type;
String typeStr = atts.getValue(RegistryConstants.ATTR_TYPE);
if (CommonUtils.isEmpty(typeStr)) {
type = DBPDriverFile.FileType.jar;
type = DBPDriverLibrary.FileType.jar;
} else {
try {
type = DBPDriverFile.FileType.valueOf(typeStr);
type = DBPDriverLibrary.FileType.valueOf(typeStr);
} catch (IllegalArgumentException e) {
log.warn(e);
type = DBPDriverFile.FileType.jar;
type = DBPDriverLibrary.FileType.jar;
}
}
String path = atts.getValue(RegistryConstants.ATTR_PATH);
DriverFileDescriptor lib = curDriver.getDriverFile(path);
DriverLibraryDescriptor lib = curDriver.getDriverFile(path);
String disabledAttr = atts.getValue(RegistryConstants.ATTR_DISABLED);
if (lib != null && CommonUtils.getBoolean(disabledAttr)) {
lib.setDisabled(true);
......
......@@ -19,7 +19,6 @@ package org.jkiss.dbeaver.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
......@@ -28,7 +27,7 @@ import java.util.List;
/**
* DriverFileSource
*/
public class DriverFileSource implements DBPDriverFile.FileSource
public class DriverFileSource
{
static final Log log = Log.getLog(DriverFileSource.class);
......
......@@ -23,7 +23,7 @@ import org.eclipse.core.runtime.Platform;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
......@@ -38,17 +38,19 @@ import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.text.NumberFormat;
import java.util.Collection;
/**
* DriverFileDescriptor
* DriverLibraryDescriptor
*/
public class DriverFileDescriptor implements DBPDriverFile
public class DriverLibraryDescriptor implements DBPDriverLibrary
{
static final Log log = Log.getLog(DriverFileDescriptor.class);
static final Log log = Log.getLog(DriverLibraryDescriptor.class);
public static final String FILE_SOURCE_MAVEN = "maven:/";
public static final String FILE_SOURCE_REPO = "repo:/";
public static final String FILE_SOURCE_PLATFORM = "platform:/";
public static final String FILE_SOURCE_LOCAL = "file:/";
private final DriverDescriptor driver;
private final FileType type;
......@@ -59,7 +61,7 @@ public class DriverFileDescriptor implements DBPDriverFile
private boolean custom;
private boolean disabled;
public DriverFileDescriptor(DriverDescriptor driver, FileType type, String path)
public DriverLibraryDescriptor(DriverDescriptor driver, FileType type, String path)
{
this.driver = driver;
this.type = type;
......@@ -68,7 +70,7 @@ public class DriverFileDescriptor implements DBPDriverFile
this.custom = true;
}
DriverFileDescriptor(DriverDescriptor driver, IConfigurationElement config)
DriverLibraryDescriptor(DriverDescriptor driver, IConfigurationElement config)
{
this.driver = driver;
this.type = FileType.valueOf(config.getAttribute(RegistryConstants.ATTR_TYPE));
......@@ -94,23 +96,12 @@ public class DriverFileDescriptor implements DBPDriverFile
return type;
}
@Override
public OSDescriptor getSystem()
{
return system;
}
@Override
public String getPath()
{
return path;
}
@Override
public String getFileType() {
return null;
}
@Override
public String getDescription()
{
......@@ -145,7 +136,7 @@ public class DriverFileDescriptor implements DBPDriverFile
return isRepositoryArtifact() || isMavenArtifact();
}
public boolean isRepositoryArtifact() {
private boolean isRepositoryArtifact() {
return path.startsWith(FILE_SOURCE_REPO);
}
......@@ -289,6 +280,12 @@ public class DriverFileDescriptor implements DBPDriverFile
return system == null || system.matches(DBeaverCore.getInstance().getLocalSystem());
}
@Nullable
@Override
public Collection<DBPDriverLibrary> getDependencies() {
return null;
}
/*
private String getMavenArtifactFileName() {
String artifactName = path.substring(FILE_SOURCE_MAVEN.length());
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
/**
* Maven artifact license references
*/
public class MavenArtifactDependency
{
private MavenArtifactReference artifactReference;
private String type;
private boolean optional;
public MavenArtifactDependency(MavenArtifactReference artifactReference, String type, boolean optional) {
this.artifactReference = artifactReference;
this.type = type;
this.optional = optional;
}
public MavenArtifactReference getArtifactReference() {
return artifactReference;
}
public String getType() {
return type;
}
public boolean isOptional() {
return optional;
}
@Override
public String toString() {
return artifactReference.toString() + ";type=" + type + "; optional=" + optional;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
/**
* Maven artifact license references
*/
public class MavenArtifactLicense
{
private String name;
private String url;
public MavenArtifactLicense(String name, String url) {
this.name = name;
this.url = url;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
@Override
public String toString() {
return name;
}
}
......@@ -26,7 +26,9 @@ import org.xml.sax.Attributes;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Maven artifact version descriptor (POM).
......@@ -40,8 +42,8 @@ public class MavenArtifactVersion
private String version;
private String description;
private String url;
private List<String> licenses;
private List<MavenArtifactReference> dependencies;
private List<MavenArtifactLicense> licenses;
private List<MavenArtifactDependency> dependencies;
MavenArtifactVersion(MavenLocalVersion localVersion) throws IOException {
this.localVersion = localVersion;
......@@ -73,29 +75,52 @@ public class MavenArtifactVersion
return url;
}
public List<String> getLicenses() {
public List<MavenArtifactLicense> getLicenses() {
return licenses;
}
public List<MavenArtifactReference> getDependencies() {
public List<MavenArtifactDependency> getDependencies() {
return dependencies;
}
@Override
public String toString() {
return localVersion.toString();
}
private enum ParserState {
ROOT,
LICENSE,
DEPENDENCIES,
DEPENDENCY
}
private void loadPOM() throws IOException {
String pomURL = localVersion.getArtifact().getFileURL(localVersion.getVersion(), MavenArtifact.FILE_POM);
InputStream mdStream = RuntimeUtils.openConnectionStream(pomURL);
try {
SAXReader reader = new SAXReader(mdStream);
reader.parse(new SAXListener() {
private boolean inRoot = true;
private ParserState state = ParserState.ROOT;
private String lastTag;
private Map<String, String> attributes = new HashMap<String, String>();
@Override
public void saxStartElement(SAXReader reader, String namespaceURI, String localName, Attributes atts) throws XMLException {
lastTag = localName;
if ("license".equals(localName)) {
state = ParserState.LICENSE;
} else if ("dependencies".equals(localName)) {
state = ParserState.DEPENDENCIES;
} else if ("dependency".equals(localName) && state == ParserState.DEPENDENCIES) {
state = ParserState.DEPENDENCY;
}
}
@Override
public void saxText(SAXReader reader, String data) throws XMLException {
if (inRoot) {
switch (state) {
case ROOT:
if ("name".equals(lastTag)) {
name = data;
} else if ("version".equals(lastTag)) {
......@@ -105,12 +130,40 @@ public class MavenArtifactVersion
} else if ("url".equals(lastTag)) {
url = data;
}
break;
case LICENSE:
case DEPENDENCY:
attributes.put(lastTag, data);
break;
}
}
@Override
public void saxEndElement(SAXReader reader, String namespaceURI, String localName) throws XMLException {
lastTag = null;
if ("license".equals(localName) && state == ParserState.LICENSE) {
state = ParserState.ROOT;
licenses.add(new MavenArtifactLicense(
attributes.get("name"),
attributes.get("url")
));
attributes.clear();
} else if ("dependencies".equals(localName) && state == ParserState.DEPENDENCIES) {
state = ParserState.ROOT;
dependencies.add(new MavenArtifactDependency(
new MavenArtifactReference(
attributes.get("groupId"),
attributes.get("artifactId"),
attributes.get("version")
),
attributes.get("type"),
Boolean.valueOf(attributes.get("optional"))
));
attributes.clear();
} else if ("dependency".equals(localName) && state == ParserState.DEPENDENCY) {
state = ParserState.DEPENDENCIES;
attributes.clear();
}
}
});
} catch (XMLException e) {
......@@ -120,9 +173,4 @@ public class MavenArtifactVersion
}
}
@Override
public String toString() {
return localVersion.toString();
}
}
......@@ -34,7 +34,6 @@ import java.util.Date;
public class MavenLocalVersion
{
static final Log log = Log.getLog(MavenLocalVersion.class);
private static final java.lang.String FILE_PROTOCOL = "file:/";
private MavenArtifact artifact;
private String version;
......
......@@ -182,7 +182,7 @@ public class ProjectExportWizard extends Wizard implements IExportWizard {
Set<File> libFiles = new HashSet<File>();
Map<String, File> libPathMap = new HashMap<String, File>();
for (DriverDescriptor driver : exportData.usedDrivers) {
for (DriverFileDescriptor fileDescriptor : driver.getDriverFiles()) {
for (DriverLibraryDescriptor fileDescriptor : driver.getDriverLibraries()) {
final File libraryFile = fileDescriptor.getLocalFile();
if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
libFiles.add(libraryFile);
......
......@@ -29,7 +29,7 @@ import org.eclipse.ui.IWorkbench;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.registry.*;
......@@ -270,7 +270,7 @@ public class ProjectImportWizard extends Wizard implements IImportWizard {
}
// Add libraries (only for managable drivers with empty library list)
if (CommonUtils.isEmpty(driver.getDriverFiles())) {
if (CommonUtils.isEmpty(driver.getDriverLibraries())) {
List<String> libraryList = new ArrayList<String>();
for (Element libElement : XMLUtils.getChildElementList(driverElement, RegistryConstants.TAG_FILE)) {
libraryList.add(libElement.getAttribute(RegistryConstants.ATTR_PATH));
......@@ -280,7 +280,7 @@ public class ProjectImportWizard extends Wizard implements IImportWizard {
File libFile = new File(libPath);
if (libFile.exists()) {
// Just use path as-is (may be it is local re-import or local environments equal to export environment)
driver.addDriverFile(libPath, DBPDriverFile.FileType.jar);
driver.addDriverFile(libPath, DBPDriverLibrary.FileType.jar);
} else {
// Get driver library from archive
String archiveLibEntry = libMap.get(libPath);
......@@ -312,7 +312,7 @@ public class ProjectImportWizard extends Wizard implements IImportWizard {
while (relativePath.charAt(0) == '/' || relativePath.charAt(0) == '\\') {
relativePath = relativePath.substring(1);
}
driver.addDriverFile(relativePath, DBPDriverFile.FileType.jar);
driver.addDriverFile(relativePath, DBPDriverLibrary.FileType.jar);
}
}
}
......
......@@ -21,24 +21,17 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.dbeaver.registry.DriverFileDescriptor;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.runtime.RunnableContextDelegate;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.preferences.PrefPageDrivers;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
......@@ -75,7 +68,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
filesTable.setHeaderVisible(true);
filesTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createTableColumn(filesTable, SWT.LEFT, "File");
for (DriverFileDescriptor file : wizard.getFiles()) {
for (DriverLibraryDescriptor file : wizard.getFiles()) {
new TableItem(filesTable, SWT.NONE).setText(file.getDisplayName());
}
UIUtils.packColumns(filesTable, true);
......@@ -97,14 +90,14 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
downloadLibraryFiles(new RunnableContextDelegate(getContainer()), getWizard().getFiles());
}
private void downloadLibraryFiles(DBRRunnableContext runnableContext, final List<DriverFileDescriptor> files)
private void downloadLibraryFiles(DBRRunnableContext runnableContext, final List<DriverLibraryDescriptor> files)
{
if (!getWizard().getDriver().acceptDriverLicenses(runnableContext)) {
return;
}
for (int i = 0, filesSize = files.size(); i < filesSize; ) {
DriverFileDescriptor lib = files.get(i);
DriverLibraryDescriptor lib = files.get(i);
int result = downloadLibraryFile(runnableContext, lib);
switch (result) {
case IDialogConstants.CANCEL_ID:
......@@ -120,7 +113,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
}
}
private int downloadLibraryFile(DBRRunnableContext runnableContext, final DriverFileDescriptor file)
private int downloadLibraryFile(DBRRunnableContext runnableContext, final DriverLibraryDescriptor file)
{
try {
runnableContext.run(true, true, new DBRRunnableWithProgress() {
......@@ -138,7 +131,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
// User just canceled download
return IDialogConstants.CANCEL_ID;
} catch (InvocationTargetException e) {
if (file.getType() == DBPDriverFile.FileType.license) {
if (file.getType() == DBPDriverLibrary.FileType.license) {
return IDialogConstants.OK_ID;
}
DownloadRetry retryConfirm = new DownloadRetry(file, e.getTargetException());
......@@ -148,11 +141,11 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
}
private class DownloadRetry implements Runnable {
private final DriverFileDescriptor file;
private final DriverLibraryDescriptor file;
private final Throwable error;
private int result;
public DownloadRetry(DriverFileDescriptor file, Throwable error)
public DownloadRetry(DriverLibraryDescriptor file, Throwable error)
{
this.file = file;
this.error = error;
......
......@@ -25,7 +25,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.dbeaver.registry.DriverFileDescriptor;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -41,7 +41,7 @@ public class DriverDownloadDialog extends WizardDialog
private boolean doDownload = false;
DriverDownloadDialog(Shell shell, DriverDescriptor driver, List<DriverFileDescriptor> files, boolean updateVersion, boolean forceDownload)
DriverDownloadDialog(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean updateVersion, boolean forceDownload)
{
super(shell, new DriverDownloadWizard(driver, files, updateVersion, forceDownload));
getWizard().init(DBeaverUI.getActiveWorkbenchWindow().getWorkbench(), null);
......@@ -110,18 +110,18 @@ public class DriverDownloadDialog extends WizardDialog
super.finishPressed();
}
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverFileDescriptor> files) {
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files) {
return downloadDriverFiles(shell, driver, files, false);
}
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverFileDescriptor> files, boolean forceDownload) {
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean forceDownload) {
DriverDownloadDialog dialog = new DriverDownloadDialog(shell, driver, files, false, forceDownload);
dialog.setMinimumPageSize(100, 100);
dialog.open();
return dialog.doDownload;
}
public static boolean updateDriverFiles(Shell shell, DriverDescriptor driver, List<DriverFileDescriptor> files, boolean forceDownload) {
public static boolean updateDriverFiles(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean forceDownload) {
DriverDownloadDialog dialog = new DriverDownloadDialog(shell, driver, files, true, forceDownload);
dialog.setMinimumPageSize(100, 100);
dialog.open();
......
......@@ -24,7 +24,7 @@ import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.dbeaver.registry.DriverFileDescriptor;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.CommonUtils;
......@@ -35,12 +35,12 @@ public class DriverDownloadWizard extends Wizard implements IExportWizard {
private static final String DRIVER_DOWNLOAD_DIALOG_SETTINGS = "DriverDownload";//$NON-NLS-1$
private DriverDescriptor driver;
private List<DriverFileDescriptor> files;
private List<DriverLibraryDescriptor> files;
private boolean updateVersion;
private boolean forceDownload;
private DriverDownloadPage downloadPage;
public DriverDownloadWizard(@NotNull DriverDescriptor driver, List<DriverFileDescriptor> files, boolean updateVersion, boolean forceDownload) {
public DriverDownloadWizard(@NotNull DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean updateVersion, boolean forceDownload) {
this.driver = driver;
this.files = files;
this.updateVersion = updateVersion;
......@@ -54,7 +54,7 @@ public class DriverDownloadWizard extends Wizard implements IExportWizard {
return driver;
}
List<DriverFileDescriptor> getFiles() {
List<DriverLibraryDescriptor> getFiles() {
return files;
}
......
......@@ -41,7 +41,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.registry.*;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom;
......@@ -102,7 +102,7 @@ public class DriverEditDialog extends HelpEnabledDialog
private Text driverPortText;
private PropertyTreeViewer parametersEditor;
private ConnectionPropertiesControl connectionPropertiesEditor;
private List<DriverFileDescriptor> libList = new ArrayList<DriverFileDescriptor>();
private List<DriverLibraryDescriptor> libList = new ArrayList<DriverLibraryDescriptor>();
private PropertySourceCustom driverPropertySource;
private PropertySourceCustom connectionPropertySource;
private ClientHomesPanel clientHomesPanel;
......@@ -326,7 +326,7 @@ public class DriverEditDialog extends HelpEnabledDialog
@Override
public void update(ViewerCell cell)
{
DriverFileDescriptor lib = (DriverFileDescriptor) cell.getElement();
DriverLibraryDescriptor lib = (DriverLibraryDescriptor) cell.getElement();
cell.setText(lib.getDisplayName());
File localFile = lib.getLocalFile();
if (localFile != null && localFile.exists()) {
......@@ -431,9 +431,9 @@ public class DriverEditDialog extends HelpEnabledDialog
File folderFile = new File(curFolder);
for (String fileName : fileNames) {
libList.add(
new DriverFileDescriptor(
new DriverLibraryDescriptor(
driver,
fileName.endsWith(".jar") || fileName.endsWith(".zip") ? DBPDriverFile.FileType.jar : DBPDriverFile.FileType.lib,
fileName.endsWith(".jar") || fileName.endsWith(".zip") ? DBPDriverLibrary.FileType.jar : DBPDriverLibrary.FileType.lib,
new File(folderFile, fileName).getAbsolutePath()));
}
changeLibContent();
......@@ -452,9 +452,9 @@ public class DriverEditDialog extends HelpEnabledDialog
String selected = fd.open();
if (selected != null) {
curFolder = fd.getFilterPath();
libList.add(new DriverFileDescriptor(
libList.add(new DriverLibraryDescriptor(
driver,
DBPDriverFile.FileType.jar,
DBPDriverLibrary.FileType.jar,
selected));
changeLibContent();
}
......@@ -467,10 +467,10 @@ public class DriverEditDialog extends HelpEnabledDialog
{
EditMavenArtifactDialog fd = new EditMavenArtifactDialog(getShell(), null);
if (fd.open() == IDialogConstants.OK_ID) {
libList.add(new DriverFileDescriptor(
libList.add(new DriverLibraryDescriptor(
driver,
DBPDriverFile.FileType.jar,
DriverFileDescriptor.FILE_SOURCE_MAVEN + fd.getArtifact().getPath()));
DBPDriverLibrary.FileType.jar,
DriverLibraryDescriptor.FILE_SOURCE_MAVEN + fd.getArtifact().getPath()));
changeLibContent();
}
}
......@@ -498,7 +498,7 @@ public class DriverEditDialog extends HelpEnabledDialog
@Override
public void widgetSelected(SelectionEvent e)
{
DriverFileDescriptor selectedLib = getSelectedLibrary();
DriverLibraryDescriptor selectedLib = getSelectedLibrary();
int selIndex = libList.indexOf(selectedLib);
Collections.swap(libList, selIndex, selIndex - 1);
changeLibContent();
......@@ -511,7 +511,7 @@ public class DriverEditDialog extends HelpEnabledDialog
@Override
public void widgetSelected(SelectionEvent e)
{
DriverFileDescriptor selectedLib = getSelectedLibrary();
DriverLibraryDescriptor selectedLib = getSelectedLibrary();
int selIndex = libList.indexOf(selectedLib);
Collections.swap(libList, selIndex, selIndex + 1);
changeLibContent();
......@@ -615,10 +615,10 @@ public class DriverEditDialog extends HelpEnabledDialog
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
private DriverFileDescriptor getSelectedLibrary()
private DriverLibraryDescriptor getSelectedLibrary()
{
IStructuredSelection selection = (IStructuredSelection) libTable.getSelection();
return selection == null || selection.isEmpty() ? null : (DriverFileDescriptor) selection.getFirstElement();
return selection == null || selection.isEmpty() ? null : (DriverLibraryDescriptor) selection.getFirstElement();
}
private void changeLibContent()
......@@ -630,7 +630,7 @@ public class DriverEditDialog extends HelpEnabledDialog
private void changeLibSelection()
{
DriverFileDescriptor selectedLib = getSelectedLibrary();
DriverLibraryDescriptor selectedLib = getSelectedLibrary();
deleteButton.setEnabled(selectedLib != null);
upButton.setEnabled(libList.indexOf(selectedLib) > 0);
downButton.setEnabled(libList.indexOf(selectedLib) < libList.size() - 1);
......@@ -662,9 +662,9 @@ public class DriverEditDialog extends HelpEnabledDialog
// anonymousCheck.setSelection(driver.isAnonymousAccess());
if (libTable != null) {
libList = new ArrayList<DriverFileDescriptor>();
for (DriverFileDescriptor lib : driver.getDriverFiles()) {
if (lib.isDisabled() || (lib.getType() != DBPDriverFile.FileType.jar && lib.getType() != DBPDriverFile.FileType.lib) || !lib.matchesCurrentPlatform()) {
libList = new ArrayList<DriverLibraryDescriptor>();
for (DriverLibraryDescriptor lib : driver.getDriverLibraries()) {
if (lib.isDisabled() || (lib.getType() != DBPDriverLibrary.FileType.jar && lib.getType() != DBPDriverLibrary.FileType.lib) || !lib.matchesCurrentPlatform()) {
continue;
}
libList.add(lib);
......@@ -706,10 +706,10 @@ public class DriverEditDialog extends HelpEnabledDialog
driver.setModified(true);
// Set libraries
for (DriverFileDescriptor lib : CommonUtils.safeCollection(libList)) {
for (DriverLibraryDescriptor lib : CommonUtils.safeCollection(libList)) {
driver.addDriverFile(lib);
}
for (DriverFileDescriptor lib : CommonUtils.copyList(driver.getDriverFiles())) {
for (DriverLibraryDescriptor lib : CommonUtils.copyList(driver.getDriverLibraries())) {
if (!libList.contains(lib)) {
driver.removeDriverFile(lib);
}
......@@ -781,9 +781,9 @@ public class DriverEditDialog extends HelpEnabledDialog
{
java.util.List<File> libFiles = new ArrayList<File>();
java.util.List<URL> libURLs = new ArrayList<URL>();
for (DriverFileDescriptor lib : libList) {
for (DriverLibraryDescriptor lib : libList) {
File libFile = lib.getLocalFile();
if (libFile != null && libFile.exists() && !libFile.isDirectory() && lib.getType() == DBPDriverFile.FileType.jar) {
if (libFile != null && libFile.exists() && !libFile.isDirectory() && lib.getType() == DBPDriverLibrary.FileType.jar) {
libFiles.add(libFile);
try {
libURLs.add(libFile.toURI().toURL());
......
......@@ -25,7 +25,7 @@ import org.eclipse.ui.IWorkbench;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.registry.*;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.SelectObjectDialog;
......@@ -122,7 +122,7 @@ public abstract class ConfigImportWizard extends Wizard implements IImportWizard
driver.setDescription(driverInfo.getDescription());
driver.setDriverDefaultPort(driverInfo.getDefaultPort());
for (String path : driverInfo.getLibraries()) {
driver.addDriverFile(path, DBPDriverFile.FileType.jar);
driver.addDriverFile(path, DBPDriverLibrary.FileType.jar);
}
driver.setModified(true);
genericProvider.addDriver(driver);
......
......@@ -79,8 +79,8 @@ public class WMIDataSourceProvider implements DBPDataSourceProvider {
private void loadNativeLib(DBPDriver driver) throws DBException
{
for (DBPDriverFile libFile : driver.getDriverFiles()) {
if (libFile.matchesCurrentPlatform() && libFile.getType() == DBPDriverFile.FileType.lib) {
for (DBPDriverLibrary libFile : driver.getDriverLibraries()) {
if (libFile.matchesCurrentPlatform() && libFile.getType() == DBPDriverLibrary.FileType.lib) {
File localFile = libFile.getLocalFile();
if (localFile != null) {
try {
......
......@@ -88,17 +88,12 @@ public interface DBPDriver extends DBPObject
ClassLoader getClassLoader();
@NotNull
Collection<? extends DBPDriverFile> getDriverFiles();
@NotNull
Collection<? extends DBPDriverFile.FileSource> getDriverFileSources();
Collection<? extends DBPDriverLibrary> getDriverLibraries();
Object getDriverInstance(DBRRunnableContext runnableContext) throws DBException;
void validateFilesPresence(DBRRunnableContext runnableContext);
void updateFiles(DBRRunnableContext runnableContext);
void loadDriver(DBRRunnableContext runnableContext) throws DBException;
}
......@@ -18,15 +18,16 @@
package org.jkiss.dbeaver.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import java.io.File;
import java.util.Collection;
/**
* DBPDriver local path
* Driver library
*/
public interface DBPDriverFile
public interface DBPDriverLibrary
{
/**
* Driver file type
......@@ -39,18 +40,13 @@ public interface DBPDriverFile
license
}
interface FileSource {
}
@NotNull
FileType getType();
OSDescriptor getSystem();
@NotNull
String getPath();
String getFileType();
@Nullable
String getDescription();
boolean isCustom();
......@@ -64,4 +60,7 @@ public interface DBPDriverFile
boolean matchesCurrentPlatform();
@Nullable
Collection<DBPDriverLibrary> getDependencies();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册