Search in sources :

Example 1 with BndEditModel

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

the class BndModelTest method testSetBuildPath.

public void testSetBuildPath() throws Exception {
    BndEditModel model = new BndEditModel();
    File bndFile = getFile(BND_BUILDPATH);
    model.loadFrom(bndFile);
    List<VersionedClause> buildPath = model.getBuildPath();
    // The remove causes the actual problem
    buildPath.remove(0);
    model.setBuildPath(buildPath);
    Document document = new Document(IO.collect(bndFile));
    model.saveChangesTo(document);
    String data = document.get();
    assertEquals(BND_BUILDPATH_EXPECTED, data);
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Document(aQute.bnd.properties.Document) BndEditModel(aQute.bnd.build.model.BndEditModel) File(java.io.File)

Example 2 with BndEditModel

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

the class BndModelTest method testEscapingBackslashes.

/**
	 * Test escaping of backslashes.
	 * 
	 * @throws Exception
	 */
public void testEscapingBackslashes() throws Exception {
    String longstring = "abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890";
    String formattedLongstring = "abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs \\\n" + "	tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 \\\n" + "	abc def ghi jkl mno pqrs tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs \\\n" + "	tuv wxy z01 234 567 890 abc def ghi jkl mno pqrs tuv wxy z01 234 567 890";
    BndEditModel model = new BndEditModel();
    model.setBundleName("abc \\ def");
    model.setBundleDescription(longstring);
    model.setBundleActivator("ሴ \n");
    assertEquals("abc \\ def", model.getBundleName());
    assertEquals("abc \\\\ def", model.getDocumentChanges().get(Constants.BUNDLE_NAME));
    assertEquals("abc \\ def", model.getProperties().get(Constants.BUNDLE_NAME));
    assertEquals(longstring, model.getBundleDescription());
    assertEquals(formattedLongstring, model.getDocumentChanges().get(Constants.BUNDLE_DESCRIPTION));
    assertEquals(longstring, model.getProperties().get(Constants.BUNDLE_DESCRIPTION));
    assertEquals("ሴ \n", model.getBundleActivator());
    assertEquals("ሴ \\n\\\n\t", model.getDocumentChanges().get(Constants.BUNDLE_ACTIVATOR));
    assertEquals("ሴ \n", model.getProperties().get(Constants.BUNDLE_ACTIVATOR));
}
Also used : BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 3 with BndEditModel

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

the class Bndrun method resolve.

public <T> T resolve(boolean failOnChanges, boolean writeOnChanges, Converter<T, Collection<? extends HeaderClause>> runbundlesFormatter) throws Exception {
    try (ProjectResolver projectResolver = new ProjectResolver(this)) {
        try {
            Map<Resource, List<Wire>> resolution = projectResolver.resolve();
            if (!projectResolver.isOk()) {
                return runbundlesFormatter.convert(Collections.<VersionedClause>emptyList());
            }
            Set<Resource> resources = resolution.keySet();
            List<VersionedClause> runBundles = new ArrayList<>();
            for (Resource resource : resources) {
                VersionedClause runBundle = ResourceUtils.toVersionClause(resource, "[===,==+)");
                if (!runBundles.contains(runBundle)) {
                    runBundles.add(runBundle);
                }
            }
            Collections.sort(runBundles, new Comparator<VersionedClause>() {

                @Override
                public int compare(VersionedClause a, VersionedClause b) {
                    int diff = a.getName().compareTo(b.getName());
                    return (diff != 0) ? diff : a.getVersionRange().compareTo(b.getVersionRange());
                }
            });
            File runFile = getPropertiesFile();
            BndEditModel bem = new BndEditModel(getWorkspace());
            Document doc = new Document(IO.collect(runFile));
            bem.loadFrom(doc);
            List<VersionedClause> bemRunBundles = bem.getRunBundles();
            if (bemRunBundles == null)
                bemRunBundles = new ArrayList<>();
            String originalRunbundlesString = runbundlesWrappedFormatter.convert(bemRunBundles);
            logger.debug("Original -runbundles was:\n\t {}", originalRunbundlesString);
            String runbundlesString = runbundlesWrappedFormatter.convert(runBundles);
            logger.debug("Resolved -runbundles is:\n\t {}", runbundlesString);
            List<VersionedClause> deltaAdd = new ArrayList<>(runBundles);
            deltaAdd.removeAll(bemRunBundles);
            List<VersionedClause> deltaRemove = new ArrayList<>(bemRunBundles);
            deltaRemove.removeAll(runBundles);
            boolean added = bemRunBundles.addAll(deltaAdd);
            boolean removed = bemRunBundles.removeAll(deltaRemove);
            if (added || removed) {
                if (failOnChanges && !bemRunBundles.isEmpty()) {
                    error("The runbundles have changed. Failing the build!\nWas: %s\nIs: %s", originalRunbundlesString, runbundlesString);
                    return runbundlesFormatter.convert(Collections.<VersionedClause>emptyList());
                }
                if (writeOnChanges) {
                    bem.setRunBundles(bemRunBundles);
                    String runBundlesProperty = bem.getDocumentChanges().get(Constants.RUNBUNDLES);
                    logger.debug("Writing changes to {}", runFile.getAbsolutePath());
                    logger.debug("{}:{}", Constants.RUNBUNDLES, runBundlesProperty);
                    bem.saveChangesTo(doc);
                    IO.store(doc.get(), runFile);
                }
            }
            return runbundlesFormatter.convert(bemRunBundles);
        } finally {
            getInfo(projectResolver);
        }
    }
}
Also used : VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) Document(aQute.bnd.properties.Document) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 4 with BndEditModel

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

the class JpmRepoTest method testSimpleResolve.

// public void testResolveProviderWithRunpath() throws Exception {
// try {
// Project provider = ws.getProject("provider");
// provider.build();
// assertTrue(provider.check());
//
// Project requirer = ws.getProject("requirer");
// requirer.build();
// assertTrue(requirer.check());
//
// BndEditModel model = new BndEditModel();
// model.setProject(requirer);
// BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
//
// Resolver resolver = new ResolverImpl(new
// org.apache.felix.resolver.Logger(4), null);
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources, "requirer", "0");
// assertNotNull(resource);
// }
// catch (ResolutionException e) {
// fail("Resolve failed " + e);
// }
// }
public void testSimpleResolve() {
    Repository repo = ws.getPlugin(Repository.class);
    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());
    Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
    assertNotNull(shell);
    assertEquals(1, shell.size());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
    Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(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.12");
        assertNotNull(resource);
    } catch (ResolutionException e) {
        fail("Resolve failed");
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) BndResolver(biz.aQute.resolve.BndResolver) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) BndrunResolveContext(biz.aQute.resolve.BndrunResolveContext) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 5 with BndEditModel

use of aQute.bnd.build.model.BndEditModel 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)

Aggregations

BndEditModel (aQute.bnd.build.model.BndEditModel)55 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 File (java.io.File)15 Resource (org.osgi.resource.Resource)15 ArrayList (java.util.ArrayList)12 Document (aQute.bnd.properties.Document)8 List (java.util.List)7 Workspace (aQute.bnd.build.Workspace)6 Resolver (org.osgi.service.resolver.Resolver)6 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)5 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 ResolutionException (org.osgi.service.resolver.ResolutionException)4