提交 b4b50497 编写于 作者: J jurgen

Dependencies model

Former-commit-id: 542ad1b3
上级 4cd2eabe
...@@ -34,6 +34,7 @@ import org.jkiss.dbeaver.model.meta.Property; ...@@ -34,6 +34,7 @@ import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode; import org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext; import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.runtime.OSDescriptor; import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.registry.DataSourceDescriptor; import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor; import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor;
...@@ -48,6 +49,7 @@ import org.jkiss.utils.xml.XMLBuilder; ...@@ -48,6 +49,7 @@ import org.jkiss.utils.xml.XMLBuilder;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.*; import java.util.*;
...@@ -126,6 +128,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -126,6 +128,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
System.setProperty(PROP_DRIVERS_LOCATION, driversHome.getAbsolutePath()); System.setProperty(PROP_DRIVERS_LOCATION, driversHome.getAbsolutePath());
} }
private DriverDependencies dependencies;
public DriverDescriptor(DataSourceProviderDescriptor providerDescriptor, String id) public DriverDescriptor(DataSourceProviderDescriptor providerDescriptor, String id)
{ {
super(providerDescriptor.getPluginId()); super(providerDescriptor.getPluginId());
...@@ -471,6 +475,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -471,6 +475,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
} }
private void resetDriverInstance() { private void resetDriverInstance() {
this.dependencies = null;
this.driverInstance = null; this.driverInstance = null;
this.driverClass = null; this.driverClass = null;
this.isLoaded = false; this.isLoaded = false;
...@@ -580,23 +585,6 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -580,23 +585,6 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
driverClassName.contains("sun.jdbc"); //$NON-NLS-1$ driverClassName.contains("sun.jdbc"); //$NON-NLS-1$
} }
/*
public boolean isLoaded()
{
return isLoaded;
}
public Class getDriverClass()
{
return driverClass;
}
public DriverClassLoader getClassLoader()
{
return classLoader;
}
*/
@Override @Override
public Collection<String> getClientHomeIds() public Collection<String> getClientHomeIds()
{ {
...@@ -624,11 +612,32 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -624,11 +612,32 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@NotNull @NotNull
@Override @Override
public DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) throws DBException { public DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) throws DBException {
DriverDependencies dependencies = new DriverDependencies(); if (dependencies == null) {
dependencies = new DriverDependencies();
dependencies.resolveDependencies(monitor, getDriverLibraries()); dependencies.resolveDependencies(monitor, getDriverLibraries());
}
return dependencies; return dependencies;
} }
private void resolveDependencies(DBRRunnableContext runnableContext) throws DBException {
try {
runnableContext.run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
resolveDependencies(monitor);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
throw new DBException("Error resolving libraries", e.getTargetException());
} catch (InterruptedException e) {
throw new DBException("Resolve interrupted", e);
}
}
public DBPDriverLibrary getDriverLibrary(String path) public DBPDriverLibrary getDriverLibrary(String path)
{ {
for (DBPDriverLibrary lib : libraries) { for (DBPDriverLibrary lib : libraries) {
...@@ -784,7 +793,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -784,7 +793,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.loadDriver(runnableContext, false, false); this.loadDriver(runnableContext, false, false);
} }
public void loadDriver(DBRRunnableContext runnableContext, boolean forceReload, boolean omitDownload) private void loadDriver(DBRRunnableContext runnableContext, boolean forceReload, boolean omitDownload)
throws DBException throws DBException
{ {
if (isLoaded && !forceReload) { if (isLoaded && !forceReload) {
...@@ -837,9 +846,11 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver ...@@ -837,9 +846,11 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
validateFilesPresence(runnableContext); validateFilesPresence(runnableContext);
} }
resolveDependencies(runnableContext);
List<URL> libraryURLs = new ArrayList<>(); List<URL> libraryURLs = new ArrayList<>();
// Load libraries // Load libraries
for (DBPDriverLibrary file : libraries) { for (DBPDriverLibrary file : dependencies.getLibraryList()) {
if (file.isDisabled() || file.getType() != DBPDriverLibrary.FileType.jar) { if (file.isDisabled() || file.getType() != DBPDriverLibrary.FileType.jar) {
continue; continue;
} }
......
...@@ -238,6 +238,8 @@ public class MavenArtifact ...@@ -238,6 +238,8 @@ public class MavenArtifact
version = new MavenLocalVersion(this, versionStr, new Date()); version = new MavenLocalVersion(this, versionStr, new Date());
version.getMetaData(monitor); version.getMetaData(monitor);
localVersions.add(version); localVersions.add(version);
repository.flushCache();
} }
if (setActive) { if (setActive) {
activeVersion = versionStr; activeVersion = versionStr;
...@@ -314,8 +316,6 @@ public class MavenArtifact ...@@ -314,8 +316,6 @@ public class MavenArtifact
localVersion = makeLocalVersion(monitor, versionInfo, true); localVersion = makeLocalVersion(monitor, versionInfo, true);
} }
repository.flushCache();
return localVersion; return localVersion;
} }
......
...@@ -196,7 +196,6 @@ public class MavenArtifactVersion { ...@@ -196,7 +196,6 @@ public class MavenArtifactVersion {
if (this.version == null) { if (this.version == null) {
this.version = parentReference.getVersion(); this.version = parentReference.getVersion();
} }
// parent = MavenRegistry.getInstance().findArtifactVersion(parentReference);
MavenArtifact parentArtifact = MavenRegistry.getInstance().findArtifact(parentReference); MavenArtifact parentArtifact = MavenRegistry.getInstance().findArtifact(parentReference);
if (parentArtifact == null) { if (parentArtifact == null) {
log.error("Artifact [" + this + "] parent [" + parentReference + "] not found"); log.error("Artifact [" + this + "] parent [" + parentReference + "] not found");
......
...@@ -43,6 +43,7 @@ import java.util.List; ...@@ -43,6 +43,7 @@ import java.util.List;
class DriverDownloadAutoPage extends DriverDownloadPage { class DriverDownloadAutoPage extends DriverDownloadPage {
private Tree filesTree; private Tree filesTree;
private DBPDriverDependencies dependencies;
DriverDownloadAutoPage() { DriverDownloadAutoPage() {
super("Automatic download", "Download driver files", null); super("Automatic download", "Download driver files", null);
...@@ -89,14 +90,13 @@ class DriverDownloadAutoPage extends DriverDownloadPage { ...@@ -89,14 +90,13 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
@Override @Override
void resolveLibraries() { void resolveLibraries() {
final DBPDriverDependencies[] ref = new DBPDriverDependencies[1];
try { try {
new RunnableContextDelegate(getContainer()).run(true, true, new DBRRunnableWithProgress() { new RunnableContextDelegate(getContainer()).run(true, true, new DBRRunnableWithProgress() {
@Override @Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException { public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Resolve dependencies", 100); monitor.beginTask("Resolve dependencies", 100);
try { try {
ref[0] = getWizard().getDriver().resolveDependencies(monitor); dependencies = getWizard().getDriver().resolveDependencies(monitor);
} catch (Exception e) { } catch (Exception e) {
throw new InvocationTargetException(e); throw new InvocationTargetException(e);
} finally { } finally {
...@@ -108,9 +108,9 @@ class DriverDownloadAutoPage extends DriverDownloadPage { ...@@ -108,9 +108,9 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
// User just canceled download // User just canceled download
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
UIUtils.showErrorDialog(null, "Resolve libraries", "Error resolving driver libraries", e.getTargetException()); UIUtils.showErrorDialog(null, "Resolve libraries", "Error resolving driver libraries", e.getTargetException());
return;
} }
DBPDriverDependencies dependencies = ref[0];
int totalItems = 0; int totalItems = 0;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) { for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
DBPDriverLibrary library = node.library; DBPDriverLibrary library = node.library;
...@@ -133,6 +133,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage { ...@@ -133,6 +133,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
shell.setSize(shell.getSize().x, shell.getSize().y + filesTree.getItemHeight() * totalItems); shell.setSize(shell.getSize().x, shell.getSize().y + filesTree.getItemHeight() * totalItems);
shell.layout(); shell.layout();
} }
private boolean addDependencies(TreeItem parent, DBPDriverDependencies.DependencyNode node) { private boolean addDependencies(TreeItem parent, DBPDriverDependencies.DependencyNode node) {
Collection<DBPDriverDependencies.DependencyNode> dependencies = node.dependencies; Collection<DBPDriverDependencies.DependencyNode> dependencies = node.dependencies;
if (dependencies != null && !dependencies.isEmpty()) { if (dependencies != null && !dependencies.isEmpty()) {
...@@ -153,17 +154,23 @@ class DriverDownloadAutoPage extends DriverDownloadPage { ...@@ -153,17 +154,23 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
return false; return false;
} }
@Override
public boolean isPageComplete() {
return dependencies != null;
}
@Override @Override
void performFinish() { void performFinish() {
downloadLibraryFiles(new RunnableContextDelegate(getContainer()), getWizard().getFiles()); downloadLibraryFiles(new RunnableContextDelegate(getContainer()));
} }
private void downloadLibraryFiles(DBRRunnableContext runnableContext, final List<? extends DBPDriverLibrary> files) private void downloadLibraryFiles(DBRRunnableContext runnableContext)
{ {
if (!getWizard().getDriver().acceptDriverLicenses(runnableContext)) { if (!getWizard().getDriver().acceptDriverLicenses(runnableContext)) {
return; return;
} }
List<DBPDriverLibrary> files = dependencies.getLibraryList();
for (int i = 0, filesSize = files.size(); i < filesSize; ) { for (int i = 0, filesSize = files.size(); i < filesSize; ) {
DBPDriverLibrary lib = files.get(i); DBPDriverLibrary lib = files.get(i);
int result = downloadLibraryFile(runnableContext, lib); int result = downloadLibraryFile(runnableContext, lib);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册