Search in sources :

Example 71 with Formatter

use of java.util.Formatter in project bnd by bndtools.

the class GitPlugin method created.

@Override
public void created(Project p) throws Exception {
    Formatter f = new Formatter();
    f.format("/%s/\n", p.getProperty(Constants.DEFAULT_PROP_TARGET_DIR, "generated"));
    f.format("/%s/\n", p.getProperty(Constants.DEFAULT_PROP_BIN_DIR, "bin"));
    f.format("/%s/\n", p.getProperty(Constants.DEFAULT_PROP_TESTBIN_DIR, "bin_test"));
    IO.store(f.toString(), p.getFile(GITIGNORE));
    f.close();
    //
    for (File dir : p.getSourcePath()) {
        touch(dir);
    }
    touch(p.getTestSrc());
}
Also used : Formatter(java.util.Formatter) File(java.io.File)

Example 72 with Formatter

use of java.util.Formatter in project bnd by bndtools.

the class Index method save.

public void save(Writer out) throws Exception {
    init();
    repo.revisionRefs = getRevisionRefs();
    Formatter f = new Formatter(out);
    repo.write(f);
}
Also used : Formatter(java.util.Formatter)

Example 73 with Formatter

use of java.util.Formatter in project bnd by bndtools.

the class Repository method programTooltip.

private String programTooltip(String bsn) throws Exception {
    Program p = getProgram(bsn, false);
    if (p != null) {
        try (Formatter sb = new Formatter()) {
            if (p.wiki != null && p.wiki.text != null)
                sb.format("%s\n", p.wiki.text.replaceAll("#\\s?", ""));
            else if (p.last.description != null)
                sb.format("%s\n", p.last.description);
            else
                sb.format("No description\n");
            if (bsn.indexOf("__") >= 0) {
                sb.format("\nThis artifact has no OSGi metadata. Its coordinates are %s:%s\n", p.groupId, p.artifactId);
            }
            j.wrap((StringBuilder) sb.out());
            return sb.toString().trim();
        }
    }
    return null;
}
Also used : Program(aQute.service.library.Library.Program) Formatter(java.util.Formatter)

Example 74 with Formatter

use of java.util.Formatter in project bnd by bndtools.

the class ReporterAdapter method report.

/**
	 * Report the errors and warnings
	 */
public void report(Appendable out) {
    Formatter f = new Formatter(out);
    report("Error", getErrors(), f);
    report("Warning", getWarnings(), f);
    f.flush();
}
Also used : Formatter(java.util.Formatter)

Example 75 with Formatter

use of java.util.Formatter in project bnd by bndtools.

the class OBRFragment method parse.

@SuppressWarnings("deprecation")
public static Reporter parse(Jar jar, ResourceBuilder resource) throws Exception {
    Manifest m = jar.getManifest();
    if (m == null)
        return null;
    Domain d = Domain.domain(m);
    d.setTranslation(jar);
    Entry<String, Attrs> bundleSymbolicName = d.getBundleSymbolicName();
    if (bundleSymbolicName == null)
        return null;
    boolean singleton = "true".equals(bundleSymbolicName.getValue().get(Constants.SINGLETON_DIRECTIVE + ":"));
    boolean isFragment = d.get(Constants.FRAGMENT_HOST) != null;
    Version version = d.getBundleVersion() == null ? Version.emptyVersion : new Version(d.getBundleVersion());
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
    identity.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, bundleSymbolicName.getKey());
    identity.addAttribute(IdentityNamespace.CAPABILITY_COPYRIGHT_ATTRIBUTE, d.translate(Constants.BUNDLE_COPYRIGHT));
    identity.addAttribute(IdentityNamespace.CAPABILITY_DESCRIPTION_ATTRIBUTE, d.translate(Constants.BUNDLE_DESCRIPTION));
    identity.addAttribute(IdentityNamespace.CAPABILITY_DOCUMENTATION_ATTRIBUTE, d.translate(Constants.BUNDLE_DOCURL));
    identity.addAttribute(IdentityNamespace.CAPABILITY_LICENSE_ATTRIBUTE, d.translate(aQute.bnd.osgi.Constants.BUNDLE_LICENSE));
    if (singleton)
        identity.addAttribute(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE, "true");
    identity.addAttribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, isFragment ? IdentityNamespace.TYPE_FRAGMENT : IdentityNamespace.TYPE_BUNDLE);
    identity.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, new Version(d.getBundleVersion()));
    resource.addCapability(identity);
    if (isFragment) {
        //
        // Fragment-Host
        //
        Entry<String, Attrs> fragmentHost = d.getFragmentHost();
        CapReqBuilder fragment = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
        String v = fragmentHost.getValue().get("version");
        if (v == null)
            v = "0";
        Version fragmentVersion = new Version(v);
        String filter = filter(PackageNamespace.PACKAGE_NAMESPACE, fragmentHost.getKey(), fragmentHost.getValue());
        fragment.addDirective(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
        resource.addRequirement(fragment);
    } else {
        //
        // Bundle-SymbolicName
        //
        CapReqBuilder bundle = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
        CapReqBuilder host = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
        bundle.addAttribute("version", version);
        host.addAttribute("version", version);
        for (Entry<String, String> e : bundleSymbolicName.getValue().entrySet()) {
            String key = e.getKey();
            if (key.endsWith(":")) {
                String directive = key.substring(0, key.length() - 1);
                if (Constants.FRAGMENT_ATTACHMENT_DIRECTIVE.equalsIgnoreCase(directive)) {
                    if (Constants.FRAGMENT_ATTACHMENT_NEVER.equalsIgnoreCase(e.getValue()))
                        host = null;
                } else if (!Constants.SINGLETON_DIRECTIVE.equalsIgnoreCase(directive)) {
                    bundle.addDirective(directive, e.getValue());
                }
                if (host != null)
                    host.addDirective(directive, e.getValue());
                bundle.addDirective(directive, e.getValue());
            } else {
                if (host != null)
                    host.addAttribute(key, e.getValue());
                bundle.addAttribute(key, e.getValue());
            }
        }
        if (host != null)
            resource.addCapability(host);
        resource.addCapability(bundle);
    }
    //
    // Export-Package
    //
    Parameters exports = d.getExportPackage();
    for (Entry<String, Attrs> entry : exports.entrySet()) {
        CapReqBuilder exported = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
        String pkgName = Processor.removeDuplicateMarker(entry.getKey());
        exported.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, pkgName);
        String versionStr = entry.getValue().get(Constants.VERSION_ATTRIBUTE);
        Version v = Version.parseVersion(entry.getValue().get("version"));
        exported.addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
        for (Entry<String, String> attribEntry : entry.getValue().entrySet()) {
            String key = attribEntry.getKey();
            if (key.endsWith(":")) {
                String directive = key.substring(0, key.length() - 1);
                exported.addDirective(directive, attribEntry.getValue());
            } else {
                if (key.equals("specification-version") || key.equals("version"))
                    exported.addAttribute("version", Version.parseVersion(attribEntry.getValue()));
                else
                    exported.addAttribute(key, attribEntry.getValue());
            }
        }
        exported.addAttribute(PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE, bundleSymbolicName.getKey());
        exported.addAttribute(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version);
        resource.addCapability(exported);
    }
    //
    // Import-Package
    //
    Parameters imports = d.getImportPackage();
    for (Entry<String, Attrs> entry : imports.entrySet()) {
        CapReqBuilder imported = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
        String name = Processor.removeDuplicateMarker(entry.getKey());
        String filter = filter(PackageNamespace.PACKAGE_NAMESPACE, Processor.removeDuplicateMarker(entry.getKey()), entry.getValue());
        imported.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
        resource.addRequirement(imported);
    }
    //
    // Require-Bundle
    //
    Parameters requires = d.getRequireBundle();
    for (Entry<String, Attrs> entry : requires.entrySet()) {
        CapReqBuilder req = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
        String bsn = Processor.removeDuplicateMarker(entry.getKey());
        String filter = filter(BundleNamespace.BUNDLE_NAMESPACE, bsn, entry.getValue());
        req.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
        resource.addRequirement(req);
    }
    //
    // Bundle-RequiredExecutionEnvironment
    //
    Parameters brees = d.getBundleRequiredExecutionEnvironment();
    try (Formatter formatter = new Formatter()) {
        formatter.format("(|");
        for (Entry<String, Attrs> bree : brees.entrySet()) {
            String name = Processor.removeDuplicateMarker(bree.getKey());
            Matcher matcher = EE_PATTERN.matcher(name);
            if (matcher.matches()) {
                name = matcher.group(1);
                Version v = Version.parseVersion(matcher.group(2));
                formatter.format("%s", filter(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE, name, MAP.$("version", v.toString())));
            }
        }
        formatter.format(")");
        CapReqBuilder breeReq = new CapReqBuilder(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
        breeReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, formatter.toString());
        for (Entry<String, Attrs> export : d.getParameters(Constants.EXPORT_SERVICE).entrySet()) {
            CapReqBuilder exportedService = new CapReqBuilder(ServiceNamespace.SERVICE_NAMESPACE);
            String service = Processor.removeDuplicateMarker(export.getKey());
            exportedService.addAttribute(ServiceNamespace.SERVICE_NAMESPACE, service);
            exportedService.addAttribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, export.getValue().get("objectclass"));
            resource.addCapability(exportedService);
        }
        for (Entry<String, Attrs> imported : d.getParameters(Constants.IMPORT_SERVICE).entrySet()) {
            CapReqBuilder importedService = new CapReqBuilder(ServiceNamespace.SERVICE_NAMESPACE);
            String service = Processor.removeDuplicateMarker(imported.getKey());
            importedService.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter(ServiceNamespace.SERVICE_NAMESPACE, service, imported.getValue()));
            resource.addRequirement(importedService);
        }
        for (Entry<String, Attrs> rc : d.getProvideCapability().entrySet()) {
            resource.addCapability(toCapability(rc.getKey(), rc.getValue()));
        }
        for (Entry<String, Attrs> rc : d.getRequireCapability().entrySet()) {
            resource.addCapability(toRequirement(rc.getKey(), rc.getValue()));
        }
    }
    return null;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Parameters(aQute.bnd.header.Parameters) Version(org.osgi.framework.Version) Matcher(java.util.regex.Matcher) Formatter(java.util.Formatter) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain)

Aggregations

Formatter (java.util.Formatter)558 ArrayList (java.util.ArrayList)26 File (java.io.File)25 IOException (java.io.IOException)25 Date (java.util.Date)22 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 Map (java.util.Map)16 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 MessageDigest (java.security.MessageDigest)14 PrintWriter (java.io.PrintWriter)13 Justif (aQute.lib.justif.Justif)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 Locale (java.util.Locale)11 BigInteger (java.math.BigInteger)10 PrintStream (java.io.PrintStream)9 Calendar (java.util.Calendar)7 LayoutBuilder (android.text.StaticLayoutTest.LayoutBuilder)6 View (android.view.View)6