提交 c1fc2055 编写于 作者: J jurgen

Dependency exclusion fix

Former-commit-id: ebd64c48
上级 c07a55e4
......@@ -220,7 +220,7 @@ public class DriverLibraryMavenArtifact extends DriverLibraryAbstract
}
if (!forceUpdate) {
MavenLocalVersion localVersion = artifact.getActiveLocalVersion();
if (localVersion != null && localVersion.getCacheFile().exists()) {
if (localVersion != null) {
// Already cached
return localVersion;
}
......
......@@ -254,6 +254,13 @@ public class MavenArtifact
}
public MavenLocalVersion resolveVersion(DBRProgressMonitor monitor, String versionRef, boolean lookupVersion) throws IOException {
/*
MavenLocalVersion localVersion = getActiveLocalVersion();
if (localVersion != null && versionRef.equals(MavenArtifactReference.VERSION_PATTERN_RELEASE) || versionRef.equals(MavenArtifactReference.VERSION_PATTERN_LATEST)) {
// No need to lookup - we already have it
return localVersion;
}
*/
if (lookupVersion && !metadataLoaded) {
loadMetadata(monitor);
}
......@@ -261,30 +268,34 @@ public class MavenArtifact
String versionInfo = versionRef;
if (lookupVersion) {
List<String> allVersions = versions;
if (versionInfo.equals(MavenArtifactReference.VERSION_PATTERN_RELEASE)) {
versionInfo = releaseVersion;
if (!CommonUtils.isEmpty(versionInfo) && isBetaVersion(versionInfo)) {
versionInfo = null;
}
} else if (versionInfo.equals(MavenArtifactReference.VERSION_PATTERN_LATEST)) {
versionInfo = latestVersion;
} else {
if (versionInfo.startsWith("[") && versionInfo.endsWith("]")) {
// Regex - find most recent version matching this pattern
String regex = versionInfo.substring(1, versionInfo.length() - 1);
try {
Pattern versionPattern = Pattern.compile(regex);
List<String> versions = new ArrayList<String>(allVersions);
for (Iterator<String> iter = versions.iterator(); iter.hasNext(); ) {
if (!versionPattern.matcher(iter.next()).matches()) {
iter.remove();
switch (versionInfo) {
case MavenArtifactReference.VERSION_PATTERN_RELEASE:
versionInfo = releaseVersion;
if (!CommonUtils.isEmpty(versionInfo) && isBetaVersion(versionInfo)) {
versionInfo = null;
}
break;
case MavenArtifactReference.VERSION_PATTERN_LATEST:
versionInfo = latestVersion;
break;
default:
if (versionInfo.startsWith("[") && versionInfo.endsWith("]")) {
// Regex - find most recent version matching this pattern
String regex = versionInfo.substring(1, versionInfo.length() - 1);
try {
Pattern versionPattern = Pattern.compile(regex);
List<String> versions = new ArrayList<String>(allVersions);
for (Iterator<String> iter = versions.iterator(); iter.hasNext(); ) {
if (!versionPattern.matcher(iter.next()).matches()) {
iter.remove();
}
}
versionInfo = findLatestVersion(versions);
} catch (Exception e) {
throw new IOException("Bad version pattern: " + regex);
}
versionInfo = findLatestVersion(versions);
} catch (Exception e) {
throw new IOException("Bad version pattern: " + regex);
}
}
break;
}
if (CommonUtils.isEmpty(versionInfo)) {
if (allVersions.isEmpty()) {
......
......@@ -142,6 +142,9 @@ public class MavenArtifactVersion {
}
public List<MavenArtifactReference> findExclusionsFor(String groupId, String artifactId) {
if (dependencies == null) {
return null;
}
for (MavenArtifactDependency dependency : dependencies) {
if (dependency.getGroupId().equals(groupId) && dependency.getArtifactId().equals(artifactId)) {
return dependency.getExclusions();
......
......@@ -131,17 +131,22 @@ public class MavenRegistry
@Nullable
public MavenArtifact findArtifact(@NotNull MavenArtifactReference ref) {
return findArtifact(ref.getGroupId(), ref.getArtifactId());
return findArtifact(ref.getGroupId(), ref.getArtifactId(), true);
}
@Nullable
private MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId) {
public MavenArtifact findArtifact(@NotNull MavenArtifactReference ref, boolean resolve) {
return findArtifact(ref.getGroupId(), ref.getArtifactId(), resolve);
}
@Nullable
private MavenArtifact findArtifact(@NotNull String groupId, @NotNull String artifactId, boolean resolve) {
String fullId = groupId + ":" + artifactId;
if (notFoundArtifacts.contains(fullId)) {
return null;
}
MavenArtifact artifact = findInRepositories(groupId, artifactId, false);
if (artifact == null) {
if (artifact == null && resolve) {
artifact = findInRepositories(groupId, artifactId, true);
}
if (artifact != null) {
......@@ -153,27 +158,6 @@ public class MavenRegistry
return null;
}
/*
@Nullable
public MavenLocalVersion findArtifactVersion(@NotNull MavenArtifactReference ref) {
String fullId = ref.getGroupId() + ":" + ref.getArtifactId();
if (notFoundArtifacts.contains(fullId)) {
return null;
}
MavenLocalVersion version = findInRepositories(groupId, artifactId, false);
if (version == null) {
version = findInRepositories(groupId, artifactId, true);
}
if (version != null) {
return version;
}
// Not found
notFoundArtifacts.add(fullId);
return null;
}
*/
public void resetArtifactInfo(MavenArtifactReference artifactReference) {
String groupId = artifactReference.getGroupId();
String artifactId = artifactReference.getArtifactId();
......
......@@ -168,6 +168,7 @@ public class MavenRepository
String path;
MavenArtifactDependency.Scope scope;
boolean optional;
List<String> exclusions;
DependencyResolveInfo(String path, MavenArtifactDependency.Scope scope, boolean optional) {
this.path = path;
......@@ -210,6 +211,7 @@ public class MavenRepository
reader.parse(new SAXListener() {
MavenArtifact lastArtifact;
VersionResolveInfo lastVersionResolveInfo;
DependencyResolveInfo lastDependencyInfo;
@Override
public void saxStartElement(SAXReader reader, String namespaceURI, String localName, Attributes atts) throws XMLException {
if (TAG_ARTIFACT.equals(localName)) {
......@@ -247,11 +249,17 @@ public class MavenRepository
log.debug(e);
}
}
lastVersionResolveInfo.dependencies.add(new DependencyResolveInfo(
lastDependencyInfo = new DependencyResolveInfo(
atts.getValue(ATTR_PATH),
scope,
CommonUtils.getBoolean(atts.getValue(ATTR_OPTIONAL), false)
));
);
lastVersionResolveInfo.dependencies.add(lastDependencyInfo);
} else if (TAG_EXCLUDE.equals(localName) && lastDependencyInfo != null) {
if (lastDependencyInfo.exclusions == null) {
lastDependencyInfo.exclusions = new ArrayList<>();
}
lastDependencyInfo.exclusions.add(atts.getValue(ATTR_PATH));
}
}
@Override
......@@ -264,6 +272,8 @@ public class MavenRepository
lastArtifact = null;
} else if (TAG_VERSION.equals(localName)) {
lastVersionResolveInfo = null;
} else if (TAG_DEPENDENCY.equals(localName)) {
lastDependencyInfo = null;
}
}
});
......@@ -279,29 +289,33 @@ public class MavenRepository
// Perform late resolution
for (VersionResolveInfo vri : lateResolutions) {
if (vri.parentPath != null) {
MavenLocalVersion parentVersion = resolveLocalVersion(vri.parentPath);
MavenLocalVersion parentVersion = resolveCachedVersion(vri.parentPath);
if (parentVersion != null) {
vri.localVersion.getMetaData().setParent(parentVersion);
}
}
for (DependencyResolveInfo dri : vri.dependencies) {
MavenLocalVersion depVersion = resolveLocalVersion(dri.path);
if (depVersion != null) {
vri.localVersion.getMetaData().addDependency(
new MavenArtifactDependency(
depVersion.getArtifact().getGroupId(),
depVersion.getArtifact().getArtifactId(),
depVersion.getVersion(),
dri.scope,
dri.optional));
//MavenLocalVersion cachedVersion = resolveCachedVersion(dri.path);
MavenArtifactReference reference = new MavenArtifactReference(dri.path);
MavenArtifactDependency dependency = new MavenArtifactDependency(
reference.getGroupId(),
reference.getArtifactId(),
reference.getVersion(),
dri.scope,
dri.optional);
if (!CommonUtils.isEmpty(dri.exclusions)) {
for (String path : dri.exclusions) {
dependency.addExclusion(new MavenArtifactReference(path));
}
}
vri.localVersion.getMetaData().addDependency(dependency);
}
}
}
private MavenLocalVersion resolveLocalVersion(String path) {
private MavenLocalVersion resolveCachedVersion(String path) {
MavenArtifactReference parentRef = new MavenArtifactReference(path);
MavenArtifact parentArtifact = MavenRegistry.getInstance().findArtifact(parentRef);
MavenArtifact parentArtifact = MavenRegistry.getInstance().findArtifact(parentRef, false);
if (parentArtifact == null) {
log.warn("Can't resolve artifact " + parentRef);
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册