Search in sources :

Example 6 with RequirementWrapper

use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.

the class ResolutionView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    this.display = parent.getDisplay();
    SashForm splitPanel = new SashForm(parent, SWT.HORIZONTAL);
    splitPanel.setLayout(new FillLayout());
    Composite reqsPanel = new Composite(splitPanel, SWT.NONE);
    reqsPanel.setBackground(parent.getBackground());
    GridLayout reqsLayout = new GridLayout(1, false);
    reqsLayout.marginWidth = 0;
    reqsLayout.marginHeight = 0;
    reqsLayout.verticalSpacing = 2;
    reqsPanel.setLayout(reqsLayout);
    new Label(reqsPanel, SWT.NONE).setText("Requirements:");
    reqsTree = new Tree(reqsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    reqsTree.setHeaderVisible(false);
    reqsTree.setLinesVisible(false);
    reqsTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    reqsViewer = new TreeViewer(reqsTree);
    ColumnViewerToolTipSupport.enableFor(reqsViewer);
    reqsViewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
    reqsViewer.setContentProvider(new CapReqMapContentProvider());
    Composite capsPanel = new Composite(splitPanel, SWT.NONE);
    capsPanel.setBackground(parent.getBackground());
    GridLayout capsLayout = new GridLayout(1, false);
    capsLayout.marginWidth = 0;
    capsLayout.marginHeight = 0;
    capsLayout.verticalSpacing = 2;
    capsPanel.setLayout(capsLayout);
    new Label(capsPanel, SWT.NONE).setText("Capabilities:");
    capsTable = new Table(capsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    capsTable.setHeaderVisible(false);
    capsTable.setLinesVisible(false);
    capsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    capsViewer = new TableViewer(capsTable);
    ColumnViewerToolTipSupport.enableFor(capsViewer);
    capsViewer.setLabelProvider(new CapabilityLabelProvider(true));
    capsViewer.setContentProvider(new CapReqMapContentProvider());
    capsViewer.setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parent, Object element) {
            return !filteredCapabilityNamespaces.contains(((Capability) element).getNamespace());
        }
    } });
    hideSelfImportsFilter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof RequirementWrapper) {
                RequirementWrapper rw = (RequirementWrapper) element;
                return !rw.resolved;
            }
            return true;
        }
    };
    reqsViewer.setFilters(new ViewerFilter[] { hideSelfImportsFilter });
    reqsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(reqsViewer));
    capsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(capsViewer));
    reqsViewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
                Object item = iter.next();
                if (item instanceof Clazz) {
                    Clazz clazz = (Clazz) item;
                    String className = clazz.getFQN();
                    IType type = null;
                    if (!loaders.isEmpty()) {
                        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
                        for (CapReqLoader loader : loaders) {
                            if (loader instanceof BndBuilderCapReqLoader) {
                                File loaderFile = ((BndBuilderCapReqLoader) loader).getFile();
                                IFile[] wsfiles = wsroot.findFilesForLocationURI(loaderFile.toURI());
                                for (IFile wsfile : wsfiles) {
                                    IJavaProject javaProject = JavaCore.create(wsfile.getProject());
                                    try {
                                        type = javaProject.findType(className);
                                        if (type != null)
                                            break;
                                    } catch (JavaModelException e) {
                                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
                                    }
                                }
                            }
                        }
                    }
                    try {
                        if (type != null)
                            JavaUI.openInEditor(type, true, true);
                    } catch (PartInitException e) {
                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java editor for class '{0}'.", className), e));
                    } catch (JavaModelException e) {
                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
                    }
                }
            }
        }
    });
    fillActionBars();
    getSite().getPage().addPostSelectionListener(this);
    getSite().getPage().addPartListener(partAdapter);
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    // Current selection & part
    IWorkbenchPart activePart = getSite().getPage().getActivePart();
    ISelection activeSelection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
    selectionChanged(activePart, activeSelection);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) CapReqMapContentProvider(bndtools.model.resolution.CapReqMapContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IType(org.eclipse.jdt.core.IType) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Iterator(java.util.Iterator) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) Clazz(aQute.bnd.osgi.Clazz) BndFileCapReqLoader(bndtools.tasks.BndFileCapReqLoader) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) JarFileCapReqLoader(bndtools.tasks.JarFileCapReqLoader) ResourceCapReqLoader(bndtools.tasks.ResourceCapReqLoader) CapReqLoader(bndtools.tasks.CapReqLoader) PartInitException(org.eclipse.ui.PartInitException) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) FillLayout(org.eclipse.swt.layout.FillLayout) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) SashForm(org.eclipse.swt.custom.SashForm) RequirementWrapperLabelProvider(bndtools.model.resolution.RequirementWrapperLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 7 with RequirementWrapper

use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.

the class AnalyseBundleResolutionJobTest method testExportAndSelfImport.

/*
     * public void testSimpleImport() { File[] files = new File[] { new File("test/tests.consumer.jar") };
     * AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("resolve", files); IStatus status = job.run(new
     * NullProgressMonitor()); assertEquals(IStatus.OK, status.getCode()); assertEquals(0,
     * job.getExportResults().size()); assertEquals(1, job.getImportResults().size()); ImportPackage apiImport =
     * job.getImportResults().get(0); assertEquals("api", apiImport.getName()); assertFalse(apiImport.isSelfImport()); }
     */
public void testExportAndSelfImport() {
    AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("resolve", Collections.singleton(new JarFileCapReqLoader(new File("test/tests.provider.jar"))));
    IStatus status = job.run(new NullProgressMonitor());
    assertEquals(IStatus.OK, status.getCode());
    Map<String, List<Capability>> caps = job.getCapabilities();
    assertEquals(4, caps.size());
    List<Capability> idCaps = caps.get("osgi.identity");
    assertEquals(1, idCaps.size());
    assertEquals("tests.provider", idCaps.get(0).getAttributes().get("osgi.identity"));
    assertEquals(new Version("0.0.0.201412192235"), idCaps.get(0).getAttributes().get("version"));
    List<Capability> bundleCaps = caps.get("osgi.wiring.bundle");
    assertEquals(1, bundleCaps.size());
    assertEquals("tests.provider", bundleCaps.get(0).getAttributes().get("osgi.wiring.bundle"));
    assertEquals(new Version("0.0.0.201412192235"), bundleCaps.get(0).getAttributes().get("bundle-version"));
    List<Capability> hostCaps = caps.get("osgi.wiring.host");
    assertEquals(1, hostCaps.size());
    assertEquals("tests.provider", hostCaps.get(0).getAttributes().get("osgi.wiring.host"));
    assertEquals(new Version("0.0.0.201412192235"), hostCaps.get(0).getAttributes().get("bundle-version"));
    List<Capability> exports = caps.get("osgi.wiring.package");
    assertEquals(1, exports.size());
    assertEquals("osgi.wiring.package", exports.get(0).getNamespace());
    assertEquals("api", exports.get(0).getAttributes().get("osgi.wiring.package"));
    Map<String, List<RequirementWrapper>> reqs = job.getRequirements();
    assertEquals(2, reqs.size());
    List<RequirementWrapper> imports = reqs.get("osgi.wiring.package");
    assertEquals(1, imports.size());
    assertTrue(imports.get(0).resolved);
    assertEquals("(&(osgi.wiring.package=api)(version>=1.0.0)(!(version>=1.1.0)))", imports.get(0).requirement.getDirectives().get("filter"));
    List<RequirementWrapper> ee = reqs.get("osgi.ee");
    assertEquals(1, ee.size());
    assertFalse(ee.get(0).resolved);
    assertEquals("(&(osgi.ee=JavaSE)(version=1.8))", ee.get(0).requirement.getDirectives().get("filter"));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) List(java.util.List) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) File(java.io.File)

Example 8 with RequirementWrapper

use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.

the class AnalyseBundleResolutionJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        // Load all the capabilities and requirements
        Map<String, List<Capability>> allCaps = new HashMap<String, List<Capability>>();
        Map<String, List<RequirementWrapper>> allReqs = new HashMap<String, List<RequirementWrapper>>();
        for (CapReqLoader loader : loaders) {
            try {
                Map<String, List<Capability>> caps = loader.loadCapabilities();
                mergeMaps(caps, allCaps);
                Map<String, List<RequirementWrapper>> reqs = loader.loadRequirements();
                mergeMaps(reqs, allReqs);
            } catch (Exception e) {
                logger.logError("Error in Bnd resolution analysis.", e);
            } finally {
                IO.close(loader);
            }
        }
        // Check for resolved requirements
        for (String namespace : allReqs.keySet()) {
            List<RequirementWrapper> rws = allReqs.get(namespace);
            List<Capability> candidates = allCaps.get(namespace);
            if (candidates == null)
                continue;
            for (RequirementWrapper rw : rws) {
                String filterStr = rw.requirement.getDirectives().get("filter");
                if (filterStr != null) {
                    aQute.lib.filter.Filter filter = new aQute.lib.filter.Filter(filterStr);
                    for (Capability cand : candidates) {
                        if (filter.matchMap(cand.getAttributes())) {
                            rw.resolved = true;
                            break;
                        }
                    }
                }
            }
        }
        // Generate the final results
        // Set<File> resultFiles = builderMap.keySet();
        // resultFileArray = resultFiles.toArray(new File[0]);
        this.requirements = allReqs;
        this.capabilities = allCaps;
        // showResults(resultFileArray, importResults, exportResults);
        return Status.OK_STATUS;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) RequirementWrapper(bndtools.model.resolution.RequirementWrapper)

Aggregations

RequirementWrapper (bndtools.model.resolution.RequirementWrapper)8 List (java.util.List)5 IStatus (org.eclipse.core.runtime.IStatus)4 Clazz (aQute.bnd.osgi.Clazz)3 File (java.io.File)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Capability (org.osgi.resource.Capability)3 CapReqMapContentProvider (bndtools.model.resolution.CapReqMapContentProvider)2 RequirementWrapperLabelProvider (bndtools.model.resolution.RequirementWrapperLabelProvider)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IType (org.eclipse.jdt.core.IType)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 IOpenListener (org.eclipse.jface.viewers.IOpenListener)2