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);
}
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"));
}
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);
}
}
Aggregations