提交 234bb652 编写于 作者: J jurgen

Dependency exclusions

上级 4734642d
......@@ -152,7 +152,7 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
return system == null || system.matches(DBeaverCore.getInstance().getLocalSystem());
}
public void downloadLibraryFile(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException, InterruptedException
public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate) throws IOException, InterruptedException
{
String externalURL = getExternalURL();
if (externalURL == null) {
......
......@@ -130,7 +130,7 @@ public class DriverLibraryLocal extends DriverLibraryAbstract
@Nullable
@Override
public Collection<DBPDriverLibrary> getDependencies(DBRProgressMonitor monitor) throws IOException {
public Collection<DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor, DBPDriverLibrary ownerLibrary) throws IOException {
return null;
}
......
......@@ -74,14 +74,20 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
}
@Nullable
@Override
public String getExternalURL() {
protected MavenLocalVersion getMavenLocalVersion() {
MavenArtifact artifact = getMavenArtifact();
if (artifact != null) {
MavenLocalVersion localVersion = artifact.getActiveLocalVersion();
if (localVersion != null) {
return localVersion.getExternalURL(MavenArtifact.FILE_JAR);
}
return artifact.getActiveLocalVersion();
}
return null;
}
@Nullable
@Override
public String getExternalURL() {
MavenLocalVersion localVersion = getMavenLocalVersion();
if (localVersion != null) {
return localVersion.getExternalURL(MavenArtifact.FILE_JAR);
}
return null;
}
......@@ -124,15 +130,38 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Nullable
@Override
public Collection<? extends DBPDriverLibrary> getDependencies(DBRProgressMonitor monitor) throws IOException {
public Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor, DBPDriverLibrary ownerLibrary) throws IOException {
List<DriverLibraryMavenDependency> dependencies = new ArrayList<>();
List<MavenArtifactReference> exclusions = null;
MavenLocalVersion localVersion = resolveLocalVersion(monitor, false);
if (localVersion != null) {
// Find owner's exclusions
if (ownerLibrary instanceof DriverLibraryMavenArtifact) {
MavenLocalVersion ownerVersion = ((DriverLibraryMavenArtifact) ownerLibrary).getMavenLocalVersion();
if (ownerVersion != null) {
exclusions = ownerVersion.getMetaData(monitor)
.findExclusionsFor(localVersion.getArtifact().getGroupId(), localVersion.getArtifact().getArtifactId());
}
}
MavenArtifactVersion metaData = localVersion.getMetaData(monitor);
List<MavenArtifactDependency> artifactDeps = metaData.getDependencies(monitor);
if (!CommonUtils.isEmpty(artifactDeps)) {
for (MavenArtifactDependency artifactDep : artifactDeps) {
boolean excluded = false;
if (exclusions != null) {
for (MavenArtifactReference ex : exclusions) {
if (ex.getGroupId().equals(artifactDep.getGroupId()) && ex.getArtifactId().equals(artifactDep.getArtifactId())) {
excluded = true;
break;
}
}
if (excluded) {
// Excluded
continue;
}
}
MavenLocalVersion depLocalVersion = artifactDep.resolveDependency(monitor);
if (depLocalVersion != null) {
dependencies.add(
......@@ -157,13 +186,11 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Override
public String getVersion() {
MavenArtifact artifact = getMavenArtifact();
if (artifact != null) {
MavenLocalVersion version = artifact.getActiveLocalVersion();
if (version != null) {
return version.getVersion();
}
MavenLocalVersion version = getMavenLocalVersion();
if (version != null) {
return version.getVersion();
}
return path;
}
......@@ -173,7 +200,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
return UIIcon.APACHE;
}
public void downloadLibraryFile(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException, InterruptedException {
public void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate) throws IOException, InterruptedException {
MavenLocalVersion localVersion = resolveLocalVersion(monitor, forceUpdate);
if (localVersion.getArtifact().getRepository().isLocal()) {
// No need to download local artifacts
......
......@@ -43,18 +43,12 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
return true;
}
@Nullable
private MavenArtifact getMavenArtifact() {
return localVersion.getArtifact();
}
@Nullable
@Override
public String getExternalURL() {
return localVersion.getExternalURL(MavenArtifact.FILE_JAR);
protected MavenLocalVersion getMavenLocalVersion() {
return localVersion;
}
@Nullable
@Override
public File getLocalFile()
......@@ -62,15 +56,6 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
return localVersion.getCacheFile();
}
@NotNull
public String getDisplayName() {
return localVersion.getArtifact().getGroupId() + ":" + localVersion.getArtifact().getArtifactId();
}
public String getVersion() {
return localVersion.getVersion();
}
protected MavenLocalVersion resolveLocalVersion(DBRProgressMonitor monitor, boolean forceUpdate) throws IOException {
return localVersion;
}
......
......@@ -21,6 +21,7 @@ import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -68,6 +69,9 @@ public class MavenArtifactDependency extends MavenArtifactReference {
}
void addExclusion(MavenArtifactReference ref) {
if (exclusions == null) {
exclusions = new ArrayList<>();
}
exclusions.add(ref);
}
......
......@@ -141,6 +141,15 @@ public class MavenArtifactVersion {
return this.dependencies;
}
public List<MavenArtifactReference> findExclusionsFor(String groupId, String artifactId) {
for (MavenArtifactDependency dependency : dependencies) {
if (dependency.getGroupId().equals(groupId) && dependency.getArtifactId().equals(artifactId)) {
return dependency.getExclusions();
}
}
return null;
}
List<MavenArtifactDependency> getDependencies() {
return dependencies;
}
......
......@@ -53,6 +53,7 @@ public class MavenRepository
public static final String TAG_ARTIFACT = "artifact";
public static final String TAG_VERSION = "version";
public static final String TAG_DEPENDENCY = "dependency";
public static final String TAG_EXCLUDE = "exclude";
public static final String ATTR_NAME = "name";
public static final String ATTR_URL = "url";
......@@ -367,6 +368,14 @@ public class MavenRepository
if (dependency.isOptional()) {
xml.addAttribute(ATTR_OPTIONAL, true);
}
List<MavenArtifactReference> exclusions = dependency.getExclusions();
if (exclusions != null) {
for (MavenArtifactReference ex : exclusions) {
try (XMLBuilder.Element e4 = xml.startElement(TAG_EXCLUDE)) {
xml.addAttribute(ATTR_PATH, ex.getPath());
}
}
}
}
}
}
......
......@@ -96,7 +96,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
monitor.beginTask("Resolve dependencies", 100);
try {
for (DBPDriverLibrary library : getWizard().getFiles()) {
resolveDependencies(monitor, library, depMap);
resolveDependencies(monitor, library, null, depMap);
}
} catch (IOException e) {
throw new InvocationTargetException(e);
......@@ -134,7 +134,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
shell.layout();
}
private void resolveDependencies(DBRProgressMonitor monitor, DBPDriverLibrary library, Map<String, List<DBPDriverLibrary>> depMap) throws IOException {
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) {
......@@ -144,11 +144,11 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
deps = new ArrayList<>();
depMap.put(libraryPath, deps);
Collection<? extends DBPDriverLibrary> dependencies = library.getDependencies(monitor);
Collection<? extends DBPDriverLibrary> dependencies = library.getDependencies(monitor, ownerLibrary);
if (dependencies != null && !dependencies.isEmpty()) {
for (DBPDriverLibrary dep : dependencies) {
deps.add(dep);
resolveDependencies(monitor, dep, depMap);
resolveDependencies(monitor, dep, library, depMap);
}
}
}
......
......@@ -83,8 +83,8 @@ public interface DBPDriverLibrary
boolean matchesCurrentPlatform();
@Nullable
Collection<? extends DBPDriverLibrary> getDependencies(DBRProgressMonitor monitor) throws IOException;
Collection<? extends DBPDriverLibrary> getDependencies(@NotNull DBRProgressMonitor monitor, @Nullable DBPDriverLibrary ownerLibrary) throws IOException;
void downloadLibraryFile(DBRProgressMonitor monitor, boolean forceUpdate)
void downloadLibraryFile(@NotNull DBRProgressMonitor monitor, boolean forceUpdate)
throws IOException, InterruptedException;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册