提交 3d6e63d3 编写于 作者: J jurgen

Dependencies model

Former-commit-id: 266a224f
上级 ccd6eb69
......@@ -17,20 +17,64 @@
*/
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 java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.util.*;
/**
* DriverDependencies
*/
public class DriverDependencies implements DBPDriverDependencies
{
public DriverDependencies(Collection<? extends DBPDriverLibrary> rootLibraries) {
public DriverDependencies() {
}
void resolveDependencies(DBRProgressMonitor monitor, Collection<? extends DBPDriverLibrary> rootLibraries) throws DBException {
try {
// Dependency map. Key is artifact version (exact)
final Map<String, List<DBPDriverLibrary>> depMap = new LinkedHashMap<>();
for (DBPDriverLibrary library : rootLibraries) {
resolveDependencies(monitor, library, null, depMap);
}
/*
// Replace multiple versions of the same artifact with the first found one
Map<String, DBPDriverLibrary> flatDependencies = new LinkedHashMap<>();
List<DependencyNode> nodes = new ArrayList<>();
for (Map.Entry<String, List<DBPDriverLibrary>> entry : depMap.entrySet()) {
}
*/
} catch (IOException e) {
throw new DBException("IO error while resolving dependencies", e);
}
}
private void resolveDependencies(DBRProgressMonitor monitor, DBPDriverLibrary library, DBPDriverLibrary ownerLibrary, Map<String, List<DBPDriverLibrary>> depMap) throws IOException {
String libraryPath = library.getPath();
List<DBPDriverLibrary> deps = depMap.get(libraryPath);
if (deps != null) {
return;
}
deps = new ArrayList<>();
depMap.put(libraryPath, deps);
Collection<? extends DBPDriverLibrary> dependencies = library.getDependencies(monitor, ownerLibrary);
if (dependencies != null && !dependencies.isEmpty()) {
for (DBPDriverLibrary dep : dependencies) {
deps.add(dep);
resolveDependencies(monitor, dep, library, depMap);
}
}
}
@Override
public List<DBPDriverLibrary> getLibraryList() {
return null;
......
......@@ -623,8 +623,10 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
@NotNull
@Override
public DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) {
return new DriverDependencies(getDriverLibraries());
public DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) throws DBException {
DriverDependencies dependencies = new DriverDependencies();
dependencies.resolveDependencies(monitor, getDriverLibraries());
return dependencies;
}
public DBPDriverLibrary getDriverLibrary(String path)
......
......@@ -43,7 +43,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
protected final DriverDescriptor driver;
protected final FileType type;
protected final OSDescriptor system;
protected String path;
protected final String path;
protected boolean custom;
protected boolean disabled;
......@@ -76,7 +76,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
{
this.driver = driver;
this.type = type;
this.system = DBeaverCore.getInstance().getLocalSystem();
this.system = null;
this.path = path;
this.custom = true;
}
......
......@@ -22,7 +22,6 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -122,12 +121,6 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
return file;
}
@Override
public boolean matchesCurrentPlatform()
{
return system == null || system.matches(DBeaverCore.getInstance().getLocalSystem());
}
@Nullable
@Override
public Collection<DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor, DBPDriverLibrary ownerLibrary) throws IOException {
......@@ -139,6 +132,11 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
return path;
}
@Override
public String getId() {
return path;
}
@NotNull
@Override
public DBIcon getIcon() {
......
......@@ -42,12 +42,16 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
public static final String PATH_PREFIX = "maven:/";
private final MavenArtifactReference reference;
public DriverLibraryMavenArtifact(DriverDescriptor driver, FileType type, String path) {
super(driver, type, path);
reference = new MavenArtifactReference(path);
}
public DriverLibraryMavenArtifact(DriverDescriptor driver, IConfigurationElement config) {
super(driver, config);
reference = new MavenArtifactReference(path);
}
@Override
......@@ -70,7 +74,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Nullable
private MavenArtifact getMavenArtifact() {
return MavenRegistry.getInstance().findArtifact(new MavenArtifactReference(path));
return MavenRegistry.getInstance().findArtifact(reference);
}
@Nullable
......@@ -114,9 +118,8 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
MavenLocalVersion localVersion = artifact.getActiveLocalVersion();
if (localVersion == null && artifact.getRepository().isLocal()) {
// In case of local artifact make version resolve
MavenArtifactReference artifactInfo = new MavenArtifactReference(path);
try {
localVersion = artifact.resolveVersion(VoidProgressMonitor.INSTANCE, artifactInfo.getVersion(), true);
localVersion = artifact.resolveVersion(VoidProgressMonitor.INSTANCE, reference.getVersion(), true);
} catch (IOException e) {
log.warn("Error resolving local artifact [" + artifact + "] version", e);
}
......@@ -184,6 +187,11 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
return path;
}
@Override
public String getId() {
return reference.getGroupId() + ":" + reference.getArtifactId();
}
@Override
public String getVersion() {
MavenLocalVersion version = getMavenLocalVersion();
......@@ -210,11 +218,10 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
}
protected MavenLocalVersion resolveLocalVersion(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException {
MavenArtifactReference artifactInfo = new MavenArtifactReference(path);
if (forceUpdate) {
MavenRegistry.getInstance().resetArtifactInfo(artifactInfo);
MavenRegistry.getInstance().resetArtifactInfo(reference);
}
MavenArtifact artifact = MavenRegistry.getInstance().findArtifact(artifactInfo);
MavenArtifact artifact = MavenRegistry.getInstance().findArtifact(reference);
if (artifact == null) {
throw new IOException("Maven artifact '" + path + "' not found");
}
......@@ -225,7 +232,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
return localVersion;
}
}
return artifact.resolveVersion(monitor, artifactInfo.getVersion(), true);
return artifact.resolveVersion(monitor, reference.getVersion(), true);
}
}
......@@ -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.DBPDriverDependencies;
import org.jkiss.dbeaver.model.connection.DBPDriverLibrary;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
......@@ -95,10 +96,12 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Resolve dependencies", 100);
try {
DBPDriverDependencies dependencies = getWizard().getDriver().resolveDependencies(monitor);
for (DBPDriverLibrary library : getWizard().getFiles()) {
resolveDependencies(monitor, library, null, depMap);
}
} catch (IOException e) {
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
......
......@@ -94,7 +94,7 @@ public interface DBPDriver extends DBPObject
Collection<? extends DBPDriverLibrary> getDriverLibraries();
@NotNull
DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor);
DBPDriverDependencies resolveDependencies(@NotNull DBRProgressMonitor monitor) throws DBException;
Object getDriverInstance(DBRRunnableContext runnableContext) throws DBException;
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.model.connection;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -26,14 +27,14 @@ import java.util.List;
public interface DBPDriverDependencies
{
class DependencyNode {
public final DependencyNode owner;
public final DBPDriverLibrary library;
public final boolean duplicate;
public final List<DependencyNode> dependencies;
public final List<DependencyNode> dependencies = new ArrayList<>();
public boolean duplicate;
public DependencyNode(DBPDriverLibrary library, boolean duplicate, List<DependencyNode> dependencies) {
public DependencyNode(DependencyNode owner, DBPDriverLibrary library) {
this.owner = owner;
this.library = library;
this.duplicate = duplicate;
this.dependencies = dependencies;
}
}
......
......@@ -47,6 +47,15 @@ public interface DBPDriverLibrary
@NotNull
String getDisplayName();
/**
* Library native id.
* Id doesn't include version information so the same libraries with different versions have the same id.
*/
String getId();
/**
* Library version. If library doesn;t support versions returns null.
*/
@Nullable
String getVersion();
......@@ -58,6 +67,7 @@ public interface DBPDriverLibrary
/**
* Native library URI.
* Could be a file path or maven artifact references or anything else.
*/
@NotNull
String getPath();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册