Search in sources :

Example 1 with VersionRange

use of org.jkiss.dbeaver.registry.maven.versioning.VersionRange in project dbeaver by serge-rider.

the class MavenArtifact method getAvailableVersions.

@Nullable
public Collection<String> getAvailableVersions(DBRProgressMonitor monitor, String versionSpec) throws IOException {
    if (CommonUtils.isEmpty(versions) && !metadataLoaded) {
        loadMetadata(monitor);
    }
    if (!isVersionPattern(versionSpec)) {
        return versions;
    }
    // Filter versions according to spec
    Pattern versionPattern = null;
    VersionRange versionRange = null;
    if (versionSpec.startsWith("{") && versionSpec.endsWith("}")) {
        // Regex - find most recent version matching this pattern
        try {
            versionPattern = Pattern.compile(versionSpec.substring(1, versionSpec.length() - 1));
        } catch (Exception e) {
            log.error("Bad version pattern: " + versionSpec);
        }
    } else {
        try {
            versionRange = VersionRange.createFromVersionSpec(versionSpec);
        } catch (Exception e) {
            log.error("Bad version specification: " + versionSpec);
        }
    }
    List<String> filtered = new ArrayList<>();
    for (String version : versions) {
        boolean matches;
        if (versionPattern != null) {
            matches = versionPattern.matcher(version).matches();
        } else if (versionRange != null) {
            matches = versionRange.containsVersion(new DefaultArtifactVersion(version));
        } else {
            matches = true;
        }
        if (matches) {
            filtered.add(version);
        }
    }
    return filtered;
}
Also used : Pattern(java.util.regex.Pattern) DefaultArtifactVersion(org.jkiss.dbeaver.registry.maven.versioning.DefaultArtifactVersion) VersionRange(org.jkiss.dbeaver.registry.maven.versioning.VersionRange) XMLException(org.jkiss.utils.xml.XMLException) IOException(java.io.IOException) Nullable(org.jkiss.code.Nullable)

Aggregations

IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 Nullable (org.jkiss.code.Nullable)1 DefaultArtifactVersion (org.jkiss.dbeaver.registry.maven.versioning.DefaultArtifactVersion)1 VersionRange (org.jkiss.dbeaver.registry.maven.versioning.VersionRange)1 XMLException (org.jkiss.utils.xml.XMLException)1