public String toString() { return getPattern(); }
public String toString() { return getPattern(); }
public List<String> list(String regex) { Instruction pattern = null; if (regex != null) pattern = Instruction.getPattern(regex); List<String> result = new ArrayList<String>(); for (String f : index.keySet()) { if (pattern == null || pattern.matches(f)) result.add(f); } return result; }
public List<String> list(String regex) { Instruction pattern = null; if (regex != null) pattern = Instruction.getPattern(regex); String list[] = root.list(); List<String> result = new ArrayList<String>(); for (String f : list) { if (pattern == null || pattern.matches(f)) result.add(f); } return result; }
public static Map<Instruction, Map<String, String>> replaceWithInstruction( Map<String, Map<String, String>> header) { Map<Instruction, Map<String, String>> map = Processor.newMap(); for (Iterator<Map.Entry<String, Map<String, String>>> e = header .entrySet().iterator(); e.hasNext();) { Map.Entry<String, Map<String, String>> entry = e.next(); String pattern = entry.getKey(); Instruction instr = getPattern(pattern); String presence = entry.getValue() .get(Constants.PRESENCE_DIRECTIVE); if ("optional".equals(presence)) instr.setOptional(); map.put(instr, entry.getValue()); } return map; }
public static Map<Instruction, Map<String, String>> replaceWitInstruction( Map<String, Map<String, String>> header, String type) { Map<Instruction, Map<String, String>> map = newMap(); for (Iterator<Map.Entry<String, Map<String, String>>> e = header .entrySet().iterator(); e.hasNext();) { Map.Entry<String, Map<String, String>> entry = e.next(); String pattern = entry.getKey(); Instruction instr = Instruction.getPattern(pattern); String presence = entry.getValue().get(PRESENCE_DIRECTIVE); if ("optional".equals(presence)) instr.setOptional(); map.put(instr, entry.getValue()); } return map; }
/** * Copy the input collection into an output set but skip names that have * been marked as duplicates or are optional. * * @param superfluous * @return */ Set<Instruction> removeMarkedDuplicates(Collection<Instruction> superfluous) { Set<Instruction> result = new HashSet<Instruction>(); for (Iterator<Instruction> i = superfluous.iterator(); i.hasNext();) { Instruction instr = (Instruction) i.next(); if (!isDuplicate(instr.getPattern()) && !instr.isOptional()) result.add(instr); } return result; }
/** * Copy the input collection into an output set but skip names that have * been marked as duplicates or are optional. * * @param superfluous * @return */ Set<Instruction> removeMarkedDuplicates(Collection<Instruction> superfluous) { Set<Instruction> result = new HashSet<Instruction>(); for (Iterator<Instruction> i = superfluous.iterator(); i.hasNext();) { Instruction instr = (Instruction) i.next(); if (!isDuplicate(instr.getPattern()) && !instr.isOptional()) result.add(instr); } return result; }
void removeAttributes(Map<String, String> attributes) { // You can add a remove-attribute: directive with a regular // expression for attributes that need to be removed. We also // remove all attributes that have a value of !. This allows // you to use macros with ${if} to remove values. String remove = attributes.remove(REMOVE_ATTRIBUTE_DIRECTIVE); Instruction removeInstr = null; if (remove != null) removeInstr = Instruction.getPattern(remove); for (Iterator<Map.Entry<String, String>> i = attributes.entrySet().iterator(); i.hasNext();) { Map.Entry<String, String> entry = i.next(); if (entry.getValue().equals("!")) i.remove(); else if (removeInstr != null && removeInstr.matches((String) entry.getKey())) i.remove(); else { // Not removed ... } } }
@Override public List<String> list(String regex) { Instruction pattern = null; if (regex != null) pattern = Instruction.getPattern(regex); String list[] = getRoot().list(); List<String> result = new ArrayList<String>(); for (String f : list) { Matcher m = REPO_FILE.matcher(f); if (!m.matches()) { continue; } String s = m.group(1); if (pattern == null || pattern.matches(s)) result.add(s); } return result; } @Override
Map<Instruction, Map<String, String>> getMakeHeader() { if (make != null) return make; make = Processor.newMap(); String s = builder.getProperty(Builder.MAKE); Map<String, Map<String, String>> make = builder.parseHeader(s); for (Iterator<Map.Entry<String, Map<String, String>>> e = make .entrySet().iterator(); e.hasNext();) { Map.Entry<String, Map<String, String>> entry = e.next(); String pattern = Processor.removeDuplicateMarker(entry.getKey()); Instruction instr = Instruction.getPattern(pattern); this.make.put(instr, entry.getValue()); } return this.make; } }
Map<Instruction, Map<String, String>> getMakeHeader() { if (make != null) return make; make = Processor.newMap(); String s = builder.getProperty(Builder.MAKE); Map<String, Map<String, String>> make = builder.parseHeader(s); for (Iterator<Map.Entry<String, Map<String, String>>> e = make .entrySet().iterator(); e.hasNext();) { Map.Entry<String, Map<String, String>> entry = e.next(); String pattern = Processor.removeDuplicateMarker(entry.getKey()); Instruction instr = Instruction.getPattern(pattern); this.make.put(instr, entry.getValue()); } return this.make; } }
private void doView(File file, String resource, String charset, int options, File output) { // out.println("doView:" + file.getAbsolutePath() ); try { Instruction instruction = Instruction.getPattern(resource); FileInputStream fin = new FileInputStream(file); ZipInputStream in = new ZipInputStream(fin); ZipEntry entry = in.getNextEntry(); while (entry != null) { // out.println("view " + file + ": " // + instruction.getPattern() + ": " + entry.getName() // + ": " + output + ": " // + instruction.matches(entry.getName())); if (instruction.matches(entry.getName()) ^ instruction.isNegated()) doView(entry.getName(), in, charset, options, output); in.closeEntry(); entry = in.getNextEntry(); } in.close(); fin.close(); } catch (Exception e) { out.println("Can not process: " + file.getAbsolutePath()); e.printStackTrace(); } }
private void doView(File file, String resource, String charset, int options, File output) { // out.println("doView:" + file.getAbsolutePath() ); try { Instruction instruction = Instruction.getPattern(resource); FileInputStream fin = new FileInputStream(file); ZipInputStream in = new ZipInputStream(fin); ZipEntry entry = in.getNextEntry(); while (entry != null) { // out.println("view " + file + ": " // + instruction.getPattern() + ": " + entry.getName() // + ": " + output + ": " // + instruction.matches(entry.getName())); if (instruction.matches(entry.getName()) ^ instruction.isNegated()) doView(entry.getName(), in, charset, options, output); in.closeEntry(); entry = in.getNextEntry(); } in.close(); fin.close(); } catch (Exception e) { out.println("Can not process: " + file.getAbsolutePath()); e.printStackTrace(); } }
public String _findfile(String args[]) { File f = getFile(args[1]); List<String> files = new ArrayList<String>(); tree(files, f, "", Instruction.getPattern(args[2])); return join(files); }
/** * * @param jar * @param name * @param instructions */ private void doExpand(Jar jar, String name, Map<Instruction, Map<String, String>> instructions, boolean mandatory) { Set<Instruction> superfluous = removeMarkedDuplicates(instructions .keySet()); for (Iterator<Jar> c = getClasspath().iterator(); c.hasNext();) { Jar now = c.next(); doExpand(jar, instructions, now, superfluous); } if (mandatory && superfluous.size() > 0) { StringBuffer sb = new StringBuffer(); String del = "Instructions in " + name + " that are never used: "; for (Iterator<Instruction> i = superfluous.iterator(); i.hasNext();) { Instruction p = i.next(); sb.append(del); sb.append(p.getPattern()); del = ", "; } warning(sb.toString()); } }
public String _findfile(String args[]) { File f = getFile(args[1]); List<String> files = new ArrayList<String>(); tree(files, f, "", Instruction.getPattern(args[2])); return join(files); }
public List<String> list(String regex) throws Exception { init(); Instruction pattern = null; if (regex != null) pattern = Instruction.getPattern(regex); List<String> result = new ArrayList<String>(); if (root == null) { if (reporter != null) reporter.error("FileRepo root directory is not set."); } else { File[] list = root.listFiles(); if (list != null) { for (File f : list) { if (!f.isDirectory()) continue; // ignore non-directories String fileName = f.getName(); if (fileName.charAt(0) == '.') continue; // ignore hidden files if (pattern == null || pattern.matches(fileName)) result.add(fileName); } } else if (reporter != null) reporter.error("FileRepo root directory (%s) does not exist", root); } return result; }
private String doResourceDirectory(Jar jar, Map<String, String> extra, boolean preprocess, File sourceFile, String destinationPath) throws Exception { String filter = extra.get("filter:"); boolean flatten = isTrue(extra.get("flatten:")); boolean recursive = true; String directive = extra.get("recursive:"); if (directive != null) { recursive = isTrue(directive); } InstructionFilter iFilter = null; if (filter != null) { iFilter = new InstructionFilter(Instruction.getPattern(filter), recursive); } else { iFilter = new InstructionFilter(null, recursive); } Map<String, File> files = newMap(); resolveFiles(sourceFile, iFilter, recursive, destinationPath, files, flatten); for (Map.Entry<String, File> entry : files.entrySet()) { copy(jar, entry.getKey(), entry.getValue(), preprocess, extra); } return destinationPath; }
private String doResourceDirectory(Jar jar, Map<String, String> extra, boolean preprocess, File sourceFile, String destinationPath) throws Exception { String filter = extra.get("filter:"); boolean flatten = isTrue(extra.get("flatten:")); boolean recursive = true; String directive = extra.get("recursive:"); if (directive != null) { recursive = isTrue(directive); } InstructionFilter iFilter = null; if (filter != null) { iFilter = new InstructionFilter(Instruction.getPattern(filter), recursive, getDoNotCopy()); } else { iFilter = new InstructionFilter(null, recursive, getDoNotCopy()); } Map<String, File> files = newMap(); resolveFiles(sourceFile, iFilter, recursive, destinationPath, files, flatten); for (Map.Entry<String, File> entry : files.entrySet()) { copy(jar, entry.getKey(), entry.getValue(), preprocess, extra); } return destinationPath; }