提交 29cd576a 编写于 作者: J jurgen

Registry refactoring

Former-commit-id: 35ce6678
上级 8932879b
......@@ -43,7 +43,7 @@ public class DriverClassLoader extends URLClassLoader
protected String findLibrary(String libname)
{
String nativeName = System.mapLibraryName(libname);
for (DriverLibraryDescriptor driverFile : driver.getDriverLibraries()) {
for (DBPDriverLibrary driverFile : driver.getDriverLibraries()) {
if (driverFile.getType() == DBPDriverLibrary.FileType.lib && driverFile.matchesCurrentPlatform()) {
final File localFile = driverFile.getLocalFile();
if (localFile != null && localFile.exists()) {
......
......@@ -102,7 +102,7 @@ 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<DriverLibraryDescriptor> files = new ArrayList<DriverLibraryDescriptor>();
private final List<DriverLibraryDescriptor> libraries = new ArrayList<DriverLibraryDescriptor>();
private final List<DriverLibraryDescriptor> origFiles = new ArrayList<DriverLibraryDescriptor>();
private final List<DBPPropertyDescriptor> connectionPropertyDescriptors = new ArrayList<DBPPropertyDescriptor>();
private final List<OSDescriptor> supportedSystems = new ArrayList<OSDescriptor>();
......@@ -169,9 +169,9 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.isLoaded = false;
for (IConfigurationElement lib : config.getChildren(RegistryConstants.TAG_FILE)) {
this.files.add(new DriverLibraryDescriptor(this, lib));
this.libraries.add(new DriverLibraryDescriptor(this, lib));
}
this.origFiles.addAll(this.files);
this.origFiles.addAll(this.libraries);
for (IConfigurationElement lib : config.getChildren(RegistryConstants.TAG_FILE_SOURCE)) {
this.fileSources.add(new DriverFileSource(lib));
......@@ -429,7 +429,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
private boolean hasValidLibraries()
{
for (DriverLibraryDescriptor lib : files) {
for (DriverLibraryDescriptor lib : libraries) {
File file = lib.getLocalFile();
if (file != null && file.exists()) {
return true;
......@@ -636,12 +636,12 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@Override
public Collection<DriverLibraryDescriptor> getDriverLibraries()
{
return files;
return libraries;
}
public DriverLibraryDescriptor getDriverFile(String path)
public DriverLibraryDescriptor getDriverLibrary(String path)
{
for (DriverLibraryDescriptor lib : files) {
for (DriverLibraryDescriptor lib : libraries) {
if (lib.getPath().equals(path)) {
return lib;
}
......@@ -649,36 +649,36 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return null;
}
public DriverLibraryDescriptor addDriverFile(String path, DBPDriverLibrary.FileType fileType)
public DriverLibraryDescriptor addDriverLibrary(String path, DBPDriverLibrary.FileType fileType)
{
for (DriverLibraryDescriptor lib : files) {
for (DriverLibraryDescriptor lib : libraries) {
if (lib.getPath().equals(path)) {
return lib;
}
}
DriverLibraryDescriptor lib = new DriverLibraryDescriptor(this, fileType, path);
addDriverFile(lib);
addDriverLibrary(lib);
return lib;
}
public boolean addDriverFile(DriverLibraryDescriptor descriptor)
public boolean addDriverLibrary(DriverLibraryDescriptor descriptor)
{
resetDriverInstance();
if (!files.contains(descriptor)) {
this.files.add(descriptor);
if (!libraries.contains(descriptor)) {
this.libraries.add(descriptor);
return true;
}
return false;
}
public boolean removeDriverFile(DriverLibraryDescriptor lib)
public boolean removeDriverLibrary(DriverLibraryDescriptor lib)
{
resetDriverInstance();
if (!lib.isCustom()) {
lib.setDisabled(true);
return true;
} else {
return this.files.remove(lib);
return this.libraries.remove(lib);
}
}
......@@ -772,7 +772,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
public String getLicense()
{
for (DriverLibraryDescriptor file : files) {
for (DriverLibraryDescriptor file : libraries) {
if (file.getType() == DBPDriverLibrary.FileType.license) {
final File licenseFile = file.getLocalFile();
if (licenseFile != null && licenseFile.exists()) {
......@@ -849,7 +849,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
List<URL> libraryURLs = new ArrayList<URL>();
// Load libraries
for (DriverLibraryDescriptor file : files) {
for (DriverLibraryDescriptor file : libraries) {
if (file.isDisabled() || file.getType() != DBPDriverLibrary.FileType.jar) {
continue;
}
......@@ -876,7 +876,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@Override
public void validateFilesPresence(final DBRRunnableContext runnableContext)
{
for (DriverLibraryDescriptor file : files) {
for (DriverLibraryDescriptor file : libraries) {
if (file.isCustom()) {
File localFile = file.getLocalFile();
if (localFile != null && localFile.exists()) {
......@@ -886,8 +886,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
final List<DriverLibraryDescriptor> downloadCandidates = new ArrayList<DriverLibraryDescriptor>();
for (DriverLibraryDescriptor file : files) {
final List<DBPDriverLibrary> downloadCandidates = new ArrayList<DBPDriverLibrary>();
for (DBPDriverLibrary file : libraries) {
if (file.isDisabled() || !file.isDownloadable()) {
// Nothing we can do about it
continue;
......@@ -915,7 +915,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
public boolean acceptDriverLicenses(DBRRunnableContext runnableContext)
{
// User must accept all licenses before actual drivers download
for (final DriverLibraryDescriptor file : getDriverLibraries()) {
for (final DriverLibraryDescriptor file : libraries) {
if (file.getType() == DBPDriverLibrary.FileType.license) {
final File libraryFile = file.getLocalFile();
if (libraryFile == null || !libraryFile.exists()) {
......@@ -1028,7 +1028,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
// Libraries
for (DriverLibraryDescriptor lib : this.getDriverLibraries()) {
for (DriverLibraryDescriptor lib : libraries) {
if ((export && !lib.isDisabled()) || lib.isCustom() || lib.isDisabled()) {
xml.startElement(RegistryConstants.TAG_LIBRARY);
xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
......@@ -1202,12 +1202,12 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
String path = atts.getValue(RegistryConstants.ATTR_PATH);
DriverLibraryDescriptor lib = curDriver.getDriverFile(path);
DriverLibraryDescriptor lib = curDriver.getDriverLibrary(path);
String disabledAttr = atts.getValue(RegistryConstants.ATTR_DISABLED);
if (lib != null && CommonUtils.getBoolean(disabledAttr)) {
lib.setDisabled(true);
} else if (lib == null) {
curDriver.addDriverFile(path, type);
curDriver.addDriverLibrary(path, type);
}
} else if (localName.equals(RegistryConstants.TAG_CLIENT_HOME)) {
curDriver.addClientHomeId(atts.getValue(RegistryConstants.ATTR_ID));
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.registry;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.maven.MavenArtifact;
import org.jkiss.dbeaver.registry.maven.MavenArtifactReference;
......@@ -37,7 +38,7 @@ public class DriverFileManager
{
static final Log log = Log.getLog(DriverFileManager.class);
public static void downloadLibraryFile(DBRProgressMonitor monitor, DriverLibraryDescriptor library, boolean updateVersion) throws IOException, InterruptedException
public static void downloadLibraryFile(DBRProgressMonitor monitor, DBPDriverLibrary library, boolean updateVersion) throws IOException, InterruptedException
{
if (library.isMavenArtifact()) {
MavenArtifact artifact = downloadMavenArtifact(monitor, library, updateVersion);
......@@ -104,7 +105,7 @@ public class DriverFileManager
monitor.done();
}
private static MavenArtifact downloadMavenArtifact(DBRProgressMonitor monitor, DriverLibraryDescriptor library, boolean updateVersion) throws IOException {
private static MavenArtifact downloadMavenArtifact(DBRProgressMonitor monitor, DBPDriverLibrary library, boolean updateVersion) throws IOException {
MavenArtifactReference artifactInfo = new MavenArtifactReference(library.getPath());
if (updateVersion) {
MavenRegistry.getInstance().resetArtifactInfo(artifactInfo);
......
......@@ -138,6 +138,7 @@ public class DriverLibraryDescriptor implements DBPDriverLibrary
return path.startsWith(FILE_SOURCE_REPO);
}
@Override
public boolean isMavenArtifact() {
return path.startsWith(FILE_SOURCE_MAVEN);
}
......
......@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.program.Program;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.CoreMessages;
......@@ -129,7 +130,8 @@ public class RuntimeUtils {
return DBeaverCore.getInstance().getLocalSystem().isWindows() ? binName + ".exe" : binName;
}
public static IStatus stripStack(IStatus status) {
@NotNull
public static IStatus stripStack(@NotNull IStatus status) {
if (status instanceof MultiStatus) {
IStatus[] children = status.getChildren();
if (children != null) {
......@@ -145,7 +147,7 @@ public class RuntimeUtils {
}
return new Status(status.getSeverity(), status.getPlugin(), status.getCode(), messagePrefix + status.getMessage(), null);
}
return null;
return status;
}
public static void pause(int ms)
......
......@@ -29,6 +29,7 @@ import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
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.*;
......@@ -182,7 +183,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 (DriverLibraryDescriptor fileDescriptor : driver.getDriverLibraries()) {
for (DBPDriverLibrary fileDescriptor : driver.getDriverLibraries()) {
final File libraryFile = fileDescriptor.getLocalFile();
if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
libFiles.add(libraryFile);
......
......@@ -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, DBPDriverLibrary.FileType.jar);
driver.addDriverLibrary(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, DBPDriverLibrary.FileType.jar);
driver.addDriverLibrary(relativePath, DBPDriverLibrary.FileType.jar);
}
}
}
......
......@@ -29,7 +29,6 @@ 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.DriverFileManager;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.runtime.RunnableContextDelegate;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
......@@ -69,7 +68,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
filesTable.setHeaderVisible(true);
filesTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createTableColumn(filesTable, SWT.LEFT, "File");
for (DriverLibraryDescriptor file : wizard.getFiles()) {
for (DBPDriverLibrary file : wizard.getFiles()) {
new TableItem(filesTable, SWT.NONE).setText(file.getDisplayName());
}
UIUtils.packColumns(filesTable, true);
......@@ -91,14 +90,14 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
downloadLibraryFiles(new RunnableContextDelegate(getContainer()), getWizard().getFiles());
}
private void downloadLibraryFiles(DBRRunnableContext runnableContext, final List<DriverLibraryDescriptor> files)
private void downloadLibraryFiles(DBRRunnableContext runnableContext, final List<? extends DBPDriverLibrary> files)
{
if (!getWizard().getDriver().acceptDriverLicenses(runnableContext)) {
return;
}
for (int i = 0, filesSize = files.size(); i < filesSize; ) {
DriverLibraryDescriptor lib = files.get(i);
DBPDriverLibrary lib = files.get(i);
int result = downloadLibraryFile(runnableContext, lib);
switch (result) {
case IDialogConstants.CANCEL_ID:
......@@ -114,7 +113,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
}
}
private int downloadLibraryFile(DBRRunnableContext runnableContext, final DriverLibraryDescriptor file)
private int downloadLibraryFile(DBRRunnableContext runnableContext, final DBPDriverLibrary file)
{
try {
runnableContext.run(true, true, new DBRRunnableWithProgress() {
......@@ -142,11 +141,11 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
}
private class DownloadRetry implements Runnable {
private final DriverLibraryDescriptor file;
private final DBPDriverLibrary file;
private final Throwable error;
private int result;
public DownloadRetry(DriverLibraryDescriptor file, Throwable error)
public DownloadRetry(DBPDriverLibrary file, Throwable error)
{
this.file = file;
this.error = error;
......
......@@ -24,6 +24,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.ui.DBeaverIcons;
......@@ -41,7 +42,7 @@ public class DriverDownloadDialog extends WizardDialog
private boolean doDownload = false;
DriverDownloadDialog(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean updateVersion, boolean forceDownload)
DriverDownloadDialog(Shell shell, DriverDescriptor driver, List<? extends DBPDriverLibrary> files, boolean updateVersion, boolean forceDownload)
{
super(shell, new DriverDownloadWizard(driver, files, updateVersion, forceDownload));
getWizard().init(DBeaverUI.getActiveWorkbenchWindow().getWorkbench(), null);
......@@ -110,18 +111,18 @@ public class DriverDownloadDialog extends WizardDialog
super.finishPressed();
}
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files) {
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DBPDriverLibrary> files) {
return downloadDriverFiles(shell, driver, files, false);
}
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean forceDownload) {
public static boolean downloadDriverFiles(Shell shell, DriverDescriptor driver, List<DBPDriverLibrary> 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<DriverLibraryDescriptor> files, boolean forceDownload) {
public static boolean updateDriverFiles(Shell shell, DriverDescriptor driver, List<? extends DBPDriverLibrary> files, boolean forceDownload) {
DriverDownloadDialog dialog = new DriverDownloadDialog(shell, driver, files, true, forceDownload);
dialog.setMinimumPageSize(100, 100);
dialog.open();
......
......@@ -23,6 +23,7 @@ import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDriverLibrary;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.dbeaver.registry.DriverLibraryDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -35,12 +36,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<DriverLibraryDescriptor> files;
private List<? extends DBPDriverLibrary> files;
private boolean updateVersion;
private boolean forceDownload;
private DriverDownloadPage downloadPage;
public DriverDownloadWizard(@NotNull DriverDescriptor driver, List<DriverLibraryDescriptor> files, boolean updateVersion, boolean forceDownload) {
public DriverDownloadWizard(@NotNull DriverDescriptor driver, List<? extends DBPDriverLibrary> files, boolean updateVersion, boolean forceDownload) {
this.driver = driver;
this.files = files;
this.updateVersion = updateVersion;
......@@ -54,7 +55,7 @@ public class DriverDownloadWizard extends Wizard implements IExportWizard {
return driver;
}
List<DriverLibraryDescriptor> getFiles() {
List<? extends DBPDriverLibrary> getFiles() {
return files;
}
......
......@@ -707,11 +707,11 @@ public class DriverEditDialog extends HelpEnabledDialog
// Set libraries
for (DriverLibraryDescriptor lib : CommonUtils.safeCollection(libList)) {
driver.addDriverFile(lib);
driver.addDriverLibrary(lib);
}
for (DriverLibraryDescriptor lib : CommonUtils.copyList(driver.getDriverLibraries())) {
if (!libList.contains(lib)) {
driver.removeDriverFile(lib);
driver.removeDriverLibrary(lib);
}
}
......@@ -781,7 +781,7 @@ public class DriverEditDialog extends HelpEnabledDialog
{
java.util.List<File> libFiles = new ArrayList<File>();
java.util.List<URL> libURLs = new ArrayList<URL>();
for (DriverLibraryDescriptor lib : libList) {
for (DBPDriverLibrary lib : libList) {
File libFile = lib.getLocalFile();
if (libFile != null && libFile.exists() && !libFile.isDirectory() && lib.getType() == DBPDriverLibrary.FileType.jar) {
libFiles.add(libFile);
......
......@@ -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, DBPDriverLibrary.FileType.jar);
driver.addDriverLibrary(path, DBPDriverLibrary.FileType.jar);
}
driver.setModified(true);
genericProvider.addDriver(driver);
......
......@@ -58,6 +58,8 @@ public interface DBPDriverLibrary
boolean isDownloadable();
boolean isMavenArtifact();
@Nullable
String getExternalURL();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册