use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.
the class LauncherTest method setUp.
@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();
}
use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.
the class bnd method _bsn2url.
public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
Project p = getProject(opts.project());
if (p == null) {
error("You need to be in a project or specify the project with -p/--project");
return;
}
MultiMap<String, Version> revisions = new MultiMap<String, Version>();
for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
if (!(repo instanceof InfoRepository))
continue;
for (String bsn : repo.list(null)) {
revisions.addAll(bsn, repo.versions(bsn));
}
}
for (List<Version> versions : revisions.values()) {
Collections.sort(versions, Collections.reverseOrder());
}
List<String> files = opts._arguments();
for (String f : files) {
try (BufferedReader r = IO.reader(getFile(f))) {
String line;
nextLine: while ((line = r.readLine()) != null) {
Matcher matcher = LINE_P.matcher(line);
if (!matcher.matches())
continue nextLine;
line = matcher.group(1);
Parameters bundles = new Parameters(line, this);
for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
String bsn = entry.getKey();
VersionRange range = new VersionRange(entry.getValue().getVersion());
List<Version> versions = revisions.get(bsn);
if (versions == null) {
error("No for versions for %s", bsn);
break nextLine;
}
for (Version version : versions) {
if (range.includes(version)) {
for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
if (!(repo instanceof InfoRepository))
continue;
InfoRepository rp = (InfoRepository) repo;
ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
if (descriptor == null) {
error("Found bundle, but no descriptor %s;version=%s", bsn, version);
return;
}
out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
}
}
}
}
}
} catch (Exception e) {
error("failed to create url list from file %s : %s", f, e);
}
}
}
use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.
the class InfoRepositoryWrapper method init.
boolean init() {
try {
if (System.currentTimeMillis() < lastTime + 10000)
return true;
} finally {
lastTime = System.currentTimeMillis();
}
Set<String> errors = new LinkedHashSet<String>();
try {
//
// Get the current repo contents
//
Set<String> toBeDeleted = new HashSet<String>(persistent.keySet());
Map<String, DownloadBlocker> blockers = new HashMap<String, DownloadBlocker>();
for (InfoRepository repo : repos) {
Map<String, ResourceDescriptor> map = collectKeys(repo);
for (final Map.Entry<String, ResourceDescriptor> entry : map.entrySet()) {
final String id = entry.getKey();
toBeDeleted.remove(id);
if (persistent.containsKey(id))
continue;
final ResourceDescriptor rd = entry.getValue();
DownloadBlocker blocker = new DownloadBlocker(null) {
//
// We steal the thread of the downloader to index
//
@Override
public void success(File file) throws Exception {
IndexResult index = null;
try {
index = repoIndexer.indexFile(file);
ResourceBuilder rb = new ResourceBuilder();
for (org.osgi.service.indexer.Capability capability : index.capabilities) {
CapReqBuilder cb = new CapReqBuilder(capability.getNamespace());
cb.addAttributes(capability.getAttributes());
cb.addDirectives(capability.getDirectives());
rb.addCapability(cb.buildSyntheticCapability());
}
for (org.osgi.service.indexer.Requirement requirement : index.requirements) {
CapReqBuilder cb = new CapReqBuilder(requirement.getNamespace());
cb.addAttributes(requirement.getAttributes());
cb.addDirectives(requirement.getDirectives());
rb.addRequirement(cb.buildSyntheticRequirement());
}
Resource resource = rb.build();
PersistentResource pr = new PersistentResource(resource);
persistent.put(id, pr);
} finally {
super.success(file);
if (index != null) {
index.resource.close();
}
}
}
};
blockers.put(entry.getKey(), blocker);
repo.get(rd.bsn, rd.version, null, blocker);
}
}
for (Entry<String, DownloadBlocker> entry : blockers.entrySet()) {
String key = entry.getKey();
DownloadBlocker blocker = entry.getValue();
String reason = blocker.getReason();
if (reason != null) {
errors.add(key + ": " + reason);
}
}
persistent.keySet().removeAll(toBeDeleted);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (!errors.isEmpty())
throw new IllegalStateException("Cannot index " + repos + " due to " + errors);
return true;
}
use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.
the class Plugin method init.
/**
* This is called when all initialization is done for the plugins, now we
* can obtain a list of appropriate repos.
*/
public void init() {
if (init)
return;
init = true;
try {
//
// Get the list if repos registered, repos that we can handle
//
List<InfoRepository> irs = new ArrayList<InfoRepository>();
for (InfoRepository ir : registry.getPlugins(InfoRepository.class)) {
irs.add(ir);
}
this.wrapper = new InfoRepositoryWrapper(dir, irs);
if (config.reindex())
this.wrapper.clear();
if (config.augments() != null) {
Workspace workspace = registry.getPlugin(Workspace.class);
try (Processor p = new Processor(workspace)) {
if (!config.augments().equals("WORKSPACE")) {
File f = IO.getFile(workspace.getBuildDir(), config.augments());
if (!f.isFile()) {
if (reporter != null)
reporter.error("No augment file found at %s", f.getAbsolutePath());
return;
}
//
// We read this in a processor that extends the
// workspace so
// we
// can use workspace properties
//
p.setProperties(f);
this.wrapper.clear(f.lastModified());
}
//
// And then add it to the indexer to use.
//
this.wrapper.addAugment(p.getFlattenedProperties());
this.wrapper.clear(workspace.getPropertiesFile().lastModified());
}
}
} catch (Exception e) {
throw Exceptions.duck(e);
}
}
use of aQute.bnd.service.repository.InfoRepository in project bnd by bndtools.
the class JpmRepoTest method testWrapper.
public void testWrapper() throws Exception {
ws.setProperty("-fixupmessages.jpmdeprecated", "aQute.bnd.jpm.Repository is deprecated");
assertNotNull(ws.getRepositories());
assertNotNull(ws.getPlugin(InfoRepository.class));
assertNotNull(ws.getPlugin(Repository.class));
assertTrue(ws.check());
// cache + jpm
assertEquals(2, ws.getRepositories().size());
InfoRepository plugin = ws.getPlugin(InfoRepository.class);
for (String bsn : plugin.list(null)) {
for (aQute.bnd.version.Version version : plugin.versions(bsn)) {
System.out.println(bsn + ";version=" + version);
}
}
}
Aggregations