public void testVerCmp() { // epoch int result = testEpoch("1", "2"); assertEquals(-1, result); result = testEpoch("2", "1"); assertEquals(1, result); result = testEpoch(null, "1"); assertEquals(-1, result); result = testEpoch("2", null); assertEquals(1, result); // version result = testVersion("1", "2"); assertEquals(-1, result); result = testVersion("2", "1"); assertEquals(1, result); result = testVersion(null, "1"); assertEquals(-1, result); result = testVersion("1", null); assertEquals(1, result); // release result = testRelease("1", "2"); assertEquals(-1, result); result = testRelease("2", "1"); assertEquals(1, result); result = testRelease(null, "1"); assertEquals(-1, result); result = testRelease("1", null); assertEquals(1, result); // make sure we test alpha-numerics through rpmVersionComparator result = testRelease("1.2b", "1.2c"); assertEquals(-1, result); result = testRelease("1.2b3a", "1.2b2"); assertEquals(1, result); // test all nulls result = testEpoch(null, null); assertEquals(0, result); // test equals result = PackageManager.verCmp("4", "2.1", "b3", "4", "2.1", "b3"); assertEquals(0, result); }
// Check to make sure up2date is 2.9.0 protected ValidatorError validateUp2dateVersion() { Server hostServer = getHostServer(); List packages = PackageManager.systemPackageList(hostServer.getId(), null); if (packages != null) { log.debug(" packages.size() : " + packages.size()); } // PackageListItem Iterator i = packages.iterator(); String up2dateepoch = null; String up2dateversion = null; String up2daterelease = null; while (i.hasNext()) { PackageListItem pli = (PackageListItem) i.next(); if (pli.getName().equals("yum-rhn-plugin")) { // found yum-rhn-plugin - returning return null; } if (pli.getName().equals("zypp-plugin-spacewalk")) { // found zypp-plugin-spacewalk - returning return null; } if (pli.getName().equals("up2date")) { log.debug(" found up2date ..."); up2dateepoch = pli.getEpoch(); up2dateversion = pli.getVersion(); up2daterelease = pli.getRelease(); log.debug(" e: " + up2dateepoch + " v: " + up2dateversion + " r : " + up2daterelease); } } if (up2dateepoch == null && up2dateversion == null && up2daterelease == null) { Object[] args = new Object[2]; args[0] = hostServer.getId(); args[1] = hostServer.getName(); return new ValidatorError("kickstart.schedule.noup2date", args); } up2dateepoch = up2dateepoch == null ? "0" : up2dateepoch; up2dateversion = up2dateversion == null ? "0" : up2dateversion; up2daterelease = up2daterelease == null ? "0" : up2daterelease; int comp = PackageManager.verCmp( up2dateepoch, up2dateversion, up2daterelease, "0", UP2DATE_VERSION, "0"); log.debug(" Got back comp from verCmp: " + comp); if (comp < 0) { Long packageId = PackageManager.getServerNeededUpdatePackageByName(hostServer.getId(), "up2date"); if (packageId == null) { Object[] args = new Object[2]; args[0] = UP2DATE_VERSION; args[1] = up2dateversion; return new ValidatorError("kickstart.schedule.noup2dateinchannel", args); } Package p = PackageFactory.lookupByIdAndUser(packageId, this.user); Map evrmap = new HashMap(); evrmap.put("name_id", p.getPackageName().getId()); evrmap.put("evr_id", p.getPackageEvr().getId()); evrmap.put("arch_id", p.getPackageArch().getId()); packagesToInstall.add(evrmap); } else { return null; } return null; }
private int testRelease(String r1, String r2) { return PackageManager.verCmp("1", "2", r1, "1", "2", r2); }
private int testVersion(String v1, String v2) { return PackageManager.verCmp("1", v1, null, "1", v2, null); }
private int testEpoch(String e1, String e2) { return PackageManager.verCmp(e1, null, null, e2, null, null); }