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

Maven artifact resolve fixed

上级 5bd46907
...@@ -26,9 +26,7 @@ import org.jkiss.dbeaver.DBeaverPreferences; ...@@ -26,9 +26,7 @@ import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
public class MavenRegistry public class MavenRegistry
{ {
...@@ -45,6 +43,8 @@ public class MavenRegistry ...@@ -45,6 +43,8 @@ public class MavenRegistry
} }
private final List<MavenRepository> repositories = new ArrayList<MavenRepository>(); 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() private MavenRegistry()
{ {
...@@ -98,17 +98,19 @@ public class MavenRegistry ...@@ -98,17 +98,19 @@ public class MavenRegistry
} }
@Nullable @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) { for (MavenRepository repository : repositories) {
MavenArtifact artifact = repository.getArtifact(groupId, artifactId, false); MavenArtifact artifact = repository.findArtifact(groupId, artifactId);
if (artifact != null) { if (artifact != null) {
return artifact; return artifact;
} }
} }
// Create artifact in default repository notFoundArtifacts.add(fullId);
if (!repositories.isEmpty()) {
return repositories.get(0).getArtifact(groupId, artifactId, true);
}
return null; return null;
} }
......
...@@ -104,19 +104,22 @@ public class MavenRepository ...@@ -104,19 +104,22 @@ public class MavenRepository
} }
@Nullable @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) { for (MavenArtifact artifact : cachedArtifacts) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)) { if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)) {
return artifact; return artifact;
} }
} }
if (create) { // Not cached - look in remote repository
MavenArtifact artifact = new MavenArtifact(this, groupId, artifactId); MavenArtifact artifact = new MavenArtifact(this, groupId, artifactId);
addCachedArtifact(artifact); try {
return artifact; artifact.loadMetadata();
} else { } catch (IOException e) {
log.debug("Artifact [" + artifact + "] not found in repository [" + getUrl() + "]");
return null; return null;
} }
cachedArtifacts.add(artifact);
return artifact;
} }
private synchronized void addCachedArtifact(@NotNull MavenArtifact 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.
先完成此消息的编辑!
想要评论请 注册