提交 066e2254 编写于 作者: J jurgen

Maven model & ui

上级 41731321
......@@ -99,6 +99,11 @@ public abstract class DriverLibraryAbstract implements DBPDriverLibrary
return driver;
}
@Override
public String getVersion() {
return null;
}
@NotNull
@Override
public FileType getType()
......
......@@ -130,30 +130,28 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
MavenLocalVersion localVersion = resolveLocalVersion(monitor, false);
if (localVersion != null) {
MavenArtifactVersion metaData = localVersion.getMetaData(monitor);
if (metaData != null) {
List<MavenArtifactDependency> artifactDeps = metaData.getDependencies();
if (!CommonUtils.isEmpty(artifactDeps)) {
for (MavenArtifactDependency artifactDep : artifactDeps) {
if (artifactDep.isOptional()) {
continue;
}
switch (artifactDep.getScope()) {
case COMPILE:
case RUNTIME:
{
MavenLocalVersion depLocalVersion = artifactDep.resolveDependency(monitor);
if (depLocalVersion != null) {
dependencies.add(
new DriverLibraryMavenDependency(
this.getDriver(),
depLocalVersion));
}
break;
List<MavenArtifactDependency> artifactDeps = metaData.getDependencies(monitor);
if (!CommonUtils.isEmpty(artifactDeps)) {
for (MavenArtifactDependency artifactDep : artifactDeps) {
if (artifactDep.isOptional()) {
continue;
}
switch (artifactDep.getScope()) {
case COMPILE:
case RUNTIME:
{
MavenLocalVersion depLocalVersion = artifactDep.resolveDependency(monitor);
if (depLocalVersion != null) {
dependencies.add(
new DriverLibraryMavenDependency(
this.getDriver(),
depLocalVersion));
}
default:
// We don't need it
break;
break;
}
default:
// We don't need it
break;
}
}
}
......@@ -163,11 +161,20 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@NotNull
public String getDisplayName() {
MavenArtifact artifact = getMavenArtifact();
if (artifact != null) {
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
return path;
}
@Override
public String getVersion() {
MavenArtifact artifact = getMavenArtifact();
if (artifact != null) {
MavenLocalVersion version = artifact.getActiveLocalVersion();
if (version != null) {
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version.getVersion();
return version.getVersion();
}
}
return path;
......
......@@ -34,7 +34,7 @@ public class DriverLibraryMavenDependency extends DriverLibraryMavenArtifact
private MavenLocalVersion localVersion;
public DriverLibraryMavenDependency(DriverDescriptor driverDescriptor, MavenLocalVersion localVersion) {
super(driverDescriptor, FileType.jar, PATH_PREFIX + localVersion.toString());
super(driverDescriptor, FileType.jar, PATH_PREFIX + localVersion.getArtifact().toString());
this.localVersion = localVersion;
}
......
......@@ -72,8 +72,8 @@ public class MavenArtifact
lastUpdate = null;
String metadataPath = getArtifactURL() + MAVEN_METADATA_XML;
monitor.subTask("Load artifact metadata [" + metadataPath + "]");
System.out.println("Load metadata " + this);
monitor.subTask("Load metadata " + this + "");
try (InputStream mdStream = RuntimeUtils.openConnectionStream(metadataPath)) {
SAXReader reader = new SAXReader(mdStream);
reader.parse(new SAXListener() {
......
......@@ -39,6 +39,8 @@ public class MavenArtifactVersion {
static final Log log = Log.getLog(MavenArtifactVersion.class);
public static final String PROP_PROJECT_VERSION = "project.version";
public static final String PROP_PROJECT_GROUP_ID = "project.groupId";
public static final String PROP_PROJECT_ARTIFACT_ID = "project.artifactId";
private MavenLocalVersion localVersion;
private String name;
......@@ -59,6 +61,10 @@ public class MavenArtifactVersion {
if (value == null) {
if (name.equals(PROP_PROJECT_VERSION)) {
value = version;
} else if (name.equals(PROP_PROJECT_GROUP_ID)) {
value = localVersion.getArtifact().getGroupId();
} else if (name.equals(PROP_PROJECT_ARTIFACT_ID)) {
value = localVersion.getArtifact().getArtifactId();
} else if (parent != null) {
return parent.getMetaData(VoidProgressMonitor.INSTANCE).variableResolver.get(name);
}
......@@ -109,8 +115,19 @@ public class MavenArtifactVersion {
return licenses;
}
public List<MavenArtifactDependency> getDependencies() {
return dependencies;
public List<MavenArtifactDependency> getDependencies(DBRProgressMonitor monitor) {
if (parent != null) {
List<MavenArtifactDependency> parentDependencies = parent.getMetaData(monitor).getDependencies(monitor);
if (!CommonUtils.isEmpty(parentDependencies)) {
if (CommonUtils.isEmpty(dependencies)) {
return parentDependencies;
}
parentDependencies = new ArrayList<>(parentDependencies);
parentDependencies.addAll(dependencies);
return parentDependencies;
}
}
return this.dependencies;
}
@Override
......@@ -129,8 +146,8 @@ public class MavenArtifactVersion {
private void loadPOM(DBRProgressMonitor monitor) throws IOException {
String pomURL = localVersion.getArtifact().getFileURL(localVersion.getVersion(), MavenArtifact.FILE_POM);
monitor.subTask("Load POM [" + pomURL + "]");
System.out.println("Load POM " + localVersion.getArtifact().toString() + ":" + localVersion.getVersion());
monitor.subTask("Load POM " + localVersion);
Document pomDocument;
try (InputStream mdStream = RuntimeUtils.openConnectionStream(pomURL)) {
pomDocument = XMLUtils.parseDocument(mdStream);
......@@ -228,8 +245,8 @@ System.out.println("Load POM " + localVersion.getArtifact().toString() + ":" + l
scope = MavenArtifactDependency.Scope.valueOf(scopeName.toUpperCase(Locale.ENGLISH));
}
result.add(new MavenArtifactDependency(
groupId,
artifactId,
evaluateString(groupId),
evaluateString(artifactId),
evaluateString(version),
scope,
CommonUtils.getBoolean(XMLUtils.getChildElementBody(dep, "optional"), false)
......
......@@ -17,6 +17,7 @@
*/
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -80,6 +81,7 @@ public class MavenLocalVersion
return artifact.getFileURL(version, fileType);
}
@NotNull
public MavenArtifactVersion getMetaData(DBRProgressMonitor monitor) {
if (metaData == null) {
try {
......
......@@ -32,6 +32,7 @@ import org.jkiss.dbeaver.runtime.RunnableContextDelegate;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
......@@ -110,21 +111,24 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
UIUtils.showErrorDialog(null, "Resolve libraries", "Error resolving driver libraries", e.getTargetException());
}
final Set<String> addedDeps = new HashSet<>();
int totalItems = 0;
for (DBPDriverLibrary file : getWizard().getFiles()) {
TreeItem item = new TreeItem(filesTree, SWT.NONE);
item.setImage(DBeaverIcons.getImage(file.getIcon()));
item.setText(0, file.getDisplayName());
item.setText(1, "");
item.setText(1, CommonUtils.notEmpty(file.getVersion()));
totalItems++;
if (addDependencies(item, file, depMap)) {
if (addDependencies(item, file, depMap, addedDeps)) {
item.setExpanded(true);
totalItems += item.getItemCount();
}
}
UIUtils.packColumns(filesTree);
// GridData gd = (GridData)filesTree.getLayoutData();
// gd.heightHint = filesTree.getItemCount() * 20 + 20;
if (totalItems > 20) {
totalItems = 20;
}
Shell shell = getContainer().getShell();
shell.setSize(shell.getSize().x, shell.getSize().y + filesTree.getItemHeight() * totalItems);
shell.layout();
......@@ -136,7 +140,7 @@ class DriverDownloadAutoPage extends DriverDownloadPage {
if (deps != null) {
return;
}
System.out.println("Resolve dependencies of [" + libraryPath + "]");
deps = new ArrayList<>();
depMap.put(libraryPath, deps);
......@@ -149,19 +153,31 @@ System.out.println("Resolve dependencies of [" + libraryPath + "]");
}
}
private boolean addDependencies(TreeItem parent, DBPDriverLibrary library, Map<String, List<DBPDriverLibrary>> depMap) {
private boolean addDependencies(TreeItem parent, DBPDriverLibrary library, Map<String, List<DBPDriverLibrary>> depMap, Set<String> addedDeps) {
Collection<? extends DBPDriverLibrary> dependencies = depMap.get(library.getPath());
if (dependencies != null && !dependencies.isEmpty()) {
Map<DBPDriverLibrary, TreeItem> itemMap = new HashMap<>();
for (DBPDriverLibrary dep : dependencies) {
TreeItem item = new TreeItem(parent, SWT.NONE);
item.setImage(DBeaverIcons.getImage(dep.getIcon()));
item.setText(0, dep.getDisplayName());
item.setText(1, "");
item.setText(1, CommonUtils.notEmpty(dep.getVersion()));
if (addDependencies(item, dep, depMap)) {
//item.setExpanded(true);
if (addedDeps.contains(dep.getPath())) {
item.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
}
itemMap.put(dep, item);
}
for (DBPDriverLibrary dep : dependencies) {
TreeItem item = itemMap.get(dep);
if (!addedDeps.contains(dep.getPath())) {
addedDeps.add(dep.getPath());
if (addDependencies(item, dep, depMap, addedDeps)) {
//item.setExpanded(true);
}
}
}
return true;
}
return false;
......
......@@ -46,6 +46,9 @@ public interface DBPDriverLibrary
@NotNull
String getDisplayName();
@Nullable
String getVersion();
@NotNull
DBIcon getIcon();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册