public static void testBumpSubBuilders() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("bump-sub"); project.setTrace(true); assertNull(project.getProperty("Bundle-Version")); project.bump("=+0"); assertNull(project.getProperty("Bundle-Version")); for (Builder b : project.getSubBuilders()) { assertEquals(new Version(1, 1, 0), new Version(b.getVersion())); } } finally { IO.deleteWithException(tmp); } }
public static void testBumpIncludeFile() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("bump-included"); project.setTrace(true); Version old = new Version(project.getProperty("Bundle-Version")); assertEquals(new Version(1, 0, 0), old); project.bump("=+0"); Processor processor = new Processor(); processor.setProperties(project.getFile("include.txt")); Version newv = new Version(processor.getProperty("Bundle-Version")); System.err.println("New version " + newv); assertEquals(1, newv.getMajor()); assertEquals(1, newv.getMinor()); assertEquals(0, newv.getMicro()); } finally { IO.deleteWithException(tmp); } }
public static void testBump() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("p1"); int size = project.getProperties().size(); Version old = new Version(project.getProperty("Bundle-Version")); System.err.println("Old version " + old); project.bump("=+0"); Version newv = new Version(project.getProperty("Bundle-Version")); System.err.println("New version " + newv); assertEquals(old.getMajor(), newv.getMajor()); assertEquals(old.getMinor() + 1, newv.getMinor()); assertEquals(0, newv.getMicro()); assertEquals(size, project.getProperties().size()); assertEquals("sometime", newv.getQualifier()); } finally { IO.deleteWithException(tmp); } }
private static void checkPackageInfoFiles( Project project, String packageName, boolean expectPackageInfo, boolean expectPackageInfoJava) throws Exception { File pkgInfo = IO.getFile(project.getSrc(), packageName + "/packageinfo"); File pkgInfoJava = IO.getFile(project.getSrc(), packageName + "/package-info.java"); assertEquals(expectPackageInfo, pkgInfo.exists()); assertEquals(expectPackageInfoJava, pkgInfoJava.exists()); }
@Override public void delete(Project p) throws IOException { File root = p.getWorkspace().getFile("pom.xml"); String rootPom = IO.collect(root); if (rootPom.contains(getTag(p))) { rootPom = rootPom.replaceAll("\n\\s*" + getTag(p) + "\\s*", "\n"); IO.store(rootPom, root); } }
@Override protected void tearDown() throws Exception { super.tearDown(); framework.stop(); IO.delete(tmp); Main.stop(); IO.delete(IO.getFile("generated/cache")); IO.delete(IO.getFile("generated/storage")); framework.waitForStop(100000); super.tearDown(); }
private void copy(File workspaceDir, InputStream in, Pattern glob, boolean overwrite) throws Exception { Jar jar = new Jar("dot", in); try { for (Entry<String, Resource> e : jar.getResources().entrySet()) { String path = e.getKey(); bnd.trace("path %s", path); if (glob != null && !glob.matcher(path).matches()) continue; Resource r = e.getValue(); File dest = Processor.getFile(workspaceDir, path); if (overwrite || !dest.isFile() || dest.lastModified() < r.lastModified() || r.lastModified() <= 0) { bnd.trace("copy %s to %s", path, dest); File dp = dest.getParentFile(); if (!dp.exists() && !dp.mkdirs()) { throw new IOException("Could not create directory " + dp); } IO.copy(r.openInputStream(), dest); } } } finally { jar.close(); } }
@Override public void created(Project p) throws IOException { Workspace workspace = p.getWorkspace(); copy("pom.xml", "pom.xml", p); File root = workspace.getFile("pom.xml"); doRoot(p, root); String rootPom = IO.collect(root); if (!rootPom.contains(getTag(p))) { rootPom = rootPom.replaceAll( "<!-- DO NOT EDIT MANAGED BY BND MAVEN LIFECYCLE PLUGIN -->\n", "$0\n\t\t" + getTag(p) + "\n"); IO.store(rootPom, root); } }
private void copy(String source, String dest, Project p) throws IOException { File f = p.getWorkspace().getFile("maven/" + source + ".tmpl"); InputStream in; if (f.isFile()) { in = new FileInputStream(f); } else { in = MavenPlugin.class.getResourceAsStream(source); if (in == null) { p.error("Cannot find Maven default for %s", source); return; } } String s = IO.collect(in); String process = p.getReplacer().process(s); File d = p.getFile(dest); d.getParentFile().mkdirs(); IO.store(process, d); }
@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); IO.copy(IO.getFile("testdata/ws"), tmp); workspace = Workspace.getWorkspace(tmp); workspace.refresh(); InfoRepository repo = workspace.getPlugin(InfoRepository.class); t1 = create("bsn-1", new Version(1, 0, 0)); t2 = create("bsn-2", new Version(1, 0, 0)); repo.put(new FileInputStream(t1), null); repo.put(new FileInputStream(t2), null); t1 = repo.get("bsn-1", new Version(1, 0, 0), null); t2 = repo.get("bsn-2", new Version(1, 0, 0), null); repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null); workspace.getPlugins().add(repo); File storage = IO.getFile("generated/storage-1"); storage.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); context = framework.getBundleContext(); location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString(); agent = context.installBundle(location); agent.start(); thread = new Thread() { @Override public void run() { try { Main.main( new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" }); } catch (Exception e) { e.printStackTrace(); } } }; thread.setDaemon(true); thread.start(); super.setUp(); }
private File create(String bsn, Version v) throws Exception { String name = bsn + "-" + v; Builder b = new Builder(); b.setBundleSymbolicName(bsn); b.setBundleVersion(v); b.setProperty("Random", random++ + ""); b.setProperty("-resourceonly", true + ""); b.setIncludeResource("foo;literal='foo'"); Jar jar = b.build(); assertTrue(b.check()); File file = IO.getFile(tmp, name + ".jar"); file.getParentFile().mkdirs(); jar.updateModified(System.currentTimeMillis(), "Force it to now"); jar.write(file); b.close(); return file; }
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 void doRoot(Project p, File root) throws IOException { if (!root.isFile()) { IO.delete(root); copy("rootpom.xml", "../pom.xml", p); } }
public static void testSetPackageVersion() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("p5"); project.setTrace(true); Version newVersion = new Version(2, 0, 0); // Package with no package info project.setPackageInfo("pkg1", newVersion); Version version = project.getPackageInfo("pkg1"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg1", true, false); // Package with package-info.java containing @Version("1.0.0") project.setPackageInfo("pkg2", newVersion); version = project.getPackageInfo("pkg2"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg2", false, true); // Package with package-info.java containing @aQute.bnd.annotations.Version("1.0.0") project.setPackageInfo("pkg3", newVersion); version = project.getPackageInfo("pkg3"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg3", false, true); // Package with package-info.java containing @aQute.bnd.annotations.Version(value="1.0.0") project.setPackageInfo("pkg4", newVersion); version = project.getPackageInfo("pkg4"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg4", false, true); // Package with package-info.java containing version + packageinfo project.setPackageInfo("pkg5", newVersion); version = project.getPackageInfo("pkg5"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg5", true, true); // Package with package-info.java NOT containing version + packageinfo project.setPackageInfo("pkg6", newVersion); version = project.getPackageInfo("pkg6"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg6", true, true); // Package with package-info.java NOT containing version project.setPackageInfo("pkg7", newVersion); version = project.getPackageInfo("pkg7"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg7", true, true); newVersion = new Version(2, 2, 0); // Update packageinfo file project.setPackageInfo("pkg1", newVersion); version = project.getPackageInfo("pkg1"); assertEquals(newVersion, version); checkPackageInfoFiles(project, "pkg1", true, false); } finally { IO.deleteWithException(tmp); } }