提交 9ab4a30e 编写于 作者: J jurgen

Dependencies resolution

Former-commit-id: 0c089ad5
上级 09c8db1d
......@@ -87,6 +87,7 @@ public class DriverDependencies implements DBPDriverDependencies
}
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) {
......
......@@ -167,7 +167,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
}
}
String externalURL = getExternalURL();
String externalURL = getExternalURL(monitor);
if (externalURL == null) {
throw new IOException("Unresolved file reference: " + getPath());
}
......
......@@ -57,13 +57,18 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
return true;
}
@Override
public void resolve(DBRProgressMonitor monitor) throws IOException {
// do nothing
}
protected String getLocalFilePath() {
return path;
}
@Nullable
@Override
public String getExternalURL() {
public String getExternalURL(DBRProgressMonitor monitor) {
return null;
}
......
......@@ -24,14 +24,15 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBIcon;
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;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* DriverLibraryDescriptor
......@@ -43,7 +44,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
public static final String PATH_PREFIX = "maven:/";
private final MavenArtifactReference reference;
private MavenArtifactVersion version;
protected MavenArtifactVersion localVersion;
public DriverLibraryMavenArtifact(DriverDescriptor driver, FileType type, String path) {
super(driver, type, path);
......@@ -69,21 +70,36 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Override
public boolean isResolved() {
return getMavenVersion() != null;
return getCachedArtifactVersion() != null;
}
@Override
public void resolve(DBRProgressMonitor monitor) throws IOException {
if (getArtifactVersion(monitor) == null) {
throw new IOException("Can't resolve artifact " + this + " version");
}
}
@Nullable
protected MavenArtifactVersion getMavenVersion() {
if (version == null) {
version = MavenRegistry.getInstance().findArtifact(VoidProgressMonitor.INSTANCE, reference);
protected MavenArtifactVersion getCachedArtifactVersion() {
if (localVersion == null) {
localVersion = MavenRegistry.getInstance().findCachedArtifact(reference);
}
return version;
return localVersion;
}
@Nullable
protected MavenArtifactVersion getArtifactVersion(DBRProgressMonitor monitor) {
if (localVersion == null) {
localVersion = MavenRegistry.getInstance().findArtifact(monitor, reference);
}
return localVersion;
}
@Nullable
@Override
public String getExternalURL() {
MavenArtifactVersion localVersion = getMavenVersion();
public String getExternalURL(DBRProgressMonitor monitor) {
MavenArtifactVersion localVersion = getArtifactVersion(monitor);
if (localVersion != null) {
return localVersion.getExternalURL(MavenArtifact.FILE_JAR);
}
......@@ -107,7 +123,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
private File detectLocalFile()
{
MavenArtifactVersion localVersion = getMavenVersion();
MavenArtifactVersion localVersion = getCachedArtifactVersion();
if (localVersion != null) {
return localVersion.getCacheFile();
}
......@@ -160,7 +176,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Override
public String getVersion() {
MavenArtifactVersion version = getMavenVersion();
MavenArtifactVersion version = getCachedArtifactVersion();
if (version != null) {
return version.getVersion();
}
......@@ -175,7 +191,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
}
public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate, String taskName) throws IOException, InterruptedException {
//monitor.beginTask(taskName + " - update version information", 1);
//monitor.beginTask(taskName + " - update localVersion information", 1);
try {
MavenArtifactVersion localVersion = resolveLocalVersion(monitor, forceUpdate);
if (localVersion.getArtifact().getRepository().isLocal()) {
......@@ -192,7 +208,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
if (forceUpdate) {
MavenRegistry.getInstance().resetArtifactInfo(reference);
}
MavenArtifactVersion version = MavenRegistry.getInstance().findArtifact(monitor, reference);
MavenArtifactVersion version = getArtifactVersion(monitor);
if (version == null) {
throw new IOException("Maven artifact '" + path + "' not found");
}
......
......@@ -17,14 +17,11 @@
*/
package org.jkiss.dbeaver.registry.driver;
import org.jkiss.code.Nullable;
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;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
......@@ -33,7 +30,6 @@ import java.util.List;
public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
{
private DriverLibraryMavenArtifact parent;
private MavenArtifactVersion localVersion;
private MavenArtifactDependency source;
public DriverLibraryMavenDependency(DriverLibraryMavenArtifact parent, MavenArtifactVersion localVersion, MavenArtifactDependency source) {
......@@ -48,23 +44,6 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
return true;
}
@Nullable
@Override
protected MavenArtifactVersion getMavenVersion() {
return localVersion;
}
@Nullable
@Override
public File getLocalFile()
{
return localVersion.getCacheFile();
}
protected MavenArtifactVersion resolveLocalVersion(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException {
return localVersion;
}
protected boolean isDependencyExcluded(DBRProgressMonitor monitor, MavenArtifactDependency dependency) {
List<MavenArtifactReference> exclusions = source.getExclusions();
if (exclusions != null) {
......
......@@ -19,6 +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;
/**
* DriverLibraryDescriptor
......@@ -48,7 +49,7 @@ public class DriverLibraryRepository extends DriverLibraryLocal
@Nullable
@Override
public String getExternalURL() {
public String getExternalURL(DBRProgressMonitor monitor) {
String localPath = getLocalFilePath();
String primarySource = DriverDescriptor.getDriversPrimarySource();
if (!primarySource.endsWith("/") && !localPath.startsWith("/")) {
......
......@@ -21,8 +21,8 @@ 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.registry.maven.versioning.DefaultArtifactVersion;
import org.jkiss.dbeaver.registry.maven.versioning.InvalidVersionSpecificationException;
import org.jkiss.dbeaver.registry.maven.versioning.VersionRange;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.utils.CommonUtils;
......@@ -208,9 +208,6 @@ public class MavenArtifact
@Nullable
public MavenArtifactVersion getVersion(String versionStr) {
if (CommonUtils.isEmpty(activeVersion)) {
return null;
}
for (MavenArtifactVersion version : localVersions) {
if (version.getVersion().equals(versionStr)) {
return version;
......@@ -226,7 +223,7 @@ public class MavenArtifact
private MavenArtifactVersion makeLocalVersion(DBRProgressMonitor monitor, String versionStr, boolean setActive) throws IllegalArgumentException, IOException {
MavenArtifactVersion version = getVersion(versionStr);
if (version == null) {
version = new MavenArtifactVersion(monitor, this, versionStr);
version = new MavenArtifactVersion(monitor, this, versionStr, true);
localVersions.add(version);
}
if (setActive) {
......@@ -236,6 +233,18 @@ public class MavenArtifact
return version;
}
public MavenArtifactVersion resolveActiveVersion() throws IOException {
if (CommonUtils.isEmpty(activeVersion)) {
return null;
}
MavenArtifactVersion version = getVersion(activeVersion);
if (version == null) {
version = new MavenArtifactVersion(VoidProgressMonitor.INSTANCE, this, activeVersion, false);
localVersions.add(version);
}
return version;
}
public MavenArtifactVersion resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException {
if (CommonUtils.isEmpty(versionRef)) {
throw new IOException("Empty artifact " + this + " version");
......
......@@ -17,8 +17,11 @@
*/
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.runtime.RuntimeUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
......@@ -83,10 +86,16 @@ public class MavenArtifactVersion {
}
};
MavenArtifactVersion(DBRProgressMonitor monitor, MavenArtifact artifact, String version) throws IOException {
/**
* 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 {
this.artifact = artifact;
this.version = version;
loadPOM(monitor);
loadPOM(monitor, readRemote);
}
public MavenArtifact getArtifact() {
......@@ -176,10 +185,15 @@ public class MavenArtifactVersion {
return artifact.getFileURL(version, MavenArtifact.FILE_POM);
}
private void loadPOM(DBRProgressMonitor monitor) throws IOException {
private void loadPOM(DBRProgressMonitor monitor, boolean readRemote) throws IOException {
File localPOM = getLocalPOM();
if (!localPOM.exists()) {
cachePOM(localPOM);
if (readRemote) {
cachePOM(localPOM);
} else {
log.warn("Local POM missing for " + this);
return;
}
}
monitor.subTask("Load POM " + this);
......
......@@ -148,6 +148,26 @@ public class MavenRegistry
return null;
}
@Nullable
public MavenArtifactVersion findCachedArtifact(@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);
if (artifact != null) {
return artifact;
}
}
MavenArtifactVersion artifact = localRepository.findCachedArtifact(ref);
if (artifact != null) {
return artifact;
}
return null;
}
public void resetArtifactInfo(MavenArtifactReference artifactReference) {
notFoundArtifacts.remove(artifactReference.getId());
......
......@@ -132,6 +132,23 @@ public class MavenRepository
}
}
public MavenArtifactVersion findCachedArtifact(MavenArtifactReference ref) {
MavenArtifact artifact = cachedArtifacts.get(ref.getId());
if (artifact == null) {
return null;
}
MavenArtifactVersion version = artifact.getVersion(ref.getVersion());
if (version == null && !CommonUtils.isEmpty(artifact.getActiveVersionName())) {
// Resolve active version
try {
version = artifact.resolveActiveVersion();
} catch (IOException e) {
log.warn("Can't resolve cached active version " + ref);
}
}
return version;
}
synchronized void resetArtifactCache(@NotNull MavenArtifactReference artifactReference) {
cachedArtifacts.remove(artifactReference.getId());
}
......@@ -176,10 +193,11 @@ public class MavenRepository
MavenArtifactVersion version = new MavenArtifactVersion(
VoidProgressMonitor.INSTANCE,
lastArtifact,
versionNumber);
versionNumber,
false);
lastArtifact.addVersion(version);
} catch (IOException e) {
log.warn("Error loading artifact version", e);
log.warn("Error loading cached artifact version " + lastArtifact + ":" + versionNumber, e);
}
}
}
......@@ -232,7 +250,7 @@ public class MavenRepository
try (XMLBuilder.Element e1 = xml.startElement(TAG_ARTIFACT)) {
xml.addAttribute(ATTR_GROUP_ID, artifact.getGroupId());
xml.addAttribute(ATTR_ARTIFACT_ID, artifact.getArtifactId());
if (CommonUtils.isEmpty(artifact.getActiveVersionName())) {
if (!CommonUtils.isEmpty(artifact.getActiveVersionName())) {
xml.addAttribute(ATTR_ACTIVE_VERSION, artifact.getActiveVersionName());
}
}
......@@ -252,4 +270,5 @@ public class MavenRepository
public String toString() {
return url;
}
}
......@@ -85,8 +85,10 @@ public interface DBPDriverLibrary
boolean isResolved();
void resolve(DBRProgressMonitor monitor) throws IOException;
@Nullable
String getExternalURL();
String getExternalURL(DBRProgressMonitor monitor);
@Nullable
File getLocalFile();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册