Search in sources :

Example 16 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverDependenciesTree method resolveLibraries.

public boolean resolveLibraries() {
    boolean resolved = false;
    try {
        runnableContext.run(true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Resolve dependencies", 100);
                try {
                    dependencies.resolveDependencies(monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        });
        resolved = true;
    } catch (InterruptedException e) {
    // User just canceled download
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError("Resolve libraries", "Error resolving driver libraries", e.getTargetException());
    }
    filesTree.removeAll();
    int totalItems = 1;
    for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
        DBPDriverLibrary library = node.library;
        TreeItem item = new TreeItem(filesTree, SWT.NONE);
        item.setData(node);
        item.setImage(DBeaverIcons.getImage(library.getIcon()));
        item.setText(0, library.getDisplayName());
        item.setText(1, CommonUtils.notEmpty(library.getVersion()));
        item.setText(2, CommonUtils.notEmpty(library.getDescription()));
        if (editable) {
            item.setFont(1, boldFont);
        }
        totalItems++;
        if (addDependencies(item, node)) {
            item.setExpanded(true);
            totalItems += item.getItemCount();
        }
    }
    UIUtils.packColumns(filesTree);
    // Check missing files
    int missingFiles = 0;
    for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryList()) {
        File localFile = node.library.getLocalFile();
        if (localFile == null || !localFile.exists()) {
            missingFiles++;
        }
    }
    if (missingFiles == 0) {
    // UIUtils.showMessageBox(getShell(), "Driver Download", "All driver files are present", SWT.ICON_INFORMATION);
    // ((DriverDownloadDialog)getWizard().getContainer()).closeWizard();
    }
    return resolved;
}
Also used : DBPDriverDependencies(org.jkiss.dbeaver.model.connection.DBPDriverDependencies) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Point(org.eclipse.swt.graphics.Point) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File)

Example 17 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverDownloadAutoPage method downloadLibraryFiles.

private void downloadLibraryFiles(final DBRProgressMonitor monitor) throws InterruptedException {
    if (!getWizard().getDriver().acceptDriverLicenses()) {
        return;
    }
    boolean processUnsecure = false;
    List<DBPDriverDependencies.DependencyNode> nodes = getWizard().getDependencies().getLibraryList();
    for (int i = 0, filesSize = nodes.size(); i < filesSize; ) {
        final DBPDriverLibrary lib = nodes.get(i).library;
        if (!processUnsecure && !lib.isSecureDownload(monitor)) {
            boolean process = new UIConfirmation() {

                @Override
                protected Boolean runTask() {
                    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
                    messageBox.setText(CoreMessages.dialog_driver_download_auto_page_driver_security_warning);
                    messageBox.setMessage(NLS.bind(CoreMessages.dialog_driver_download_auto_page_driver_security_warning_msg, lib.getDisplayName(), lib.getExternalURL(monitor)));
                    int response = messageBox.open();
                    return (response == SWT.YES);
                }
            }.execute();
            if (process) {
                processUnsecure = true;
            } else {
                break;
            }
        }
        int result = IDialogConstants.OK_ID;
        try {
            lib.downloadLibraryFile(monitor, getWizard().isForceDownload(), NLS.bind(CoreMessages.dialog_driver_download_auto_page_download_rate, (i + 1), filesSize));
        } catch (final IOException e) {
            if (lib.getType() == DBPDriverLibrary.FileType.license) {
                result = IDialogConstants.OK_ID;
            } else {
                result = new UITask<Integer>() {

                    @Override
                    protected Integer runTask() {
                        DownloadErrorDialog dialog = new DownloadErrorDialog(null, lib.getDisplayName(), CoreMessages.dialog_driver_download_auto_page_download_failed_msg, e);
                        return dialog.open();
                    }
                }.execute();
            }
        }
        switch(result) {
            case IDialogConstants.CANCEL_ID:
            case IDialogConstants.ABORT_ID:
                return;
            case IDialogConstants.RETRY_ID:
                continue;
            case IDialogConstants.OK_ID:
            case IDialogConstants.IGNORE_ID:
                i++;
                break;
        }
    }
    getWizard().getDriver().setModified(true);
// DataSourceProviderRegistry.getInstance().saveDrivers();
}
Also used : UIConfirmation(org.jkiss.dbeaver.ui.UIConfirmation) IOException(java.io.IOException) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary)

Example 18 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverDownloadAutoPage method createControl.

@Override
public void createControl(Composite parent) {
    final DriverDownloadWizard wizard = getWizard();
    final DriverDescriptor driver = wizard.getDriver();
    setMessage(NLS.bind(CoreMessages.dialog_driver_download_auto_page_download_specific_driver_files, driver.getFullName()));
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createPlaceholder(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (!wizard.isForceDownload()) {
        Composite infoGroup = UIUtils.createPlaceholder(composite, 2, 5);
        infoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        Label infoText = new Label(infoGroup, SWT.NONE);
        infoText.setText(NLS.bind(CoreMessages.dialog_driver_download_auto_page_driver_file_missing_text, driver.getFullName()));
        infoText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final Button forceCheckbox = UIUtils.createCheckbox(infoGroup, CoreMessages.dialog_driver_download_auto_page_force_download, wizard.isForceDownload());
        forceCheckbox.setToolTipText(CoreMessages.dialog_driver_download_auto_page_force_download_tooltip);
        forceCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_BEGINNING));
        forceCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                wizard.setForceDownload(forceCheckbox.getSelection());
            }
        });
    }
    {
        Group filesGroup = UIUtils.createControlGroup(composite, CoreMessages.dialog_driver_download_auto_page_required_files, 1, -1, -1);
        filesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        depsTree = new DriverDependenciesTree(filesGroup, new RunnableContextDelegate(getContainer()), getWizard().getDependencies(), driver, driver.getDriverLibraries(), true) {

            protected void setLibraryVersion(final DBPDriverLibrary library, final String version) {
                String curVersion = library.getVersion();
                if (CommonUtils.equalObjects(curVersion, version)) {
                    return;
                }
                library.setPreferredVersion(version);
                resolveLibraries();
            }
        };
        new Label(filesGroup, SWT.NONE).setText(CoreMessages.dialog_driver_download_auto_page_change_driver_version_text);
    }
    if (!wizard.isForceDownload()) {
        Label infoText = new Label(composite, SWT.NONE);
        infoText.setText(CoreMessages.dialog_driver_download_auto_page_obtain_driver_files_text);
        infoText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    createLinksPanel(composite);
    setControl(composite);
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) RunnableContextDelegate(org.jkiss.dbeaver.runtime.RunnableContextDelegate) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 19 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.

the class DriverEditDialog method changeLibContent.

private void changeLibContent() {
    libTable.setInput(driver.getEnabledDriverLibraries());
    boolean hasFiles = false, hasDownloads = false;
    for (DBPDriverLibrary library : driver.getDriverLibraries()) {
        final File localFile = library.getLocalFile();
        hasFiles = hasFiles || (!library.isDisabled() && localFile != null && localFile.exists());
        if (!hasFiles && !library.isDisabled()) {
            final Collection<DriverDescriptor.DriverFileInfo> files = driver.getLibraryFiles(library);
            if (files != null) {
                for (DriverDescriptor.DriverFileInfo file : files) {
                    if (file.getFile() != null && file.getFile().exists()) {
                        hasFiles = true;
                    }
                }
            }
        }
        if (!library.isDisabled() && library.isDownloadable()) {
            hasDownloads = true;
        }
    }
    findClassButton.setEnabled(provider.isDriversManagable() && hasFiles);
    updateVersionButton.setEnabled(hasDownloads);
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) File(java.io.File)

Example 20 with DBPDriverLibrary

use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.

the class DriverDependencies method resolveDependencies.

@Override
public void resolveDependencies(DBRProgressMonitor monitor) throws DBException {
    IOException lastError = null;
    {
        rootNodes.clear();
        final Map<String, DependencyNode> libMap = new LinkedHashMap<>();
        for (DBPDriverLibrary library : rootLibraries) {
            DependencyNode node = new DependencyNode(null, library);
            try {
                final Map<String, DependencyNode> localLibMap = new LinkedHashMap<>();
                localLibMap.put(node.library.getId(), node);
                resolveDependencies(monitor, node, localLibMap);
                rootNodes.add(node);
                libMap.putAll(localLibMap);
            } catch (IOException e) {
                lastError = e;
                log.error("Error resolving library '" + library.getDisplayName() + "' dependencies", e);
            }
        }
        libraryList.clear();
        libraryList.addAll(libMap.values());
    /*
                StringBuilder sb = new StringBuilder();
                Set<String> ns = new TreeSet<>();
                for (String lib : libMap.keySet()) {
                    String newName = lib.replaceAll(".+\\:", "");
                    if (ns.contains(newName)) {
                        //System.out.println(123);
                    }
                    ns.add(newName);
                }
                for (String lib : ns) {
                    sb.append(lib).append("\n");
                }
                System.out.println(sb.toString());

                System.out.println("---------------------------");
                for (DependencyNode node : rootNodes) {
                    dumpNode(node, 0);
                }
*/
    }
    if (lastError != null) {
        throw new DBException("Error resolving dependencies", lastError);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) IOException(java.io.IOException)

Aggregations

DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)23 File (java.io.File)8 IOException (java.io.IOException)6 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DBException (org.jkiss.dbeaver.DBException)3 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)3 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JarFile (java.util.jar.JarFile)2