提交 dacd822e 编写于 作者: J jurgen

Maven classifiers support.

Driver editor fix.
Maria driver dependencies fix
上级 17d3241c
......@@ -682,8 +682,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
public boolean addDriverLibrary(DBPDriverLibrary descriptor)
{
resetDriverInstance();
if (!libraries.contains(descriptor)) {
resetDriverInstance();
this.libraries.add(descriptor);
return true;
}
......
......@@ -160,7 +160,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
@Override
public String getId() {
return reference.getGroupId() + ":" + reference.getArtifactId();
return reference.getId();
}
@Override
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
/**
* Maven artifact reference
*/
public interface IMavenIdentifier
{
@NotNull
String getGroupId();
@NotNull
String getArtifactId();
@Nullable
String getClassifier();
@NotNull
String getVersion();
@NotNull
String getId();
}
......@@ -41,7 +41,7 @@ import java.util.regex.Pattern;
/**
* Maven artifact descriptor
*/
public class MavenArtifact
public class MavenArtifact implements IMavenIdentifier
{
static final Log log = Log.getLog(MavenArtifact.class);
......@@ -50,24 +50,29 @@ public class MavenArtifact
public static final String FILE_JAR = "jar";
public static final String FILE_POM = "pom";
@NotNull
private final MavenRepository repository;
@NotNull
private final String groupId;
@NotNull
private final String artifactId;
@Nullable
private final String classifier;
private List<String> versions = new ArrayList<>();
private final List<String> versions = new ArrayList<>();
private String latestVersion;
private String releaseVersion;
private Date lastUpdate;
private transient boolean metadataLoaded = false;
private final List<MavenArtifactVersion> localVersions = new ArrayList<>();
private List<MavenArtifactVersion> localVersions = new ArrayList<>();
//private String activeVersion;
private transient boolean metadataLoaded = false;
public MavenArtifact(MavenRepository repository, String groupId, String artifactId)
public MavenArtifact(@NotNull MavenRepository repository, @NotNull String groupId, @NotNull String artifactId, @Nullable String classifier)
{
this.repository = repository;
this.groupId = groupId;
this.artifactId = artifactId;
this.classifier = classifier;
}
public void loadMetadata(DBRProgressMonitor monitor) throws IOException {
......@@ -76,7 +81,7 @@ public class MavenArtifact
versions.clear();
lastUpdate = null;
String metadataPath = getArtifactURL() + MAVEN_METADATA_XML;
String metadataPath = getBaseArtifactURL() + MAVEN_METADATA_XML;
monitor.subTask("Load metadata " + this + "");
try (InputStream mdStream = RuntimeUtils.openConnectionStream(metadataPath)) {
......@@ -85,7 +90,7 @@ public class MavenArtifact
log.warn("Error parsing artifact metadata", e);
} catch (IOException e) {
// Metadata xml not found. It happens in rare cases. Let's try to get directory listing
try (InputStream dirStream = RuntimeUtils.openConnectionStream(getArtifactURL())) {
try (InputStream dirStream = RuntimeUtils.openConnectionStream(getBaseArtifactURL())) {
parseDirectory(dirStream);
} catch (XMLException e1) {
log.warn("Error parsing artifact directory", e);
......@@ -153,39 +158,65 @@ public class MavenArtifact
});
}
@NotNull
public MavenRepository getRepository() {
return repository;
}
@NotNull
public String getGroupId() {
return groupId;
}
@NotNull
public String getArtifactId() {
return artifactId;
}
@Nullable
public String getClassifier() {
return classifier;
}
@NotNull
@Override
public String getVersion() {
return "";
}
@NotNull
@Override
public String getId() {
return MavenArtifactReference.makeId(this);
}
public Date getLastUpdate() {
return lastUpdate;
}
private String getArtifactURL() {
private String getBaseArtifactURL() {
String dir = groupId.replace('.', '/') + "/" + artifactId;
return repository.getUrl() + dir + "/";
}
public String getFileURL(String version, String fileType) {
return getArtifactURL() + version + "/" + getVersionFileName(version, fileType);
return getBaseArtifactURL() + version + "/" + getVersionFileName(version, fileType);
}
@NotNull
String getVersionFileName(String version, String fileType) {
return artifactId + "-" + version + "." + fileType;
String getVersionFileName(@NotNull String version, @NotNull String fileType) {
StringBuilder sb = new StringBuilder();
sb.append(artifactId).append("-").append(version);
if (FILE_JAR.equals(fileType) && !CommonUtils.isEmpty(classifier)) {
sb.append('-').append(classifier);
}
sb.append(".").append(fileType);
return sb.toString();
}
@Override
public String toString() {
return MavenArtifactReference.makeId(groupId, artifactId);
return getId();
}
// @Nullable
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import java.util.ArrayList;
import java.util.List;
......@@ -41,8 +42,8 @@ public class MavenArtifactDependency extends MavenArtifactReference {
private List<MavenArtifactReference> exclusions;
private boolean broken;
public MavenArtifactDependency(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, Scope scope, boolean optional) {
super(groupId, artifactId, version);
public MavenArtifactDependency(@NotNull String groupId, @NotNull String artifactId, @Nullable String classifier, @NotNull String version, Scope scope, boolean optional) {
super(groupId, artifactId, classifier, version);
this.scope = scope;
this.optional = optional;
}
......
......@@ -18,11 +18,12 @@
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
/**
* Maven artifact reference
*/
public class MavenArtifactReference
public class MavenArtifactReference implements IMavenIdentifier
{
public static final String VERSION_PATTERN_RELEASE = "RELEASE";
public static final String VERSION_PATTERN_LATEST = "LATEST";
......@@ -38,12 +39,15 @@ public class MavenArtifactReference
private final String version;
@NotNull
private final String id;
@Nullable
private final String classifier;
public MavenArtifactReference(@NotNull String groupId, @NotNull String artifactId, @NotNull String version) {
public MavenArtifactReference(@NotNull String groupId, @NotNull String artifactId, @Nullable String classifier, @NotNull String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.id = makeId(groupId, artifactId);
this.classifier = classifier;
this.id = makeId(this);
}
public MavenArtifactReference(String ref) {
......@@ -54,46 +58,68 @@ public class MavenArtifactReference
}
divPos = mavenUri.indexOf(':');
if (divPos < 0) {
// No artifact ID
groupId = mavenUri;
artifactId = mavenUri;
version = DEFAULT_MAVEN_VERSION;
id = makeId(groupId, artifactId);
return;
}
groupId = mavenUri.substring(0, divPos);
int divPos2 = mavenUri.indexOf(':', divPos + 1);
if (divPos2 < 0) {
artifactId = mavenUri.substring(divPos + 1);
classifier = null;
version = DEFAULT_MAVEN_VERSION;
} else {
artifactId = mavenUri.substring(divPos + 1, divPos2);
version = mavenUri.substring(divPos2 + 1);
groupId = mavenUri.substring(0, divPos);
int divPos2 = mavenUri.indexOf(':', divPos + 1);
if (divPos2 < 0) {
// No version
artifactId = mavenUri.substring(divPos + 1);
classifier = null;
version = DEFAULT_MAVEN_VERSION;
} else {
int divPos3 = mavenUri.indexOf(':', divPos2 + 1);
if (divPos3 < 0) {
// No classifier
artifactId = mavenUri.substring(divPos + 1, divPos2);
classifier = null;
version = mavenUri.substring(divPos2 + 1);
} else {
artifactId = mavenUri.substring(divPos + 1, divPos2);
classifier = mavenUri.substring(divPos2 + 1, divPos3);
version = mavenUri.substring(divPos3 + 1);
}
}
}
id = makeId(groupId, artifactId);
id = makeId(this);
}
@Override
@NotNull
public String getGroupId() {
return groupId;
}
@Override
@NotNull
public String getArtifactId() {
return artifactId;
}
@Override
@Nullable
public String getClassifier() {
return classifier;
}
@Override
@NotNull
public String getVersion() {
return version;
}
@Override
@NotNull
public String getId() {
return id;
}
public String getPath() {
return groupId + ":" + artifactId + ":" + version;
return id + ":" + version;
}
@Override
......@@ -106,8 +132,12 @@ public class MavenArtifactReference
return groupId.hashCode() + artifactId.hashCode() + version.hashCode();
}
static String makeId(String groupId, String artifactId) {
return groupId + ":" + artifactId;
static String makeId(IMavenIdentifier identifier) {
if (identifier.getClassifier() != null) {
return identifier.getGroupId() + ":" + identifier.getArtifactId() + ":" + identifier.getClassifier();
} else {
return identifier.getGroupId() + ":" + identifier.getArtifactId();
}
}
}
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
......@@ -38,7 +39,7 @@ import java.util.*;
/**
* Maven artifact version descriptor (POM).
*/
public class MavenArtifactVersion {
public class MavenArtifactVersion implements IMavenIdentifier {
static final Log log = Log.getLog(MavenArtifactVersion.class);
public static final String PROP_PROJECT_VERSION = "project.version";
......@@ -97,10 +98,36 @@ public class MavenArtifactVersion {
return name;
}
@NotNull
@Override
public String getGroupId() {
return artifact.getGroupId();
}
@NotNull
@Override
public String getArtifactId() {
return artifact.getArtifactId();
}
@Nullable
@Override
public String getClassifier() {
return artifact.getClassifier();
}
@NotNull
@Override
public String getVersion() {
return version;
}
@NotNull
@Override
public String getId() {
return MavenArtifactReference.makeId(this);
}
public String getDescription() {
return description;
}
......@@ -233,8 +260,8 @@ public class MavenArtifactVersion {
MavenArtifactReference parentReference = new MavenArtifactReference(
parentGroupId,
parentArtifactId,
parentVersion
);
null,
parentVersion);
if (this.version == null) {
this.version = parentReference.getVersion();
}
......@@ -368,6 +395,7 @@ public class MavenArtifactVersion {
log.warn("Broken dependency reference: " + groupId + ":" + artifactId);
continue;
}
String classifier = evaluateString(XMLUtils.getChildElementBody(dep, "classifier"));
MavenArtifactDependency dmInfo = depManagement ? null : findDependencyManagement(groupId, artifactId);
......@@ -401,6 +429,7 @@ public class MavenArtifactVersion {
MavenArtifactReference importReference = new MavenArtifactReference(
groupId,
artifactId,
classifier,
version);
MavenArtifactVersion importedVersion = MavenRegistry.getInstance().findArtifact(monitor, this, importReference);
if (importedVersion == null) {
......@@ -422,12 +451,12 @@ public class MavenArtifactVersion {
}
MavenArtifactDependency dependency = new MavenArtifactDependency(
evaluateString(groupId),
evaluateString(artifactId),
evaluateString(version),
groupId,
artifactId,
classifier,
version,
scope,
optional
);
optional);
result.add(dependency);
// Exclusions
......@@ -438,6 +467,7 @@ public class MavenArtifactVersion {
new MavenArtifactReference(
CommonUtils.notEmpty(XMLUtils.getChildElementBody(exclusion, "groupId")),
CommonUtils.notEmpty(XMLUtils.getChildElementBody(exclusion, "artifactId")),
null,
""));
}
}
......
......@@ -97,7 +97,7 @@ public class MavenRepository
boolean newArtifact = false;
MavenArtifact artifact = cachedArtifacts.get(ref.getId());
if (artifact == null) {
artifact = new MavenArtifact(this, ref.getGroupId(), ref.getArtifactId());
artifact = new MavenArtifact(this, ref.getGroupId(), ref.getArtifactId(), ref.getClassifier());
newArtifact = true;
}
try {
......
......@@ -331,12 +331,12 @@ public class DriverEditDialog extends HelpEnabledDialog
DBPDriverLibrary lib = (DBPDriverLibrary) cell.getElement();
cell.setText(lib.getDisplayName());
File localFile = lib.getLocalFile();
if (localFile != null && localFile.exists()) {
cell.setForeground(null);
if (localFile != null && !localFile.exists()) {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
} else if (!driver.isLibraryResolved(lib)) {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
} else {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
cell.setForeground(null);
}
cell.setImage(DBeaverIcons.getImage(lib.getIcon()));
}
......
......@@ -38,12 +38,13 @@ class EditMavenArtifactDialog extends Dialog
private MavenArtifactReference artifact;
private Text groupText;
private Text artifactText;
private Text classifierText;
private Combo versionText;
public EditMavenArtifactDialog(Shell shell, MavenArtifactReference artifact)
{
super(shell);
this.artifact = artifact == null ? new MavenArtifactReference("", "", MavenArtifactReference.VERSION_PATTERN_RELEASE) : artifact;
this.artifact = artifact == null ? new MavenArtifactReference("", "", null, MavenArtifactReference.VERSION_PATTERN_RELEASE) : artifact;
}
public MavenArtifactReference getArtifact() {
......@@ -71,6 +72,9 @@ class EditMavenArtifactDialog extends Dialog
groupText.setLayoutData(gd);
artifactText = UIUtils.createLabelText(composite, "Artifact Id", artifact.getArtifactId());
artifactText.setLayoutData(gd);
classifierText = UIUtils.createLabelText(composite, "Classifier", CommonUtils.notEmpty(artifact.getClassifier()));
classifierText.setLayoutData(gd);
versionText = UIUtils.createLabelCombo(composite, "Version", SWT.DROP_DOWN | SWT.BORDER);
versionText.setLayoutData(gd);
......@@ -86,6 +90,7 @@ class EditMavenArtifactDialog extends Dialog
};
groupText.addModifyListener(ml);
artifactText.addModifyListener(ml);
classifierText.addModifyListener(ml);
versionText.addModifyListener(ml);
return composite;
......@@ -107,10 +112,13 @@ class EditMavenArtifactDialog extends Dialog
@Override
protected void okPressed() {
String classifier = classifierText.getText();
artifact = new MavenArtifactReference(
groupText.getText(),
artifactText.getText(),
CommonUtils.isEmpty(classifier) ? null : classifier,
versionText.getText());
super.okPressed();
}
}
\ No newline at end of file
......@@ -155,7 +155,6 @@
webURL="http://www.mysql.com/products/connector/"
description="MySQL standard driver">
<file type="jar" path="maven:/org.mariadb.jdbc:mariadb-java-client:RELEASE"/>
<file type="jar" path="maven:/org.slf4j:slf4j-api:RELEASE"/>
</driver>
</drivers>
<views>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册