use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverDependencies method resolveDependencies.
private void resolveDependencies(DBRProgressMonitor monitor, DependencyNode ownerNode, Map<String, DependencyNode> libMap) throws IOException {
Collection<? extends DBPDriverLibrary> dependencies = ownerNode.library.getDependencies(monitor);
if (dependencies != null && !dependencies.isEmpty()) {
for (DBPDriverLibrary dep : dependencies) {
DependencyNode node = new DependencyNode(ownerNode, dep);
DependencyNode prevNode = libMap.get(node.library.getId());
if (prevNode == null || prevNode.depth > node.depth) {
// if (node.library.isDownloadable()) {
libMap.put(node.library.getId(), node);
// }
if (prevNode != null) {
prevNode.duplicate = true;
}
} else {
node.duplicate = true;
}
ownerNode.dependencies.add(node);
}
for (DependencyNode node : ownerNode.dependencies) {
if (!node.duplicate) {
resolveDependencies(monitor, node, libMap);
}
}
}
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverDescriptorSerializerLegacy method serialize.
public void serialize(XMLBuilder xml, boolean export) throws IOException {
Map<String, String> pathSubstitutions = getPathSubstitutions();
try (XMLBuilder.Element e0 = xml.startElement(RegistryConstants.TAG_DRIVER)) {
if (export) {
xml.addAttribute(RegistryConstants.ATTR_PROVIDER, driver.getProviderDescriptor().getId());
}
xml.addAttribute(RegistryConstants.ATTR_ID, driver.getId());
if (driver.isDisabled()) {
xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
}
if (!CommonUtils.isEmpty(driver.getCategory())) {
xml.addAttribute(RegistryConstants.ATTR_CATEGORY, driver.getCategory());
}
xml.addAttribute(RegistryConstants.ATTR_CATEGORIES, String.join(",", driver.getCategories()));
xml.addAttribute(RegistryConstants.ATTR_NAME, driver.getName());
xml.addAttribute(RegistryConstants.ATTR_CLASS, driver.getDriverClassName());
if (!CommonUtils.isEmpty(driver.getSampleURL())) {
xml.addAttribute(RegistryConstants.ATTR_URL, driver.getSampleURL());
}
if (!CommonUtils.isEmpty(driver.getDefaultPort())) {
xml.addAttribute(RegistryConstants.ATTR_PORT, driver.getDefaultPort());
}
if (!CommonUtils.isEmpty(driver.getDefaultDatabase())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_DATABASE, driver.getDefaultDatabase());
}
if (!CommonUtils.isEmpty(driver.getDefaultServer())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_SERVER, driver.getDefaultServer());
}
if (!CommonUtils.isEmpty(driver.getDefaultUser())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_USER, driver.getDefaultUser());
}
xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.notEmpty(driver.getDescription()));
if (driver.isCustomDriverLoader()) {
xml.addAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
}
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
if (driver.isEmbedded()) {
xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
}
if (driver.isAnonymousAccess()) {
xml.addAttribute(RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
}
if (driver.isAllowsEmptyPassword()) {
xml.addAttribute("allowsEmptyPassword", driver.isAllowsEmptyPassword());
}
if (!driver.isInstantiable()) {
xml.addAttribute(RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
}
// Libraries
for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
if (export && !lib.isDisabled()) {
continue;
}
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_LIBRARY)) {
xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, lib.getPath()));
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
if (lib.isDisabled()) {
xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
}
if (!CommonUtils.isEmpty(lib.getPreferredVersion())) {
xml.addAttribute(RegistryConstants.ATTR_VERSION, lib.getPreferredVersion());
}
// xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
List<DriverDescriptor.DriverFileInfo> files = driver.getResolvedFiles().get(lib);
if (files != null) {
for (DriverDescriptor.DriverFileInfo file : files) {
try (XMLBuilder.Element e2 = xml.startElement(RegistryConstants.TAG_FILE)) {
if (file.getFile() == null) {
log.warn("File missing in " + file.getId());
continue;
}
xml.addAttribute(RegistryConstants.ATTR_ID, file.getId());
if (!CommonUtils.isEmpty(file.getVersion())) {
xml.addAttribute(RegistryConstants.ATTR_VERSION, file.getVersion());
}
xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, file.getFile().getAbsolutePath()));
}
}
}
}
}
// Client homes
for (DBPNativeClientLocation location : driver.getNativeClientHomes()) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_CLIENT_HOME)) {
xml.addAttribute(RegistryConstants.ATTR_ID, location.getName());
if (location.getPath() != null) {
xml.addAttribute(RegistryConstants.ATTR_PATH, location.getPath().getAbsolutePath());
}
}
}
// Parameters
for (Map.Entry<String, Object> paramEntry : driver.getCustomParameters().entrySet()) {
if (!CommonUtils.equalObjects(paramEntry.getValue(), driver.getDefaultParameters().get(paramEntry.getKey()))) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PARAMETER)) {
xml.addAttribute(RegistryConstants.ATTR_NAME, paramEntry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(paramEntry.getValue()));
}
}
}
// Properties
for (Map.Entry<String, Object> propEntry : driver.getCustomConnectionProperties().entrySet()) {
if (!CommonUtils.equalObjects(propEntry.getValue(), driver.getDefaultConnectionProperties().get(propEntry.getKey()))) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PROPERTY)) {
xml.addAttribute(RegistryConstants.ATTR_NAME, propEntry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(propEntry.getValue()));
}
}
}
}
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class ProjectExportWizard method exportProjects.
private void exportProjects(DBRProgressMonitor monitor, final ProjectExportData exportData) throws IOException, CoreException, InterruptedException {
if (!exportData.getOutputFolder().exists()) {
if (!exportData.getOutputFolder().mkdirs()) {
// $NON-NLS-2$
throw new IOException("Cannot create directory '" + exportData.getOutputFolder().getAbsolutePath() + "'");
}
}
String archiveName = exportData.getArchiveFileName() + ExportConstants.ARCHIVE_FILE_EXT;
File archiveFile = new File(exportData.getOutputFolder(), archiveName);
FileOutputStream exportStream = new FileOutputStream(archiveFile);
try {
ByteArrayOutputStream metaBuffer = new ByteArrayOutputStream(10000);
ZipOutputStream archiveStream = new ZipOutputStream(exportStream);
// Start meta
XMLBuilder meta = new XMLBuilder(metaBuffer, GeneralUtils.UTF8_ENCODING);
meta.startElement(ExportConstants.TAG_ARCHIVE);
meta.addAttribute(ExportConstants.ATTR_VERSION, ExportConstants.ARCHIVE_VERSION_CURRENT);
exportData.initExport(DBWorkbench.getPlatform().getWorkspace(), meta, archiveStream);
{
// Export source info
meta.startElement(ExportConstants.TAG_SOURCE);
meta.addAttribute(ExportConstants.ATTR_TIME, System.currentTimeMillis());
meta.addAttribute(ExportConstants.ATTR_ADDRESS, InetAddress.getLocalHost().getHostAddress());
meta.addAttribute(ExportConstants.ATTR_HOST, InetAddress.getLocalHost().getHostName());
meta.endElement();
}
Map<DBPProject, Integer> resCountMap = new HashMap<>();
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_collect_info, exportData.getProjectsToExport().size());
for (DBPProject project : exportData.getProjectsToExport()) {
// Add used drivers to export data
final DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
if (dataSourceRegistry != null) {
for (DBPDataSourceContainer dataSourceDescriptor : dataSourceRegistry.getDataSources()) {
exportData.usedDrivers.add(dataSourceDescriptor.getDriver());
}
}
resCountMap.put(project, getChildCount(exportData, project.getEclipseProject()));
monitor.worked(1);
}
monitor.done();
{
// Export projects
exportData.meta.startElement(ExportConstants.TAG_PROJECTS);
for (DBPProject project : exportData.getProjectsToExport()) {
monitor.beginTask(NLS.bind(CoreMessages.dialog_project_export_wizard_monitor_export_project, project.getName()), resCountMap.get(project));
try {
exportProject(monitor, exportData, project.getEclipseProject());
} finally {
monitor.done();
}
}
exportData.meta.endElement();
}
if (exportData.isExportDrivers()) {
// Export driver libraries
Set<File> libFiles = new HashSet<>();
Map<String, File> libPathMap = new HashMap<>();
for (DBPDriver driver : exportData.usedDrivers) {
for (DBPDriverLibrary fileDescriptor : driver.getDriverLibraries()) {
final File libraryFile = fileDescriptor.getLocalFile();
if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
libFiles.add(libraryFile);
libPathMap.put(fileDescriptor.getPath(), libraryFile);
}
}
}
if (!libFiles.isEmpty()) {
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_export_libraries, libFiles.size());
// $NON-NLS-1$
final ZipEntry driversFolder = new ZipEntry(ExportConstants.DIR_DRIVERS + "/");
// $NON-NLS-1$
driversFolder.setComment("Database driver libraries");
exportData.archiveStream.putNextEntry(driversFolder);
exportData.archiveStream.closeEntry();
exportData.meta.startElement(ExportConstants.TAG_LIBRARIES);
Set<String> libFileNames = new HashSet<>();
for (String libPath : libPathMap.keySet()) {
final File libFile = libPathMap.get(libPath);
// Check for file name duplications
final String libFileName = libFile.getName();
if (libFileNames.contains(libFileName)) {
// $NON-NLS-1$
log.warn("Duplicate driver library file name: " + libFileName);
continue;
}
libFileNames.add(libFileName);
monitor.subTask(libFileName);
exportData.meta.startElement(RegistryConstants.TAG_FILE);
exportData.meta.addAttribute(ExportConstants.ATTR_PATH, libPath);
// $NON-NLS-1$
exportData.meta.addAttribute(ExportConstants.ATTR_FILE, "drivers/" + libFileName);
exportData.meta.endElement();
// $NON-NLS-1$
final ZipEntry driverFile = new ZipEntry(ExportConstants.DIR_DRIVERS + "/" + libFileName);
// $NON-NLS-1$
driverFile.setComment("Driver library");
exportData.archiveStream.putNextEntry(driverFile);
try (InputStream is = new FileInputStream(libFile)) {
IOUtils.copyStream(is, exportData.archiveStream, COPY_BUFFER_SIZE);
}
exportData.archiveStream.closeEntry();
monitor.worked(1);
}
exportData.meta.endElement();
monitor.done();
}
}
// Add meta to archive
{
exportData.meta.endElement();
exportData.meta.flush();
archiveStream.putNextEntry(new ZipEntry(ExportConstants.META_FILENAME));
archiveStream.write(metaBuffer.toByteArray());
archiveStream.closeEntry();
}
// Finish archive creation
archiveStream.finish();
} finally {
ContentUtils.close(exportStream);
}
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverClassFindJob method findDriverClasses.
private void findDriverClasses(IProgressMonitor monitor) {
java.util.List<File> libFiles = new ArrayList<>();
java.util.List<URL> libURLs = new ArrayList<>();
for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
File libFile = lib.getLocalFile();
if (libFile != null && libFile.exists() && !libFile.isDirectory() && lib.getType() == DBPDriverLibrary.FileType.jar) {
libFiles.add(libFile);
try {
libURLs.add(libFile.toURI().toURL());
} catch (MalformedURLException e) {
log.debug(e);
}
} else {
final Collection<DriverDescriptor.DriverFileInfo> files = driver.getLibraryFiles(lib);
if (files != null) {
for (DriverDescriptor.DriverFileInfo file : files) {
if (file.getFile() != null && file.getFile().exists()) {
libFiles.add(file.getFile());
}
}
}
}
}
ClassLoader findCL = new URLClassLoader(libURLs.toArray(new URL[libURLs.size()]));
for (File libFile : libFiles) {
if (monitor.isCanceled()) {
break;
}
findDriverClasses(monitor, findCL, libFile);
}
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.
the class ProjectExportWizard method exportProjects.
public void exportProjects(DBRProgressMonitor monitor, final ProjectExportData exportData) throws IOException, CoreException, InterruptedException {
if (!exportData.getOutputFolder().exists()) {
if (!exportData.getOutputFolder().mkdirs()) {
// $NON-NLS-2$
throw new IOException("Cannot create directory '" + exportData.getOutputFolder().getAbsolutePath() + "'");
}
}
String archiveName = exportData.getArchiveFileName() + ExportConstants.ARCHIVE_FILE_EXT;
File archiveFile = new File(exportData.getOutputFolder(), archiveName);
FileOutputStream exportStream = new FileOutputStream(archiveFile);
try {
ByteArrayOutputStream metaBuffer = new ByteArrayOutputStream(10000);
ZipOutputStream archiveStream = new ZipOutputStream(exportStream);
// Start meta
XMLBuilder meta = new XMLBuilder(metaBuffer, GeneralUtils.UTF8_ENCODING);
meta.startElement(ExportConstants.TAG_ARCHIVE);
meta.addAttribute(ExportConstants.ATTR_VERSION, ExportConstants.ARCHIVE_VERSION_CURRENT);
exportData.initExport(DBeaverCore.getInstance().getProjectRegistry(), meta, archiveStream);
{
// Export source info
meta.startElement(ExportConstants.TAG_SOURCE);
meta.addAttribute(ExportConstants.ATTR_TIME, Long.valueOf(System.currentTimeMillis()));
meta.addAttribute(ExportConstants.ATTR_ADDRESS, InetAddress.getLocalHost().getHostAddress());
meta.addAttribute(ExportConstants.ATTR_HOST, InetAddress.getLocalHost().getHostName());
meta.endElement();
}
Map<IProject, Integer> resCountMap = new HashMap<>();
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_collect_info, exportData.getProjectsToExport().size());
for (IProject project : exportData.getProjectsToExport()) {
// Add used drivers to export data
final DataSourceRegistry dataSourceRegistry = exportData.projectRegistry.getDataSourceRegistry(project);
if (dataSourceRegistry != null) {
for (DataSourceDescriptor dataSourceDescriptor : dataSourceRegistry.getDataSources()) {
exportData.usedDrivers.add(dataSourceDescriptor.getDriver());
}
}
resCountMap.put(project, getChildCount(exportData, project));
monitor.worked(1);
}
monitor.done();
{
// Export drivers meta
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_export_driver_info, 1);
exportData.meta.startElement(RegistryConstants.TAG_DRIVERS);
for (DriverDescriptor driver : exportData.usedDrivers) {
driver.serialize(exportData.meta, true);
}
exportData.meta.endElement();
monitor.done();
}
{
// Export projects
exportData.meta.startElement(ExportConstants.TAG_PROJECTS);
for (IProject project : exportData.getProjectsToExport()) {
monitor.beginTask(NLS.bind(CoreMessages.dialog_project_export_wizard_monitor_export_project, project.getName()), resCountMap.get(project));
try {
exportProject(monitor, exportData, project);
} finally {
monitor.done();
}
}
exportData.meta.endElement();
}
if (exportData.isExportDrivers()) {
// Export driver libraries
Set<File> libFiles = new HashSet<>();
Map<String, File> libPathMap = new HashMap<>();
for (DriverDescriptor driver : exportData.usedDrivers) {
for (DBPDriverLibrary fileDescriptor : driver.getDriverLibraries()) {
final File libraryFile = fileDescriptor.getLocalFile();
if (libraryFile != null && !fileDescriptor.isDisabled() && libraryFile.exists()) {
libFiles.add(libraryFile);
libPathMap.put(fileDescriptor.getPath(), libraryFile);
}
}
}
if (!libFiles.isEmpty()) {
monitor.beginTask(CoreMessages.dialog_project_export_wizard_monitor_export_libraries, libFiles.size());
// $NON-NLS-1$
final ZipEntry driversFolder = new ZipEntry(ExportConstants.DIR_DRIVERS + "/");
// $NON-NLS-1$
driversFolder.setComment("Database driver libraries");
exportData.archiveStream.putNextEntry(driversFolder);
exportData.archiveStream.closeEntry();
exportData.meta.startElement(ExportConstants.TAG_LIBRARIES);
Set<String> libFileNames = new HashSet<>();
for (String libPath : libPathMap.keySet()) {
final File libFile = libPathMap.get(libPath);
// Check for file name duplications
final String libFileName = libFile.getName();
if (libFileNames.contains(libFileName)) {
// $NON-NLS-1$
log.warn("Duplicate driver library file name: " + libFileName);
continue;
}
libFileNames.add(libFileName);
monitor.subTask(libFileName);
exportData.meta.startElement(RegistryConstants.TAG_FILE);
exportData.meta.addAttribute(ExportConstants.ATTR_PATH, libPath);
// $NON-NLS-1$
exportData.meta.addAttribute(ExportConstants.ATTR_FILE, "drivers/" + libFileName);
exportData.meta.endElement();
// $NON-NLS-1$
final ZipEntry driverFile = new ZipEntry(ExportConstants.DIR_DRIVERS + "/" + libFileName);
// $NON-NLS-1$
driverFile.setComment("Driver library");
exportData.archiveStream.putNextEntry(driverFile);
try (InputStream is = new FileInputStream(libFile)) {
IOUtils.copyStream(is, exportData.archiveStream, COPY_BUFFER_SIZE);
}
exportData.archiveStream.closeEntry();
monitor.worked(1);
}
exportData.meta.endElement();
monitor.done();
}
}
// Add meta to archive
{
exportData.meta.endElement();
exportData.meta.flush();
archiveStream.putNextEntry(new ZipEntry(ExportConstants.META_FILENAME));
archiveStream.write(metaBuffer.toByteArray());
archiveStream.closeEntry();
}
// Finish archive creation
archiveStream.finish();
} finally {
ContentUtils.close(exportStream);
}
}
Aggregations