public String getVersion() { return version.getVersion(); }
public String getMaintenanceRelease() { return this.version.getMaintenanceRelease(); // String[] versions = this.version.split("\\."); // String majorRelease=(versions.length>0)?versions[0]:"0"; // String minorRelease = majorRelease.concat(".".concat((versions.length>1)?versions[1]:"0")); // return minorRelease.concat(".".concat((versions.length>2)?versions[2]:"0")); // }
/** * Compares this library ID with the provided library ID using, in that order, * group, artifact, or version. */ @Override public int compareTo(Object _other) { if(_other instanceof LibraryId) { final LibraryId other_libid = (LibraryId)_other; int result = this.getMvnGroup().compareToIgnoreCase(other_libid.getMvnGroup()); if(result==0) result = this.getArtifact().compareToIgnoreCase(other_libid.getArtifact()); if(result==0){ Version v = new Version(this.getVersion()); result = v.compareTo(new Version(other_libid.getVersion())); } return result; } else { throw new IllegalArgumentException("Expected object of type LibraryId, got [" + _other.getClass().getName() + "]"); } }
if(i.getLibraryId()!=null && i.getLibraryId().getMvnGroup().equals(a.getGroup()) && i.getLibraryId().getArtifact().equals(a.getArtifact()) ){ Version toCompare = new Version(i.getLibraryId().getVersion()); if(a.getVersionObject().getMaintenanceRelease().equals(toCompare.getMaintenanceRelease()) || toCompare.isMaintenanceRelease()){ if(a.getVersionObject().compareTo(toCompare)==0){ isGreater=false; break; else if (!i.getAffected() && a.getVersionObject().compareTo(toCompare)>0){ isGreater=true; else if (i.getAffected() && a.getVersionObject().compareTo(toCompare)<0){ isSmaller=true;
/** * * This method compares the versions of ArtifactResults2 according to the following priorities * 1) compare version numbers of the form major.minor[.maintenance[.build]], if only digits are contained * 2) compare timestap (of latest update in maven central) * 3) alphanumerical comparison * * @param other * @return */ public int compareVersion(ArtifactResult2 other) { int i = this.version.compareNumberVersion(other.getVersionObject()); if(i==0 && this.getTimestamp()!=null && other.getTimestamp()!=null) i = this.timestamp.compareTo(other.getTimestamp()); //if the execution is here it means that at least one of the compared version contains something else than numbers // if the version does not only contains numbers, we resort to the timestamp to order them, however if the timestamp is the same we resort to // a simple string comparison if(i==0) i=this.version.compareTo(other.getVersionObject()); return i; }
public ArtifactResult2(String _g, String _a, String _v, boolean _s, Long timestamp) { this.group = _g; this.artifact = _a; this.version = new Version(_v); this.timestamp = timestamp; this.sourcesAvailable = _s; this.constructPathAssessments = new ArrayList<ConstructPathAssessment2>(); }
public String getMajorRelease() { return this.version.getMajorRelease(); // String[] versions = this.version.split("\\."); // return (versions.length>0)?versions[0]:"0"; }
public String getMinorRelease() { return this.version.getMinorRelease(); // String[] versions = this.version.split("\\."); // String majorRelease=(versions.length>0)?versions[0]:"0"; // //check whether the minor starts with numbers: if it contains also letter just consider the numbers // // if(versions.length>1){ // Pattern p = Pattern.compile("^[0-9]*"); // Matcher m = p.matcher(versions[1]); // if(m.find() ){ // return majorRelease.concat(".".concat(m.group())); // } // } // return majorRelease.concat(".0"); }
@Override public int compareTo(Object _other) { if(_other instanceof Artifact) { final Artifact other_libid = (Artifact)_other; int result = this.getLibId().getMvnGroup().compareToIgnoreCase(other_libid.getLibId().getMvnGroup()); if(result==0) result = this.getLibId().getArtifact().compareToIgnoreCase(other_libid.getLibId().getArtifact()); if(result==0 && this.getTimestamp()!=null && other_libid.getTimestamp()!=null) result = this.getTimestamp().compareTo(other_libid.getTimestamp()); if(result==0){ Version v = new Version(this.getLibId().getVersion()); result = v.compareTo(new Version(other_libid.getLibId().getVersion())); } // result = this.getLibId().getVersion().compareToIgnoreCase(((Artifact) _other).getLibId().getVersion()); return result; } else { throw new IllegalArgumentException("Expected object of type Artifact, got [" + _other.getClass().getName() + "]"); } }
public ArtifactResult2(String _g, String _a, String _v, boolean _s) { this.group = _g; this.artifact = _a; this.version = new Version(_v); this.sourcesAvailable = _s; this.constructPathAssessments = new ArrayList<ConstructPathAssessment2>(); }
List<com.sap.psr.vulas.shared.json.model.LibraryId> greater_libids = new ArrayList<com.sap.psr.vulas.shared.json.model.LibraryId>(); for(LibraryId l: known_libids) { if(greaterThanVersion!=null && (new Version(l.getVersion()).compareTo(new Version(greaterThanVersion))>0)) greater_libids.add(l.toSharedType()); for(AffectedLibrary afflib: l.getAffLibraries()) {
/** * This method compares versions that only contains numbers. It returns 0 if they are equal or contains letters * * @param other version to compare * @return 0 if they are equal or contains letters; 1 if this.version>other.version; -1 otherwise */ public int compareNumberVersion(Version other) { String[] varray = this.version.split("\\."); String[] otherVersions = other.getVersion().split("\\."); for(int v=0;v<varray.length&&v<otherVersions.length;v++){ if(!varray[v].equals(otherVersions[v])){ //check that it only contains numbers Pattern p = Pattern.compile("^[0-9]*$"); Matcher m = p.matcher(varray[v]); Matcher m1 = p.matcher(otherVersions[v]); if(m.matches() && m1.matches()){ if (Integer.parseInt(varray[v])==Integer.parseInt(otherVersions[v])) break; return (Integer.parseInt(varray[v])>Integer.parseInt(otherVersions[v]))?1:-1; } } } return 0; }
@Override public int compareTo(Version o) { Matcher this_m = VERSION_PATTERN.matcher(this.getVersion()); Matcher other_m = VERSION_PATTERN.matcher(o.getVersion()); String this_v = (this_m.matches() ? this_m.group(1) : this.getVersion()); String other_v = (other_m.matches() ? other_m.group(1) : o.getVersion()); Version.log.debug("Versions to compare: [" + this.getVersion() + ", " + o.getVersion() + "], remove suffix for comparison [" + this_v + ", " + other_v + "]"); log.debug(this.version + " is greater than " + o.getVersion()); return 1; log.debug(this.version + " is smaller than " + o.getVersion()); return -1; String this_v_tag = (this_m.matches() ? this_m.group(2) : this.getVersion()); String other_v_tag = (other_m.matches() ? other_m.group(2) : o.getVersion()); log.debug(this.version + " is greater than " + o.getVersion()); return 1; log.debug(this.version + " is smaller than " + o.getVersion()); return -1; Version.log.debug("Compare artifact versions: Original [" + this.getVersion() + ", " + o.getVersion() + "], modified for comparison based on tag (if any)[" + this_v_tag + ", " + other_v_tag + "] returns : " +this_v_tag.compareToIgnoreCase(other_v_tag));