use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class OSGiHeader method parseHeader.
public static Parameters parseHeader(String value, Reporter logger, Parameters result) {
if (value == null || value.trim().length() == 0)
return result;
QuotedTokenizer qt = new QuotedTokenizer(value, ";=,");
char del = 0;
do {
boolean hadAttribute = false;
Attrs clause = new Attrs();
List<String> aliases = Create.list();
String name = qt.nextToken(",;");
del = qt.getSeparator();
if (name == null || name.length() == 0) {
if (logger != null && logger.isPedantic()) {
logger.warning("Empty clause, usually caused by repeating a comma without any name field or by having spaces after the backslash of a property file: %s", value);
}
if (name == null)
break;
} else {
name = name.trim();
aliases.add(name);
while (del == ';') {
String adname = qt.nextToken();
if ((del = qt.getSeparator()) != '=') {
if (hadAttribute)
if (logger != null) {
logger.error("Header contains name field after attribute or directive: %s from %s. Name fields must be consecutive, separated by a ';' like a;b;c;x=3;y=4", adname, value);
}
if (adname != null && adname.length() > 0)
aliases.add(adname.trim());
} else {
String advalue = qt.nextToken();
if (clause.containsKey(adname)) {
if (result.allowDuplicateAttributes()) {
while (clause.containsKey(adname)) adname += "~";
} else {
if (logger != null && logger.isPedantic())
logger.warning("Duplicate attribute/directive name %s in %s. This attribute/directive will be ignored", adname, value);
}
}
if (advalue == null) {
if (logger != null)
logger.error("No value after '=' sign for attribute %s", adname);
advalue = "";
}
clause.put(adname.trim(), advalue);
del = qt.getSeparator();
hadAttribute = true;
}
}
// add a number of "~" to make it unique.
for (String clauseName : aliases) {
if (result.containsKey(clauseName)) {
if (logger != null && logger.isPedantic())
logger.warning("Duplicate name %s used in header: '%s'. Duplicate names are specially marked in Bnd with a ~ at the end (which is stripped at printing time).", clauseName, value);
while (result.containsKey(clauseName)) clauseName += "~";
}
result.put(clauseName, clause);
}
}
} while (del == ',');
return result;
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class Header method parseProperties.
public static Props parseProperties(String input, Reporter logger) {
if (input == null || input.trim().length() == 0)
return new Props();
Props result = new Props();
QuotedTokenizer qt = new QuotedTokenizer(input, "=,");
char del = ',';
while (del == ',') {
String key = qt.nextToken(",=");
String value = "";
del = qt.getSeparator();
if (del == '=') {
value = qt.nextToken(",=");
if (value == null)
value = "";
del = qt.getSeparator();
}
result.put(key.trim(), value);
}
if (del != 0) {
if (logger == null)
throw new IllegalArgumentException("Invalid syntax for properties: " + input);
logger.error("Invalid syntax for properties: %s", input);
}
return result;
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class BndTask method addAll.
void addAll(List<File> list, String files, String separator) {
logger.debug("addAll '{}' with {}", files, separator);
QuotedTokenizer qt = new QuotedTokenizer(files, separator);
String[] entries = qt.getTokens();
File project = getProject().getBaseDir();
for (int i = 0; i < entries.length; i++) {
File f = getFile(project, entries[i]);
if (f.exists())
list.add(f);
else
messages.NoSuchFile_(f.getAbsoluteFile());
}
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class WrapTask method addAll.
void addAll(List<File> list, String files, String separator) {
QuotedTokenizer qt = new QuotedTokenizer(files, separator);
String[] entries = qt.getTokens();
File project = getProject().getBaseDir();
for (int i = 0; i < entries.length; i++) {
File f = getFile(project, entries[i]);
if (f.exists())
list.add(f);
else
messages.NoSuchFile_(f.getAbsoluteFile());
}
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class Project method parseRepoFilter.
protected RepoFilter parseRepoFilter(Map<String, String> attrs) {
if (attrs == null)
return null;
String patternStr = attrs.get("repo");
if (patternStr == null)
return null;
List<Pattern> patterns = new LinkedList<>();
QuotedTokenizer tokenize = new QuotedTokenizer(patternStr, ",");
String token = tokenize.nextToken();
while (token != null) {
patterns.add(Glob.toPattern(token));
token = tokenize.nextToken();
}
return new RepoFilter(patterns.toArray(new Pattern[0]));
}
Aggregations