public String _range(String args[]) { verifyCommand(args, _rangeHelp, _rangePattern, 2, 3); Version version = null; if (args.length >= 3) version = new Version(args[2]); else { String v = domain.getProperty("@"); if (v == null) return null; version = new Version(v); } String spec = args[1]; Matcher m = RANGE_MASK.matcher(spec); m.matches(); String floor = m.group(1); String floorMask = m.group(2); String ceilingMask = m.group(3); String ceiling = m.group(4); String left = version(version, floorMask); String right = version(version, ceilingMask); StringBuilder sb = new StringBuilder(); sb.append(floor); sb.append(left); sb.append(","); sb.append(right); sb.append(ceiling); String s = sb.toString(); VersionRange vr = new VersionRange(s); if (!(vr.includes(vr.getHigh()) || vr.includes(vr.getLow()))) { domain.error( "${range} macro created an invalid range %s from %s and mask %s", s, version, spec); } return sb.toString(); }
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); }
public static void testBumpIncludeFile() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("bump-included"); project.setTrace(true); Version old = new Version(project.getProperty("Bundle-Version")); assertEquals(new Version(1, 0, 0), old); project.bump("=+0"); Processor processor = new Processor(); processor.setProperties(project.getFile("include.txt")); Version newv = new Version(processor.getProperty("Bundle-Version")); System.err.println("New version " + newv); assertEquals(1, newv.getMajor()); assertEquals(1, newv.getMinor()); assertEquals(0, newv.getMicro()); } finally { IO.deleteWithException(tmp); } }
String version(Version version, String mask) { if (version == null) { String v = domain.getProperty("@"); if (v == null) { domain.error( "No version specified for ${version} or ${range} and no implicit version ${@} either, mask=%s", mask); v = "0"; } version = new Version(v); } StringBuilder sb = new StringBuilder(); String del = ""; for (int i = 0; i < mask.length(); i++) { char c = mask.charAt(i); String result = null; if (c != '~') { if (i == 3) { result = version.getQualifier(); } else if (Character.isDigit(c)) { // Handle masks like +00, =+0 result = String.valueOf(c); } else { int x = version.get(i); switch (c) { case '+': x++; break; case '-': x--; break; case '=': break; } result = Integer.toString(x); } if (result != null) { sb.append(del); del = "."; sb.append(result); } } } return sb.toString(); }
public String _def(String args[]) { if (args.length != 2) throw new RuntimeException("Need a value for the ${def;<value>} macro"); return domain.getProperty(args[1], ""); }