提交 545a4985 编写于 作者: J jurgen

Maven artifact resolve fixed

上级 5bd46907
......@@ -26,9 +26,7 @@ import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.*;
public class MavenRegistry
{
......@@ -45,6 +43,8 @@ public class MavenRegistry
}
private final List<MavenRepository> repositories = new ArrayList<MavenRepository>();
// Cache for not found artifact ids. Avoid multiple remote metadata reading
private final Set<String> notFoundArtifacts = new HashSet<String>();
private MavenRegistry()
{
......@@ -98,17 +98,19 @@ public class MavenRegistry
}
@Nullable
public MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId) {
private MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId) {
String fullId = groupId + ":" + artifactId;
if (notFoundArtifacts.contains(fullId)) {
return null;
}
for (MavenRepository repository : repositories) {
MavenArtifact artifact = repository.getArtifact(groupId, artifactId, false);
MavenArtifact artifact = repository.findArtifact(groupId, artifactId);
if (artifact != null) {
return artifact;
}
}
// Create artifact in default repository
if (!repositories.isEmpty()) {
return repositories.get(0).getArtifact(groupId, artifactId, true);
}
notFoundArtifacts.add(fullId);
return null;
}
......
......@@ -104,19 +104,22 @@ public class MavenRepository
}
@Nullable
public MavenArtifact getArtifact(@NotNull String groupId, @NotNull String artifactId, boolean create) {
public MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId) {
for (MavenArtifact artifact : cachedArtifacts) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)) {
return artifact;
}
}
if (create) {
MavenArtifact artifact = new MavenArtifact(this, groupId, artifactId);
addCachedArtifact(artifact);
return artifact;
} else {
// 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;
}
private synchronized void addCachedArtifact(@NotNull MavenArtifact artifact) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册