Search in sources :

Example 1 with ProjectResolver

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());
            }
        }
    }
}
Also used : Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) HashMap(java.util.HashMap) ProjectResolver(biz.aQute.resolve.ProjectResolver) Resource(org.osgi.resource.Resource) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 2 with ProjectResolver

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction.writeCommandAction(com.intellij.openapi.command.WriteCommandAction.writeCommandAction) Constants(aQute.bnd.osgi.Constants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) Workspace(aQute.bnd.build.Workspace) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) BndEditModel(aQute.bnd.build.model.BndEditModel) OsmorcBundle(org.osmorc.i18n.OsmorcBundle) ProjectResolver(biz.aQute.resolve.ProjectResolver) FileModificationService(com.intellij.codeInsight.FileModificationService) Resource(org.osgi.resource.Resource) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Run(aQute.bnd.build.Run) Collectors(java.util.stream.Collectors) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) BndFileType(org.jetbrains.osgi.bnd.BndFileType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IDocument(aQute.bnd.properties.IDocument) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Wire(org.osgi.resource.Wire) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ResolutionException(org.osgi.service.resolver.ResolutionException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ProjectResolver(biz.aQute.resolve.ProjectResolver) Attrs(aQute.bnd.header.Attrs) Document(com.intellij.openapi.editor.Document) IDocument(aQute.bnd.properties.IDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IDocument(aQute.bnd.properties.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 3 with ProjectResolver

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());
        }
    }
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) ProjectResolver(biz.aQute.resolve.ProjectResolver) Run(aQute.bnd.build.Run) Workspace(aQute.bnd.build.Workspace)

Aggregations

ProjectResolver (biz.aQute.resolve.ProjectResolver)3 Run (aQute.bnd.build.Run)2 Workspace (aQute.bnd.build.Workspace)2 Resource (org.osgi.resource.Resource)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 BndEditModel (aQute.bnd.build.model.BndEditModel)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 Attrs (aQute.bnd.header.Attrs)1 Constants (aQute.bnd.osgi.Constants)1 FilterParser (aQute.bnd.osgi.resource.FilterParser)1 Expression (aQute.bnd.osgi.resource.FilterParser.Expression)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 IDocument (aQute.bnd.properties.IDocument)1 FileModificationService (com.intellij.codeInsight.FileModificationService)1 NotificationType (com.intellij.notification.NotificationType)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 WriteCommandAction.writeCommandAction (com.intellij.openapi.command.WriteCommandAction.writeCommandAction)1