Search in sources :

Example 26 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class LauncherTest method create.

private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());
    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 27 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class RemoteTest method create.

private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());
    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 28 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class AgentTest method create.

/**
	 * Launches against main
	 */
private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());
    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 29 with Builder

use of aQute.bnd.osgi.Builder in project bndtools by bndtools.

the class BundleVersionErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new LinkedList<MarkerData>();
    IFile bndFile = null;
    LineLocation loc = null;
    BundleInfo info = (BundleInfo) location.details;
    for (Builder builder : model.getSubBuilders()) {
        if (builder.getBsn().equals(info.bsn)) {
            File propsFile = builder.getPropertiesFile();
            // Try to find in the sub-bundle file
            if (propsFile != null) {
                bndFile = project.getWorkspace().getRoot().getFileForLocation(new Path(propsFile.getAbsolutePath()));
                if (bndFile != null) {
                    loc = findBundleVersionHeader(bndFile);
                }
            }
            if (loc == null) {
                // Not found in sub-bundle file, try bnd.bnd
                bndFile = project.getFile(Project.BNDFILE);
                loc = findBundleVersionHeader(bndFile);
            }
            if (loc != null) {
                Map<String, Object> attribs = new HashMap<String, Object>();
                attribs.put(IMarker.MESSAGE, location.message);
                attribs.put(IMarker.LINE_NUMBER, loc.lineNum);
                attribs.put(IMarker.CHAR_START, loc.start);
                attribs.put(IMarker.CHAR_END, loc.end);
                String qualifier = null;
                String currentVersion = builder.getUnprocessedProperty(Constants.BUNDLE_VERSION, "");
                if (currentVersion != null) {
                    Matcher m = VERSION_ACCEPTING_MACRO.matcher(currentVersion);
                    if (m.matches()) {
                        qualifier = m.group(4);
                    }
                }
                attribs.put(PROP_SUGGESTED_VERSION, info.suggestedVersion.toString() + (qualifier != null ? '.' + qualifier : ""));
                result.add(new MarkerData(bndFile, attribs, true, BndtoolsConstants.MARKER_JAVA_BASELINE));
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) MarkerData(org.bndtools.build.api.MarkerData) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Builder(aQute.bnd.osgi.Builder) LinkedList(java.util.LinkedList) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 30 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class Profiles method _create.

public void _create(CreateOptions options) throws Exception {
    Builder b = new Builder();
    bnd.addClose(b);
    b.setBase(bnd.getBase());
    if (options.properties() != null) {
        for (String propertyFile : options.properties()) {
            File pf = bnd.getFile(propertyFile);
            b.addProperties(pf);
        }
    }
    if (options.bsn() != null)
        b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
    if (options.version() != null)
        b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
    Instructions match = options.match();
    Parameters packages = new Parameters();
    Parameters capabilities = new Parameters();
    Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
    if (paths.isEmpty())
        paths = options._arguments();
    logger.debug("input {}", paths);
    ResourceBuilder pb = new ResourceBuilder();
    for (String root : paths) {
        File f = bnd.getFile(root);
        if (!f.exists()) {
            error("could not find %s", f);
        } else {
            Glob g = options.extension();
            if (g == null)
                g = new Glob("*.jar");
            Collection<File> files = IO.tree(f, "*.jar");
            logger.debug("will profile {}", files);
            for (File file : files) {
                Domain domain = Domain.domain(file);
                if (domain == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                String bsn = domain.getBundleSymbolicName().getKey();
                if (bsn == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                if (match != null) {
                    Instruction instr = match.finder(bsn);
                    if (instr == null || instr.isNegated()) {
                        logger.debug("skipped {} because of non matching bsn {}", file, bsn);
                        continue;
                    }
                }
                Parameters eps = domain.getExportPackage();
                Parameters pcs = domain.getProvideCapability();
                logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
                packages.mergeWith(eps, false);
                capabilities.mergeWith(pcs, false);
            }
        }
    }
    b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
    b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
    logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
    Jar jar = b.build();
    File f = b.getOutputFile(options.output());
    logger.debug("Saving as {}", f);
    jar.write(f);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Aggregations

Builder (aQute.bnd.osgi.Builder)426 Jar (aQute.bnd.osgi.Jar)225 File (java.io.File)197 Manifest (java.util.jar.Manifest)93 Properties (java.util.Properties)91 Resource (aQute.bnd.osgi.Resource)82 Attributes (java.util.jar.Attributes)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)41 XmlTester (aQute.bnd.test.XmlTester)39 Parameters (aQute.bnd.header.Parameters)35 Document (org.w3c.dom.Document)27 Attrs (aQute.bnd.header.Attrs)21 JarResource (aQute.bnd.osgi.JarResource)20 LogService (org.osgi.service.log.LogService)17 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)13 Project (aQute.bnd.build.Project)10 Baseline (aQute.bnd.differ.Baseline)9 Packages (aQute.bnd.osgi.Packages)9 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9