use of aQute.libg.glob.Glob in project bnd by bndtools.
the class WorkspaceRepository method list.
public List<String> list(String pattern) throws Exception {
List<String> names = new ArrayList<String>();
Collection<Project> projects = workspace.getAllProjects();
for (Project project : projects) {
for (String bsn : project.getBsns()) {
if (pattern != null) {
Glob glob = new Glob(pattern);
Matcher matcher = glob.matcher(bsn);
if (matcher.matches()) {
if (!names.contains(bsn)) {
names.add(bsn);
}
}
} else {
if (!names.contains(bsn)) {
names.add(bsn);
}
}
}
}
return names;
}
use of aQute.libg.glob.Glob in project bnd by bndtools.
the class BridgeRepository method list.
public List<String> list(String pattern) throws Exception {
List<String> bsns = new ArrayList<>();
if (pattern == null || pattern.equals("*") || pattern.equals("")) {
bsns.addAll(index.keySet());
} else {
String[] split = pattern.split("\\s+");
Glob[] globs = new Glob[split.length];
for (int i = 0; i < split.length; i++) {
globs[i] = new Glob(split[i]);
}
outer: for (String bsn : index.keySet()) {
for (Glob g : globs) {
if (g.matcher(bsn).find()) {
bsns.add(bsn);
continue outer;
}
}
}
}
return bsns;
}
use of aQute.libg.glob.Glob in project bnd by bndtools.
the class ReplacerAdapter method replace.
protected String replace(String key, Link link) {
if (link != null && link.contains(key))
return "${infinite:" + link + "}";
if (key != null) {
key = key.trim();
if (key.length() > 0) {
Domain source = domain;
String value = null;
if (key.indexOf(';') < 0) {
if (WILDCARD.matcher(key).find()) {
Glob ins = new Glob(key);
StringBuilder sb = new StringBuilder();
String del = "";
for (String k : getAllKeys()) {
if (ins.matcher(k).find()) {
String v = replace(k, new Link(source, link, key));
if (v != null) {
sb.append(del);
del = ",";
sb.append(v);
}
}
}
return sb.toString();
}
while (value == null && source != null) {
value = source.getMap().get(key);
if (value != null)
return process(value, new Link(source, link, key));
source = source.getParent();
}
}
value = doCommands(key, link);
if (value != null)
return process(value, new Link(source, link, key));
if (key != null && key.trim().length() > 0) {
value = System.getProperty(key);
if (value != null)
return value;
}
if (key.indexOf(';') >= 0) {
String[] parts = key.split(";");
if (parts.length > 1) {
if (parts.length >= 16) {
error("too many arguments for template: %s, max is 16", key);
}
String template = domain.getMap().get(parts[0]);
if (template != null) {
final Domain old = domain;
try {
final Map<String, String> args = new HashMap<String, String>();
for (int i = 0; i < 16; i++) {
args.put("" + i, i < parts.length ? parts[i] : "null");
}
domain = new Domain() {
public Map<String, String> getMap() {
return args;
}
public Domain getParent() {
return old;
}
};
ExtList<String> args0 = new ExtList<String>(parts);
args0.remove(0);
args.put("#", args0.join());
value = process(template, new Link(domain, link, key));
if (value != null)
return value;
} finally {
domain = old;
}
}
}
}
if (!flattening && !key.equals("@"))
reporter.warning("No translation found for macro: %s", key);
} else {
reporter.warning("Found empty macro key");
}
} else {
reporter.warning("Found null macro key");
}
return "${" + key + "}";
}
use of aQute.libg.glob.Glob in project bnd by bndtools.
the class Main method _update.
@Description("Perform updates for installed commands and services")
public void _update(UpdateOptions opts) throws Exception {
if (!jpm.hasAccess()) {
error("No write acces, might require administrator or root privileges (sudo in *nix)");
return;
}
ArrayList<String> refs = new ArrayList<String>();
for (CommandData data : jpm.getCommands()) {
refs.add(data.name);
}
for (ServiceData data : jpm.getServices()) {
refs.add(data.name);
}
ArrayList<UpdateMemo> notFound = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
ArrayList<UpdateMemo> upToDate = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
ArrayList<UpdateMemo> toUpdate = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
ArrayList<CommandData> datas = new ArrayList<CommandData>();
if (opts._arguments().size() == 0) {
datas.addAll(jpm.getCommands());
datas.addAll(jpm.getServices());
} else {
for (String pattern : opts._arguments()) {
Glob glob = new Glob(pattern);
for (String name : refs) {
if (glob.matcher(name).matches()) {
CommandData data = jpm.getCommand(name);
if (data == null) {
Service service = jpm.getService(name);
if (service != null) {
data = service.getServiceData();
}
}
if (data != null) {
datas.add(data);
}
}
}
}
}
for (CommandData data : datas) {
jpm.listUpdates(notFound, upToDate, toUpdate, data, opts.staged());
}
if (opts.all() || opts._arguments().size() > 0) {
for (UpdateMemo memo : toUpdate) {
jpm.update(memo);
}
out.format("%d command(s) updated%n", toUpdate.size());
} else {
Justif justif = new Justif(100, 20, 50);
StringBuilder sb = new StringBuilder();
Formatter f = new Formatter(sb);
if (upToDate.size() > 0) {
f.format("Up to date:%n");
for (UpdateMemo memo : upToDate) {
if (memo.current instanceof ServiceData) {
f.format(" - %s (service) \t0- %s%n", memo.current.name, memo.current.version);
} else {
f.format(" - %s \t0- %s%n", memo.current.name, memo.current.version);
}
}
f.format("%n");
}
if (toUpdate.size() > 0) {
f.format("Update available:%n");
for (UpdateMemo memo : toUpdate) {
if (memo.current instanceof ServiceData) {
f.format(" - %s (service) \t0- %s \t1-> %s%n", memo.current.name, memo.current.version, memo.best.version);
} else {
f.format(" - %s \t0- %s \t1-> %s%n", memo.current.name, memo.current.version, memo.best.version);
}
}
f.format("%n");
}
if (notFound.size() > 0) {
if (opts.staged()) {
f.format("Information not found (local install ?):%n");
} else {
f.format("Information not found (try including staging versions with the --staged (-s) flag)%n");
}
for (UpdateMemo memo : notFound) {
if (memo.current instanceof ServiceData) {
f.format(" - %s (service)%n", memo.current.name);
} else {
f.format(" - %s%n", memo.current.name);
}
}
}
if (toUpdate.size() > 0) {
f.format("%nIn order to apply all possible updates, run jpm update again with the --all (or -a) flag.%n");
}
f.flush();
justif.wrap(sb);
out.println(sb.toString());
f.close();
}
}
use of aQute.libg.glob.Glob in project bndtools by bndtools.
the class GitOBRRepo method configFileInit.
protected void configFileInit() {
if (configFileList == null) {
return;
}
if (configFileInited.compareAndSet(false, true)) {
mappings.clear();
StringTokenizer tokenizer = new StringTokenizer(configFileList, ",");
while (tokenizer.hasMoreTokens()) {
String configFileName = tokenizer.nextToken().trim();
File file = new File(configFileName);
if (file.exists()) {
Properties props = new Properties();
try (InputStream stream = IO.stream(file)) {
props.load(stream);
for (Object key : props.keySet()) {
String name = (String) key;
if (name.startsWith(PREFIX_PATTERN)) {
String id = name.substring(PREFIX_PATTERN.length());
Glob glob = new Glob(props.getProperty(name));
String uid = props.getProperty(PREFIX_USER + id);
String pwd = props.getProperty(PREFIX_PASSWORD + id);
mappings.add(new Mapping(glob, uid, pwd));
}
}
} catch (IOException e) {
reporter.error("Failed to load %s", configFileName);
}
}
}
}
}
Aggregations