예제 #1
0
파일: Macro.java 프로젝트: bramk/bnd
  String ls(String args[], boolean relative) {
    if (args.length < 2)
      throw new IllegalArgumentException(
          "the ${ls} macro must at least have a directory as parameter");

    File dir = domain.getFile(args[1]);
    if (!dir.isAbsolute())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter is not absolute: " + dir);

    if (!dir.exists())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter does not exist: " + dir);

    if (!dir.isDirectory())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter points to a file instead of a directory: " + dir);

    Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles()));

    for (int i = 2; i < args.length; i++) {
      Instructions filters = new Instructions(args[i]);
      files = filters.select(files, true);
    }

    List<String> result = new ArrayList<String>();
    for (File file : files) result.add(relative ? file.getName() : file.getAbsolutePath());

    return Processor.join(result, ",");
  }
예제 #2
0
파일: Macro.java 프로젝트: bramk/bnd
  public String _fmodified(String args[]) throws Exception {
    verifyCommand(args, _fmodifiedHelp, null, 2, Integer.MAX_VALUE);

    long time = 0;
    Collection<String> names = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
      Processor.split(args[i], names);
    }
    for (String name : names) {
      File f = new File(name);
      if (f.exists() && f.lastModified() > time) time = f.lastModified();
    }
    return "" + time;
  }
예제 #3
0
파일: Macro.java 프로젝트: bramk/bnd
 public String _basename(String args[]) {
   if (args.length < 2) {
     domain.warning("Need at least one file name for ${basename;...}");
     return null;
   }
   String del = "";
   StringBuilder sb = new StringBuilder();
   for (int i = 1; i < args.length; i++) {
     File f = domain.getFile(args[i]);
     if (f.exists() && f.getParentFile().exists()) {
       sb.append(del);
       sb.append(f.getName());
       del = ",";
     }
   }
   return sb.toString();
 }