private void verifyManifestFirst() { if (!dot.manifestFirst) { error("Invalid JAR stream: Manifest should come first to be compatible with JarInputStream, it was not"); } }
private void verifyManifestFirst() { if (!dot.manifestFirst) { error("Invalid JAR stream: Manifest should come first to be compatible with JarInputStream, it was not"); } }
public boolean verifyFilter(String value) { try { verifyFilter(value, 0); return true; } catch (Exception e) { error("Not a valid filter: " + value + e.getMessage()); return false; } }
private void verifySymbolicName() { Map<String, Map<String, String>> bsn = parseHeader(getHeader(Analyzer.BUNDLE_SYMBOLICNAME)); if (!bsn.isEmpty()) { if (bsn.size() > 1) error("More than one BSN specified " + bsn); String name = (String) bsn.keySet().iterator().next(); if (!SYMBOLICNAME.matcher(name).matches()) { error("Symbolic Name has invalid format: " + name); } } }
public void verifyFilter(String value) { try { verifyFilter(value, 0); } catch (Exception e) { error("Not a valid filter: " + value + e.getMessage()); } }
private void verifyHeaders(Attributes main) { for (Object element : main.keySet()) { Attributes.Name header = (Attributes.Name) element; String h = header.toString(); if (!HEADER_PATTERN.matcher(h).matches()) error("Invalid Manifest header: " + h + ", pattern=" + HEADER_PATTERN); } }
private void verifySymbolicName() { Map<String, Map<String, String>> bsn = parseHeader(getHeader(Analyzer.BUNDLE_SYMBOLICNAME)); if (!bsn.isEmpty()) { if (bsn.size() > 1) error("More than one BSN specified " + bsn); String name = (String) bsn.keySet().iterator().next(); if (!isBsn(name)) { error("Symbolic Name has invalid format: " + name); } } }
private void verifyActivator() { String bactivator = getHeader("Bundle-Activator"); if (bactivator != null) { Clazz cl = loadClass(bactivator); if (cl == null) { int n = bactivator.lastIndexOf('.'); if (n > 0) { String pack = bactivator.substring(0, n); if (mimports.containsKey(pack)) return; error("Bundle-Activator not found on the bundle class path nor in imports: " + bactivator); } else error("Activator uses default package and is not local (default package can not be imported): " + bactivator); } } }
private void verifyActivator() { String bactivator = getHeader("Bundle-Activator"); if (bactivator != null) { Clazz cl = loadClass(bactivator); if (cl == null) { int n = bactivator.lastIndexOf('.'); if (n > 0) { String pack = bactivator.substring(0, n); if (mimports.containsKey(pack)) return; error("Bundle-Activator not found on the bundle class path nor in imports: " + bactivator); } else error("Activator uses default package and is not local (default package can not be imported): " + bactivator); } } }
private void verifyHeaders(Attributes main) { for (Object element : main.keySet()) { Attributes.Name header = (Attributes.Name) element; String h = header.toString(); if (!HEADER_PATTERN.matcher(h).matches()) error("Invalid Manifest header: " + h + ", pattern=" + HEADER_PATTERN); } }
private boolean verifyListHeader(String name, Pattern regex, boolean error) { String value = manifest.getMainAttributes().getValue(name); if (value == null) return false; Map<String, Map<String, String>> map = parseHeader(value); for (String header : map.keySet()) { if (!regex.matcher(header).matches()) { String msg = "Invalid value for " + name + ", " + value + " does not match " + regex.pattern(); if (error) error(msg); else warning(msg); } } return true; }
private boolean verifyListHeader(String name, Pattern regex, boolean error) { String value = manifest.getMainAttributes().getValue(name); if (value == null) return false; Map<String, Map<String, String>> map = parseHeader(value); for (String header : map.keySet()) { if (!regex.matcher(header).matches()) { String msg = "Invalid value for " + name + ", " + value + " does not match " + regex.pattern(); if (error) error(msg); else warning(msg); } } return true; }
/** * Invalid exports are exports mentioned in the manifest but not found on * the classpath. This can be calculated with: exports - contains. * * Unfortunately, we also must take duplicate names into account. These * duplicates are of course no erroneous. */ private void verifyInvalidExports() { Set<String> invalidExport = newSet(mexports.keySet()); invalidExport.removeAll(contained.keySet()); // We might have duplicate names that are marked for it. These // should not be counted. Should we test them against the contained // set? Hmm. If someone wants to hang himself by using duplicates than // I guess he can go ahead ... This is not a recommended practice for (Iterator<String> i = invalidExport.iterator(); i.hasNext();) { String pack = i.next(); if (isDuplicate(pack)) i.remove(); } if (!invalidExport.isEmpty()) error("Exporting packages that are not on the Bundle-Classpath" + bundleClasspath + ": " + invalidExport); }
@SuppressWarnings("unchecked") private boolean verifyHeader(String name, Pattern regex, boolean error) { String value = manifest.getMainAttributes().getValue(name); if (value == null) return false; QuotedTokenizer st = new QuotedTokenizer(value.trim(), ","); for (Iterator<String> i = st.getTokenSet().iterator(); i.hasNext();) { if (!verify((String) i.next(), regex)) { String msg = "Invalid value for " + name + ", " + value + " does not match " + regex.pattern(); if (error) error(msg); else warning(msg); } } return true; }
private boolean verifyHeader(String name, Pattern regex, boolean error) { String value = manifest.getMainAttributes().getValue(name); if (value == null) return false; QuotedTokenizer st = new QuotedTokenizer(value.trim(), ","); for (Iterator<String> i = st.getTokenSet().iterator(); i.hasNext();) { if (!verify((String) i.next(), regex)) { String msg = "Invalid value for " + name + ", " + value + " does not match " + regex.pattern(); if (error) error(msg); else warning(msg); } } return true; }
private void verifyComponent() { String serviceComponent = getHeader("Service-Component"); if (serviceComponent != null) { Map<String, Map<String, String>> map = parseHeader(serviceComponent); for (String component : map.keySet()) { if (component.indexOf("*") < 0 && !dot.exists(component)) { error("Service-Component entry can not be located in JAR: " + component); } else { // validate component ... } } } }
private void verifyComponent() { String serviceComponent = getHeader("Service-Component"); if (serviceComponent != null) { Map<String, Map<String, String>> map = parseHeader(serviceComponent); for (String component : map.keySet()) { if (component.indexOf("*") < 0 && !dot.exists(component)) { error("Service-Component entry can not be located in JAR: " + component); } else { // validate component ... } } } }
public void verifyBundleClasspath() { Map<String, Map<String, String>> bcp = parseHeader(getHeader(Analyzer.BUNDLE_CLASSPATH)); if (bcp.isEmpty() || bcp.containsKey(".")) return; for ( String path : bcp.keySet() ) { if ( path.endsWith("/")) error("A Bundle-ClassPath entry must not end with '/': %s", path); if ( dot.getDirectories().containsKey(path)) // We assume that any classes are in a directory // and therefore do not care when the bundle is included return; } for (String path : dot.getResources().keySet()) { if (path.endsWith(".class")) { warning("The Bundle-Classpath does not contain the actual bundle JAR (as specified with '.' in the Bundle-Classpath) but the JAR does contain classes. Is this intentional?"); return; } } }
public Verifier(Jar jar, Properties properties) throws Exception { this.dot = jar; this.properties = properties; this.manifest = jar.getManifest(); if (manifest == null) { manifest = new Manifest(); error("This file contains no manifest and is therefore not a bundle"); } main = this.manifest.getMainAttributes(); verifyHeaders(main); r3 = getHeader(Analyzer.BUNDLE_MANIFESTVERSION) == null; usesRequire = getHeader(Analyzer.REQUIRE_BUNDLE) != null; fragment = getHeader(Analyzer.FRAGMENT_HOST) != null; bundleClasspath = getBundleClassPath(); mimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE)); mdynimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.DYNAMICIMPORT_PACKAGE)); mexports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE)); ignore = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IGNORE_PACKAGE)); }
public Verifier(Jar jar, Properties properties) throws Exception { this.dot = jar; this.properties = properties; this.manifest = jar.getManifest(); if (manifest == null) { manifest = new Manifest(); error("This file contains no manifest and is therefore not a bundle"); } main = this.manifest.getMainAttributes(); verifyHeaders(main); r3 = getHeader(Analyzer.BUNDLE_MANIFESTVERSION) == null; usesRequire = getHeader(Analyzer.REQUIRE_BUNDLE) != null; fragment = getHeader(Analyzer.FRAGMENT_HOST) != null; bundleClasspath = getBundleClassPath(); mimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE)); mdynimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.DYNAMICIMPORT_PACKAGE)); mexports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE)); ignore = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IGNORE_PACKAGE)); }