diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDependencies.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDependencies.java index 297b1050881d41afaf536ef52ab9cc88441ae9b7..3dd794fe732b272e3b1629b0abd29fdac5a63118 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDependencies.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDependencies.java @@ -20,8 +20,7 @@ package org.jkiss.dbeaver.registry.driver; import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.connection.DBPDriverDependencies; import org.jkiss.dbeaver.model.connection.DBPDriverLibrary; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; -import org.jkiss.dbeaver.registry.maven.MavenContext; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import java.io.IOException; import java.util.*; @@ -34,7 +33,7 @@ public class DriverDependencies implements DBPDriverDependencies final List rootNodes = new ArrayList<>(); final List libraryList = new ArrayList<>(); - void resolveDependencies(MavenContext context, Collection rootLibraries) throws DBException { + void resolveDependencies(DBPDriverContext context, Collection rootLibraries) throws DBException { try { { rootNodes.clear(); @@ -44,7 +43,7 @@ public class DriverDependencies implements DBPDriverDependencies DependencyNode node = new DependencyNode(null, library); libMap.put(node.library.getId(), node.library); - resolveDependencies(context.getMonitor(), node, libMap); + resolveDependencies(context, node, libMap); rootNodes.add(node); } libraryList.clear(); @@ -86,9 +85,9 @@ public class DriverDependencies implements DBPDriverDependencies } } - private void resolveDependencies(DBRProgressMonitor monitor, DependencyNode ownerNode, Map libMap) throws IOException { - ownerNode.library.resolve(monitor); - Collection dependencies = ownerNode.library.getDependencies(monitor); + private void resolveDependencies(DBPDriverContext context, DependencyNode ownerNode, Map libMap) throws IOException { + ownerNode.library.resolve(context); + Collection dependencies = ownerNode.library.getDependencies(context); if (dependencies != null && !dependencies.isEmpty()) { for (DBPDriverLibrary dep : dependencies) { DependencyNode node = new DependencyNode(ownerNode, dep); @@ -101,7 +100,7 @@ public class DriverDependencies implements DBPDriverDependencies } for (DependencyNode node : ownerNode.dependencies) { if (!node.duplicate) { - resolveDependencies(monitor, node, libMap); + resolveDependencies(context, node, libMap); } } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDescriptor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDescriptor.java index edb321ba73c8f9d036b12d670e841bb562acfe75..0ef5cf0f61c721e7a6efd790490cd67d830be103 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDescriptor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverDescriptor.java @@ -39,7 +39,7 @@ import org.jkiss.dbeaver.model.runtime.OSDescriptor; import org.jkiss.dbeaver.registry.DataSourceDescriptor; import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor; import org.jkiss.dbeaver.registry.RegistryConstants; -import org.jkiss.dbeaver.registry.maven.MavenContext; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.dialogs.AcceptLicenseDialog; import org.jkiss.dbeaver.ui.dialogs.driver.DriverDownloadDialog; @@ -60,10 +60,10 @@ import java.util.*; */ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver { - public static final String PROP_DRIVERS_LOCATION = "DRIVERS_LOCATION"; static final Log log = Log.getLog(DriverDescriptor.class); public static final String DRIVERS_FOLDER = "drivers"; //$NON-NLS-1$ + public static final String PROP_DRIVERS_LOCATION = "DRIVERS_LOCATION"; public static final char URL_GROUP_START = '{'; //$NON-NLS-1$ public static final char URL_GROUP_END = '}'; //$NON-NLS-1$ @@ -614,7 +614,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver @Override public DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) throws DBException { if (dependencies == null) { - try (MavenContext mavenContext = new MavenContext(monitor)) { + try (DBPDriverContext mavenContext = new DBPDriverContext(monitor)) { DriverDependencies depsResolver = new DriverDependencies(); depsResolver.resolveDependencies(mavenContext, getDriverLibraries()); this.dependencies = depsResolver; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryAbstract.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryAbstract.java index 2e29ac1cbbdd87eca579055ab4d5ca734641b93b..1f48515a365a8165da598c701ec2c301dc0d9186 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryAbstract.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryAbstract.java @@ -21,8 +21,8 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.core.DBeaverCore; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.connection.DBPDriverLibrary; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.OSDescriptor; import org.jkiss.dbeaver.registry.RegistryConstants; import org.jkiss.dbeaver.runtime.RuntimeUtils; @@ -151,7 +151,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary return system == null || system.matches(DBeaverCore.getInstance().getLocalSystem()); } - public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName) throws IOException, InterruptedException + public void downloadLibraryFile(@NotNull DBPDriverContext context, boolean forceUpdate, String taskName) throws IOException, InterruptedException { final File localFile = getLocalFile(); if (localFile == null) { @@ -167,7 +167,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary } } - String externalURL = getExternalURL(monitor); + String externalURL = getExternalURL(context); if (externalURL == null) { throw new IOException("Unresolved file reference: " + getPath()); } @@ -185,7 +185,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary if (bufferLength < 50000) { bufferLength = 50000; } - monitor.beginTask(taskName + " - " + externalURL, contentLength); + context.getMonitor().beginTask(taskName + " - " + externalURL, contentLength); boolean success = false; try (final OutputStream outputStream = new FileOutputStream(localFile)) { try (final InputStream inputStream = connection.getInputStream()) { @@ -193,7 +193,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary byte[] buffer = new byte[bufferLength]; int totalRead = 0; for (;;) { - if (monitor.isCanceled()) { + if (context.getMonitor().isCanceled()) { throw new InterruptedException(); } //monitor.subTask(numberFormat.format(totalRead) + "/" + numberFormat.format(contentLength)); @@ -203,7 +203,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary break; } outputStream.write(buffer, 0, count); - monitor.worked(count); + context.getMonitor().worked(count); totalRead += count; } } @@ -213,7 +213,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary log.warn("Can't delete local driver file '" + localFile.getAbsolutePath() + "'"); } } - monitor.done(); + context.getMonitor().done(); } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryLocal.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryLocal.java index 1fc09ec40efb06c00afeacd073bb481d7d5b298c..6efc4da792aa59bdd01f4e375bbece99189f5891 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryLocal.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryLocal.java @@ -23,8 +23,8 @@ import org.eclipse.core.runtime.Platform; import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; import org.jkiss.dbeaver.model.DBIcon; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.connection.DBPDriverLibrary; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.ui.UIIcon; import java.io.File; @@ -58,7 +58,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract } @Override - public void resolve(DBRProgressMonitor monitor) throws IOException { + public void resolve(DBPDriverContext context) throws IOException { // do nothing } @@ -68,7 +68,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract @Nullable @Override - public String getExternalURL(DBRProgressMonitor monitor) { + public String getExternalURL(DBPDriverContext context) { return null; } @@ -115,7 +115,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract @Nullable @Override - public Collection getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException { + public Collection getDependencies(@NotNull DBPDriverContext context) throws IOException { return null; } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenArtifact.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenArtifact.java index 74f68de05beaa4f15aa96c5a3658b23a54a77e81..5501f30d2ff697b16914a488bc6eac9e7f6aefd6 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenArtifact.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenArtifact.java @@ -22,8 +22,9 @@ import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.DBIcon; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.connection.DBPDriverLibrary; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.registry.maven.*; import org.jkiss.dbeaver.ui.UIIcon; import org.jkiss.utils.CommonUtils; @@ -74,8 +75,8 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract } @Override - public void resolve(DBRProgressMonitor monitor) throws IOException { - if (getArtifactVersion(monitor) == null) { + public void resolve(DBPDriverContext context) throws IOException { + if (getArtifactVersion(context) == null) { throw new IOException("Can't resolve artifact " + this + " version"); } } @@ -83,23 +84,25 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract @Nullable protected MavenArtifactVersion getCachedArtifactVersion() { if (localVersion == null) { - localVersion = MavenRegistry.getInstance().findCachedArtifact(reference); + try (DBPDriverContext context = new DBPDriverContext(VoidProgressMonitor.INSTANCE)) { + localVersion = MavenRegistry.getInstance().findCachedArtifact(context, reference); + } } return localVersion; } @Nullable - protected MavenArtifactVersion getArtifactVersion(DBRProgressMonitor monitor) { + protected MavenArtifactVersion getArtifactVersion(DBPDriverContext context) { if (localVersion == null) { - localVersion = MavenRegistry.getInstance().findArtifact(monitor, reference); + localVersion = MavenRegistry.getInstance().findArtifact(context, reference); } return localVersion; } @Nullable @Override - public String getExternalURL(DBRProgressMonitor monitor) { - MavenArtifactVersion localVersion = getArtifactVersion(monitor); + public String getExternalURL(DBPDriverContext context) { + MavenArtifactVersion localVersion = getArtifactVersion(context); if (localVersion != null) { return localVersion.getExternalURL(MavenArtifact.FILE_JAR); } @@ -132,18 +135,18 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract @Nullable @Override - public Collection getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException { + public Collection getDependencies(@NotNull DBPDriverContext context) throws IOException { List dependencies = new ArrayList<>(); - MavenArtifactVersion localVersion = resolveLocalVersion(monitor, false); + MavenArtifactVersion localVersion = resolveLocalVersion(context, false); if (localVersion != null) { - List artifactDeps = localVersion.getDependencies(monitor); + List artifactDeps = localVersion.getDependencies(context); if (!CommonUtils.isEmpty(artifactDeps)) { for (MavenArtifactDependency dependency : artifactDeps) { - if (isDependencyExcluded(monitor, dependency)) { + if (isDependencyExcluded(context, dependency)) { continue; } - MavenArtifactVersion depArtifact = MavenRegistry.getInstance().findArtifact(monitor, dependency); + MavenArtifactVersion depArtifact = MavenRegistry.getInstance().findArtifact(context, dependency); if (depArtifact != null) { dependencies.add( new DriverLibraryMavenDependency( @@ -160,7 +163,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract return dependencies; } - protected boolean isDependencyExcluded(DBRProgressMonitor monitor, MavenArtifactDependency dependency) { + protected boolean isDependencyExcluded(DBPDriverContext context, MavenArtifactDependency dependency) { return false; } @@ -190,10 +193,10 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract return UIIcon.APACHE; } - public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName) throws IOException, InterruptedException { + public void downloadLibraryFile(@NotNull DBPDriverContext context, boolean forceUpdate, String taskName) throws IOException, InterruptedException { //monitor.beginTask(taskName + " - update localVersion information", 1); try { - MavenArtifactVersion localVersion = resolveLocalVersion(monitor, forceUpdate); + MavenArtifactVersion localVersion = resolveLocalVersion(context, forceUpdate); if (localVersion.getArtifact().getRepository().isLocal()) { // No need to download local artifacts return; @@ -201,14 +204,14 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract } finally { //monitor.done(); } - super.downloadLibraryFile(monitor, forceUpdate, taskName); + super.downloadLibraryFile(context, forceUpdate, taskName); } - protected MavenArtifactVersion resolveLocalVersion(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException { + protected MavenArtifactVersion resolveLocalVersion(DBPDriverContext context, boolean forceUpdate) throws IOException { if (forceUpdate) { MavenRegistry.getInstance().resetArtifactInfo(reference); } - MavenArtifactVersion version = getArtifactVersion(monitor); + MavenArtifactVersion version = getArtifactVersion(context); if (version == null) { throw new IOException("Maven artifact '" + path + "' not found"); } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenDependency.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenDependency.java index ba7a87309facd032225ca68b15b887881720ee67..eef128424cd6dfa1d97a13796e1e0b4783d31dbb 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenDependency.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryMavenDependency.java @@ -17,7 +17,7 @@ */ package org.jkiss.dbeaver.registry.driver; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.registry.maven.MavenArtifactDependency; import org.jkiss.dbeaver.registry.maven.MavenArtifactReference; import org.jkiss.dbeaver.registry.maven.MavenArtifactVersion; @@ -44,7 +44,7 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact return true; } - protected boolean isDependencyExcluded(DBRProgressMonitor monitor, MavenArtifactDependency dependency) { + protected boolean isDependencyExcluded(DBPDriverContext context, MavenArtifactDependency dependency) { List exclusions = source.getExclusions(); if (exclusions != null) { for (MavenArtifactReference exReference : exclusions) { @@ -54,7 +54,7 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact } } - return parent.isDependencyExcluded(monitor, dependency); + return parent.isDependencyExcluded(context, dependency); } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryRepository.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryRepository.java index 8782063eb8280fb4d768d9ef3e8b4c0142aed59f..e1f110fac975759417b339711ae64f3abe060775 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryRepository.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/driver/DriverLibraryRepository.java @@ -19,7 +19,7 @@ package org.jkiss.dbeaver.registry.driver; import org.eclipse.core.runtime.IConfigurationElement; import org.jkiss.code.Nullable; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; /** * DriverLibraryDescriptor @@ -49,7 +49,7 @@ public class DriverLibraryRepository extends DriverLibraryLocal @Nullable @Override - public String getExternalURL(DBRProgressMonitor monitor) { + public String getExternalURL(DBPDriverContext context) { String localPath = getLocalFilePath(); String primarySource = DriverDescriptor.getDriversPrimarySource(); if (!primarySource.endsWith("/") && !localPath.startsWith("/")) { diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java index 9b347508195f02ea3f629cc434caa5f1200b804a..32035c33890413c9d8eed16ab3ec588e978f9b59 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java @@ -20,7 +20,7 @@ package org.jkiss.dbeaver.registry.maven; import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; import org.jkiss.dbeaver.Log; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.registry.maven.versioning.DefaultArtifactVersion; import org.jkiss.dbeaver.registry.maven.versioning.VersionRange; @@ -71,14 +71,14 @@ public class MavenArtifact this.artifactId = artifactId; } - public void loadMetadata(DBRProgressMonitor monitor) throws IOException { + public void loadMetadata(DBPDriverContext context) throws IOException { latestVersion = null; releaseVersion = null; versions.clear(); lastUpdate = null; String metadataPath = getArtifactURL() + MAVEN_METADATA_XML; - monitor.subTask("Load metadata " + this + ""); + context.getMonitor().subTask("Load metadata " + this + ""); try (InputStream mdStream = RuntimeUtils.openConnectionStream(metadataPath)) { parseMetadata(mdStream); @@ -92,7 +92,7 @@ public class MavenArtifact log.warn("Error parsing artifact directory", e); } } finally { - monitor.worked(1); + context.getMonitor().worked(1); } metadataLoaded = true; } @@ -220,10 +220,10 @@ public class MavenArtifact localVersions.add(version); } - private MavenArtifactVersion makeLocalVersion(DBRProgressMonitor monitor, String versionStr, boolean setActive) throws IllegalArgumentException, IOException { + private MavenArtifactVersion makeLocalVersion(DBPDriverContext context, String versionStr, boolean setActive) throws IllegalArgumentException, IOException { MavenArtifactVersion version = getVersion(versionStr); if (version == null) { - version = new MavenArtifactVersion(monitor, this, versionStr, true); + version = new MavenArtifactVersion(context, this, versionStr, true); localVersions.add(version); } if (setActive) { @@ -233,19 +233,19 @@ public class MavenArtifact return version; } - public MavenArtifactVersion resolveActiveVersion() throws IOException { + public MavenArtifactVersion resolveActiveVersion(DBPDriverContext context) throws IOException { if (CommonUtils.isEmpty(activeVersion)) { return null; } MavenArtifactVersion version = getVersion(activeVersion); if (version == null) { - version = new MavenArtifactVersion(VoidProgressMonitor.INSTANCE, this, activeVersion, false); + version = new MavenArtifactVersion(context, this, activeVersion, false); localVersions.add(version); } return version; } - public MavenArtifactVersion resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException { + public MavenArtifactVersion resolveVersion(DBPDriverContext context, String versionRef) throws IOException { if (CommonUtils.isEmpty(versionRef)) { throw new IOException("Empty artifact " + this + " version"); } @@ -269,7 +269,7 @@ public class MavenArtifact } } if (lookupVersion && !metadataLoaded) { - loadMetadata(monitor); + loadMetadata(context); } String versionInfo; @@ -323,7 +323,7 @@ public class MavenArtifact MavenArtifactVersion localVersion = getVersion(versionInfo); if (localVersion == null) { - localVersion = makeLocalVersion(monitor, versionInfo, lookupVersion); + localVersion = makeLocalVersion(context, versionInfo, lookupVersion); } return localVersion; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java index f22d847fc512c9bd07f977a0c75da391e2367d48..d72b52717169abe4b734b113ef42bfb490bcef89 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java @@ -18,10 +18,8 @@ package org.jkiss.dbeaver.registry.maven; import org.jkiss.code.NotNull; -import org.jkiss.code.Nullable; import org.jkiss.dbeaver.Log; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; -import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.runtime.RuntimeUtils; import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.utils.CommonUtils; @@ -86,16 +84,10 @@ public class MavenArtifactVersion { } }; - /** - * Makes new version - * @param monitor if null then do not try to get remote POM - * @param readRemote - * @throws IOException - */ - MavenArtifactVersion(@NotNull DBRProgressMonitor monitor, @NotNull MavenArtifact artifact, @NotNull String version, boolean readRemote) throws IOException { + MavenArtifactVersion(@NotNull DBPDriverContext context, @NotNull MavenArtifact artifact, @NotNull String version, boolean readRemote) throws IOException { this.artifact = artifact; this.version = version; - loadPOM(monitor, readRemote); + loadPOM(context, readRemote); } public MavenArtifact getArtifact() { @@ -126,7 +118,7 @@ public class MavenArtifactVersion { return licenses; } - public List getDependencies(DBRProgressMonitor monitor) { + public List getDependencies(DBPDriverContext context) { List dependencies = new ArrayList<>(); for (MavenProfile profile : profiles) { if (profile.isActive() && !CommonUtils.isEmpty(profile.dependencies)) { @@ -134,7 +126,7 @@ public class MavenArtifactVersion { } } if (parent != null) { - List parentDependencies = parent.getDependencies(monitor); + List parentDependencies = parent.getDependencies(context); if (!CommonUtils.isEmpty(parentDependencies)) { dependencies.addAll(parentDependencies); } @@ -185,7 +177,7 @@ public class MavenArtifactVersion { return artifact.getFileURL(version, MavenArtifact.FILE_POM); } - private void loadPOM(DBRProgressMonitor monitor, boolean readRemote) throws IOException { + private void loadPOM(DBPDriverContext context, boolean readRemote) throws IOException { File localPOM = getLocalPOM(); if (!localPOM.exists()) { if (readRemote) { @@ -196,7 +188,7 @@ public class MavenArtifactVersion { } } - monitor.subTask("Load POM " + this); + context.getMonitor().subTask("Load POM " + this); Document pomDocument; try (InputStream mdStream = new FileInputStream(localPOM)) { @@ -227,7 +219,7 @@ public class MavenArtifactVersion { if (this.version == null) { this.version = parentReference.getVersion(); } - parent = MavenRegistry.getInstance().findArtifact(monitor, parentReference); + parent = MavenRegistry.getInstance().findArtifact(context, parentReference); if (parent == null) { log.error("Artifact [" + this + "] parent [" + parentReference + "] not found"); } @@ -252,7 +244,7 @@ public class MavenArtifactVersion { MavenProfile defaultProfile = new MavenProfile(DEFAULT_PROFILE_ID); defaultProfile.active = true; profiles.add(defaultProfile); - parseProfile(monitor, defaultProfile, root); + parseProfile(context, defaultProfile, root); { // Profiles @@ -261,15 +253,15 @@ public class MavenArtifactVersion { for (Element profElement : XMLUtils.getChildElementList(licensesElement, "profile")) { MavenProfile profile = new MavenProfile(XMLUtils.getChildElementBody(profElement, "id")); profiles.add(profile); - parseProfile(monitor, profile, profElement); + parseProfile(context, profile, profElement); } } } - monitor.worked(1); + context.getMonitor().worked(1); } - private void parseProfile(DBRProgressMonitor monitor, MavenProfile profile, Element element) { + private void parseProfile(DBPDriverContext context, MavenProfile profile, Element element) { { // Activation Element activationElement = XMLUtils.getChildElement(element, "activation"); @@ -314,9 +306,9 @@ public class MavenArtifactVersion { // Dependencies Element dmElement = XMLUtils.getChildElement(element, "dependencyManagement"); if (dmElement != null) { - profile.dependencyManagement = parseDependencies(monitor, dmElement, true); + profile.dependencyManagement = parseDependencies(context, dmElement, true); } - profile.dependencies = parseDependencies(monitor, element, false); + profile.dependencies = parseDependencies(context, element, false); } } @@ -337,7 +329,7 @@ public class MavenArtifactVersion { } } - private List parseDependencies(DBRProgressMonitor monitor, Element element, boolean depManagement) { + private List parseDependencies(DBPDriverContext context, Element element, boolean depManagement) { List result = new ArrayList<>(); Element dependenciesElement = XMLUtils.getChildElement(element, "dependencies"); if (dependenciesElement != null) { @@ -367,7 +359,7 @@ public class MavenArtifactVersion { groupId, artifactId, version); - MavenArtifactVersion importedVersion = MavenRegistry.getInstance().findArtifact(monitor, importReference); + MavenArtifactVersion importedVersion = MavenRegistry.getInstance().findArtifact(context, importReference); if (importedVersion == null) { log.error("Imported artifact [" + importReference + "] not found. Skip."); } @@ -379,7 +371,7 @@ public class MavenArtifactVersion { // TODO: maybe we should include optional or PROVIDED if (version == null) { - version = findDependencyVersion(monitor, groupId, artifactId); + version = findDependencyVersion(context, groupId, artifactId); } if (version == null) { log.error("Can't resolve artifact [" + groupId + ":" + artifactId + "] version. Skip."); @@ -421,7 +413,7 @@ public class MavenArtifactVersion { scope == MavenArtifactDependency.Scope.PROVIDED*/; } - private String findDependencyVersion(DBRProgressMonitor monitor, String groupId, String artifactId) { + private String findDependencyVersion(DBPDriverContext context, String groupId, String artifactId) { for (MavenProfile profile : profiles) { if (profile.isActive() && profile.dependencyManagement != null) { for (MavenArtifactDependency dmArtifact : profile.dependencyManagement) { @@ -435,13 +427,13 @@ public class MavenArtifactVersion { // Check in imported BOMs if (imports != null) { for (MavenArtifactVersion i : imports) { - String dependencyVersion = i.findDependencyVersion(monitor, groupId, artifactId); + String dependencyVersion = i.findDependencyVersion(context, groupId, artifactId); if (dependencyVersion != null) { return dependencyVersion; } } } - return parent == null ? null : parent.findDependencyVersion(monitor, groupId, artifactId); + return parent == null ? null : parent.findDependencyVersion(context, groupId, artifactId); } private String evaluateString(String value) { diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContext.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContextInfo.java similarity index 67% rename from plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContext.java rename to plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContextInfo.java index da88827f614021ca49b75936baad1dcbdb606518..798af615048666e7ac22a254373b9c0cfaeef98d 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContext.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenContextInfo.java @@ -17,37 +17,19 @@ */ package org.jkiss.dbeaver.registry.maven; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; - -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; /** - * Maven resolve context + * Driver resolve context */ -public class MavenContext implements AutoCloseable { +public class MavenContextInfo { - private final DBRProgressMonitor monitor; - private final Date initTime = new Date(); - private final Map properties = new HashMap<>(); private final Map> artifactRepositories = new LinkedHashMap<>(); private final List activeRepositories = new ArrayList<>(); - public MavenContext(DBRProgressMonitor monitor) { - this.monitor = monitor; - } - - public DBRProgressMonitor getMonitor() { - return monitor; - } - - public Date getInitTime() { - return initTime; - } - - public Map getProperties() { - return properties; - } - public List getActiveRepositories() { return activeRepositories; } @@ -60,8 +42,4 @@ public class MavenContext implements AutoCloseable { artifactRepositories.remove(artifactVersion); } - @Override - public void close() { - - } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java index 6c167b27aba7206925c61f8117bd46d9807fa6ae..ce07dab89bff82a72f77d7c15b8446879aa201ee 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java @@ -25,6 +25,7 @@ import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; import org.jkiss.dbeaver.DBeaverPreferences; import org.jkiss.dbeaver.core.DBeaverCore; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.runtime.AbstractJob; import org.jkiss.utils.CommonUtils; @@ -133,12 +134,12 @@ public class MavenRegistry } @Nullable - public MavenArtifactVersion findArtifact(@NotNull DBRProgressMonitor monitor, @NotNull MavenArtifactReference ref) { + public MavenArtifactVersion findArtifact(@NotNull DBPDriverContext context, @NotNull MavenArtifactReference ref) { String fullId = ref.getId(); if (notFoundArtifacts.contains(fullId)) { return null; } - MavenArtifactVersion artifact = findInRepositories(monitor, ref); + MavenArtifactVersion artifact = findInRepositories(context, ref); if (artifact != null) { return artifact; } @@ -149,19 +150,19 @@ public class MavenRegistry } @Nullable - public MavenArtifactVersion findCachedArtifact(@NotNull MavenArtifactReference ref) { + public MavenArtifactVersion findCachedArtifact(DBPDriverContext context, @NotNull MavenArtifactReference ref) { String fullId = ref.getId(); if (notFoundArtifacts.contains(fullId)) { return null; } // Try all available repositories (without resolve) for (MavenRepository repository : repositories) { - MavenArtifactVersion artifact = repository.findCachedArtifact(ref); + MavenArtifactVersion artifact = repository.findCachedArtifact(context, ref); if (artifact != null) { return artifact; } } - MavenArtifactVersion artifact = localRepository.findCachedArtifact(ref); + MavenArtifactVersion artifact = localRepository.findCachedArtifact(context, ref); if (artifact != null) { return artifact; } @@ -178,15 +179,15 @@ public class MavenRegistry } @Nullable - private MavenArtifactVersion findInRepositories(@NotNull DBRProgressMonitor monitor, @NotNull MavenArtifactReference ref) { + private MavenArtifactVersion findInRepositories(@NotNull DBPDriverContext context, @NotNull MavenArtifactReference ref) { // Try all available repositories (without resolve) for (MavenRepository repository : repositories) { - MavenArtifactVersion artifact = repository.findArtifact(monitor, ref); + MavenArtifactVersion artifact = repository.findArtifact(context, ref); if (artifact != null) { return artifact; } } - MavenArtifactVersion artifact = localRepository.findArtifact(monitor, ref); + MavenArtifactVersion artifact = localRepository.findArtifact(context, ref); if (artifact != null) { return artifact; } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java index 66f3e3466f933a89dc95ef1445b8808332bd787a..039eb106664dfb2ebe13975f416b9b4d29af0eea 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java @@ -22,7 +22,7 @@ import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.core.DBeaverActivator; -import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.registry.RegistryConstants; import org.jkiss.utils.CommonUtils; @@ -112,7 +112,7 @@ public class MavenRepository } @Nullable - public synchronized MavenArtifactVersion findArtifact(DBRProgressMonitor monitor, @NotNull MavenArtifactReference ref) { + public synchronized MavenArtifactVersion findArtifact(DBPDriverContext context, @NotNull MavenArtifactReference ref) { boolean newArtifact = false; MavenArtifact artifact = cachedArtifacts.get(ref.getId()); if (artifact == null) { @@ -120,7 +120,7 @@ public class MavenRepository newArtifact = true; } try { - MavenArtifactVersion version = artifact.resolveVersion(monitor, ref.getVersion()); + MavenArtifactVersion version = artifact.resolveVersion(context, ref.getVersion()); if (newArtifact) { cachedArtifacts.put(ref.getId(), artifact); flushCache(); @@ -132,7 +132,7 @@ public class MavenRepository } } - public MavenArtifactVersion findCachedArtifact(MavenArtifactReference ref) { + public MavenArtifactVersion findCachedArtifact(DBPDriverContext context, MavenArtifactReference ref) { MavenArtifact artifact = cachedArtifacts.get(ref.getId()); if (artifact == null) { return null; @@ -141,7 +141,7 @@ public class MavenRepository if (version == null && !CommonUtils.isEmpty(artifact.getActiveVersionName())) { // Resolve active version try { - version = artifact.resolveActiveVersion(); + version = artifact.resolveActiveVersion(context); } catch (IOException e) { log.warn("Can't resolve cached active version " + ref); } @@ -170,6 +170,7 @@ public class MavenRepository if (!cacheFile.exists()) { return; } + final DBPDriverContext context = new DBPDriverContext(VoidProgressMonitor.INSTANCE); try { InputStream mdStream = new FileInputStream(cacheFile); try { @@ -191,7 +192,7 @@ public class MavenRepository String versionNumber = atts.getValue(ATTR_VERSION); try { MavenArtifactVersion version = new MavenArtifactVersion( - VoidProgressMonitor.INSTANCE, + context, lastArtifact, versionNumber, false); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/driver/DriverDownloadAutoPage.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/driver/DriverDownloadAutoPage.java index de85a2aabbbedc55360da316e7c7c7dc0d8a7c7a..bfa0018cbbcd9f53b300080e3da7d1382497a77f 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/driver/DriverDownloadAutoPage.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/dialogs/driver/DriverDownloadAutoPage.java @@ -23,6 +23,7 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.*; +import org.jkiss.dbeaver.model.connection.DBPDriverContext; import org.jkiss.dbeaver.model.connection.DBPDriverDependencies; import org.jkiss.dbeaver.model.connection.DBPDriverLibrary; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; @@ -170,48 +171,12 @@ class DriverDownloadAutoPage extends DriverDownloadPage { return; } - List files = dependencies.getLibraryList(); - for (int i = 0, filesSize = files.size(); i < filesSize; ) { - DBPDriverLibrary lib = files.get(i); - int result = downloadLibraryFile(runnableContext, lib, "Download " + (i + 1) + "/" + filesSize); - 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; - } - } - } - - private int downloadLibraryFile(DBRRunnableContext runnableContext, final DBPDriverLibrary file, final String taskName) - { try { - runnableContext.run(true, true, new DBRRunnableWithProgress() { - @Override - public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - file.downloadLibraryFile(monitor, false, taskName); - } catch (IOException e) { - throw new InvocationTargetException(e); - } - } - }); - return IDialogConstants.OK_ID; - } catch (InterruptedException e) { - // User just canceled download - return IDialogConstants.CANCEL_ID; + runnableContext.run(true, true, new LibraryDownloader()); } catch (InvocationTargetException e) { - if (file.getType() == DBPDriverLibrary.FileType.license) { - return IDialogConstants.OK_ID; - } - DownloadRetry retryConfirm = new DownloadRetry(file, e.getTargetException()); - UIUtils.runInUI(null, retryConfirm); - return retryConfirm.result; + UIUtils.showErrorDialog(getShell(), "Driver download", "Error downloading driver files", e.getTargetException()); + } catch (InterruptedException e) { + // ignore } } @@ -282,4 +247,38 @@ class DriverDownloadAutoPage extends DriverDownloadPage { } } + private class LibraryDownloader implements DBRRunnableWithProgress { + @Override + public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + DBPDriverContext context = new DBPDriverContext(monitor); + + List files = dependencies.getLibraryList(); + for (int i = 0, filesSize = files.size(); i < filesSize; ) { + DBPDriverLibrary lib = files.get(i); + int result = IDialogConstants.OK_ID; + try { + lib.downloadLibraryFile(context, false, "Download " + (i + 1) + "/" + filesSize); + } catch (IOException e) { + if (lib.getType() == DBPDriverLibrary.FileType.license) { + result = IDialogConstants.OK_ID; + } else { + DownloadRetry retryConfirm = new DownloadRetry(lib, e); + UIUtils.runInUI(null, retryConfirm); + result = retryConfirm.result; + } + } + 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; + } + } + } + } } diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverContext.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverContext.java new file mode 100644 index 0000000000000000000000000000000000000000..c2203a860a43e38f019c9099542c84eaf8f0452b --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverContext.java @@ -0,0 +1,70 @@ +/* + * 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.model.connection; + +import org.jkiss.dbeaver.Log; +import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; + +import java.util.*; + +/** + * Driver resolve context + */ +public class DBPDriverContext implements AutoCloseable { + + static final Log log = Log.getLog(DBPDriverContext.class); + + private final DBRProgressMonitor monitor; + private final Date initTime = new Date(); + private final Map properties = new HashMap<>(); + private final Map infoMap = new HashMap<>(); + + public DBPDriverContext(DBRProgressMonitor monitor) { + this.monitor = monitor; + } + + public DBRProgressMonitor getMonitor() { + return monitor; + } + + public Date getInitTime() { + return initTime; + } + + public Map getProperties() { + return properties; + } + + public T getInfo(Class type) { + Object o = infoMap.get(type); + if (o == null) { + try { + o = type.newInstance(); + } catch (Exception e) { + log.error("Can't create context info " + type.getName(), e); + } + infoMap.put(type, o); + } + return type.cast(o); + } + + @Override + public void close() { + + } +} diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverLibrary.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverLibrary.java index a555dc6e36ba531d0b73be4fba666391955eb376..70ff79d145c5691a1a308db8450aedfce78686e5 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverLibrary.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/connection/DBPDriverLibrary.java @@ -79,16 +79,16 @@ public interface DBPDriverLibrary boolean isDisabled(); - void setDisabled(boolean diabled); + void setDisabled(boolean disabled); boolean isDownloadable(); boolean isResolved(); - void resolve(DBRProgressMonitor monitor) throws IOException; + void resolve(DBPDriverContext context) throws IOException; @Nullable - String getExternalURL(DBRProgressMonitor monitor); + String getExternalURL(DBPDriverContext context); @Nullable File getLocalFile(); @@ -96,8 +96,8 @@ public interface DBPDriverLibrary boolean matchesCurrentPlatform(); @Nullable - Collection getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException; + Collection getDependencies(@NotNull DBPDriverContext context) throws IOException; - void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName) + void downloadLibraryFile(@NotNull DBPDriverContext context, boolean forceUpdate, String taskName) throws IOException, InterruptedException; }