Search in sources :

Example 66 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Project method getBundles.

/**
	 * Analyze the header and return a list of files that should be on the
	 * build, test or some other path. The list is assumed to be a list of bsns
	 * with a version specification. The special case of version=project
	 * indicates there is a project in the same workspace. The path to the
	 * output directory is calculated. The default directory ${bin} can be
	 * overridden with the output attribute.
	 *
	 * @param strategyx STRATEGY_LOWEST or STRATEGY_HIGHEST
	 * @param spec The header
	 */
public List<Container> getBundles(Strategy strategyx, String spec, String source) throws Exception {
    List<Container> result = new ArrayList<Container>();
    Parameters bundles = new Parameters(spec, this);
    try {
        for (Iterator<Entry<String, Attrs>> i = bundles.entrySet().iterator(); i.hasNext(); ) {
            Entry<String, Attrs> entry = i.next();
            String bsn = removeDuplicateMarker(entry.getKey());
            Map<String, String> attrs = entry.getValue();
            Container found = null;
            String versionRange = attrs.get("version");
            boolean triedGetBundle = false;
            if (bsn.indexOf('*') >= 0) {
                return getBundlesWildcard(bsn, versionRange, strategyx, attrs);
            }
            if (versionRange != null) {
                if (versionRange.equals(VERSION_ATTR_LATEST) || versionRange.equals(VERSION_ATTR_SNAPSHOT)) {
                    found = getBundle(bsn, versionRange, strategyx, attrs);
                    triedGetBundle = true;
                }
            }
            if (found == null) {
                //
                if (versionRange != null && (versionRange.equals(VERSION_ATTR_PROJECT) || versionRange.equals(VERSION_ATTR_LATEST))) {
                    //
                    // Use the bin directory ...
                    //
                    Project project = getWorkspace().getProject(bsn);
                    if (project != null && project.exists()) {
                        File f = project.getOutput();
                        found = new Container(project, bsn, versionRange, Container.TYPE.PROJECT, f, null, attrs, null);
                    } else {
                        msgs.NoSuchProject(bsn, spec).context(bsn).header(source);
                        continue;
                    }
                } else if (versionRange != null && versionRange.equals("file")) {
                    File f = getFile(bsn);
                    String error = null;
                    if (!f.exists())
                        error = "File does not exist: " + f.getAbsolutePath();
                    if (f.getName().endsWith(".lib")) {
                        found = new Container(this, bsn, "file", Container.TYPE.LIBRARY, f, error, attrs, null);
                    } else {
                        found = new Container(this, bsn, "file", Container.TYPE.EXTERNAL, f, error, attrs, null);
                    }
                } else if (!triedGetBundle) {
                    found = getBundle(bsn, versionRange, strategyx, attrs);
                }
            }
            if (found != null) {
                List<Container> libs = found.getMembers();
                for (Container cc : libs) {
                    if (result.contains(cc)) {
                        if (isPedantic())
                            warning("Multiple bundles with the same final URL: %s, dropped duplicate", cc);
                    } else {
                        if (cc.getError() != null) {
                            error("Cannot find %s", cc).context(bsn).header(source);
                        }
                        result.add(cc);
                    }
                }
            } else {
                // Oops, not a bundle in sight :-(
                Container x = new Container(this, bsn, versionRange, Container.TYPE.ERROR, null, bsn + ";version=" + versionRange + " not found", attrs, null);
                result.add(x);
                error("Can not find URL for bsn %s", bsn).context(bsn).header(source);
            }
        }
    } catch (CircularDependencyException e) {
        String message = e.getMessage();
        if (source != null)
            message = String.format("%s (from property: %s)", message, source);
        msgs.CircularDependencyContext_Message_(getName(), message);
    } catch (Exception e) {
        msgs.Unexpected_Error_(spec, e);
    }
    return result;
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) IOException(java.io.IOException) Entry(java.util.Map.Entry) File(java.io.File)

Example 67 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class ProjectBuilder method fillInLocationForPackageInfo.

public void fillInLocationForPackageInfo(Location location, String packageName) throws Exception {
    Parameters eps = getExportPackage();
    Attrs attrs = eps.get(packageName);
    if (attrs != null && attrs.containsKey(Constants.VERSION_ATTRIBUTE)) {
        FileLine fl = getHeader(PATTERN_EXPORT_PACKAGE);
        if (fl != null) {
            location.file = fl.file.getAbsolutePath();
            location.line = fl.line;
            location.length = fl.length;
            return;
        }
    }
    Parameters ecs = getExportContents();
    attrs = ecs.get(packageName);
    if (attrs != null && attrs.containsKey(Constants.VERSION_ATTRIBUTE)) {
        FileLine fl = getHeader(PATTERN_EXPORT_CONTENTS);
        if (fl != null) {
            location.file = fl.file.getAbsolutePath();
            location.line = fl.line;
            location.length = fl.length;
            return;
        }
    }
    String path = packageName.replace('.', '/');
    for (File src : project.getSourcePath()) {
        File packageDir = IO.getFile(src, path);
        File pi = IO.getFile(packageDir, "package-info.java");
        if (pi.isFile()) {
            FileLine fl = findHeader(pi, PATTERN_VERSION_ANNOTATION);
            if (fl != null) {
                location.file = fl.file.getAbsolutePath();
                location.line = fl.line;
                location.length = fl.length;
                return;
            }
        }
        pi = IO.getFile(packageDir, "packageinfo");
        if (pi.isFile()) {
            FileLine fl = findHeader(pi, PATTERN_VERSION_PACKAGEINFO);
            if (fl != null) {
                location.file = fl.file.getAbsolutePath();
                location.line = fl.line;
                location.length = fl.length;
                return;
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) File(java.io.File)

Example 68 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Project method fillActions.

public void fillActions(Map<String, Action> all) {
    List<NamedAction> plugins = getPlugins(NamedAction.class);
    for (NamedAction a : plugins) all.put(a.getName(), a);
    Parameters actions = new Parameters(getProperty("-actions", DEFAULT_ACTIONS), this);
    for (Entry<String, Attrs> entry : actions.entrySet()) {
        String key = Processor.removeDuplicateMarker(entry.getKey());
        Action action;
        if (entry.getValue().get("script") != null) {
            // TODO check for the type
            action = new ScriptAction(entry.getValue().get("type"), entry.getValue().get("script"));
        } else {
            action = new ReflectAction(key);
        }
        String label = entry.getValue().get("label");
        all.put(label.toLowerCase(), action);
    }
}
Also used : NamedAction(aQute.bnd.service.action.NamedAction) Action(aQute.bnd.service.action.Action) NamedAction(aQute.bnd.service.action.NamedAction) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 69 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Project method getReleaseRepos.

private List<RepositoryPlugin> getReleaseRepos(String names) {
    Parameters repoNames = parseReleaseRepos(names);
    List<RepositoryPlugin> plugins = getPlugins(RepositoryPlugin.class);
    List<RepositoryPlugin> result = new ArrayList<>();
    if (repoNames == null) {
        // -releaserepo unspecified
        for (RepositoryPlugin plugin : plugins) {
            if (plugin.canWrite()) {
                result.add(plugin);
                break;
            }
        }
        if (result.isEmpty()) {
            msgs.NoNameForReleaseRepository();
        }
        return result;
    }
    repoNames: for (String repoName : repoNames.keySet()) {
        for (RepositoryPlugin plugin : plugins) {
            if (plugin.canWrite() && repoName.equals(plugin.getName())) {
                result.add(plugin);
                continue repoNames;
            }
        }
        msgs.ReleaseRepository_NotFoundIn_(repoName, plugins);
    }
    return result;
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Example 70 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class ResourceBuilder method addManifest.

/**
	 * Parse the manifest and turn them into requirements & capabilities
	 * 
	 * @param manifest The manifest to parse
	 * @throws Exception
	 */
public boolean addManifest(Domain manifest) throws Exception {
    //
    // Do the Bundle Identity Ns
    //
    int bundleManifestVersion = Integer.parseInt(manifest.get(Constants.BUNDLE_MANIFESTVERSION, "1"));
    Entry<String, Attrs> bsn = manifest.getBundleSymbolicName();
    if (bsn == null) {
        reporter.warning("No BSN set, not a bundle");
        return false;
    }
    boolean singleton = "true".equals(bsn.getValue().get(Constants.SINGLETON_DIRECTIVE + ":"));
    boolean fragment = manifest.getFragmentHost() != null;
    String versionString = manifest.getBundleVersion();
    if (versionString == null)
        versionString = "0";
    else if (!aQute.bnd.version.Version.isVersion(versionString))
        throw new IllegalArgumentException("Invalid version in bundle " + bsn + ": " + versionString);
    aQute.bnd.version.Version version = aQute.bnd.version.Version.parseVersion(versionString);
    //
    // First the identity
    //
    CapReqBuilder identity = new CapReqBuilder(resource, IdentityNamespace.IDENTITY_NAMESPACE);
    identity.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, bsn.getKey());
    identity.addAttribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, fragment ? IdentityNamespace.TYPE_FRAGMENT : IdentityNamespace.TYPE_BUNDLE);
    identity.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
    if (singleton) {
        identity.addDirective(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE, "true");
    }
    String copyright = manifest.get(Constants.BUNDLE_COPYRIGHT);
    if (copyright != null) {
        identity.addAttribute(IdentityNamespace.CAPABILITY_COPYRIGHT_ATTRIBUTE, copyright);
    }
    String description = manifest.get(Constants.BUNDLE_DESCRIPTION);
    if (description != null) {
        identity.addAttribute(IdentityNamespace.CAPABILITY_DESCRIPTION_ATTRIBUTE, description);
    }
    String docurl = manifest.get(Constants.BUNDLE_DOCURL);
    if (docurl != null) {
        identity.addAttribute(IdentityNamespace.CAPABILITY_DOCUMENTATION_ATTRIBUTE, docurl);
    }
    String license = manifest.get("Bundle-License");
    if (license != null) {
        identity.addAttribute(IdentityNamespace.CAPABILITY_LICENSE_ATTRIBUTE, license);
    }
    addCapability(identity.buildCapability());
    if ((bundleManifestVersion >= 2) && (!fragment)) {
        CapReqBuilder provideBundle = new CapReqBuilder(resource, BundleNamespace.BUNDLE_NAMESPACE);
        provideBundle.addAttributesOrDirectives(bsn.getValue());
        provideBundle.addAttribute(BundleNamespace.BUNDLE_NAMESPACE, bsn.getKey());
        provideBundle.addAttribute(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version);
        addCapability(provideBundle.buildCapability());
    }
    //
    // Import/Export service
    //
    @SuppressWarnings("deprecation") Parameters importServices = OSGiHeader.parseHeader(manifest.get(Constants.IMPORT_SERVICE));
    addImportServices(importServices);
    @SuppressWarnings("deprecation") Parameters exportServices = OSGiHeader.parseHeader(manifest.get(Constants.EXPORT_SERVICE));
    addExportServices(exportServices);
    //
    // Handle Require Bundle
    //
    Parameters requireBundle = manifest.getRequireBundle();
    addRequireBundles(requireBundle);
    if (fragment) {
        Entry<String, Attrs> fragmentHost = manifest.getFragmentHost();
        addFragmentHost(fragmentHost.getKey(), fragmentHost.getValue());
    } else {
        addFragmentHostCap(bsn.getKey(), version);
    }
    //
    // Add the exported package. These need
    // to be converted to osgi.wiring.package ns
    //
    addExportPackages(manifest.getExportPackage());
    //
    // Add the imported package. These need
    // to be converted to osgi.wiring.package ns
    //
    addImportPackages(manifest.getImportPackage());
    //
    // Add the provided capabilities, they're easy!
    //
    addProvideCapabilities(manifest.getProvideCapability());
    //
    // Add the required capabilities, they're also easy!
    //
    addRequireCapabilities(manifest.getRequireCapability());
    //
    // Manage native code header
    //
    addRequirement(getNativeCode(manifest.getBundleNative()));
    return true;
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Aggregations

Parameters (aQute.bnd.header.Parameters)157 Attrs (aQute.bnd.header.Attrs)78 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)20 Map (java.util.Map)16 Attributes (java.util.jar.Attributes)16 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Version (aQute.bnd.version.Version)11 Instructions (aQute.bnd.osgi.Instructions)9 HashSet (java.util.HashSet)9 Requirement (org.osgi.resource.Requirement)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7