/** * Verify that the Meta-Persistence header is correctly verified * * @throws Exception */ public void verifyMetaPersistence() throws Exception { Builder b = new Builder(); b.setIncludeResource("foo.xml;literal='I exist'"); Jar inner = b.build(); assertTrue(b.check()); Jar outer = new Jar("x"); outer.putResource("foo.jar", new JarResource(inner)); Manifest m = new Manifest(); m.getMainAttributes() .putValue(Constants.META_PERSISTENCE, "foo.jar, foo.jar!/foo.xml, absent.xml"); outer.setManifest(m); Verifier v = new Verifier(outer); v.verifyMetaPersistence(); assertTrue(v.check("Meta-Persistence refers to resources not in the bundle: \\[absent.xml\\]")); }
public static void testnativeCode() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("-resourceonly", "true"); b.setProperty("Include-Resource", "native/win32/NTEventLogAppender-1.2.dll;literal='abc'"); b.setProperty( "Bundle-NativeCode", "native/win32/NTEventLogAppender-1.2.dll; osname=Win32; processor=x86"); b.build(); Verifier v = new Verifier(b); v.verifyNative(); System.err.println(v.getErrors()); assertEquals(0, v.getErrors().size()); v.close(); b.close(); }
/** * Prepare the reference, will check for any errors. @param analyzer the analyzer to report errors * to. @throws Exception */ public void prepare(Analyzer analyzer) throws Exception { if (name == null) analyzer.error("No name for a reference"); if ((updated != null && !updated.equals("-")) || policyOption != null) updateVersion(AnnotationReader.V1_2); if (target != null) { String error = Verifier.validateFilter(target); if (error != null) analyzer.error("Invalid target filter %s for %s", target, name); } if (service == null) analyzer.error("No interface specified on %s", name); if (scope != null || field != null) updateVersion(AnnotationReader.V1_3); }
public void _workspace(WorkspaceOptions opts) throws Exception { File base = bnd.getBase(); String name = opts._arguments().get(0); File workspaceDir = Processor.getFile(base, name); name = workspaceDir.getName(); base = workspaceDir.getParentFile(); if (base == null) { bnd.error( "You cannot create a workspace in the root (%s). The parent of a workspace %n" + "must be a valid directory. Recommended is to dedicate a directory to %n" + "all (or related) workspaces.", workspaceDir); return; } if (!opts.anyname() && !Verifier.isBsn(name)) { bnd.error( "You specified a workspace name that does not follow the recommended pattern " + "(it should be like a Bundle Symbolic name). It is a bit pedantic but it " + "really helps hwne you get many workspaces. If you insist on this name, use the -a/--anyname option."); return; } Workspace ws = bnd.getWorkspace((File) null); if (ws != null && ws.isValid()) { bnd.error( "You are currently in a workspace already (%s) in %s. You can only create a new workspace outside an existing workspace", ws, base); return; } File eclipseDir = workspaceDir; workspaceDir.mkdirs(); if (!opts.single()) workspaceDir = new File(workspaceDir, "scm"); workspaceDir.mkdirs(); if (!base.isDirectory()) { bnd.error("Could not create directory for the bnd workspace %s", base); } else if (!eclipseDir.isDirectory()) { bnd.error("Could not create directory for the Eclipse workspace %s", eclipseDir); } if (!workspaceDir.isDirectory()) { bnd.error("Could not create the workspace directory %s", workspaceDir); return; } if (!opts.update() && !opts.force() && workspaceDir.list().length > 0) { bnd.error( "The workspace directory %s is not empty, specify -u/--update to update or -f/--force to replace", workspaceDir); } InputStream in = getClass().getResourceAsStream("/templates/enroute.zip"); if (in == null) { bnd.error("Cannot find template in this jar %s", "/templates/enroute.zip"); return; } Pattern glob = Pattern.compile("[^/]+|cnf/.*|\\...+/.*"); copy(workspaceDir, in, glob, opts.force()); File readme = new File(workspaceDir, "README.md"); if (readme.isFile()) IO.copy(readme, bnd.out); bnd.out.printf( "%nWorkspace %s created.%n%n" // + " Start Eclipse:%n" // + " 1) Select the Eclipse workspace %s%n" // + " 2) Package Explorer context menu: Import/General/Existing Projects from %s%n" + "%n" + "", // workspaceDir.getName(), eclipseDir, workspaceDir); }
private static void testFilter(String string) { int index = Verifier.verifyFilter(string, 0); while (index < string.length() && Character.isWhitespace(string.charAt(index))) index++; if (index != string.length()) throw new IllegalArgumentException("Characters after filter"); }
public static void testFailedOSGiJar() throws Exception { Jar jar = new Jar("jar/osgi.residential-4.3.0.jar"); Verifier v = new Verifier(jar); assertTrue(v.check()); }