Search in sources :

Example 1 with OSDescriptor

use of org.jkiss.dbeaver.model.runtime.OSDescriptor in project dbeaver by dbeaver.

the class PostgreDataSourceProvider method findLocalClients.

public static synchronized void findLocalClients() {
    if (localServers != null) {
        return;
    }
    localServers = new LinkedHashMap<>();
    // find homes in Windows registry
    OSDescriptor localSystem = DBeaverCore.getInstance().getLocalSystem();
    if (localSystem.isWindows()) {
        try {
            List<String> homeKeys = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE, PostgreConstants.PG_INSTALL_REG_KEY);
            if (homeKeys != null) {
                for (String homeKey : homeKeys) {
                    Map<String, String> valuesMap = WinRegistry.readStringValues(WinRegistry.HKEY_LOCAL_MACHINE, PostgreConstants.PG_INSTALL_REG_KEY + "\\" + homeKey);
                    if (valuesMap != null) {
                        for (String key : valuesMap.keySet()) {
                            if (PostgreConstants.PG_INSTALL_PROP_BASE_DIRECTORY.equalsIgnoreCase(key)) {
                                String baseDir = CommonUtils.removeTrailingSlash(valuesMap.get(PostgreConstants.PG_INSTALL_PROP_BASE_DIRECTORY));
                                String version = valuesMap.get(PostgreConstants.PG_INSTALL_PROP_VERSION);
                                String branding = valuesMap.get(PostgreConstants.PG_INSTALL_PROP_BRANDING);
                                String dataDir = valuesMap.get(PostgreConstants.PG_INSTALL_PROP_DATA_DIRECTORY);
                                localServers.put(homeKey, new PostgreServerHome(homeKey, baseDir, version, branding, dataDir));
                                break;
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            log.warn("Error reading Windows registry", e);
        }
    }
}
Also used : OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor)

Example 2 with OSDescriptor

use of org.jkiss.dbeaver.model.runtime.OSDescriptor in project dbeaver by dbeaver.

the class MySQLDataSourceProvider method findLocalClients.

public static synchronized void findLocalClients() {
    if (localServers != null) {
        return;
    }
    localServers = new LinkedHashMap<>();
    // read from path
    String path = System.getenv("PATH");
    if (path != null) {
        for (String token : path.split(System.getProperty(StandardConstants.ENV_PATH_SEPARATOR))) {
            token = CommonUtils.removeTrailingSlash(token);
            File mysqlFile = new File(token, MySQLUtils.getMySQLConsoleBinaryName());
            if (mysqlFile.exists()) {
                // .getName()
                File binFolder = mysqlFile.getAbsoluteFile().getParentFile();
                if (binFolder.getName().equalsIgnoreCase("bin")) {
                    String homeId = CommonUtils.removeTrailingSlash(binFolder.getParentFile().getAbsolutePath());
                    localServers.put(homeId, new MySQLServerHome(homeId, null));
                }
            }
        }
    }
    // find homes in Windows registry
    OSDescriptor localSystem = DBeaverCore.getInstance().getLocalSystem();
    if (localSystem.isWindows()) {
        try {
            // Search MySQL entries
            {
                final String registryRoot = localSystem.is64() ? REGISTRY_ROOT_MYSQL_64 : REGISTRY_ROOT_MYSQL_32;
                List<String> homeKeys = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE, registryRoot);
                if (homeKeys != null) {
                    for (String homeKey : homeKeys) {
                        Map<String, String> valuesMap = WinRegistry.readStringValues(WinRegistry.HKEY_LOCAL_MACHINE, registryRoot + "\\" + homeKey);
                        if (valuesMap != null) {
                            for (String key : valuesMap.keySet()) {
                                if (SERER_LOCATION_KEY.equalsIgnoreCase(key)) {
                                    String serverPath = CommonUtils.removeTrailingSlash(valuesMap.get(key));
                                    localServers.put(serverPath, new MySQLServerHome(serverPath, homeKey));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // Search MariaDB entries
            {
                List<String> homeKeys = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE, REGISTRY_ROOT_MARIADB);
                if (homeKeys != null) {
                    for (String homeKey : homeKeys) {
                        Map<String, String> valuesMap = WinRegistry.readStringValues(WinRegistry.HKEY_LOCAL_MACHINE, REGISTRY_ROOT_MARIADB + "\\" + homeKey);
                        if (valuesMap != null) {
                            for (String key : valuesMap.keySet()) {
                                if (INSTALLDIR_KEY.equalsIgnoreCase(key)) {
                                    String serverPath = CommonUtils.removeTrailingSlash(valuesMap.get(key));
                                    localServers.put(serverPath, new MySQLServerHome(serverPath, homeKey));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            log.warn("Error reading Windows registry", e);
        }
    }
}
Also used : File(java.io.File) OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor)

Example 3 with OSDescriptor

use of org.jkiss.dbeaver.model.runtime.OSDescriptor in project dbeaver by dbeaver.

the class DBeaverCore method initialize.

private void initialize() {
    long startTime = System.currentTimeMillis();
    log.debug("Initialize Core...");
    DBPPreferenceStore prefsStore = getGlobalPreferenceStore();
    // ' Global pref events forwarder
    prefsStore.addPropertyChangeListener(new DBPPreferenceListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            // Forward event to all data source preferences
            for (DataSourceDescriptor ds : DataSourceRegistry.getAllDataSources()) {
                ds.getPreferenceStore().firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
            }
        }
    });
    // Register properties adapter
    this.workspace = ResourcesPlugin.getWorkspace();
    this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch());
    {
        this.language = PlatformLanguageRegistry.getInstance().getLanguage(Locale.getDefault());
        if (this.language == null) {
            log.debug("Language for locale '" + Locale.getDefault() + "' not found. Use default.");
            this.language = PlatformLanguageRegistry.getInstance().getLanguage(Locale.ENGLISH);
        }
    }
    QMUtils.initApplication(this);
    this.queryManager = new QMControllerImpl();
    this.qmLogWriter = new QMLogFileWriter();
    this.queryManager.registerMetaListener(qmLogWriter);
    // Init default network settings
    Authenticator.setDefault(new GlobalProxyAuthenticator());
    ProxySelector.setDefault(new GlobalProxySelector(ProxySelector.getDefault()));
    this.certificateStorage = new DefaultCertificateStorage(new File(DBeaverActivator.getInstance().getStateLocation().toFile(), "security"));
    // Init project registry
    this.projectRegistry = new ProjectRegistry(workspace);
    // Projects registry
    initializeProjects();
    // Navigator model
    this.navigatorModel = new DBNModel(this);
    this.navigatorModel.initialize();
    // Activate plugin services
    for (IPluginService pluginService : PluginServiceRegistry.getInstance().getServices()) {
        try {
            pluginService.activateService();
            activatedServices.add(pluginService);
        } catch (Throwable e) {
            log.error("Error activating plugin service", e);
        }
    }
    // Keep-alive job
    new KeepAliveJob(this).scheduleMonitor();
    log.debug("Core initialized (" + (System.currentTimeMillis() - startTime) + "ms)");
}
Also used : DefaultCertificateStorage(org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage) QMControllerImpl(org.jkiss.dbeaver.runtime.qm.QMControllerImpl) QMLogFileWriter(org.jkiss.dbeaver.runtime.qm.QMLogFileWriter) KeepAliveJob(org.jkiss.dbeaver.runtime.jobs.KeepAliveJob) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) GlobalProxySelector(org.jkiss.dbeaver.runtime.net.GlobalProxySelector) IPluginService(org.jkiss.dbeaver.runtime.IPluginService) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor) File(java.io.File) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)

Example 4 with OSDescriptor

use of org.jkiss.dbeaver.model.runtime.OSDescriptor in project dbeaver by serge-rider.

the class PostgreDataSourceProvider method findLocalClients.

public static synchronized void findLocalClients() {
    if (localServers != null) {
        return;
    }
    localServers = new LinkedHashMap<>();
    // find homes in Windows registry
    OSDescriptor localSystem = DBWorkbench.getPlatform().getLocalSystem();
    if (localSystem.isWindows()) {
        try {
            if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, PostgreConstants.PG_INSTALL_REG_KEY)) {
                String[] homeKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, PostgreConstants.PG_INSTALL_REG_KEY);
                if (homeKeys != null) {
                    for (String homeKey : homeKeys) {
                        Map<String, Object> valuesMap = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, PostgreConstants.PG_INSTALL_REG_KEY + "\\" + homeKey);
                        for (String key : valuesMap.keySet()) {
                            if (PostgreConstants.PG_INSTALL_PROP_BASE_DIRECTORY.equalsIgnoreCase(key)) {
                                String baseDir = CommonUtils.removeTrailingSlash(CommonUtils.toString(valuesMap.get(PostgreConstants.PG_INSTALL_PROP_BASE_DIRECTORY)));
                                String branding = CommonUtils.toString(valuesMap.get(PostgreConstants.PG_INSTALL_PROP_BRANDING));
                                localServers.put(homeKey, new PostgreServerHome(homeKey, baseDir, branding));
                                break;
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            log.warn("Error reading Windows registry", e);
        }
    } else if (GeneralUtils.isMacOS()) {
        Collection<File> postgresDirs = new ArrayList<>();
        Collections.addAll(postgresDirs, NativeClientLocationUtils.getSubdirectories(NativeClientLocationUtils.getSubdirectoriesWithNamesStartingWith("postgresql", new File(NativeClientLocationUtils.HOMEBREW_FORMULAE_LOCATION))));
        Collections.addAll(postgresDirs, // standard location for EDB installer
        NativeClientLocationUtils.getSubdirectories(new File("/Library/PostgreSQL/")));
        Collections.addAll(postgresDirs, NativeClientLocationUtils.getSubdirectories(new File("/Applications/Postgres.app/Contents/versions/")));
        for (File dir : postgresDirs) {
            File bin = new File(dir, NativeClientLocationUtils.BIN);
            File psql = new File(bin, "psql");
            if (!bin.exists() || !bin.isDirectory() || !psql.exists() || !psql.canExecute()) {
                continue;
            }
            String branding = getBranding(dir);
            if (branding.isEmpty()) {
                continue;
            }
            String canonicalPath = NativeClientLocationUtils.getCanonicalPath(dir);
            if (canonicalPath.isEmpty()) {
                continue;
            }
            PostgreServerHome home = new PostgreServerHome(branding, canonicalPath, branding);
            PostgreServerHome duplicate = localServers.putIfAbsent(branding, home);
            if (duplicate == null) {
                continue;
            }
            localServers.remove(branding);
            home = new PostgreServerHome(canonicalPath, canonicalPath, canonicalPath);
            String duplicatePath = duplicate.getPath().getAbsolutePath();
            duplicate = new PostgreServerHome(duplicatePath, duplicatePath, duplicatePath);
            localServers.put(canonicalPath, home);
            localServers.put(duplicatePath, duplicate);
        // there is a possibility that there will be more that two duplicates. the code above does not account for that
        }
    }
}
Also used : OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor) File(java.io.File)

Example 5 with OSDescriptor

use of org.jkiss.dbeaver.model.runtime.OSDescriptor in project dbeaver by serge-rider.

the class MySQLDataSourceProvider method findLocalClients.

public static synchronized void findLocalClients() {
    if (localServers != null) {
        return;
    }
    localServers = new LinkedHashMap<>();
    // read from path
    String path = System.getenv("PATH");
    if (path != null && GeneralUtils.isWindows()) {
        for (String token : path.split(System.getProperty(StandardConstants.ENV_PATH_SEPARATOR))) {
            token = CommonUtils.removeTrailingSlash(token);
            File mysqlFile = new File(token, MySQLUtils.getMySQLConsoleBinaryName());
            if (mysqlFile.exists()) {
                // .getName()
                File binFolder = mysqlFile.getAbsoluteFile().getParentFile();
                if (binFolder.getName().equalsIgnoreCase("bin")) {
                    String homeId = CommonUtils.removeTrailingSlash(binFolder.getParentFile().getAbsolutePath());
                    localServers.put(homeId, new MySQLServerHome(homeId, null));
                }
            }
        }
    }
    // find homes in Windows registry
    OSDescriptor localSystem = DBWorkbench.getPlatform().getLocalSystem();
    if (localSystem.isWindows()) {
        try {
            // Search MySQL entries
            {
                final String registryRoot = localSystem.is64() ? REGISTRY_ROOT_MYSQL_64 : REGISTRY_ROOT_MYSQL_32;
                if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, registryRoot)) {
                    String[] homeKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, registryRoot);
                    if (homeKeys != null) {
                        for (String homeKey : homeKeys) {
                            Map<String, Object> valuesMap = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, registryRoot + "\\" + homeKey);
                            for (String key : valuesMap.keySet()) {
                                if (SERER_LOCATION_KEY.equalsIgnoreCase(key)) {
                                    String serverPath = CommonUtils.removeTrailingSlash(CommonUtils.toString(valuesMap.get(key)));
                                    if (new File(serverPath, "bin").exists()) {
                                        localServers.put(serverPath, new MySQLServerHome(serverPath, homeKey));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Search MariaDB entries
            if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, REGISTRY_ROOT_MARIADB)) {
                String[] homeKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, REGISTRY_ROOT_MARIADB);
                if (homeKeys != null) {
                    for (String homeKey : homeKeys) {
                        Map<String, Object> valuesMap = Advapi32Util.registryGetValues(WinReg.HKEY_LOCAL_MACHINE, REGISTRY_ROOT_MARIADB + "\\" + homeKey);
                        for (String key : valuesMap.keySet()) {
                            if (INSTALLDIR_KEY.equalsIgnoreCase(key)) {
                                String serverPath = CommonUtils.removeTrailingSlash(CommonUtils.toString(valuesMap.get(key)));
                                if (new File(serverPath, "bin").exists()) {
                                    localServers.put(serverPath, new MySQLServerHome(serverPath, homeKey));
                                }
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            log.warn("Error reading Windows registry", e);
        }
    } else if (GeneralUtils.isMacOS()) {
        Collection<File> mysqlDirs = new ArrayList<>();
        Collections.addAll(mysqlDirs, // clients installed via installer downloaded from mysql site
        NativeClientLocationUtils.getSubdirectoriesWithNamesStartingWith("mysql", new File(NativeClientLocationUtils.USR_LOCAL)));
        Collections.addAll(mysqlDirs, NativeClientLocationUtils.getSubdirectories(NativeClientLocationUtils.getSubdirectoriesWithNamesStartingWith("mysql", new File(NativeClientLocationUtils.HOMEBREW_FORMULAE_LOCATION))));
        Collections.addAll(mysqlDirs, NativeClientLocationUtils.getSubdirectories(NativeClientLocationUtils.getSubdirectoriesWithNamesStartingWith("mariadb", new File(NativeClientLocationUtils.HOMEBREW_FORMULAE_LOCATION))));
        for (File dir : mysqlDirs) {
            File bin = new File(dir, NativeClientLocationUtils.BIN);
            File binary = new File(bin, MySQLUtils.getMySQLConsoleBinaryName());
            if (!bin.exists() || !bin.isDirectory() || !binary.exists() || !binary.canExecute()) {
                continue;
            }
            String version = getFullServerVersion(dir);
            if (version == null) {
                continue;
            }
            String canonicalPath = NativeClientLocationUtils.getCanonicalPath(dir);
            if (canonicalPath.isEmpty()) {
                continue;
            }
            MySQLServerHome home = new MySQLServerHome(canonicalPath, "MySQL " + version);
            localServers.put(canonicalPath, home);
        }
    }
}
Also used : OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor)

Aggregations

OSDescriptor (org.jkiss.dbeaver.model.runtime.OSDescriptor)6 File (java.io.File)3 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)2 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)2 IPluginService (org.jkiss.dbeaver.runtime.IPluginService)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 DefaultCertificateStorage (org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage)1 AbstractPreferenceStore (org.jkiss.dbeaver.model.impl.preferences.AbstractPreferenceStore)1 DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)1 KeepAliveJob (org.jkiss.dbeaver.runtime.jobs.KeepAliveJob)1 KeepAliveListenerJob (org.jkiss.dbeaver.runtime.jobs.KeepAliveListenerJob)1 GlobalProxySelector (org.jkiss.dbeaver.runtime.net.GlobalProxySelector)1 QMControllerImpl (org.jkiss.dbeaver.runtime.qm.QMControllerImpl)1 QMLogFileWriter (org.jkiss.dbeaver.runtime.qm.QMLogFileWriter)1