Search in sources :

Example 61 with Formatter

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

the class WorkspaceTest method config.

void config(Map<String, String> override) throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put("local", tmpName + "/local");
    config.put("index", tmpName + "/index");
    config.put("releaseUrl", fnx.getBaseURI() + "/repo/");
    if (override != null)
        config.putAll(override);
    try (Formatter sb = new Formatter()) {
        sb.format("-plugin.maven= \\\n");
        sb.format("  %s; \\\n", MavenBndRepository.class.getName());
        sb.format("  name=test; \\\n", MavenBndRepository.class.getName());
        sb.format("  local=%s; \\\n", config.get("local"));
        sb.format("  releaseUrl=%s; \\\n", config.get("releaseUrl"));
        sb.format("  index=%s\n", config.get("index"));
        build.getParentFile().mkdirs();
        IO.store(sb.toString(), build);
        workspace = Workspace.getWorkspace(build.getParentFile().getParentFile());
        repo = workspace.getPlugin(MavenBndRepository.class);
    }
}
Also used : HashMap(java.util.HashMap) Formatter(java.util.Formatter)

Example 62 with Formatter

use of java.util.Formatter in project android_frameworks_base by crdroidandroid.

the class Chronometer method updateText.

private synchronized void updateText(long now) {
    mNow = now;
    long seconds = mCountDown ? mBase - now : now - mBase;
    seconds /= 1000;
    boolean negative = false;
    if (seconds < 0) {
        seconds = -seconds;
        negative = true;
    }
    String text = DateUtils.formatElapsedTime(mRecycle, seconds);
    if (negative) {
        text = getResources().getString(R.string.negative_duration, text);
    }
    if (mFormat != null) {
        Locale loc = Locale.getDefault();
        if (mFormatter == null || !loc.equals(mFormatterLocale)) {
            mFormatterLocale = loc;
            mFormatter = new Formatter(mFormatBuilder, loc);
        }
        mFormatBuilder.setLength(0);
        mFormatterArgs[0] = text;
        try {
            mFormatter.format(mFormat, mFormatterArgs);
            text = mFormatBuilder.toString();
        } catch (IllegalFormatException ex) {
            if (!mLogged) {
                Log.w(TAG, "Illegal format string: " + mFormat);
                mLogged = true;
            }
        }
    }
    setText(text);
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) IllegalFormatException(java.util.IllegalFormatException)

Example 63 with Formatter

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

the class Workspace method addPlugin.

/**
	 * Add a plugin
	 * 
	 * @param plugin
	 * @throws Exception
	 */
public boolean addPlugin(Class<?> plugin, String alias, Map<String, String> parameters, boolean force) throws Exception {
    BndPlugin ann = plugin.getAnnotation(BndPlugin.class);
    if (alias == null) {
        if (ann != null)
            alias = ann.name();
        else {
            alias = Strings.getLastSegment(plugin.getName()).toLowerCase();
            if (alias.endsWith("plugin")) {
                alias = alias.substring(0, alias.length() - "plugin".length());
            }
        }
    }
    if (!Verifier.isBsn(alias)) {
        error("Not a valid plugin name %s", alias);
    }
    File ext = getFile(Workspace.CNFDIR + "/" + Workspace.EXT);
    IO.mkdirs(ext);
    File f = new File(ext, alias + ".bnd");
    if (!force) {
        if (f.exists()) {
            error("Plugin %s already exists", alias);
            return false;
        }
    } else {
        IO.delete(f);
    }
    Object l = plugin.getConstructor().newInstance();
    try (Formatter setup = new Formatter()) {
        setup.format(//
        "#\n" + //
        "# Plugin %s setup\n" + "#\n", alias);
        setup.format("-plugin.%s = %s", alias, plugin.getName());
        for (Map.Entry<String, String> e : parameters.entrySet()) {
            setup.format("; \\\n \t%s = '%s'", e.getKey(), escaped(e.getValue()));
        }
        setup.format("\n\n");
        String out = setup.toString();
        if (l instanceof LifeCyclePlugin) {
            out = ((LifeCyclePlugin) l).augmentSetup(out, alias, parameters);
            ((LifeCyclePlugin) l).init(this);
        }
        logger.debug("setup {}", out);
        IO.store(out, f);
    }
    refresh();
    for (LifeCyclePlugin lp : getPlugins(LifeCyclePlugin.class)) {
        lp.addedPlugin(this, plugin.getName(), alias, parameters);
    }
    return true;
}
Also used : LifeCyclePlugin(aQute.bnd.service.lifecycle.LifeCyclePlugin) Formatter(java.util.Formatter) BndPlugin(aQute.bnd.annotation.plugin.BndPlugin) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 64 with Formatter

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

the class ResolveProcess method format.

public static String format(Collection<Requirement> requirements) {
    Set<Requirement> mandatory = new HashSet<>();
    Set<Requirement> optional = new HashSet<>();
    for (Requirement req : requirements) {
        if (isOptional(req))
            optional.add(req);
        else
            mandatory.add(req);
    }
    try (Formatter f = new Formatter()) {
        f.format("%n  Mandatory:");
        for (Requirement req : mandatory) {
            f.format("%n    [%-19s] %s", req.getNamespace(), req);
        }
        f.format("%n  Optional:");
        for (Requirement req : optional) {
            f.format("%n    [%-19s] %s", req.getNamespace(), req);
        }
        return f.toString();
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Formatter(java.util.Formatter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 65 with Formatter

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

the class JustifTest method testSimple.

public void testSimple() throws Exception {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    try {
        Justif j = new Justif(40, 4, 8);
        f.format("0123456789012345\nxx\t0-\t1can\n" + "           use instead of including individual modules in your project. Note:\n" + "           It does not include the Jiffle scripting language or Jiffle image\n" + "           operator.");
        f.flush();
        j.wrap(sb);
        System.out.println(sb);
    } finally {
        f.close();
    }
}
Also used : Formatter(java.util.Formatter)

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