public void update(UpdateMemo memo) throws Exception { ArtifactData target = put(memo.best.urls.iterator().next()); memo.current.version = new Version(memo.best.version); target.sync(); memo.current.sha = target.sha; // memo.current.dependencies = target.dependencies; // memo.current.dependencies.add((new File(repoDir, // Hex.toHexString(target.sha))).getCanonicalPath()); // memo.current.runbundles = target.runbundles; // memo.current.description = target.description; memo.current.time = target.time; if (memo.current instanceof ServiceData) { Service service = getService((ServiceData) memo.current); service.remove(); createService((ServiceData) memo.current); IO.delete(new File(IO.getFile(serviceDir, memo.current.name), "data")); storeData(new File(IO.getFile(serviceDir, memo.current.name), "data"), memo.current); } else { platform.deleteCommand(memo.current); createCommand(memo.current, false); IO.delete(IO.getFile(commandDir, memo.current.name)); storeData(IO.getFile(commandDir, memo.current.name), memo.current); } }
@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); BundleContext context = framework.getBundleContext(); String[] bundles = { "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar", "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar", "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar" }; for (String bundle : bundles) { String location = "reference:" + IO.getFile(bundle).toURI().toString(); Bundle b = context.installBundle(location); if (!bundle.contains("slf4j-simple")) { b.start(); } } super.setUp(); }
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 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(); }
@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(); }
/** The default policy is truncate micro. Check if this is applied to the import. */ public static void testImportMicroTruncated() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty("Import-Package", "org.osgi.service.event"); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[1.0,2)", s); }
public ArtifactData get(byte[] sha) throws Exception { String name = Hex.toHexString(sha); File data = IO.getFile(repoDir, name + ".json"); reporter.trace("artifact data file %s", data); if (data.isFile()) { // Bin + metadata ArtifactData artifact = codec.dec().from(data).get(ArtifactData.class); artifact.file = IO.getFile(repoDir, name).getAbsolutePath(); return artifact; } File bin = IO.getFile(repoDir, name); if (bin.exists()) { // Only bin ArtifactData artifact = new ArtifactData(); artifact.file = bin.getAbsolutePath(); artifact.sha = sha; return artifact; } return null; }
/** Test if we can get the version from the source and apply the default policy. */ public static void testVersionPolicyImportedExportsDefaultPolicy() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "org.osgi.service.event"); b.setProperty("Private-Package", "test.refer"); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[1.0,2)", s); }
/** * See if we a can override the version from the export statement and the version from the source. */ public static void testImportOverridesDiscoveredVersion() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "org.osgi.service.event"); b.setProperty("Private-Package", "test.refer"); b.setProperty("Import-Package", "org.osgi.service.event;version=2.1.3.q"); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("2.1.3.q", s); }
/** Check if we can set a specific version on the import that does not use a version policy. */ public static void testImportMicroNotTruncated() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty( "Import-Package", "org.osgi.service.event;version=${@}, org.osgi.service.log;version=\"${range;[==,=+)}\""); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); String l = b.getImports().getByFQN("org.osgi.service.log").get("version"); assertEquals("1.0.1", s); assertEquals("[1.3,1.4)", l); }
/** Test import provide:. */ public static void testExportProvided() throws Exception { Builder a = new Builder(); a.addClasspath(IO.getFile("jar/osgi.jar")); a.addClasspath(new File("bin")); a.setProperty("Private-Package", "test.refer"); a.setProperty("Export-Package", "org.osgi.service.http;provide:=true"); Jar jar = a.build(); Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event"); assertEquals("[1.0,2)", event.get("version")); Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http"); assertEquals("[1.2,1.3)", http.get("version")); Manifest m = jar.getManifest(); String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE); assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE)); }
/** hardcoded imports */ public static void testHardcodedImports() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty("-versionpolicy", "${range;[==,+)}"); b.setProperty("Private-Package", "org.objectweb.asm"); b.setProperty("Import-Package", "org.osgi.framework,org.objectweb.asm,abc;version=2.0.0,*"); b.build(); Manifest m = b.getJar().getManifest(); m.write(System.err); String s = b.getImports().getByFQN("org.objectweb.asm").get("version"); assertNull(s); s = b.getImports().getByFQN("abc").get("version"); assertEquals("2.0.0", s); s = b.getImports().getByFQN("org.osgi.framework").get("version"); assertEquals("[1.3,2)", s); }
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; }
private String listSupportFiles(List<File> toDelete) throws Exception { Formatter f = new Formatter(); try { if (toDelete == null) { toDelete = new ArrayList<File>(); } int precount = toDelete.size(); File confFile = IO.getFile(platform.getConfigFile()).getCanonicalFile(); if (confFile.exists()) { f.format(" * %s \t0 Config file%n", confFile); toDelete.add(confFile); } String result = (toDelete.size() > precount) ? f.toString() : null; return result; } finally { f.close(); } }
public void testJMXBundleDeployer() throws Exception { JMXBundleDeployer jmxBundleDeployer = new JMXBundleDeployer(); long bundleId = jmxBundleDeployer.deploy( "biz.aQute.remote.agent", IO.getFile("generated/biz.aQute.remote.agent.jar")); assertTrue(bundleId > 0); BundleDTO agentBundle = null; long state = -1; for (BundleDTO bundle : jmxBundleDeployer.listBundles()) { if (bundle.symbolicName.equals("biz.aQute.remote.agent")) { agentBundle = bundle; state = bundle.state; } } assertNotNull(agentBundle); assertEquals(Bundle.ACTIVE, state); }
/** * Constructor * * @throws IOException */ public JustAnotherPackageManager(Reporter reporter, Platform platform, File homeDir, File binDir) throws IOException { this.platform = platform; this.reporter = reporter; this.homeDir = homeDir; if (!homeDir.exists() && !homeDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + homeDir); repoDir = IO.getFile(homeDir, "repo"); if (!repoDir.exists() && !repoDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + repoDir); commandDir = new File(homeDir, COMMANDS); serviceDir = new File(homeDir, SERVICE); commandDir.mkdir(); serviceDir.mkdir(); service = new File(repoDir, SERVICE_JAR_FILE); if (!service.isFile()) init(); this.binDir = binDir; if (!binDir.exists() && !binDir.mkdirs()) throw new IllegalArgumentException("Could not create bin directory " + binDir); }
public void deinit(Appendable out, boolean force) throws Exception { Settings settings = new Settings(platform.getConfigFile()); if (!force) { Justif justify = new Justif(80, 40); StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); try { String list = listFiles(platform.getGlobal()); if (list != null) { f.format("In global default environment:%n"); f.format(list); } list = listFiles(platform.getLocal()); if (list != null) { f.format("In local default environment:%n"); f.format(list); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL))); if (list != null) { f.format("In global configured environment:%n"); f.format(list); } } if (settings.containsKey(JPM_CACHE_LOCAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL))); if (list != null) { f.format("In local configured environment:%n"); f.format(list); } } list = listSupportFiles(); if (list != null) { f.format("jpm support files:%n"); f.format(list); } f.format("%n%n"); f.format( "All files listed above will be deleted if deinit is run with the force flag set" + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n"); f.flush(); justify.wrap(sb); out.append(sb.toString()); } finally { f.close(); } } else { // i.e. if(force) int count = 0; File[] caches = {platform.getGlobal(), platform.getLocal(), null, null}; if (settings.containsKey(JPM_CACHE_LOCAL)) { caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL)); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL)); } ArrayList<File> toDelete = new ArrayList<File>(); for (File cache : caches) { if (cache == null || !cache.exists()) { continue; } listFiles(cache, toDelete); if (toDelete.size() > count) { count = toDelete.size(); if (!cache.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + cache + ")"); return; } toDelete.add(cache); } } listSupportFiles(toDelete); for (File f : toDelete) { if (f.exists() && !f.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + f + ")"); } } if (reporter.getErrors().size() > 0) { return; } for (File f : toDelete) { if (f.exists()) { IO.deleteWithException(f); } } } }