Search in sources :

Example 51 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.

the class ResolveTest method testResolveWithDistro.

/**
	 * Test if we can resolve with a distro
	 * 
	 * @throws ResolutionException
	 */
public void testResolveWithDistro() throws ResolutionException {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.setDistro(Arrays.asList("testdata/distro.jar;version=file"));
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    context.setLevel(0);
    context.init();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    Map<Resource, List<Wire>> resolved = resolver.resolve(context);
    Set<Resource> resources = resolved.keySet();
    Resource shell = getResource(resources, "org.apache.felix.gogo.shell", "0.10.0");
    assertNotNull(shell);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 52 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bnd by bndtools.

the class ResolveTest method testSimpleResolve.

/**
	 * This is a basic test of resolving. This test is paired with
	 * {@link #testResolveWithDistro()}. If you change the resources, make sure
	 * this is done in the same way. The {@link #testResolveWithDistro()} has a
	 * negative check while this one checks positive.
	 */
public void testSimpleResolve() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
        Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.10");
        assertNotNull(resource);
    } catch (ResolutionException e) {
        fail("Resolve failed");
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 53 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bndtools by bndtools.

the class ExportPatternsListPart method getProject.

Project getProject() {
    Project project = null;
    try {
        BndEditModel model = (BndEditModel) getManagedForm().getInput();
        File bndFile = model.getBndResource();
        IPath path = Central.toPath(bndFile);
        IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        project = Central.getProject(resource.getProject());
    } catch (Exception e) {
        logger.logError("Error getting project from editor model", e);
    }
    return project;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) BndEditModel(aQute.bnd.build.model.BndEditModel) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 54 with BndEditModel

use of aQute.bnd.build.model.BndEditModel in project bndtools by bndtools.

the class EnrouteProjectTemplate method generateBndFile.

private Resource generateBndFile(String projectName, String pkg) {
    BndEditModel model = new BndEditModel();
    model.setPrivatePackages(Arrays.asList(new String[] { pkg + ".provider" }));
    model.setExportedPackages(Arrays.asList(new ExportedPackage(projectName + ".api", new Attrs())));
    model.setBundleDescription("${warning:please explain what this bundle does}");
    model.setBundleVersion("1.0.0.${tstamp}");
    List<VersionedClause> buildPath = new ArrayList<VersionedClause>();
    List<VersionedClause> tmp;
    tmp = model.getBuildPath();
    if (tmp != null)
        buildPath.addAll(tmp);
    Attrs attrs = new Attrs();
    attrs.put("version", "@1.0");
    buildPath.add(new VersionedClause("osgi.enroute.base.api", attrs));
    buildPath.add(new VersionedClause("osgi.enroute.base.junit", attrs));
    model.setBuildPath(buildPath);
    Document doc = new Document("");
    model.saveChangesTo(doc);
    StringResource bndBndResource = new StringResource(doc.get());
    return bndBndResource;
}
Also used : StringResource(org.bndtools.templating.StringResource) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) Document(aQute.bnd.properties.Document) BndEditModel(aQute.bnd.build.model.BndEditModel)

Aggregations

BndEditModel (aQute.bnd.build.model.BndEditModel)54 Requirement (org.osgi.resource.Requirement)35 MockRegistry (test.lib.MockRegistry)34 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)32 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)25 Capability (org.osgi.resource.Capability)25 Resource (org.osgi.resource.Resource)15 File (java.io.File)14 ArrayList (java.util.ArrayList)12 Document (aQute.bnd.properties.Document)8 List (java.util.List)6 Resolver (org.osgi.service.resolver.Resolver)6 Workspace (aQute.bnd.build.Workspace)5 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)5 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 ResolutionException (org.osgi.service.resolver.ResolutionException)4