@Override public Object call() throws Exception { try { return doVersionRequest(current.toString()); } catch (IOException e) { return null; } } });
public static Status getStatus(final PomVersion serverVersion, final PomVersion clientVersion) { // WARN has to be dealt with on an ad-hoc basis. Since no warnings at this time, we don't // have any code here if (serverVersion.equals(clientVersion)) { return Status.EQUAL; } if (serverVersion.getMajor() != clientVersion.getMajor()) { return Status.INCOMPATIBLE; } // older clients, newer server within major version if (serverVersion.getMinor() >= clientVersion.getMinor()) { return Status.COMPATIBLE; } // newer client, older server within major version return Status.MAYBE; } }
public static PomVersion parse(final String str) { boolean isSnapshot = false; String version = str; if (str.endsWith("-SNAPSHOT")) { isSnapshot = true; version = version.substring(0, str.length() - 9); } final Iterable<String> bits = Splitter.on(".").split(version); if (size(bits) != 3) { throw new RuntimeException("Version string format is invalid"); } try { final Integer newMajor = Integer.valueOf(get(bits, 0)); final Integer newMinor = Integer.valueOf(get(bits, 1)); final Integer newPatch = Integer.valueOf(get(bits, 2)); return new PomVersion(isSnapshot, newMajor, newMinor, newPatch); } catch (NumberFormatException e) { throw new RuntimeException("Version portions are not numbers! " + str, e); } }
@Test public void testPatchVersion() throws Exception { final String newVersion = current.getMajor() + "." + current.getMinor() + "." + (current.getPatch() + 1); final HttpURLConnection connection = doVersionRequest(newVersion); assertResponseCodeType(connection, 2); assertServerVersion(connection); assertVersionStatus(connection, "COMPATIBLE"); }
/** * Given the client version, returns the version status, i.e. whether or not they should be * compatible or not. * * @param client The client version. * * @return The VersionCheckResponse object. */ @GET @Path("/check") @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public VersionCheckResponse versionCheck( @QueryParam("client") @DefaultValue("") final String client) { final PomVersion serverVersion = PomVersion.parse(Version.POM_VERSION); final VersionCompatibility.Status status; if (isNullOrEmpty(client)) { return new VersionCheckResponse(VersionCompatibility.Status.MISSING, serverVersion, Version.RECOMMENDED_VERSION); } final PomVersion clientVersion = PomVersion.parse(client); status = VersionCompatibility.getStatus(serverVersion, clientVersion); return new VersionCheckResponse(status, serverVersion, Version.RECOMMENDED_VERSION); } }
@Test public void testMinorVersion() throws Exception { final String newVersion = current.getMajor() + "." + (current.getMinor() + 1) + ".0"; final HttpURLConnection connection = doVersionRequest(newVersion); assertResponseCodeType(connection, 2); assertServerVersion(connection); assertVersionStatus(connection, "MAYBE"); }
@Test public void testMajorVersion() throws Exception { final String newVersion = (current.getMajor() + 1) + ".0.0"; final HttpURLConnection connection = doVersionRequest(newVersion); assertResponseCodeType(connection, 4); assertServerVersion(connection); assertVersionStatus(connection, "INCOMPATIBLE"); }
@Before public void setUp() throws Exception { startDefaultMaster(); current = PomVersion.parse(Version.POM_VERSION); // Wait for master to come up Polling.await(1, TimeUnit.MINUTES, new Callable<Object>() { @Override public Object call() throws Exception { try { return doVersionRequest(current.toString()); } catch (IOException e) { return null; } } }); }
/** * Given the client version, returns the version status, i.e. whether or not they should be * compatible or not. * @param client The client version. * @return The VersionCheckResponse object. */ @GET @Path("/check") @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public VersionCheckResponse versionCheck(@QueryParam("client") final String client) { final PomVersion clientVersion = PomVersion.parse(client); final PomVersion serverVersion = PomVersion.parse(Version.POM_VERSION); final VersionCompatibility.Status status = VersionCompatibility.getStatus(serverVersion, clientVersion); return new VersionCheckResponse(status, serverVersion, Version.RECOMMENDED_VERSION); } }