提交 84fbe383 编写于 作者: J jurgen

Maven local repository

上级 cc329424
......@@ -26,6 +26,7 @@ import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.registry.maven.MavenArtifact;
import org.jkiss.dbeaver.registry.maven.MavenArtifactReference;
import org.jkiss.dbeaver.registry.maven.MavenLocalVersion;
......@@ -34,7 +35,8 @@ import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.utils.ContentUtils;
import java.io.*;
import java.net.*;
import java.net.URL;
import java.net.URLConnection;
import java.text.NumberFormat;
/**
......@@ -171,6 +173,15 @@ public class DriverFileDescriptor implements DBPDriverFile
MavenArtifact artifact = getMavenArtifact();
if (artifact != null) {
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());
} catch (IOException e) {
log.warn("Error resolving local artifact [" + artifact + "] version", e);
}
}
if (localVersion != null) {
return localVersion.getCacheFile();
}
......
......@@ -64,6 +64,11 @@ public class MavenArtifact
}
public void loadMetadata() throws IOException {
latestVersion = null;
releaseVersion = null;
versions.clear();
lastUpdate = null;
String metadataPath = getArtifactDir() + MAVEN_METADATA_XML;
InputStream mdStream = RuntimeUtils.openConnectionStream(metadataPath);
try {
......@@ -211,7 +216,7 @@ public class MavenArtifact
localVersions.remove(version);
}
public void resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException {
public MavenLocalVersion resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException {
monitor.beginTask("Download Maven artifact '" + this + "'", 3);
try {
monitor.subTask("Download metadata from " + repository.getUrl());
......@@ -257,12 +262,14 @@ public class MavenArtifact
localVersion = null;
}
if (localVersion == null) {
makeLocalVersion(versionInfo, true);
localVersion = makeLocalVersion(versionInfo, true);
}
monitor.worked(1);
monitor.subTask("Save repository cache");
repository.flushCache();
monitor.worked(1);
return localVersion;
} finally {
monitor.done();
}
......
......@@ -21,6 +21,9 @@ import org.jkiss.dbeaver.Log;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
/**
......@@ -31,6 +34,7 @@ import java.util.Date;
public class MavenLocalVersion
{
static final Log log = Log.getLog(MavenLocalVersion.class);
private static final java.lang.String FILE_PROTOCOL = "file:/";
private MavenArtifact artifact;
private String version;
......@@ -63,7 +67,13 @@ public class MavenLocalVersion
public File getCacheFile() {
if (artifact.getRepository().isLocal()) {
return new File(getExternalURL(MavenArtifact.FILE_JAR));
String externalURL = getExternalURL(MavenArtifact.FILE_JAR);
try {
return new File(new URL(externalURL).toURI());
} catch (Exception e) {
log.warn("Bad repository URL", e);
return new File(externalURL);
}
}
return new File(artifact.getRepository().getLocalCacheDir(), artifact.getGroupId() + "/" + fileName);
}
......
......@@ -119,22 +119,32 @@ public class MavenRegistry
if (notFoundArtifacts.contains(fullId)) {
return null;
}
MavenArtifact artifact = findInRepositories(groupId, artifactId, false);
if (artifact == null) {
artifact = findInRepositories(groupId, artifactId, true);
}
if (artifact != null) {
return artifact;
}
// Try all available repositories
// Not found
notFoundArtifacts.add(fullId);
return null;
}
@Nullable
private MavenArtifact findInRepositories(@NotNull String groupId, @NotNull String artifactId, boolean resolve) {
// Try all available repositories (without resolve)
for (MavenRepository repository : repositories) {
MavenArtifact artifact = repository.findArtifact(groupId, artifactId);
MavenArtifact artifact = repository.findArtifact(groupId, artifactId, resolve);
if (artifact != null) {
return artifact;
}
}
// Try local repository
MavenArtifact artifact = localRepository.findArtifact(groupId, artifactId);
MavenArtifact artifact = localRepository.findArtifact(groupId, artifactId, resolve);
if (artifact != null) {
return artifact;
}
// Not found
notFoundArtifacts.add(fullId);
return null;
}
......
......@@ -81,6 +81,7 @@ public class MavenRepository
MavenRepository(String id, String name, String url, boolean local) {
this.id = id;
this.name = name;
if (!url.endsWith("/")) url += "/";
this.url = url;
this.local = local;
if (!local) {
......@@ -113,22 +114,25 @@ public class MavenRepository
}
@Nullable
public MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId) {
public MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId, boolean resolve) {
for (MavenArtifact artifact : cachedArtifacts) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)) {
return artifact;
}
}
// Not cached - look in remote repository
MavenArtifact artifact = new MavenArtifact(this, groupId, artifactId);
try {
artifact.loadMetadata();
} catch (IOException e) {
log.debug("Artifact [" + artifact + "] not found in repository [" + getUrl() + "]");
return null;
if (resolve) {
// Not cached - look in remote repository
MavenArtifact artifact = new MavenArtifact(this, groupId, artifactId);
try {
artifact.loadMetadata();
} catch (IOException e) {
log.debug("Artifact [" + artifact + "] not found in repository [" + getUrl() + "]");
return null;
}
cachedArtifacts.add(artifact);
return artifact;
}
cachedArtifacts.add(artifact);
return artifact;
return null;
}
private synchronized void addCachedArtifact(@NotNull MavenArtifact artifact) {
......@@ -244,4 +248,8 @@ public class MavenRepository
}
}
@Override
public String toString() {
return url;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册