List of usage examples for org.apache.maven.artifact.versioning ComparableVersion ComparableVersion
public ComparableVersion(String version)
From source file:com.github.klieber.phantomjs.util.VersionUtil.java
License:Open Source License
public static int compare(String versionA, String versionB) { if (versionA == versionB) { return 0; }//from w w w .jav a 2 s. c o m if (versionA == null) { return -1; } if (versionB == null) { return 1; } return new ComparableVersion(versionA).compareTo(new ComparableVersion(versionB)); }
From source file:com.github.robozonky.app.version.VersionComparator.java
License:Apache License
@Override public int compare(final String s1, final String s2) { return new ComparableVersion(s1).compareTo(new ComparableVersion(s2)); }
From source file:com.insightfullogic.release.Version.java
License:Apache License
public final void parseVersion(String version) { comparable = new ComparableVersion(version); int index = version.indexOf("-"); String part1;/*ww w . j av a 2 s . c om*/ String part2 = null; if (index < 0) { part1 = version; } else { part1 = version.substring(0, index); part2 = version.substring(index + 1); } if (part2 != null) { try { if ((part2.length() == 1) || !part2.startsWith("0")) { buildNumber = Integer.valueOf(part2); } else { qualifier = part2; } } catch (NumberFormatException e) { qualifier = part2; } } if ((part1.indexOf(".") < 0) && !part1.startsWith("0")) { try { majorVersion = Integer.valueOf(part1); } catch (NumberFormatException e) { // qualifier is the whole version, including "-" qualifier = version; buildNumber = null; } } else { boolean fallback = false; StringTokenizer tok = new StringTokenizer(part1, "."); try { majorVersion = getNextIntegerToken(tok); if (tok.hasMoreTokens()) { minorVersion = getNextIntegerToken(tok); } if (tok.hasMoreTokens()) { incrementalVersion = getNextIntegerToken(tok); } if (tok.hasMoreTokens()) { fallback = true; } // string tokenzier won't detect these and ignores them if (part1.indexOf("..") >= 0 || part1.startsWith(".") || part1.endsWith(".")) { fallback = true; } } catch (NumberFormatException e) { fallback = true; } if (fallback) { // qualifier is the whole version, including "-" qualifier = version; majorVersion = null; minorVersion = null; incrementalVersion = null; buildNumber = null; } } }
From source file:com.yodle.vantage.component.service.ComponentService.java
License:Apache License
private List<VersionId> ensureReferencedVersionsExist(Version version, boolean excludeRequestedDependencies) { Set<VersionId> realVersionsToEnsureCreated = new HashSet<>(); realVersionsToEnsureCreated.add(versionPurifier.requireRealVersion(version.toId())); realVersionsToEnsureCreated.addAll(version.getResolvedDependencies().stream() //we don't just use isRealVersion to filter because if we have a resolved dependency that's not //either latest or real we want to fail .filter(dep -> !versionPurifier.isLatestVersion(dep.getVersion().getVersion())) .map(dep -> versionPurifier.requireRealVersion(dep.getVersion().toId())) .collect(Collectors.toSet())); if (!excludeRequestedDependencies) { realVersionsToEnsureCreated.addAll(version.getResolvedDependencies().stream() .flatMap(dep -> dep.getVersion().getRequestedDependencies().stream()) .filter(dep -> versionPurifier.isRealVersion(dep.getVersion().getVersion())) .map(dep -> dep.getVersion().toId()).collect(Collectors.toSet())); realVersionsToEnsureCreated.addAll(version.getRequestedDependencies().stream() .filter(dep -> versionPurifier.isRealVersion(dep.getVersion().getVersion())) .map(dep -> dep.getVersion().toId()).collect(Collectors.toSet())); }//from w w w . j a v a 2 s . c o m Set<VersionId> shadowVersionsToEnsureCreated = new HashSet<>(); shadowVersionsToEnsureCreated.addAll(version.getResolvedDependencies().stream() .filter(dep -> versionPurifier.isLatestVersion(dep.getVersion().getVersion())) .map(dep -> dep.getVersion().toId()).collect(Collectors.toSet())); if (!excludeRequestedDependencies) { shadowVersionsToEnsureCreated.addAll(version.getResolvedDependencies().stream() .flatMap(dep -> dep.getVersion().getRequestedDependencies().stream()) .filter(dep -> !versionPurifier.isRealVersion(dep.getVersion().getVersion())) .map(dep -> dep.getVersion().toId()).map(versionPurifier::purifyVersion) .collect(Collectors.toSet())); shadowVersionsToEnsureCreated.addAll(version.getRequestedDependencies().stream() .filter(dep -> !versionPurifier.isRealVersion(dep.getVersion().getVersion())) .map(dep -> dep.getVersion().toId()).map(versionPurifier::purifyVersion) .collect(Collectors.toSet())); } //Regardless of versioning scheme, we're doing maven ordering. Maven versions need to be done in maven ordering //since when we fix precedence we want to fix precedence in maven order to prevent deadlocks. Non-maven version // precedence is based on create //timestamp, which means that if we were ever fixing precedence for multiple non-maven versions for the same component //at the same time, it means we created two non-maven versions at the same time and we don't have an ordering //guarantee between them so we can insert them in the precedence list in an arbitrary order. We choose maven //ordering to ensure we create them in a deterministic order so as to prevent deadlocks Comparator<VersionId> versionComparator = (o1, o2) -> { if (o1.getComponent().equals(o2.getComponent())) { return new ComparableVersion(o1.getVersion()).compareTo(new ComparableVersion(o2.getVersion())); } else { return o1.getComponent().compareTo(o2.getComponent()); } }; shadowVersionsToEnsureCreated.stream().sorted(versionComparator) .forEach(v -> versionDao.createShadowVersion(v.getComponent(), v.getVersion())); return realVersionsToEnsureCreated.stream().sorted(versionComparator) .filter(v -> versionDao.createNewVersion(v.getComponent(), v.getVersion())) .collect(Collectors.toList()); }
From source file:com.yodle.vantage.component.service.ComponentService.java
License:Apache License
public Optional<List<Version>> getVersions(String component) { return getComponent(component).map(c -> { List<String> versions = versionDao.getVersions(component); Set<String> activeVersions = Sets.newHashSet(versionDao.getActiveVersions(component)); Map<String, Collection<Issue>> directIssues = issueDao.getIssuesDirectlyAffectingVersions(component); Map<String, Collection<Issue>> transitiveIssues = issueDao .getIssuesTransitivelyAffectingVersions(component); List<Version> vs = versions.stream().map(vName -> { Version v = new Version(component, vName, activeVersions.contains(vName)); v.setDirectIssues(directIssues.get(v.getVersion())); v.setTransitiveIssues(transitiveIssues.get(v.getVersion())); return v; }).collect(Collectors.toList()); if (isMavenStrategy(versions)) { vs = vs.stream().sorted((v1, v2) -> new ComparableVersion(v2.getVersion()) .compareTo(new ComparableVersion(v1.getVersion()))).collect(Collectors.toList()); }/*from ww w .j a va 2 s . c o m*/ return vs; }); }
From source file:com.yodle.vantage.component.service.PrecedenceFixer.java
License:Apache License
public void fixPrecendence(VersionId version) { //get all known versions List<String> versions = versionDao.getVersions(version.getComponent()); //determine insertion strategy boolean standard = isMavenStrategy(versions); if (standard) { List<ComparableVersion> comparableVersions = versions.stream().map(ComparableVersion::new) .collect(Collectors.toList()); TreeSet<ComparableVersion> cvTree = new TreeSet<>(); cvTree.addAll(comparableVersions); ComparableVersion inserted = new ComparableVersion(version.getVersion()); SortedSet<ComparableVersion> allPrev = cvTree.headSet(inserted); String prev = allPrev.size() > 0 ? allPrev.last().toString() : null; SortedSet<ComparableVersion> allNext = cvTree.tailSet(inserted, false); String next = allNext.size() > 0 ? allNext.first().toString() : null; versionDao.insertPrecendenceBetween(version.getComponent(), version.getVersion(), prev, next); } else {/*w w w.ja v a 2 s.c o m*/ versionDao.insertPrecedenceAtEnd(version.getComponent(), version.getVersion()); } }
From source file:de.dentrassi.pm.unzip.UnzipServlet.java
License:Open Source License
protected static void handleMavenPerfect(final Supplier<Collection<Artifact>> artifactsSupplier, final String channelIdOrName, final LinkedList<String> path, final IOConsumer<MavenVersionedArtifact> consumer) throws IOException { requirePathPrefix(path, 3,//www. j a v a 2 s. c o m "The 'maven' method requires at least one parameter: channel. e.g. /unzip/maven/perfect/<channelIdOrName>/<group.id>/<artifact.id>/<version>/path/to/file"); final String groupId = path.pop(); final String artifactId = path.pop(); final String versionString = path.pop(); final ComparableVersion v = new ComparableVersion(versionString); final List<MavenVersionedArtifact> arts = getMavenArtifacts(artifactsSupplier, groupId, artifactId, true, (a) -> a.compareTo(v) == 0); if (arts.isEmpty()) { // no result, throw new IllegalStateException(String.format( "No artifacts found for - groupId: %s, artifactId: %s, version: %s", groupId, artifactId, v)); } processArtifacts(String.format("maven artifact %s/%s/%s in channel %s", groupId, artifactId, versionString, channelIdOrName), arts, consumer); }
From source file:de.dentrassi.pm.unzip.UnzipServlet.java
License:Open Source License
private static ComparableVersion parseVersion(final String version) { if (version == null) { return null; }/*from w w w . j a v a 2s . co m*/ try { return new ComparableVersion(version); } catch (final Exception e) { logger.debug("Version not parsable: " + version, e); return null; } }
From source file:de.dktk.dd.rpb.portal.web.mb.edc.RandomisationBean.java
License:Open Source License
public void reload() { try {/*from w w w . j a va 2 s . c o m*/ if (this.rpbActiveStudy == null) { throw new Exception("There is no RPB study defined for your current active study in OpenClinica."); } if (!this.rpbActiveStudy.getIsRandomisedClinicalTrial()) { throw new Exception( "To access RadPlanBio subject randomisation feature the active study have to be randomised clinical trial."); } this.studyIntegrationFacade.init(this.mainBean); // Faster load with new OC REST APIs if (new ComparableVersion(this.mainBean.getMyAccount().getPartnerSite().getEdc().getVersion()) .compareTo(new ComparableVersion("3.7")) >= 0) { this.studyIntegrationFacade.setRetreiveStudySubjectOID(Boolean.FALSE); } List<Subject> ocSubjects = this.studyIntegrationFacade.loadSubjects(); // Subject which have been randomised for RadPlanBio study in specific site List<TrialSubject> randomisedSubjects; if (this.isPrincipalSite()) { randomisedSubjects = this.trialSubjectRepository.find(); //TODO: Make the select accroding to study and site } else { throw new Exception( "Cannot load randomised subjects because this is not the principal partner site and decentral randomisation is not implemented."); } // Compose subjects aggregate RadPlanBio subjects association with trial subject for randomisation // This is a good candidate for moving the code to study integration facade this.entityList = new ArrayList<Subject>(); for (Subject ocSubject : ocSubjects) { Subject subject = new Subject(); subject.setUniqueIdentifier(ocSubject.getUniqueIdentifier()); subject.setStudySubjectId(ocSubject.getStudySubjectId()); subject.setSecondaryId(ocSubject.getSecondaryId()); subject.setGender(ocSubject.getGender()); TrialSubject alreadyRandomisedSubject = null; for (TrialSubject ts : randomisedSubjects) { if (ts.getOcStudySubjectId().equals(ocSubject.getStudySubjectId())) { alreadyRandomisedSubject = ts; break; } } if (alreadyRandomisedSubject != null) { subject.setArm(alreadyRandomisedSubject.getTreatmentArm()); } entityList.add(subject); } // Prepare new data for UI data binding this.prepareNewEntity(); } catch (Exception err) { this.messageUtil.error(err); } }
From source file:de.dktk.dd.rpb.portal.web.mb.pacs.DicomPatientStudyBean.java
License:Open Source License
/** * Reload RadPlanBio subjects//from w w w . j a v a 2 s . co m */ public void reloadSubjects() { this.resetSubjects(); this.resetSubjectEvents(); this.resetDicomStudies(); try { this.studyIntegrationFacade.init(this.mainBean); // Faster load with new OC REST APIs if (new ComparableVersion(this.mainBean.getMyAccount().getPartnerSite().getEdc().getVersion()) .compareTo(new ComparableVersion("3.7")) >= 0) { this.studyIntegrationFacade.setRetreiveStudySubjectOID(Boolean.FALSE); } this.studySubjectsList = this.studyIntegrationFacade.loadSubjects(); } catch (Exception err) { this.messageUtil.error(err); } }