示例#1
0
  private void loadObjects() throws ConfigurationException {
    if (!isExecutionMode()) {
      // Import objects from file system
      File objectsDirectory = new File(tangaraPath.getParentFile(), "objects");
      System.out.println("using path " + objectsDirectory.getAbsolutePath());

      // 1st Load libraries
      File libDirectory = new File(objectsDirectory, "lib");
      File libraries[] = libDirectory.listFiles();
      for (int i = 0; i < libraries.length; i++) {
        if (libraries[i].getName().endsWith(".jar")) {
          System.out.println("Loading library " + libraries[i].getName());
          addClassPathToScriptEngine(libraries[i]);
        }
      }

      // 2nd load objects
      File objects[] = objectsDirectory.listFiles();
      for (int i = 0; i < objects.length; i++) {
        if (objects[i].getName().endsWith(".jar")) {
          System.out.println("Loading object " + objects[i].getName());
          addClassPathToScriptEngine(objects[i]);
        }
      }
    }
    // import the localized objects package
    importLocalizedObjectsPackage();
  }
示例#2
0
 private void addClassPathToScriptEngine(File jarFile) throws ConfigurationException {
   try {
     StringBuilder cmd = new StringBuilder(addClassPathCmd);
     int tagStartPos = cmd.indexOf(parameterTag);
     int tageEndPos = tagStartPos + parameterTag.length();
     cmd.replace(tagStartPos, tageEndPos, jarFile.getAbsolutePath().replace("\\", "/"));
     // System.out.println("cmd " + cmd.toString());
     engine.eval("add-classpath", 1, 1, cmd.toString()); // $NON-NLS-1$
   } catch (Exception ex) {
     String msg = String.format("Failed to load class path %s", jarFile.getName()); // $NON-NLS-1$
     System.err.println(msg + " " + ex);
     throw new ConfigurationException(msg, ex);
   }
 }
示例#3
0
 private File getRedirectionPath(File redirectFile) {
   File path = null;
   if (redirectFile.exists()) {
     InputStream redirectStream = null;
     try {
       Properties redirectProperties = new Properties();
       redirectStream = new FileInputStream(redirectFile);
       redirectProperties.load(redirectStream);
       if (redirectProperties.containsKey(REDIRECT_PATH_P)) {
         path = new File(redirectProperties.getProperty(REDIRECT_PATH_P));
       }
     } catch (Exception e) {
       System.err.println(
           "Error while reading redirect file '" + redirectFile.getAbsolutePath() + "'\n" + e);
     } finally {
       IOUtils.closeQuietly(redirectStream);
     }
   }
   return path;
 }
示例#4
0
  /**
   * Loads a default file, located in the same directory as the JAR file 1st we look for a valid
   * local redirection file (in user.home/PROPERTIES_DIRECTORY_NAME) 2nd we look for a valid
   * redirection file located with tangara binary 2nd we look for a local config file 4th we look
   * for a config file located with tangara binary
   */
  public void loadLocalCfgFile() {
    File propertiesDirectory, binaryDirectory, configFile;
    // Initialize directories
    propertiesDirectory = new File(System.getProperty("user.home"), PROPERTIES_DIRECTORY_NAME);
    binaryDirectory = getTangaraPath().getParentFile();
    configFile = null;

    // 1st look for a local redirection file
    if (propertiesDirectory.exists()) {
      File configDirectory =
          getRedirectionPath(new File(propertiesDirectory, REDIRECT_PROPERTIES_FILENAME));
      if (configDirectory != null) {
        // we could find a redirection path: test if there is a config
        // file there
        File testFile = new File(configDirectory, PROPERTIES_FILENAME);
        if (testFile.exists()) {
          // we could find a config file: set configFile accordingly
          System.out.println(
              "Reading configuration from path: '" + configDirectory.getAbsolutePath() + "'");
          configFile = testFile;
        }
      }
    }

    // 2nd look for a valid redirection file located with tangara binary
    if (configFile == null) {
      File configDirectory =
          getRedirectionPath(new File(binaryDirectory, REDIRECT_PROPERTIES_FILENAME));
      if (configDirectory != null) {
        // we could find a redirection path: test if there is a config
        // file there
        File testFile = new File(configDirectory, PROPERTIES_FILENAME);
        if (testFile.exists()) {
          // we could find a config file: set configFile accordingly
          System.out.println(
              "Reading configuration from path: '" + configDirectory.getAbsolutePath() + "'");
          configFile = testFile;
        }
      }
    }

    // 3dr look for a local config file
    if (configFile == null) {
      File testFile = new File(propertiesDirectory, PROPERTIES_FILENAME);
      if (testFile.exists()) {
        // we could find a config file: set configFile accordingly
        System.out.println(
            "Reading configuration from path: '" + propertiesDirectory.getAbsolutePath() + "'");
        configFile = testFile;
      }
    }

    // 4th look for a config file located with tangara binary
    if (configFile == null) {
      File testFile = new File(binaryDirectory, PROPERTIES_FILENAME);
      if (testFile.exists()) {
        // we could find a config file: set configFile accordingly
        System.out.println(
            "Reading configuration from path: '" + binaryDirectory.getAbsolutePath() + "'");
        configFile = testFile;
      }
    }

    // Finally read config file
    if (configFile != null) {
      InputStream configStream = null;
      try {
        configStream = new FileInputStream(configFile);
        properties.load(configStream);
      } catch (FileNotFoundException ex) {
        System.err.println(
            "Could not find configuration file '" + configFile.getAbsolutePath() + "'\n" + ex);
      } catch (IOException ioEx) {
        System.err.println(
            "Failed to load configuration file '" + configFile.getAbsolutePath() + "'\n" + ioEx);
      } finally {
        IOUtils.closeQuietly(configStream);
      }
    }
  }