use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.
the class AnalyseBundleResolutionJobTest method testOptionalImport.
public void testOptionalImport() {
AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("resolve", Collections.singleton(new JarFileCapReqLoader(new File("test/example2.jar"))));
IStatus status = job.run(new NullProgressMonitor());
assertEquals(IStatus.OK, status.getCode());
Map<String, List<RequirementWrapper>> reqs = job.getRequirements();
assertEquals(2, reqs.size());
List<RequirementWrapper> imports = reqs.get("osgi.wiring.package");
assertEquals("optional", imports.get(0).requirement.getDirectives().get("resolution"));
}
use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.
the class PackageDropAdapter method performDrop.
@Override
public boolean performDrop(Object data) {
int insertionIndex = -1;
Object target = getCurrentTarget();
if (target != null) {
insertionIndex = indexOf(target);
int loc = getCurrentLocation();
if (loc == LOCATION_ON || loc == LOCATION_AFTER)
insertionIndex++;
}
List<T> newEntries = new ArrayList<T>();
if (data instanceof IResource[]) {
for (IResource resource : (IResource[]) data) {
IJavaElement javaElement = JavaCore.create(resource);
if (javaElement instanceof IPackageFragment) {
newEntries.add(createNewEntry(javaElement.getElementName()));
}
}
} else if (data instanceof IStructuredSelection) {
Iterator<?> iterator = ((IStructuredSelection) data).iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof IPackageFragment) {
IPackageFragment pkg = (IPackageFragment) element;
newEntries.add(createNewEntry(pkg.getElementName()));
} else if (element instanceof Capability) {
Capability cap = (Capability) element;
String namespace = cap.getNamespace();
if (PackageNamespace.PACKAGE_NAMESPACE.equals(namespace)) {
String pkgName = (String) cap.getAttributes().get(namespace);
newEntries.add(createNewEntry(pkgName));
}
} else if (element instanceof Requirement) {
String pkgName = getPackageNameFromRequirement((Requirement) element);
if (pkgName != null)
newEntries.add(createNewEntry(pkgName));
} else if (element instanceof RequirementWrapper) {
String pkgName = getPackageNameFromRequirement(((RequirementWrapper) element).requirement);
if (pkgName != null)
newEntries.add(createNewEntry(pkgName));
}
}
}
addRows(insertionIndex, newEntries);
return true;
}
use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.
the class BndBuilderCapReqLoader method loadRequirements.
@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
Builder builder = getBuilder();
if (builder == null)
return Collections.emptyMap();
Jar jar = builder.getJar();
if (jar == null)
return Collections.emptyMap();
Manifest manifest = jar.getManifest();
if (manifest == null)
return Collections.emptyMap();
Attributes attribs = manifest.getMainAttributes();
Map<String, List<RequirementWrapper>> requirements = new HashMap<String, List<RequirementWrapper>>();
// Process imports
String importPkgStr = attribs.getValue(Constants.IMPORT_PACKAGE);
Parameters importsMap = new Parameters(importPkgStr);
for (Entry<String, Attrs> entry : importsMap.entrySet()) {
String pkgName = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
String filter = createVersionFilter(PackageNamespace.PACKAGE_NAMESPACE, pkgName, attrs.get(Constants.VERSION_ATTRIBUTE), PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
rb.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
Collection<Clazz> importers = findImportingClasses(pkgName, builder);
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
rw.requirers = importers;
addRequirement(requirements, rw);
}
// Process require-bundle
String requireBundleStr = attribs.getValue(Constants.REQUIRE_BUNDLE);
Parameters requireBundles = new Parameters(requireBundleStr);
for (Entry<String, Attrs> entry : requireBundles.entrySet()) {
String bsn = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
String filter = createVersionFilter(BundleNamespace.BUNDLE_NAMESPACE, bsn, attrs.get(Constants.BUNDLE_VERSION_ATTRIBUTE), AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
rb.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
addRequirement(requirements, rw);
}
// Process generic requires
String requiresStr = attribs.getValue(Constants.REQUIRE_CAPABILITY);
Parameters requires = new Parameters(requiresStr);
for (Entry<String, Attrs> entry : requires.entrySet()) {
String ns = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(ns);
for (String key : attrs.keySet()) {
if (key.endsWith(":"))
rb.addDirective(key.substring(0, key.length() - 1), attrs.get(key));
else
rb.addAttribute(key, attrs.getTyped(key));
}
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
addRequirement(requirements, rw);
}
return requirements;
}
use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.
the class ResourceCapReqLoader method loadRequirements.
@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
Map<String, List<RequirementWrapper>> result = new HashMap<String, List<RequirementWrapper>>();
List<Requirement> reqs = resource.getRequirements(null);
for (Requirement req : reqs) {
String ns = req.getNamespace();
List<RequirementWrapper> listForNamespace = result.get(ns);
if (listForNamespace == null) {
listForNamespace = new LinkedList<RequirementWrapper>();
result.put(ns, listForNamespace);
}
RequirementWrapper wrapper = new RequirementWrapper();
wrapper.requirement = req;
listForNamespace.add(wrapper);
}
return result;
}
use of bndtools.model.resolution.RequirementWrapper in project bndtools by bndtools.
the class BundleCalculatedImportsPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
// CREATE COMPONENTS
section.setText(Messages.BundleCalculatedImportsPart_title);
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem showSelfImportsItem = new ToolItem(toolbar, SWT.CHECK);
showSelfImportsItem.setImage(imgShowSelfImports);
showSelfImportsItem.setToolTipText(Messages.BundleCalculatedImportsPart_tooltipShowSelfImports);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// toolkit.createLabel(composite,
// Messages.BundleCalculatedImportsPart_description, SWT.WRAP);
tree = toolkit.createTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
viewer = new TreeViewer(tree);
viewer.setContentProvider(new CapReqMapContentProvider());
viewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
ColumnViewerToolTipSupport.enableFor(viewer);
nonPkgFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof RequirementWrapper)
return PackageNamespace.PACKAGE_NAMESPACE.equals(((RequirementWrapper) element).requirement.getNamespace());
return true;
}
};
hideSelfImportsFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof RequirementWrapper)
return !((RequirementWrapper) element).resolved;
return true;
}
};
viewer.setFilters(new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter });
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getManagedForm().fireSelectionChanged(BundleCalculatedImportsPart.this, event.getSelection());
}
});
viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
if (transfer.isSupportedType(event.dataType))
transfer.setSelection(viewer.getSelection());
}
});
viewer.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 importUsedBy = (Clazz) item;
String className = importUsedBy.getFQN();
IType type = null;
IFile file = getEditorFile();
if (file != null) {
IJavaProject javaProject = JavaCore.create(file.getProject());
try {
type = javaProject.findType(className);
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, Messages.BundleCalculatedImportsPart_errorFindingType, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
try {
if (type != null)
JavaUI.openInEditor(type, true, true);
} catch (PartInitException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningJavaEditor, className), e));
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
}
}
});
// LISTENERS
showSelfImportsItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean showSelfImports = showSelfImportsItem.getSelection();
ViewerFilter[] filters = showSelfImports ? new ViewerFilter[] { nonPkgFilter } : new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter };
viewer.setFilters(filters);
}
});
// LAYOUT
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 2;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 75;
gd.widthHint = 75;
tree.setLayoutData(gd);
}
Aggregations