use of biz.aQute.resolve.ProjectResolver in project bnd by bndtools.
the class ResolveCommand method _query.
public void _query(QueryOptions options) throws Exception {
List<String> args = options._arguments();
String bsn = args.remove(0);
String version = null;
if (!args.isEmpty())
version = args.remove(0);
ProjectResolver pr = new ProjectResolver(bnd.getProject(options.project()));
addClose(pr);
IdentityCapability resource = pr.getResource(bsn, version);
bnd.out.printf("%-30s %-20s %s\n", resource.osgi_identity(), resource.version(), resource.description(""));
Resource r = resource.getResource();
FilterParser p = new FilterParser();
if (r != null) {
List<Requirement> requirements = resource.getResource().getRequirements(null);
if (!requirements.isEmpty()) {
bnd.out.println("Requirements:");
for (Requirement req : requirements) {
Expression parse = p.parse(req);
bnd.out.printf(" %-20s %s\n", req.getNamespace(), parse);
}
}
List<Capability> capabilities = resource.getResource().getCapabilities(null);
if (!capabilities.isEmpty()) {
bnd.out.println("Capabilities:");
for (Capability cap : capabilities) {
Map<String, Object> attrs = new HashMap<String, Object>(cap.getAttributes());
Object id = attrs.remove(cap.getNamespace());
Object vv = attrs.remove("version");
if (vv == null)
vv = attrs.remove("bundle-version");
bnd.out.printf(" %-20s %-40s %-20s attrs=%s dirs=%s\n", cap.getNamespace(), id, vv, attrs, cap.getDirectives());
}
}
}
}
use of biz.aQute.resolve.ProjectResolver in project intellij-plugins by JetBrains.
the class ResolveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
Project project = event.getProject();
if (virtualFile == null || project == null)
return;
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {
private Map<Resource, List<Wire>> resolveResult;
private String updatedText;
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
File file = new File(virtualFile.getPath());
try (Workspace workspace = Workspace.findWorkspace(file);
Run run = Run.createRun(workspace, file);
ProjectResolver projectResolver = new ProjectResolver(run)) {
resolveResult = projectResolver.resolve();
List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
return new VersionedClause(c.getBundleSymbolicName(), attrs);
}).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
BndEditModel editModel = new BndEditModel();
IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
editModel.loadFrom(bndDocument);
editModel.setRunBundles(versionedClauses);
editModel.saveChangesTo(bndDocument);
updatedText = bndDocument.get();
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
throw new WrappingException(e);
}
indicator.checkCanceled();
}
@Override
public void onSuccess() {
if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
}
}
@Override
public void onThrowable(@NotNull Throwable t) {
Throwable cause = t instanceof WrappingException ? t.getCause() : t;
LOG.warn("Resolution failed", cause);
if (cause instanceof ResolutionException) {
new ResolutionFailedDialog(project, (ResolutionException) cause).show();
} else {
OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
}
}
}.queue();
}
use of biz.aQute.resolve.ProjectResolver in project bnd by bndtools.
the class ResolveCommand method _find.
public void _find(FindOptions options, bnd bnd) throws Exception {
List<String> args = options._arguments();
for (String bndrun : args) {
Project p = bnd.getProject(options.project());
Workspace workspace = p == null ? bnd.getWorkspace(options.workspace()) : p.getWorkspace();
Run run = new Run(workspace, p != null ? p.getBase() : IO.work, IO.getFile(bndrun));
ProjectResolver pr = new ProjectResolver(run);
addClose(pr);
pr.resolve();
bnd.out.println("Resolved " + run);
for (Container c : pr.getRunBundles()) {
bnd.out.printf("%-30s %-20s %-6s %s\n", c.getBundleSymbolicName(), c.getVersion(), c.getType(), c.getFile());
}
}
}
Aggregations