use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class bnd method _grep.
@Description("Grep the manifest of bundles/jar files. ")
public void _grep(grepOptions opts) throws Exception {
List<String> args = opts._arguments();
String s = args.remove(0);
Pattern pattern = Glob.toPattern(s);
if (pattern == null) {
messages.InvalidGlobPattern_(s);
return;
}
if (args.isEmpty()) {
args = new ExtList<String>(getBase().list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
}));
}
Set<String> headers = opts.headers();
if (headers == null)
headers = new TreeSet<String>();
if (opts.exports())
headers.add(Constants.EXPORT_PACKAGE);
if (opts.bsn())
headers.add(Constants.BUNDLE_SYMBOLICNAME);
if (opts.imports())
headers.add(Constants.IMPORT_PACKAGE);
Instructions instructions = new Instructions(headers);
for (String fileName : args) {
File file = getFile(fileName);
if (!file.isFile()) {
messages.NoSuchFile_(file);
continue;
}
try (JarInputStream in = new JarInputStream(IO.stream(file))) {
Manifest m = in.getManifest();
for (Object header : m.getMainAttributes().keySet()) {
Attributes.Name name = (Name) header;
if (instructions.isEmpty() || instructions.matches(name.toString())) {
String h = m.getMainAttributes().getValue(name);
QuotedTokenizer qt = new QuotedTokenizer(h, ",;=");
for (String value : qt.getTokenSet()) {
Matcher matcher = pattern.matcher(value);
while (matcher.find()) {
int start = matcher.start() - 8;
if (start < 0)
start = 0;
int end = matcher.end() + 8;
if (end > value.length())
end = value.length();
out.printf("%40s : %20s ...%s[%s]%s...\n", fileName, name, value.substring(start, matcher.start()), value.substring(matcher.start(), matcher.end()), value.substring(matcher.end(), end));
}
}
}
}
}
}
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class SimpleListConverter method convert.
public List<R> convert(String input) throws IllegalArgumentException {
if (input == null)
return null;
List<R> result = new ArrayList<R>();
if (input == null || Constants.EMPTY_HEADER.equalsIgnoreCase(input.trim()))
return result;
QuotedTokenizer qt = new QuotedTokenizer(input, ",");
String token = qt.nextToken();
while (token != null) {
result.add(itemConverter.convert(token.trim()));
token = qt.nextToken();
}
return result;
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class Verifier method verifyHeader.
private boolean verifyHeader(String name, Pattern regex, boolean error) {
String value = manifest.getMainAttributes().getValue(name);
if (value == null)
return false;
QuotedTokenizer st = new QuotedTokenizer(value.trim(), ",");
for (Iterator<String> i = st.getTokenSet().iterator(); i.hasNext(); ) {
if (!verify(i.next(), regex)) {
if (error)
error("Invalid value for %s, %s does not match %s", name, value, regex.pattern());
else
warning("Invalid value for %s, %s does not match %s", name, value, regex.pattern());
}
}
return true;
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class Verifier method doNative.
public void doNative(String nc) {
if (nc != null) {
QuotedTokenizer qt = new QuotedTokenizer(nc, ",;=", false);
char del;
do {
do {
String name = qt.nextToken();
if (name == null) {
error("Can not parse name from bundle native code header: %s", nc);
return;
}
del = qt.getSeparator();
if (del == ';') {
if (dot != null && !dot.exists(name)) {
error("Native library not found in JAR: %s", name);
}
} else {
String value = null;
if (del == '=')
value = qt.nextToken();
String key = name.toLowerCase();
if (key.equals("osname")) {
// ...
} else if (key.equals("osversion")) {
// verify version range
verify(value, VERSIONRANGE);
} else if (key.equals("language")) {
verify(value, ISO639);
} else if (key.equals("processor")) {
// verify(value, PROCESSORS);
} else if (key.equals("selection-filter")) {
// verify syntax filter
verifyFilter(value);
} else if (name.equals("*") && value == null) {
// Wildcard must be at end.
if (qt.nextToken() != null)
error("Bundle-Native code header may only END in wildcard %s", nc);
} else {
warning("Unknown attribute in native code: %s=%s", name, value);
}
del = qt.getSeparator();
}
} while (del == ';');
} while (del == ',');
}
}
use of aQute.libg.qtokens.QuotedTokenizer in project bnd by bndtools.
the class TestQuotedTokenizer method testSimple.
public static void testSimple() {
String[] s = new QuotedTokenizer("1.jar, 2.jar, \t 3.jar", ",").getTokens();
assertEquals("Length", 3, s.length);
assertEquals("1.jar", s[0]);
assertEquals("2.jar", s[1]);
assertEquals("3.jar", s[2]);
}
Aggregations