@Test public void isJavaDir() { assertEquals("1.7.0", Capsule.isJavaDir("jre7")); assertEquals("1.7.0_45", Capsule.isJavaDir("jdk1.7.0_45")); assertEquals("1.7.0_51", Capsule.isJavaDir("jdk1.7.0_51.jdk")); assertEquals("1.7.0", Capsule.isJavaDir("1.7.0.jdk")); assertEquals("1.8.0", Capsule.isJavaDir("jdk1.8.0.jdk")); assertEquals("1.7.0", Capsule.isJavaDir("java-7-openjdk-amd64")); assertEquals("1.7.0", Capsule.isJavaDir("java-1.7.0-openjdk-amd64")); assertEquals("1.7.0", Capsule.isJavaDir("java-1.7.0-openjdk-1.7.0.79.x86_64")); assertEquals("1.8.0", Capsule.isJavaDir("java-8-oracle")); assertEquals("1.8.0", Capsule.isJavaDir("jdk-8-oracle")); assertEquals("1.8.0", Capsule.isJavaDir("jre-8-oracle")); assertEquals("1.8.0", Capsule.isJavaDir("jdk-8-oracle-x64")); assertEquals("1.8.0", Capsule.isJavaDir("jdk-1.8.0")); assertEquals("1.8.0", Capsule.isJavaDir("jre-1.8.0")); }
static String isJavaDir(String fileName) { fileName = fileName.toLowerCase(); if ((fileName.startsWith("java-") || fileName.startsWith("jdk-") || fileName.startsWith("jre-")) && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("^[^\\-]+-([0-9\\.]+)-").matcher(fileName); if (!m.find()) throw new RuntimeException("Cannot parse Java directory name: " + fileName); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk-") && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("java-([0-9]+)-").matcher(fileName); m.find(); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk") || fileName.startsWith("jre") || fileName.endsWith(".jdk") || fileName.endsWith(".jre")) { if (fileName.startsWith("jdk-") || fileName.startsWith("jre-")) fileName = fileName.substring(4); else if (fileName.startsWith("jdk") || fileName.startsWith("jre")) fileName = fileName.substring(3); if (fileName.endsWith(".jdk") || fileName.endsWith(".jre")) fileName = fileName.substring(0, fileName.length() - 4); return shortJavaVersion(fileName); } else return null; }
Capsule implements Runnable, InvocationHandler { static String isJavaDir(String fileName) { fileName = fileName.toLowerCase(); if ((fileName.startsWith("java-") || fileName.startsWith("jdk-") || fileName.startsWith("jre-")) && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("^[^\\-]+-([0-9\\.]+)-").matcher(fileName); if (!m.find()) throw new RuntimeException("Cannot parse Java directory name: " + fileName); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk-") && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("java-([0-9]+)-").matcher(fileName); m.find(); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk") || fileName.startsWith("jre") || fileName.endsWith(".jdk") || fileName.endsWith(".jre")) { if (fileName.startsWith("jdk-") || fileName.startsWith("jre-")) fileName = fileName.substring(4); else if (fileName.startsWith("jdk") || fileName.startsWith("jre")) fileName = fileName.substring(3); if (fileName.endsWith(".jdk") || fileName.endsWith(".jre")) fileName = fileName.substring(0, fileName.length() - 4); return shortJavaVersion(fileName); } else return null; } }
Capsule implements Runnable, InvocationHandler { static String isJavaDir(String fileName) { fileName = fileName.toLowerCase(); if ((fileName.startsWith("java-") || fileName.startsWith("jdk-") || fileName.startsWith("jre-")) && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("^[^\\-]+-([0-9\\.]+)-").matcher(fileName); if (!m.find()) throw new RuntimeException("Cannot parse Java directory name: " + fileName); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk-") && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("java-([0-9]+)-").matcher(fileName); m.find(); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk") || fileName.startsWith("jre") || fileName.endsWith(".jdk") || fileName.endsWith(".jre")) { if (fileName.startsWith("jdk-") || fileName.startsWith("jre-")) fileName = fileName.substring(4); else if (fileName.startsWith("jdk") || fileName.startsWith("jre")) fileName = fileName.substring(3); if (fileName.endsWith(".jdk") || fileName.endsWith(".jre")) fileName = fileName.substring(0, fileName.length() - 4); return shortJavaVersion(fileName); } else return null; } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); }
Capsule implements Runnable, InvocationHandler { static String isJavaDir(String fileName) { fileName = fileName.toLowerCase(); if ((fileName.startsWith("java-") || fileName.startsWith("jdk-") || fileName.startsWith("jre-")) && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("^[^\\-]+-([0-9\\.]+)-").matcher(fileName); if (!m.find()) throw new RuntimeException("Cannot parse Java directory name: " + fileName); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk-") && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("java-([0-9]+)-").matcher(fileName); m.find(); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk") || fileName.startsWith("jre") || fileName.endsWith(".jdk") || fileName.endsWith(".jre")) { if (fileName.startsWith("jdk-") || fileName.startsWith("jre-")) fileName = fileName.substring(4); else if (fileName.startsWith("jdk") || fileName.startsWith("jre")) fileName = fileName.substring(3); if (fileName.endsWith(".jdk") || fileName.endsWith(".jre")) fileName = fileName.substring(0, fileName.length() - 4); return shortJavaVersion(fileName); } else return null; } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); static final void main(String[] args); @SuppressWarnings({"BroadCatchBlock", "UnusedAssignment"}) static int main0(String[] args0); static void premain(String agentArgs, Instrumentation inst); static Object getCapsule(String capletClassName); boolean isAgent(); @Override final void run(); @Override Object invoke(Object proxy, Method method, Object[] args); @Override final int hashCode(); @Override final boolean equals(Object obj); @Override String toString(); }
Capsule implements Runnable, InvocationHandler { static String isJavaDir(String fileName) { fileName = fileName.toLowerCase(); if ((fileName.startsWith("java-") || fileName.startsWith("jdk-") || fileName.startsWith("jre-")) && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("^[^\\-]+-([0-9\\.]+)-").matcher(fileName); if (!m.find()) throw new RuntimeException("Cannot parse Java directory name: " + fileName); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk-") && (fileName.contains("-openjdk") || fileName.contains("-oracle"))) { final Matcher m = Pattern.compile("java-([0-9]+)-").matcher(fileName); m.find(); return shortJavaVersion(m.group(1)); } else if (fileName.startsWith("jdk") || fileName.startsWith("jre") || fileName.endsWith(".jdk") || fileName.endsWith(".jre")) { if (fileName.startsWith("jdk-") || fileName.startsWith("jre-")) fileName = fileName.substring(4); else if (fileName.startsWith("jdk") || fileName.startsWith("jre")) fileName = fileName.substring(3); if (fileName.endsWith(".jdk") || fileName.endsWith(".jre")) fileName = fileName.substring(0, fileName.length() - 4); return shortJavaVersion(fileName); } else return null; } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); static final void main(String[] args); @SuppressWarnings({"BroadCatchBlock", "UnusedAssignment"}) static int main0(String[] args0); static void premain(String agentArgs, Instrumentation inst); static Object getCapsule(String capletClassName); boolean isAgent(); @Override final void run(); @Override Object invoke(Object proxy, Method method, Object[] args); @Override final int hashCode(); @Override final boolean equals(Object obj); @Override String toString(); static final String VERSION; }