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);
}
}
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);
}
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;
}
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();
}
}
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();
}
}
Aggregations