@Test public void ensureNoJdkJarsIncluded() throws SAXException, ParserConfigurationException, XPathExpressionException, IOException { ApplicationChecksums ac = new ApplicationChecksums(); String javaHome = System.getProperty("java.home"); List<File> jars = ac.findNonJdkJars(); for (File f : jars) { assertFalse(f.getCanonicalPath().startsWith(javaHome)); } }
List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); String javaHome = System.getProperty("java.home"); List<File> ret = new LinkedList<File>(); while (manifests.hasMoreElements()) { URL u = manifests.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); File f = new File(file); String canonicalPath = f.getCanonicalPath(); if (!canonicalPath.startsWith(javaHome)) { ret.add(f); } } else { logger.info("Can't include code in checksum which isn't in a JAR: " + u); } } return ret; }
ApplicationChecksums implements DynamicMBean, InitializingBean { List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); String javaHome = System.getProperty("java.home"); List<File> ret = new LinkedList<File>(); while (manifests.hasMoreElements()) { URL u = manifests.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); File f = new File(file); String canonicalPath = f.getCanonicalPath(); if (!canonicalPath.startsWith(javaHome)) { ret.add(f); } } else { logger.info("Can't include code in checksum which isn't in a JAR: " + u); } } return ret; } }
ApplicationChecksums implements DynamicMBean, InitializingBean { List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); String javaHome = System.getProperty("java.home"); List<File> ret = new LinkedList<File>(); while (manifests.hasMoreElements()) { URL u = manifests.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); File f = new File(file); String canonicalPath = f.getCanonicalPath(); if (!canonicalPath.startsWith(javaHome)) { ret.add(f); } } else { logger.info("Can't include code in checksum which isn't in a JAR: " + u); } } return ret; }  }
ApplicationChecksums implements DynamicMBean, InitializingBean { List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); String javaHome = System.getProperty("java.home"); List<File> ret = new LinkedList<File>(); while (manifests.hasMoreElements()) { URL u = manifests.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); File f = new File(file); String canonicalPath = f.getCanonicalPath(); if (!canonicalPath.startsWith(javaHome)) { ret.add(f); } } else { logger.info("Can't include code in checksum which isn't in a JAR: " + u); } } return ret; }  @Override void afterPropertiesSet(); void setAlgorithms(String algorithms); @ManagedAttribute String[] getAlgorithmsArray(); Map<String, Map<String, String>> getFileCheckSumsByAlgorithm(); @Override Object getAttribute(String attribute); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] attributes); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo(); Map<String, String> getAppCheckSumsByAlgorithm(); }
ApplicationChecksums implements DynamicMBean, InitializingBean { List<File> findNonJdkJars() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { Enumeration<URL> manifests = LibraryVersions.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); String javaHome = System.getProperty("java.home"); List<File> ret = new LinkedList<File>(); while (manifests.hasMoreElements()) { URL u = manifests.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); File f = new File(file); String canonicalPath = f.getCanonicalPath(); if (!canonicalPath.startsWith(javaHome)) { ret.add(f); } } else { logger.info("Can't include code in checksum which isn't in a JAR: " + u); } } return ret; }  @Override void afterPropertiesSet(); void setAlgorithms(String algorithms); @ManagedAttribute String[] getAlgorithmsArray(); Map<String, Map<String, String>> getFileCheckSumsByAlgorithm(); @Override Object getAttribute(String attribute); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] attributes); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo(); Map<String, String> getAppCheckSumsByAlgorithm(); static final String FILES_INCLUDED_ATTRIBUTE; static final String APPLICATION_CHECKSUM; static final String SEP; }