Refine search
public Macro getReplacer() { if (replacer == null) return replacer = new Macro(this, getMacroDomains()); return replacer; }
public String _foreach(String args[]) throws Exception { verifyCommand(args, _foreach, null, 2, Integer.MAX_VALUE); String macro = args[1]; List<String> list = toList(args, 2, args.length); List<String> result = new ArrayList<>(); int n = 0; for (String s : list) { String invoc = process("${" + macro + ";" + s + ";" + n++ + "}"); result.add(invoc); } return Processor.join(result); }
public String _filter(String args[]) { return filter(args, false); }
if (!info.containsKey(Constants.VERSION_ATTRIBUTE)) { if (version != null) { version = getReplacer().process(version); if (Verifier.VERSION.matcher(version).matches()) info.put(VERSION_ATTRIBUTE, version); else error("Export annotation in %s has invalid version info: %s", clazz, version); Version bv = new Version(version); if (!av.equals(bv)) { error("Version from annotation for %s differs with packageinfo or Manifest", clazz .getClassName().getFQN()); Attrs attrs = doAttrbutes((Object[]) a.get(Export.MANDATORY), clazz, getReplacer()); if (!attrs.isEmpty()) { info.putAll(attrs); info.put(MANDATORY_DIRECTIVE, Processor.join(attrs.keySet())); attrs = doAttrbutes((Object[]) a.get(Export.OPTIONAL), clazz, getReplacer()); if (!attrs.isEmpty()) { info.putAll(attrs); String del = ""; for (Object i : excluded) { Matcher m = OBJECT_REFERENCE.matcher((String) i); if (m.matches()) { sb.append(del);
/** * Take all the properties and translate them to actual values. This method * takes the set properties and traverse them over all entries, including * the default properties for that properties. The values no longer contain * macros. * * @return A new Properties with the flattened values */ public Properties getFlattenedProperties() { // Some macros only work in a lower processor, so we // do not report unknown macros while flattening flattening = true; try { Properties flattened = new Properties(); Properties source = domain.getProperties(); for (Enumeration< ? > e = source.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); if (!key.startsWith("_")) if (key.startsWith("-")) flattened.put(key, source.getProperty(key)); else flattened.put(key, process(source.getProperty(key))); } return flattened; } finally { flattening = false; } }
private void readBuildProperties() throws Exception { try { File f = getFile("build.properties"); if (f.isFile()) { Properties p = loadProperties(f); for (Enumeration< ? > e = p.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String newkey = key; if (key.indexOf('$') >= 0) { newkey = getReplacer().process(key); } setProperty(newkey, p.getProperty(key)); } } } catch (Exception e) { e.printStackTrace(); } }
try { Properties flattened = new UTF8Properties(); Properties source = domain.getProperties(); for (String key : Iterables.iterable(source.propertyNames(), String.class::cast)) { if (!key.startsWith("_")) { String value = source.getProperty(key); if (value == null) { Object raw = source.get(key); domain.warning("Key '%s' has a non-String value: %s:%s", key, raw == null ? "" : raw.getClass() .getName(), flattened.put(key, value); else flattened.put(key, process(value));
if (!ins.isLiteral()) { String keyname = key; return domain.stream() .filter(ins::matches) .sorted() .map(k -> replace(k, new Link(domain, link, keyname), begin, end)) .filter(Objects::nonNull) .collect(joining(",")); for (Processor source = domain; source != null; source = source.getParent()) { String value = source.getProperties() .getProperty(key); if (value != null) { return process(value, new Link(source, link, key)); String value = doCommands(key, link); if (value != null) { if (value == NULLVALUE) if (value == LITERALVALUE) return LITERALVALUE; return process(value, new Link(domain, link, key)); value = process(template, new Link(domain, link, key)); if (value != null) return value; String replace = getMacro(key, link, begin, end, profile); if (replace != null)
public String _warning(String args[]) throws Exception { for (int i = 1; i < args.length; i++) { SetLocation warning = domain.warning("%s", process(args[i])); FileLine header = domain.getHeader(Pattern.compile(".*"), Pattern.compile("\\$\\{warning;")); if (header != null) header.set(warning); } return ""; }
Instruction ins = new Instruction(key); if (!ins.isLiteral()) { SortedList<String> sortedList = SortedList.fromIterator(domain.iterator()); StringBuilder sb = new StringBuilder(); String del = ""; for (String k : sortedList) { if (ins.matches(k)) { String v = replace(k, new Link(source, link, key)); if (v != null) { sb.append(del); value = source.getProperties().getProperty(key); source = source.getParent(); return process(value, new Link(source, link, key)); value = doCommands(key, link); if (value != null) return process(value, new Link(source, link, key));
private String doCommands(String key, Link source) { String[] args = commands.split(key); if (args == null || args.length == 0) return null; for (int i = 0; i < args.length; i++) if (args[i].indexOf('\\') >= 0) args[i] = args[i].replaceAll("\\\\;", ";"); if (args[0].startsWith("^")) { String varname = args[0].substring(1).trim(); Processor parent = source.start.getParent(); if (parent != null) return parent.getProperty(varname); return null; } Processor rover = domain; while (rover != null) { String result = doCommand(rover, args[0], args); if (result != null) return result; rover = rover.getParent(); } for (int i = 0; targets != null && i < targets.length; i++) { String result = doCommand(targets[i], args[0], args); if (result != null) return result; } return doCommand(this, args[0], args); }
setProperty(CURRENT_USES, sb.toString()); override = getReplacer().process(override); unsetProperty(CURRENT_USES); } else override = override.replaceAll(USES_USES, Matcher.quoteReplacement(sb.toString())).trim();
String applyVersionPolicy(String exportVersion, String importRange, boolean provider) { try { setProperty("@", exportVersion); if (importRange != null) { importRange = cleanupVersion(importRange); importRange = getReplacer().process(importRange); } else importRange = getVersionPolicy(provider); } finally { unsetProperty("@"); } return importRange; }
private void add(String name, String value) { if (value == null) return; Processor next = new Processor(analyzer); next.setProperty("@class", current.getFQN()); next.setProperty("@class-short", current.getClassName().getShortName()); PackageRef pref = current.getClassName().getPackageRef(); next.setProperty("@package", pref.getFQN()); Attrs info = analyzer.getClasspathExports().get(pref); if (info == null) info = analyzer.getContained().get(pref); if (info != null && info.containsKey("version")) { next.setProperty("@version", info.get("version")); } Macro macro = next.getReplacer(); /* * These strings come from code, which might also be included from * external parties. So we just do not want to call any system commands * from these sources */ boolean prev = macro.setNosystem(true); try { value = macro.process(value); headers.add(name, value); next.close(); } finally { macro.setNosystem(prev); } }
if (c1 == end) { if (--nesting == 0) { result.append(replace(variable.toString(), link)); return index; } else if (c1 == '$' && index < line.length() - 2) { char c2 = line.charAt(index); char terminator = getTerminator(c2); if (terminator != 0) { index = process(line, index + 1, c2, terminator, variable, link); continue outer; variable.append(domain.getBase().getAbsolutePath()); variable.append('/'); continue outer;
/** * Fixup Attributes Execute any macros on an export and * * @throws IOException */ void fixupAttributes(PackageRef packageRef, Attrs attributes) throws IOException { // Convert any attribute values that have macros. for (String key : attributes.keySet()) { String value = attributes.get(key); if (value.indexOf('$') >= 0) { value = getReplacer().process(value); attributes.put(key, value); } if (!key.endsWith(":")) { String from = attributes.get(FROM_DIRECTIVE); verifyAttribute(from, "package info for " + packageRef, key, value); } } }
/** * Return the properties but expand all macros. This always returns a new * Properties object that can be used in any way. */ public Properties getFlattenedProperties(boolean ignoreInstructions) { return getReplacer().getFlattenedProperties(ignoreInstructions); }
/** * Wildcard a directory. The lists can contain Instruction that are matched * against the given directory ${lsr;<dir>;<list>(;<list>)*} * ${lsa;<dir>;<list>(;<list>)*} * * @author aqute */ public String _lsr(String args[]) { return ls(args, true); }
public String _system_allow_fail(String args[]) throws Exception { String result = ""; try { result = system_internal(true, args); return result == null ? "" : result; } catch (Throwable t) { /* ignore */ return ""; } }