Example #1
0
File: Macro.java Project: 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, ",");
  }
Example #2
0
 /**
  * Method to build an absolute path
  *
  * @param dir the root dir
  * @param name the name of the new directory
  * @return if name is an absolute directory, returns name, else returns dir+name
  */
 public static String getDir(String dir, String name) {
   if (!dir.endsWith(File.separator)) dir = dir + File.separator;
   File mv = new File(name);
   String new_dir = null;
   if (!mv.isAbsolute()) {
     new_dir = dir + name;
   } else new_dir = name;
   return new_dir;
 }