Package org.crsh.vfs

Examples of org.crsh.vfs.Resource


  @Override
  public void init() {
    PluginContext context = getContext();

    //
    Resource config = null;

    //
    URL configURL = TelnetPlugin.class.getResource("/crash/telnet.properties");
    if (configURL != null) {
      try {
        log.log(Level.FINE, "Found embedded telnet config url " + configURL);
        config = new Resource("telnet.properties", configURL);
      }
      catch (IOException e) {
        log.log(Level.FINE, "Could not load embedded telnet config url " + configURL + " will bypass it", e);
      }
    }

    // Override from config if any
    Resource res = getContext().loadResource("telnet.properties", ResourceKind.CONFIG);
    if (res != null) {
      config = res;
      log.log(Level.FINE, "Found telnet config url " + configURL);
    }
View Full Code Here


    if (authTimeout == null) {
      authTimeout = SSH_SERVER_AUTH_DEFAULT_TIMEOUT;
    }

    //
    Resource serverKey = null;
    KeyPairProvider keyPairProvider = null;

    // Get embedded default key
    URL serverKeyURL = SSHPlugin.class.getResource("/crash/hostkey.pem");
    if (serverKeyURL != null) {
      try {
        log.log(Level.FINE, "Found embedded key url " + serverKeyURL);
        serverKey = new Resource("hostkey.pem", serverKeyURL);
      }
      catch (IOException e) {
        log.log(Level.FINE, "Could not load ssh key from url " + serverKeyURL, e);
      }
    }

    // Override from config if any
    Resource serverKeyRes = getContext().loadResource("hostkey.pem", ResourceKind.CONFIG);
    if (serverKeyRes != null) {
      serverKey = serverKeyRes;
      log.log(Level.FINE, "Found server ssh key url");
    }

    // If we have a key path, we convert is as an URL
    String serverKeyPath = getContext().getProperty(SSH_SERVER_KEYPATH);
    if (serverKeyPath != null) {
      log.log(Level.FINE, "Found server key path " + serverKeyPath);
      File f = new File(serverKeyPath);
      String keyGen = getContext().getProperty(SSH_SERVER_KEYGEN);
      if (keyGen != null && keyGen.equals("true")) {
        keyPairProvider = new PEMGeneratorHostKeyProvider(serverKeyPath, "RSA");
      } else if (f.exists() && f.isFile()) {
        try {
          serverKeyURL = f.toURI().toURL();
          serverKey = new Resource("hostkey.pem", serverKeyURL);
        } catch (MalformedURLException e) {
          log.log(Level.FINE, "Ignoring invalid server key " + serverKeyPath, e);
        } catch (IOException e) {
          log.log(Level.FINE, "Could not load SSH key from " + serverKeyPath, e);
        }
View Full Code Here

   
    // Get properties from system properties
    Properties config = new Properties();

    // Load properties from configuration file
    Resource res = context.loadResource("crash.properties", ResourceKind.CONFIG);
    if (res != null) {
      try {
        config.load(new ByteArrayInputStream(res.getContent()));
        log.log(Level.FINE, "Loaded properties from " + config);
      } catch (IOException e) {
        log.log(Level.WARNING, "Could not configure from crash.properties", e);
      }
    } else {
View Full Code Here

          copyCmd(child, new File(dst, child.getName()));
        }
      }
    } else {
      if (!dst.exists()) {
        Resource resource = src.getResource();
        if (resource != null) {
          log.info("Copied command " + src.getPath().getValue() + " to " + dst.getCanonicalPath());
          Utils.copy(new ByteArrayInputStream(resource.getContent()), new FileOutputStream(dst));
        }
      }
    }
  }
View Full Code Here

  }

  private void copyConf(org.crsh.vfs.File src, File dst) throws IOException {
    if (!src.hasChildren()) {
      if (!dst.exists()) {
        Resource resource = ResourceManager.loadConf(src);
        if (resource != null) {
          log.info("Copied resource " + src.getPath().getValue() + " to " + dst.getCanonicalPath());
          Utils.copy(new ByteArrayInputStream(resource.getContent()), new FileOutputStream(dst));
        }
      }
    }
  }
View Full Code Here

            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            long timestamp = Long.MIN_VALUE;
            for (File path : dirs) {
              File f = path.child(resourceId + ".groovy");
              if (f != null) {
                Resource sub = f.getResource();
                if (sub != null) {
                  buffer.write(sub.getContent());
                  buffer.write('\n');
                  timestamp = Math.max(timestamp, sub.getTimestamp());
                }
              }
            }
            return Collections.singleton(new Resource(resourceId + ".groovy", buffer.toByteArray(), timestamp));
          }
          break;
        case COMMAND:
          // Find the resource first, we find for the first found
          for (File path : dirs) {
View Full Code Here

      Iterator<Resource> i = file.getResources().iterator();
      if (i.hasNext()) {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        long timestamp = 0;
        while (i.hasNext()) {
          Resource resource = i.next();
          byte[] bytes = resource.getContent();
          buffer.write(bytes);
          timestamp = Math.max(timestamp, resource.getTimestamp());
          if (i.hasNext()) {
            // Go to line
            buffer.write(SEPARATOR);
            // Cosmetic blank line
            buffer.write(SEPARATOR);
          }
        }
        return new Resource(file.getName(), buffer.toByteArray(), timestamp);
      } else {
        return null;
      }
    } else {
      return file.getResource();
View Full Code Here

    public Support(final String crontab) throws Exception {
      lifecycle = new TestPluginLifeCycle(new CronPlugin() {
        @Override
        protected Resource getConfig() {
          return new Resource("contrab", crontab.getBytes(), 0);
        }
      }, new GroovyLanguageProxy(), new CRaSHShellFactory());
      lifecycle.start();
    }
View Full Code Here

   * @return read the config file and return it
   */
  protected Resource getConfig() {

    //
    Resource config = null;
    String configPath = getContext().getProperty(CRON_CONFIG_PATH);
    if (configPath != null) {
      File configFile = new File(configPath);
      if (configFile.exists()) {
        log.log(Level.FINE, "Found crontab file " + configPath);
        if (configFile.isFile()) {
          try {
            config = new Resource("crontab", configFile.toURI().toURL());
          }
          catch (MalformedURLException e) {
            log.log(Level.SEVERE, "Could not retrieve cron config file from " + configPath, e);
          }
          catch (IOException e) {
            log.log(Level.FINE, "Could not load cron config file from " + configPath, e);
          }
        } else {
          log.log(Level.FINE, "Crontab file " + configPath + " is not a file");
        }
      } else {
        log.log(Level.FINE, "Crontab file " + configPath + " does not exist");
      }
    } else {
      // Override from config if any
      Resource res = getContext().loadResource("crontab", ResourceKind.CONFIG);
      if (res != null) {
        config = res;
        log.log(Level.FINE, "Found crontab config url " + res);
      }
    }
View Full Code Here

  }

  public TaskTable getTasks() {

    //
    Resource res = getConfig();
    List<String> lines = null;
    try {
      lines = new ArrayList<String>();
      BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(res.getContent()), "UTF-8"));
      while (true) {
        String cronLine = reader.readLine();
        if (cronLine == null) {
          break;
        } else {
View Full Code Here

TOP

Related Classes of org.crsh.vfs.Resource

Copyright © 2018 www.massapicom. 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.