@Override public Optional<BlackArtifact> getArtifact(String groupId, String artifactId, String version) { SuffixedVersion parsedVersion = versionParser.parse(version); Optional<BlackArtifact> artifact = blackArtifactDAO.findArtifact(groupId, artifactId, parsedVersion.unsuffixedVesion()); if (parsedVersion.isSuffixed() && !artifact.isPresent()) { artifact = blackArtifactDAO.findArtifact(groupId, artifactId, version); } return artifact; }
private int compareByDistance(SuffixedVersion v1, SuffixedVersion v2) { if (base.equals(v1)) { return -1; if (base.equals(v2)) { return 1; if (v1.getMajor() != v2.getMajor()) { if (v1.getMajor() == base.getMajor()) { return -1; if (v2.getMajor() == base.getMajor()) { return 1; if (v1.getMajor() == v2.getMajor() && v1.getMinor() == v2.getMinor() && v1.getMicro() == v2.getMicro()) { candidate *= -1;
private Optional<String> findBiggestMatchingVersion(SuffixedVersion queryVersion, Collection<SuffixedVersion> versions) { String bestMatchVersion = null; int biggestBuildNumber = 0; String unsuffixedVesion = queryVersion.unsuffixedVesion(); List<SuffixedVersion> candidateVersions = versions.stream() .filter(SuffixedVersion::isSuffixed) .filter(v-> unsuffixedVesion.equals(v.unsuffixedVesion())) .collect(Collectors.toList()); boolean onlyDefaultSuffixPresent = candidateVersions.stream() .map(v -> v.getSuffix().get()) .allMatch(VersionAnalyzer::isDefaultSuffix); List<SuffixedVersion> versionsToSearch = candidateVersions.stream() .filter(v -> onlyDefaultSuffixPresent || !isDefaultSuffix(v.getSuffix().get())) .collect(Collectors.toList()); for (SuffixedVersion ver : versionsToSearch) { int foundBuildNumber = ver.getSuffixVersion().get(); if (bestMatchVersion == null || foundBuildNumber > biggestBuildNumber) { bestMatchVersion = ver.getOriginalVersion(); biggestBuildNumber = foundBuildNumber; } else if (foundBuildNumber == biggestBuildNumber) { bestMatchVersion = getMoreSpecificVersion(bestMatchVersion, ver.getOriginalVersion()); } } return Optional.ofNullable(bestMatchVersion); }
/** * Return information about first part of version that is different. */ public VersionDifference difference(String version1, String version2) { SuffixedVersion v1 = versionParser.parse(version1); SuffixedVersion v2 = versionParser.parse(version2); if (v1.getMajor() != v2.getMajor()) { return VersionDifference.MAJOR; } if (v1.getMinor() != v2.getMinor()) { return VersionDifference.MINOR; } if (v1.getMicro() != v2.getMicro()) { return VersionDifference.MICRO; } if (!v1.getQualifier().equals(v2.getQualifier())) { return VersionDifference.QUALIFIER; } if (!v1.getSuffix().equals(v2.getSuffix())) { return VersionDifference.SUFFIX; } if (!v1.getSuffixVersion().equals(v2.getSuffixVersion())) { return VersionDifference.RH_SUFFIX; } return VersionDifference.EQUAL; }
public SuffixedVersion parse(String version) { SuffixedVersion suffixedVersion = parseVersion(versionPattern.matcher(version), version, suffix); if (!suffixedVersion.isSuffixed()) { suffixedVersion = parseVersion(defaultPattern.matcher(version), version, DEFAULT_SUFFIX); } return suffixedVersion; }
private SuffixedVersion parseVersion(Matcher versionMatcher, String version, String parseSuffix) throws NumberFormatException, IllegalArgumentException { if (!versionMatcher.matches()) { throw new IllegalArgumentException("Version " + version + "is unparsable"); } String majorString = versionMatcher.group("major"); String minorString = versionMatcher.group("minor"); String microString = versionMatcher.group("micro"); String qualifierString = versionMatcher.group("qualifier"); String suffixVersionString = versionMatcher.group("suffixversion"); int major = parseNumberString(majorString); int minor = parseNumberString(minorString); int micro = parseNumberString(microString); String qualifier = qualifierString == null ? "" : qualifierString; if (suffixVersionString == null) { return new SuffixedVersion(major, minor, micro, qualifier, version); } else { int suffixVersion = Integer.parseInt(suffixVersionString); return new SuffixedVersion(major, minor, micro, qualifier, parseSuffix, suffixVersion, version); } }
@Override public int compare(String version1, String version2) { SuffixedVersion v1 = versionParser.parse(version1); SuffixedVersion v2 = versionParser.parse(version2); int r = v1.compareTo(v2); if (r == 0 || base == null) { return r; } else { return compareByDistance(v1, v2); } }
private Stream<String> getVersionsStream(GA ga) { if (!ga.isValid()) { log.warn("Received nonvalid GA: " + ga); return Stream.empty(); } try { return aproxConnector.getVersionsOfGA(ga).stream() .filter(v -> versionParser.parse(v).isSuffixed()) .distinct(); } catch (CommunicationException ex) { throw new ProductException(ex); } }
private Stream<String> getVersionsStream(GA ga, String repository) { if (!ga.isValid()) { log.warn("Received nonvalid GA: " + ga); return Stream.empty(); } try { return aproxConnector.getVersionsOfGA(ga, repository).stream() .filter(v -> versionParser.parse(v).isSuffixed()) .distinct(); } catch (CommunicationException ex) { throw new ProductException(ex); } }
private WhiteArtifact createArtifact(String groupId, String artifactId, String version) { SuffixedVersion parsedVersion = versionParser.parse(version); final boolean is3rdParty = !parsedVersion.isSuffixed(); final String osgiVersion = VersionParser.getOSGiVersion(version); GA ga = gaDAO.findOrCreate(groupId, artifactId); WhiteArtifact a = new WhiteArtifact(ga, version, currentUser(), osgiVersion, is3rdParty); whiteArtifactDAO.create(a); return a; }
} else { if (parser.parse(dep.getVersion()).isSuffixed()) continue;