in mr/src/main/java/org/elasticsearch/hadoop/util/Version.java [44:112]
static {
// check classpath
String target = Version.class.getName().replace(".", "/").concat(".class");
Enumeration<URL> res = null;
try {
res = Version.class.getClassLoader().getResources(target);
} catch (IOException ex) {
LogFactory.getLog(Version.class).warn("Cannot detect ES-Hadoop jar; it typically indicates a deployment issue...");
}
if (res != null) {
List<URL> urls = Collections.list(res);
Map<String, List<URL>> normalized = new LinkedHashMap<String, List<URL>>();
// On mac, the /tmp dir is a link to /private/tmp due to legacy weirdness.
// Both paths get added to the classpath for local YARN node managers when
// running Spark. This could happen in any number of other scenarios, and
// in each case, the jars that share a canonical path should be identical,
// so we'll bucket the URL's by their canonical path before counting them.
for (URL url : urls) {
try {
String canonicalPath = IOUtils.toCanonicalFilePath(url);
List<URL> pathURLs = normalized.get(canonicalPath);
if (pathURLs == null) {
pathURLs = new ArrayList<URL>();
normalized.put(canonicalPath, pathURLs);
}
pathURLs.add(url);
} catch (URISyntaxException e) {
String message = "Could not parse classpath resource URI: " + url.toString();
throw new RuntimeException(message, e);
} catch (IOException e) {
String message = "Could not retrieve canonical path to classpath resource: " + url.toString();
throw new RuntimeException(message, e);
}
}
// We only really want to fail if someone has added multiple JAR files to the classpath.
// Since the resource URLs will be collapsed by their canonical file paths, just get the
// first URL from each file path bucket and see if it is a jar URL for the purposes of
// counting unique jar instances.
int foundJars = 0;
if (normalized.size() > 1) {
StringBuilder sb = new StringBuilder("Multiple ES-Hadoop versions detected in the classpath; please use only one\n");
for (List<URL> pathURLs : normalized.values()) {
String path = pathURLs.get(0).toString();
if (path.contains("jar:")) {
foundJars++;
sb.append(path.replace("!/" + target, ""));
sb.append("\n");
}
}
if (foundJars > 1) {
throw new RuntimeException(sb.toString());
}
}
}
Properties build = new Properties();
try {
build = IOUtils.propsFromString(IOUtils.asString(Version.class.getResourceAsStream("/esh-build.properties")));
} catch (Exception ex) {
// ignore if no build info was found
}
VER = build.getProperty("version", UNKNOWN);
HASH = build.getProperty("hash", UNKNOWN);
SHORT_HASH = HASH.length() > 10 ? HASH.substring(0, 10) : HASH;
}