Search in sources :

Example 1 with ExportedPackage

use of aQute.bnd.build.model.clauses.ExportedPackage in project bnd by bndtools.

the class ResolveTest method testMultipleOptionsNotDuplicated.

/**
	 * Simple test that resolves a requirement
	 * 
	 * @throws ResolutionException
	 */
public void testMultipleOptionsNotDuplicated() throws ResolutionException {
    // Resolve against repo 5
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo5/index.xml"), "Test-5"));
    // Set up a simple Java 7 Felix requirement as per Issue #971
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework;version='4.2.1'");
    runModel.setEE(EE.JavaSE_1_7);
    runModel.setSystemPackages(Collections.singletonList(new ExportedPackage("org.w3c.dom.traversal", null)));
    runModel.setGenericString("-resolve.effective", "active");
    // Require the log service, GoGo shell and GoGo commands
    List<Requirement> requirements = new ArrayList<Requirement>();
    requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.log)").buildSyntheticRequirement());
    requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.shell)").buildSyntheticRequirement());
    requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.command)").buildSyntheticRequirement());
    runModel.setRunRequires(requirements);
    // Resolve the bndrun
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
    Collection<Resource> resolvedResources = new ResolveProcess().resolveRequired(runModel, registry, resolver, Collections.<ResolutionCallback>emptyList(), log).keySet();
    Map<String, Resource> mandatoryResourcesBySymbolicName = new HashMap<String, Resource>();
    for (Resource r : resolvedResources) {
        Capability cap = r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
        // We shouldn't have more than one match for each symbolic name for
        // this resolve
        String symbolicName = (String) cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
        assertNull("Multiple results for " + symbolicName, mandatoryResourcesBySymbolicName.put(symbolicName, r));
    }
    assertEquals(4, resolvedResources.size());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 2 with ExportedPackage

use of aQute.bnd.build.model.clauses.ExportedPackage in project bnd by bndtools.

the class BndrunResolveContextTest method testResolveSystemPackagesExtra.

public static void testResolveSystemPackagesExtra() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.setEE(EE.JavaSE_1_6);
    runModel.setSystemPackages(Collections.singletonList(new ExportedPackage("sun.reflect", new Attrs())));
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=sun.reflect)").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) MockRegistry(test.lib.MockRegistry) Attrs(aQute.bnd.header.Attrs) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 3 with ExportedPackage

use of aQute.bnd.build.model.clauses.ExportedPackage in project bndtools by bndtools.

the class ExportPatternsListPart method selectPackagesToAdd.

protected List<ExportedPackage> selectPackagesToAdd() {
    List<ExportedPackage> added = null;
    final IPackageFilter filter = new IPackageFilter() {

        @Override
        public boolean select(String packageName) {
            if (packageName.equals("java") || packageName.startsWith("java."))
                return false;
            return true;
        }
    };
    IFormPage page = (IFormPage) getManagedForm().getContainer();
    IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
    // Prepare the package lister from the Java project
    IProject project = ResourceUtil.getResource(page.getEditorInput()).getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    JavaSearchScopePackageLister packageLister = new JavaSearchScopePackageLister(searchScope, window);
    // Create and open the dialog
    PackageSelectionDialog dialog = new PackageSelectionDialog(window.getShell(), packageLister, filter, "Select new packages to export from the bundle.");
    dialog.setSourceOnly(true);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        added = new LinkedList<ExportedPackage>();
        // Select the results
        for (Object result : results) {
            String newPackageName = (String) result;
            ExportedPackage newPackage = new ExportedPackage(newPackageName, new Attrs());
            added.add(newPackage);
        }
    }
    return added;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Attrs(aQute.bnd.header.Attrs) IFormPage(org.eclipse.ui.forms.editor.IFormPage) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) JavaSearchScopePackageLister(bndtools.internal.pkgselection.JavaSearchScopePackageLister) IPackageFilter(bndtools.internal.pkgselection.IPackageFilter) PackageSelectionDialog(bndtools.internal.pkgselection.PackageSelectionDialog)

Example 4 with ExportedPackage

use of aQute.bnd.build.model.clauses.ExportedPackage in project bnd by bndtools.

the class BndEditModel method isIncludedPackage.

public boolean isIncludedPackage(String packageName) {
    final Collection<String> privatePackages = getPrivatePackages();
    if (privatePackages != null) {
        if (privatePackages.contains(packageName))
            return true;
    }
    final Collection<ExportedPackage> exportedPackages = getExportedPackages();
    if (exportedPackages != null) {
        for (ExportedPackage pkg : exportedPackages) {
            if (packageName.equals(pkg.getName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage)

Example 5 with ExportedPackage

use of aQute.bnd.build.model.clauses.ExportedPackage in project bnd by bndtools.

the class BndEditModelTest method testVariableInSystemPackages.

public static void testVariableInSystemPackages() throws Exception {
    Workspace ws = new Workspace(new File("testresources/ws"));
    BndEditModel model = new BndEditModel(ws);
    File f = new File("testresources/ws/p7/syspkg.bndrun");
    model.setBndResource(f);
    model.setBndResourceName("syspkg.bndrun");
    model.loadFrom(f);
    List<ExportedPackage> ep = model.getSystemPackages();
    assertEquals("com.sun.xml.internal.bind", model.getProperties().mergeProperties(Constants.RUNSYSTEMPACKAGES));
    ExportedPackage e = new ExportedPackage("testing", null);
    ep = new LinkedList<ExportedPackage>();
    ep.add(e);
    model.setSystemPackages(ep);
    ep = model.getSystemPackages();
    assertEquals(1, ep.size());
    assertEquals("testing", ep.get(0).getName());
    e = new ExportedPackage("${var}", null);
    ep = new LinkedList<ExportedPackage>();
    ep.add(e);
    model.setSystemPackages(ep);
    ep = model.getSystemPackages();
    assertEquals(1, ep.size());
    assertEquals("com.sun.xml.internal.bind", model.getProperties().mergeProperties(Constants.RUNSYSTEMPACKAGES));
}
Also used : ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) Workspace(aQute.bnd.build.Workspace)

Aggregations

ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)10 BndEditModel (aQute.bnd.build.model.BndEditModel)5 Attrs (aQute.bnd.header.Attrs)3 HashMap (java.util.HashMap)3 IProject (org.eclipse.core.resources.IProject)3 ImportPattern (aQute.bnd.build.model.clauses.ImportPattern)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 Document (aQute.bnd.properties.Document)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 Capability (org.osgi.resource.Capability)2 Requirement (org.osgi.resource.Requirement)2 MockRegistry (test.lib.MockRegistry)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 IDocument (aQute.bnd.properties.IDocument)1