public static String getHazelcastVersionFromJAR(String classPath) { String hzVersion = getHazelcastVersionFromJarOrNull(classPath); int majorVersion = (hzVersion != null) ? getMajorVersion(hzVersion) : DEFAULT_MAJOR_VERSION; int minorVersion = (hzVersion != null) ? getMinorVersion(hzVersion) : DEFAULT_MINOR_VERSION; return format("%d%d", majorVersion, minorVersion); }
static int getMajorVersion() { return getMajorVersion(getVersion()); }
public static boolean isMinVersion(String minVersion) { return isMinVersion(minVersion, getVersion()); }
static int getMinorVersion() { return getMinorVersion(getVersion()); }
static boolean isMinVersion(String minVersion, String version) { if (version == null) { return false; } return VersionUtils.isMinVersion(minVersion, getVersion()); }
private String getClasspath(File workerHome) { String simulatorHome = getSimulatorHome().getAbsolutePath(); String hzVersionDirectory = directoryForVersionSpec(workerProcessSettings.getVersionSpec()); String testJarVersion = getHazelcastVersionFromJAR(simulatorHome + "/hz-lib/" + hzVersionDirectory + "/*"); LOGGER.info(format("Adding Hazelcast %s and test JARs %s to classpath", hzVersionDirectory, testJarVersion)); String uploadClassPath = ""; File uploadDirectory = new File(workerHome, "upload").getAbsoluteFile(); if (uploadDirectory.exists() && uploadDirectory.isDirectory()) { File[] files = uploadDirectory.listFiles(); if (files != null && files.length > 0) { uploadClassPath = CLASSPATH_SEPARATOR + uploadDirectory.getAbsolutePath() + "/*"; LOGGER.info(format("Adding upload directory %s to classpath", uploadClassPath)); } } // we have to reverse the classpath to monkey patch version specific classes return new File(agent.getSessionDirectory(), "lib/*").getAbsolutePath() + CLASSPATH_SEPARATOR + simulatorHome + "/user-lib/*" + CLASSPATH_SEPARATOR + simulatorHome + "/test-lib/" + testJarVersion + "/*" + CLASSPATH_SEPARATOR + simulatorHome + "/test-lib/common/*" + CLASSPATH_SEPARATOR + simulatorHome + "/hz-lib/" + hzVersionDirectory + "/*" + uploadClassPath + CLASSPATH_SEPARATOR + CLASSPATH; }
static String getHazelcastVersionFromJarOrNull(String classPath) { try { List<File> jarFiles = getFilesFromClassPath(classPath); for (File jarFile : jarFiles) { String version = getVersion(jarFile); if (version != null) { return version; } } } catch (UncheckedIOException ignored) { ignore(ignored); } return null; }