Package org.jboss.fresh.shell.commands

Source Code of org.jboss.fresh.shell.commands.MkDirExe

package org.jboss.fresh.shell.commands;

import org.jboss.fresh.vfs.FileInfo;
import org.jboss.fresh.vfs.FileName;
import org.jboss.fresh.vfs.VFS;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.shell.AbstractExecutable;

import java.io.PrintWriter;


// EX OK

public class MkDirExe extends AbstractExecutable {
  private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(MkDirExe.class);

  /**
   Makes new specified subdirectoryes on the current working directory.
   */

  public void process(String exename, String[] params) throws Exception {
    log.debug("entered");

    if (helpRequested()) {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      out.print("Usage: mkdir [--help] [-ex] PATHS\n");
      out.print("    PATHS : new directoryes to be made in the current working directory.\n");
      out.print("    --help : this help\n");
      out.close();
      log.debug("done");
      return;
    }

    PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
    VFS vfs = shell.getVFS();
    FileName pwd = new FileName(shell.getEnvProperty("PWD"));

    // List paths = new LinkedList();

    for (int i = 0; i < params.length; i++) {
      String param = params[i];

      FileName path = new FileName(param);
      if (path.isRelative())
        path = pwd.absolutize(path);

//      path = vfs.resolve(shell.getUserCtx(), path, true);

      if (vfs.exists(shell.getUserCtx(), path.getPath(), true)) {

        if (!vfs.exists(shell.getUserCtx(), path, true)) {
          FileInfo dir = new FileInfo(path, FileInfo.TYPE_DIR);
          vfs.createFile(shell.getUserCtx(), dir);
          //out.println(param+ ": Directory successfully created.");

        } else {
          if (canThrowEx()) {
            throw new RuntimeException(param + ": Path already exists!");
          } else {
            out.println(param + ": Path already exists!");
          }
        }

      } else {
        if (canThrowEx()) {
          throw new RuntimeException(param + ": Parent must exist!");
        } else {
          out.println(param + ": Parent must exist!");
        }
      }

    }

    out.close();

    log.debug("done");
  }
}
TOP

Related Classes of org.jboss.fresh.shell.commands.MkDirExe

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.