提交 01d30c1f 编写于 作者: J jurgen

Get rid of driver context

Former-commit-id: 5a64c29e
上级 7a616b88
......@@ -20,7 +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.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.io.IOException;
import java.util.*;
......@@ -39,7 +39,7 @@ public class DriverDependencies implements DBPDriverDependencies
}
@Override
public void resolveDependencies(DBPDriverContext context) throws DBException {
public void resolveDependencies(DBRProgressMonitor monitor) throws DBException {
try {
{
rootNodes.clear();
......@@ -49,7 +49,7 @@ public class DriverDependencies implements DBPDriverDependencies
DependencyNode node = new DependencyNode(null, library);
libMap.put(node.library.getId(), node.library);
resolveDependencies(context, node, libMap);
resolveDependencies(monitor, node, libMap);
rootNodes.add(node);
}
libraryList.clear();
......@@ -70,12 +70,10 @@ public class DriverDependencies implements DBPDriverDependencies
}
System.out.println(sb.toString());
*/
/*
System.out.println("---------------------------");
for (DependencyNode node : rootNodes) {
dumpNode(node, 0);
}
*/
}
} catch (IOException e) {
throw new DBException("IO error while resolving dependencies", e);
......@@ -93,9 +91,9 @@ public class DriverDependencies implements DBPDriverDependencies
}
}
private void resolveDependencies(DBPDriverContext context, DependencyNode ownerNode, Map<String, DBPDriverLibrary> libMap) throws IOException {
ownerNode.library.resolve(context);
Collection<? extends DBPDriverLibrary> dependencies = ownerNode.library.getDependencies(context);
private void resolveDependencies(DBRProgressMonitor monitor, DependencyNode ownerNode, Map<String, DBPDriverLibrary> libMap) throws IOException {
ownerNode.library.resolve(monitor);
Collection<? extends DBPDriverLibrary> dependencies = ownerNode.library.getDependencies(monitor);
if (dependencies != null && !dependencies.isEmpty()) {
for (DBPDriverLibrary dep : dependencies) {
DependencyNode node = new DependencyNode(ownerNode, dep);
......@@ -108,7 +106,7 @@ public class DriverDependencies implements DBPDriverDependencies
}
for (DependencyNode node : ownerNode.dependencies) {
if (!node.duplicate) {
resolveDependencies(context, node, libMap);
resolveDependencies(monitor, node, libMap);
}
}
}
......
......@@ -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 DBPDriverContext context, boolean forceUpdate, String taskName) throws IOException, InterruptedException
public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, 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(context);
String externalURL = getExternalURL(monitor);
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;
}
context.getMonitor().beginTask(taskName + " - " + externalURL, contentLength);
monitor.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 (context.getMonitor().isCanceled()) {
if (monitor.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);
context.getMonitor().worked(count);
monitor.worked(count);
totalRead += count;
}
}
......@@ -213,7 +213,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
log.warn("Can't delete local driver file '" + localFile.getAbsolutePath() + "'");
}
}
context.getMonitor().done();
monitor.done();
}
}
......
......@@ -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(DBPDriverContext context) throws IOException {
public void resolve(DBRProgressMonitor monitor) throws IOException {
// do nothing
}
......@@ -68,7 +68,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
@Nullable
@Override
public String getExternalURL(DBPDriverContext context) {
public String getExternalURL(DBRProgressMonitor monitor) {
return null;
}
......@@ -115,7 +115,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
@Nullable
@Override
public Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBPDriverContext context) throws IOException {
public Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException {
return null;
}
......
......@@ -22,8 +22,8 @@ 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.registry.maven.*;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.utils.CommonUtils;
......@@ -74,24 +74,24 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
}
@Override
public void resolve(DBPDriverContext context) throws IOException {
if (getArtifactVersion(context) == null) {
public void resolve(DBRProgressMonitor monitor) throws IOException {
if (getArtifactVersion(monitor) == null) {
throw new IOException("Can't resolve artifact " + this + " version");
}
}
@Nullable
protected MavenArtifactVersion getArtifactVersion(DBPDriverContext context) {
protected MavenArtifactVersion getArtifactVersion(DBRProgressMonitor monitor) {
if (localVersion == null) {
localVersion = MavenRegistry.getInstance().findArtifact(context, null, reference);
localVersion = MavenRegistry.getInstance().findArtifact(monitor, null, reference);
}
return localVersion;
}
@Nullable
@Override
public String getExternalURL(DBPDriverContext context) {
MavenArtifactVersion localVersion = getArtifactVersion(context);
public String getExternalURL(DBRProgressMonitor monitor) {
MavenArtifactVersion localVersion = getArtifactVersion(monitor);
if (localVersion != null) {
return localVersion.getExternalURL(MavenArtifact.FILE_JAR);
}
......@@ -123,19 +123,19 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Nullable
@Override
public Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBPDriverContext context) throws IOException {
public Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException {
List<DriverLibraryMavenDependency> dependencies = new ArrayList<>();
MavenArtifactVersion localVersion = resolveLocalVersion(context, false);
MavenArtifactVersion localVersion = resolveLocalVersion(monitor, false);
if (localVersion != null) {
List<MavenArtifactDependency> artifactDeps = localVersion.getDependencies(context);
List<MavenArtifactDependency> artifactDeps = localVersion.getDependencies(monitor);
if (!CommonUtils.isEmpty(artifactDeps)) {
for (MavenArtifactDependency dependency : artifactDeps) {
if (isDependencyExcluded(context, dependency)) {
if (isDependencyExcluded(monitor, dependency)) {
continue;
}
MavenArtifactVersion depArtifact = MavenRegistry.getInstance().findArtifact(context, localVersion, dependency);
MavenArtifactVersion depArtifact = MavenRegistry.getInstance().findArtifact(monitor, localVersion, dependency);
if (depArtifact != null) {
dependencies.add(
new DriverLibraryMavenDependency(
......@@ -152,7 +152,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
return dependencies;
}
protected boolean isDependencyExcluded(DBPDriverContext context, MavenArtifactDependency dependency) {
protected boolean isDependencyExcluded(DBRProgressMonitor monitor, MavenArtifactDependency dependency) {
return false;
}
......@@ -181,10 +181,10 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
return UIIcon.APACHE;
}
public void downloadLibraryFile(@NotNull DBPDriverContext context, boolean forceUpdate, String taskName) throws IOException, InterruptedException {
public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName) throws IOException, InterruptedException {
//monitor.beginTask(taskName + " - update localVersion information", 1);
try {
MavenArtifactVersion localVersion = resolveLocalVersion(context, forceUpdate);
MavenArtifactVersion localVersion = resolveLocalVersion(monitor, forceUpdate);
if (localVersion.getArtifact().getRepository().getType() == MavenRepository.RepositoryType.LOCAL) {
// No need to download local artifacts
return;
......@@ -192,14 +192,14 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
} finally {
//monitor.done();
}
super.downloadLibraryFile(context, forceUpdate, taskName);
super.downloadLibraryFile(monitor, forceUpdate, taskName);
}
protected MavenArtifactVersion resolveLocalVersion(DBPDriverContext context, boolean forceUpdate) throws IOException {
protected MavenArtifactVersion resolveLocalVersion(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException {
if (forceUpdate) {
MavenRegistry.getInstance().resetArtifactInfo(reference);
}
MavenArtifactVersion version = getArtifactVersion(context);
MavenArtifactVersion version = getArtifactVersion(monitor);
if (version == null) {
throw new IOException("Maven artifact '" + path + "' not found");
}
......
......@@ -17,7 +17,7 @@
*/
package org.jkiss.dbeaver.registry.driver;
import org.jkiss.dbeaver.model.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
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(DBPDriverContext context, MavenArtifactDependency dependency) {
protected boolean isDependencyExcluded(DBRProgressMonitor monitor, MavenArtifactDependency dependency) {
List<MavenArtifactReference> exclusions = source.getExclusions();
if (exclusions != null) {
for (MavenArtifactReference exReference : exclusions) {
......@@ -54,7 +54,7 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
}
}
return parent.isDependencyExcluded(context, dependency);
return parent.isDependencyExcluded(monitor, dependency);
}
}
......@@ -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.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
/**
* DriverLibraryDescriptor
......@@ -49,7 +49,7 @@ public class DriverLibraryRepository extends DriverLibraryLocal
@Nullable
@Override
public String getExternalURL(DBPDriverContext context) {
public String getExternalURL(DBRProgressMonitor monitor) {
String localPath = getLocalFilePath();
String primarySource = DriverDescriptor.getDriversPrimarySource();
if (!primarySource.endsWith("/") && !localPath.startsWith("/")) {
......
......@@ -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.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.maven.versioning.DefaultArtifactVersion;
import org.jkiss.dbeaver.registry.maven.versioning.VersionRange;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
......@@ -70,14 +70,14 @@ public class MavenArtifact
this.artifactId = artifactId;
}
public void loadMetadata(DBPDriverContext context) throws IOException {
public void loadMetadata(DBRProgressMonitor monitor) throws IOException {
latestVersion = null;
releaseVersion = null;
versions.clear();
lastUpdate = null;
String metadataPath = getArtifactURL() + MAVEN_METADATA_XML;
context.getMonitor().subTask("Load metadata " + this + "");
monitor.subTask("Load metadata " + this + "");
try (InputStream mdStream = RuntimeUtils.openConnectionStream(metadataPath)) {
parseMetadata(mdStream);
......@@ -91,7 +91,7 @@ public class MavenArtifact
log.warn("Error parsing artifact directory", e);
}
} finally {
context.getMonitor().worked(1);
monitor.worked(1);
}
metadataLoaded = true;
}
......@@ -173,14 +173,6 @@ public class MavenArtifact
return localVersions;
}
// public String getActiveVersionName() {
// return activeVersion;
// }
//
// public void setActiveVersionName(String activeVersion) {
// this.activeVersion = activeVersion;
// }
private String getArtifactURL() {
String dir = groupId.replace('.', '/') + "/" + artifactId;
return repository.getUrl() + dir + "/";
......@@ -219,10 +211,10 @@ public class MavenArtifact
localVersions.add(version);
}
private MavenArtifactVersion makeLocalVersion(DBPDriverContext context, String versionStr, boolean setActive) throws IllegalArgumentException, IOException {
private MavenArtifactVersion makeLocalVersion(DBRProgressMonitor monitor, String versionStr, boolean setActive) throws IllegalArgumentException, IOException {
MavenArtifactVersion version = getVersion(versionStr);
if (version == null) {
version = new MavenArtifactVersion(context, this, versionStr);
version = new MavenArtifactVersion(monitor, this, versionStr);
localVersions.add(version);
}
// if (setActive) {
......@@ -233,7 +225,7 @@ public class MavenArtifact
}
/*
public MavenArtifactVersion resolveActiveVersion(DBPDriverContext context) throws IOException {
public MavenArtifactVersion resolveActiveVersion(DBRProgressMonitor monitor) throws IOException {
if (CommonUtils.isEmpty(activeVersion)) {
return null;
}
......@@ -246,7 +238,7 @@ public class MavenArtifact
}
*/
public MavenArtifactVersion resolveVersion(DBPDriverContext context, String versionRef) throws IOException {
public MavenArtifactVersion resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException {
if (CommonUtils.isEmpty(versionRef)) {
throw new IOException("Empty artifact " + this + " version");
}
......@@ -262,7 +254,7 @@ public class MavenArtifact
predefinedVersion;
if (lookupVersion && !metadataLoaded) {
loadMetadata(context);
loadMetadata(monitor);
}
String versionInfo;
......@@ -316,7 +308,7 @@ public class MavenArtifact
MavenArtifactVersion localVersion = getVersion(versionInfo);
if (localVersion == null) {
localVersion = makeLocalVersion(context, versionInfo, lookupVersion);
localVersion = makeLocalVersion(monitor, versionInfo, lookupVersion);
}
return localVersion;
......
......@@ -19,7 +19,7 @@ package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
......@@ -82,11 +82,11 @@ public class MavenArtifactVersion {
}
};
MavenArtifactVersion(@NotNull DBPDriverContext context, @NotNull MavenArtifact artifact, @NotNull String version) throws IOException {
MavenArtifactVersion(@NotNull DBRProgressMonitor monitor, @NotNull MavenArtifact artifact, @NotNull String version) throws IOException {
this.artifact = artifact;
this.version = version;
loadPOM(context);
loadPOM(monitor);
}
public MavenArtifact getArtifact() {
......@@ -121,7 +121,7 @@ public class MavenArtifactVersion {
return profiles;
}
public List<MavenArtifactDependency> getDependencies(DBPDriverContext context) {
public List<MavenArtifactDependency> getDependencies(DBRProgressMonitor monitor) {
List<MavenArtifactDependency> dependencies = new ArrayList<>();
for (MavenProfile profile : profiles) {
if (profile.isActive() && !CommonUtils.isEmpty(profile.dependencies)) {
......@@ -129,7 +129,7 @@ public class MavenArtifactVersion {
}
}
if (parent != null) {
List<MavenArtifactDependency> parentDependencies = parent.getDependencies(context);
List<MavenArtifactDependency> parentDependencies = parent.getDependencies(monitor);
if (!CommonUtils.isEmpty(parentDependencies)) {
dependencies.addAll(parentDependencies);
}
......@@ -197,13 +197,13 @@ public class MavenArtifactVersion {
}
}
private void loadPOM(DBPDriverContext context) throws IOException {
private void loadPOM(DBRProgressMonitor monitor) throws IOException {
File localPOM = getLocalPOM();
if (!localPOM.exists()) {
cachePOM(localPOM);
}
context.getMonitor().subTask("Load POM " + this);
monitor.subTask("Load POM " + this);
Document pomDocument;
try (InputStream mdStream = new FileInputStream(localPOM)) {
......@@ -234,7 +234,7 @@ public class MavenArtifactVersion {
if (this.version == null) {
this.version = parentReference.getVersion();
}
parent = MavenRegistry.getInstance().findArtifact(context, this, parentReference);
parent = MavenRegistry.getInstance().findArtifact(monitor, this, parentReference);
if (parent == null) {
log.error("Artifact [" + this + "] parent [" + parentReference + "] not found");
}
......@@ -259,7 +259,7 @@ public class MavenArtifactVersion {
MavenProfile defaultProfile = new MavenProfile(DEFAULT_PROFILE_ID);
defaultProfile.active = true;
profiles.add(defaultProfile);
parseProfile(context, defaultProfile, root);
parseProfile(monitor, defaultProfile, root);
{
// Profiles
......@@ -268,15 +268,15 @@ public class MavenArtifactVersion {
for (Element profElement : XMLUtils.getChildElementList(licensesElement, "profile")) {
MavenProfile profile = new MavenProfile(XMLUtils.getChildElementBody(profElement, "id"));
profiles.add(profile);
parseProfile(context, profile, profElement);
parseProfile(monitor, profile, profElement);
}
}
}
context.getMonitor().worked(1);
monitor.worked(1);
}
private void parseProfile(DBPDriverContext context, MavenProfile profile, Element element) {
private void parseProfile(DBRProgressMonitor monitor, MavenProfile profile, Element element) {
{
// Activation
Element activationElement = XMLUtils.getChildElement(element, "activation");
......@@ -347,13 +347,13 @@ public class MavenArtifactVersion {
// Dependencies
Element dmElement = XMLUtils.getChildElement(element, "dependencyManagement");
if (dmElement != null) {
profile.dependencyManagement = parseDependencies(context, dmElement, true);
profile.dependencyManagement = parseDependencies(monitor, dmElement, true);
}
profile.dependencies = parseDependencies(context, element, false);
profile.dependencies = parseDependencies(monitor, element, false);
}
}
private List<MavenArtifactDependency> parseDependencies(DBPDriverContext context, Element element, boolean depManagement) {
private List<MavenArtifactDependency> parseDependencies(DBRProgressMonitor monitor, Element element, boolean depManagement) {
List<MavenArtifactDependency> result = new ArrayList<>();
Element dependenciesElement = XMLUtils.getChildElement(element, "dependencies");
if (dependenciesElement != null) {
......@@ -383,7 +383,7 @@ public class MavenArtifactVersion {
groupId,
artifactId,
version);
MavenArtifactVersion importedVersion = MavenRegistry.getInstance().findArtifact(context, this, importReference);
MavenArtifactVersion importedVersion = MavenRegistry.getInstance().findArtifact(monitor, this, importReference);
if (importedVersion == null) {
log.error("Imported artifact [" + importReference + "] not found. Skip.");
}
......@@ -395,7 +395,7 @@ public class MavenArtifactVersion {
// TODO: maybe we should include optional or PROVIDED
if (version == null) {
version = findDependencyVersion(context, groupId, artifactId);
version = findDependencyVersion(monitor, groupId, artifactId);
}
if (version == null) {
log.error("Can't resolve artifact [" + groupId + ":" + artifactId + "] version. Skip.");
......@@ -437,7 +437,7 @@ public class MavenArtifactVersion {
scope == MavenArtifactDependency.Scope.PROVIDED*/;
}
private String findDependencyVersion(DBPDriverContext context, String groupId, String artifactId) {
private String findDependencyVersion(DBRProgressMonitor monitor, String groupId, String artifactId) {
for (MavenProfile profile : profiles) {
if (profile.isActive() && profile.dependencyManagement != null) {
for (MavenArtifactDependency dmArtifact : profile.dependencyManagement) {
......@@ -451,13 +451,13 @@ public class MavenArtifactVersion {
// Check in imported BOMs
if (imports != null) {
for (MavenArtifactVersion i : imports) {
String dependencyVersion = i.findDependencyVersion(context, groupId, artifactId);
String dependencyVersion = i.findDependencyVersion(monitor, groupId, artifactId);
if (dependencyVersion != null) {
return dependencyVersion;
}
}
}
return parent == null ? null : parent.findDependencyVersion(context, groupId, artifactId);
return parent == null ? null : parent.findDependencyVersion(monitor, groupId, artifactId);
}
private String evaluateString(String value) {
......
......@@ -24,7 +24,7 @@ import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
......@@ -120,12 +120,12 @@ public class MavenRegistry
}
@Nullable
public MavenArtifactVersion findArtifact(@NotNull DBPDriverContext context, @Nullable MavenArtifactVersion owner, @NotNull MavenArtifactReference ref) {
public MavenArtifactVersion findArtifact(@NotNull DBRProgressMonitor monitor, @Nullable MavenArtifactVersion owner, @NotNull MavenArtifactReference ref) {
String fullId = ref.getId();
if (notFoundArtifacts.contains(fullId)) {
return null;
}
MavenArtifactVersion artifact = findInRepositories(context, owner, ref);
MavenArtifactVersion artifact = findInRepositories(monitor, owner, ref);
if (artifact != null) {
return artifact;
}
......@@ -145,10 +145,10 @@ public class MavenRegistry
}
@Nullable
private MavenArtifactVersion findInRepositories(@NotNull DBPDriverContext context, MavenArtifactVersion owner, @NotNull MavenArtifactReference ref) {
private MavenArtifactVersion findInRepositories(@NotNull DBRProgressMonitor monitor, MavenArtifactVersion owner, @NotNull MavenArtifactReference ref) {
MavenRepository currentRepository = owner == null ? null : owner.getArtifact().getRepository();
if (currentRepository != null) {
MavenArtifactVersion artifact = currentRepository.findArtifact(context, ref);
MavenArtifactVersion artifact = currentRepository.findArtifact(monitor, ref);
if (artifact != null) {
return artifact;
}
......@@ -157,7 +157,7 @@ public class MavenRegistry
// Try all available repositories (without resolve)
for (MavenRepository repository : repositories) {
if (repository != currentRepository) {
MavenArtifactVersion artifact = repository.findArtifact(context, ref);
MavenArtifactVersion artifact = repository.findArtifact(monitor, ref);
if (artifact != null) {
return artifact;
}
......@@ -167,7 +167,7 @@ public class MavenRegistry
// Try context repositories
for (MavenRepository repository : owner.getActiveRepositories()) {
if (repository != currentRepository) {
MavenArtifactVersion artifact = repository.findArtifact(context, ref);
MavenArtifactVersion artifact = repository.findArtifact(monitor, ref);
if (artifact != null) {
return artifact;
}
......@@ -176,7 +176,7 @@ public class MavenRegistry
}
if (localRepository != currentRepository) {
MavenArtifactVersion artifact = localRepository.findArtifact(context, ref);
MavenArtifactVersion artifact = localRepository.findArtifact(monitor, ref);
if (artifact != null) {
return artifact;
}
......
......@@ -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.connection.DBPDriverContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.utils.CommonUtils;
......@@ -42,18 +42,8 @@ public class MavenRepository
public static final String EXTENSION_ID = "org.jkiss.dbeaver.mavenRepository";
public static final String METADATA_CACHE_FILE = "metadata-cache.xml";
public static final String TAG_CACHE = "cache";
public static final String TAG_ARTIFACT = "artifact";
public static final String TAG_VERSION = "version";
public static final String ATTR_ID = "id";
public static final String ATTR_NAME = "name";
public static final String ATTR_URL = "url";
public static final String ATTR_GROUP_ID = "groupId";
public static final String ATTR_ARTIFACT_ID = "artifactId";
public static final String ATTR_VERSION = "version";
public enum RepositoryType {
GLOBAL, // Globally defined repositories (came from plugin.xml)
......@@ -67,8 +57,6 @@ public class MavenRepository
private final String url;
private final RepositoryType type;
private transient volatile boolean needsToSave = false;
private Map<String, MavenArtifact> cachedArtifacts = new LinkedHashMap<>();
public MavenRepository(IConfigurationElement config)
......@@ -88,10 +76,6 @@ public class MavenRepository
this.type = type;
}
public void flushCache() {
needsToSave = true;
}
public String getId() {
return id;
}
......@@ -109,7 +93,7 @@ public class MavenRepository
}
@Nullable
public synchronized MavenArtifactVersion findArtifact(DBPDriverContext context, @NotNull MavenArtifactReference ref) {
public synchronized MavenArtifactVersion findArtifact(DBRProgressMonitor monitor, @NotNull MavenArtifactReference ref) {
boolean newArtifact = false;
MavenArtifact artifact = cachedArtifacts.get(ref.getId());
if (artifact == null) {
......@@ -117,10 +101,9 @@ public class MavenRepository
newArtifact = true;
}
try {
MavenArtifactVersion version = artifact.resolveVersion(context, ref.getVersion());
MavenArtifactVersion version = artifact.resolveVersion(monitor, ref.getVersion());
if (newArtifact) {
cachedArtifacts.put(ref.getId(), artifact);
flushCache();
}
return version;
} catch (IOException e) {
......@@ -165,7 +148,7 @@ public class MavenRepository
if (!cacheFile.exists()) {
return;
}
try (final DBPDriverContext context = new DBPDriverContext(VoidProgressMonitor.INSTANCE)) {
try (final DBRProgressMonitor monitor = new DBPDriverContext(VoidProgressMonitor.INSTANCE)) {
InputStream mdStream = new FileInputStream(cacheFile);
try {
SAXReader reader = new SAXReader(mdStream);
......
......@@ -23,7 +23,6 @@ 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;
......@@ -38,7 +37,7 @@ import org.jkiss.utils.CommonUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Collection;
import java.util.List;
class DriverDownloadAutoPage extends DriverDownloadPage {
......@@ -95,8 +94,8 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Resolve dependencies", 100);
try (DBPDriverContext context = new DBPDriverContext(monitor)) {
getWizard().getDependencies().resolveDependencies(context);
try {
getWizard().getDependencies().resolveDependencies(monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
......@@ -249,14 +248,13 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
private class LibraryDownloader implements DBRRunnableWithProgress {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBPDriverContext context = new DBPDriverContext(monitor);
List<DBPDriverLibrary> files = getWizard().getDependencies().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);
lib.downloadLibraryFile(monitor, false, "Download " + (i + 1) + "/" + filesSize);
} catch (IOException e) {
if (lib.getType() == DBPDriverLibrary.FileType.license) {
result = IDialogConstants.OK_ID;
......
/*
* 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.code.NotNull;
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<String, String> properties = new HashMap<>();
private final Map<Class, AutoCloseable> infoMap = new HashMap<>();
public DBPDriverContext(DBRProgressMonitor monitor) {
this.monitor = monitor;
}
public DBRProgressMonitor getMonitor() {
return monitor;
}
public Date getInitTime() {
return initTime;
}
public Map<String, String> getProperties() {
return properties;
}
@NotNull
public <T extends AutoCloseable> T getInfo(Class<T> type) {
AutoCloseable o = infoMap.get(type);
if (o == null) {
try {
o = type.newInstance();
} catch (Exception e) {
throw new IllegalArgumentException("Can't create context info " + type.getName(), e);
}
infoMap.put(type, o);
}
return type.cast(o);
}
@Override
public void close() {
for (AutoCloseable info : infoMap.values()) {
try {
info.close();
} catch (Exception e) {
log.error(e);
}
}
}
}
......@@ -19,6 +19,7 @@
package org.jkiss.dbeaver.model.connection;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.util.ArrayList;
import java.util.List;
......@@ -49,5 +50,5 @@ public interface DBPDriverDependencies
List<DependencyNode> getLibraryMap();
void resolveDependencies(DBPDriverContext context) throws DBException;
void resolveDependencies(DBRProgressMonitor monitor) throws DBException;
}
......@@ -21,6 +21,7 @@ package org.jkiss.dbeaver.model.connection;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.io.File;
import java.io.IOException;
......@@ -84,10 +85,10 @@ public interface DBPDriverLibrary
boolean isResolved();
void resolve(DBPDriverContext context) throws IOException;
void resolve(DBRProgressMonitor monitor) throws IOException;
@Nullable
String getExternalURL(DBPDriverContext context);
String getExternalURL(DBRProgressMonitor monitor);
@Nullable
File getLocalFile();
......@@ -95,8 +96,8 @@ public interface DBPDriverLibrary
boolean matchesCurrentPlatform();
@Nullable
Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBPDriverContext context) throws IOException;
Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor) throws IOException;
void downloadLibraryFile(@NotNull DBPDriverContext context, boolean forceUpdate, String taskName)
void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName)
throws IOException, InterruptedException;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册