Ejemplo n.º 1
0
 /**
  * Gets the urlClassLoader that enables to access to the objects jar files.
  *
  * @return an URLClassLoader
  */
 public URLClassLoader getObjectsClassLoader() {
   if (objectsClassLoader == null) {
     try {
       if (isExecutionMode()) {
         URL[] listUrl = new URL[1];
         listUrl[0] = instance.getTangaraPath().toURI().toURL();
         objectsClassLoader = new URLClassLoader(listUrl);
       } else {
         File f = new File(instance.getTangaraPath().getParentFile(), "objects");
         File[] list = f.listFiles();
         Vector<URL> vector = new Vector<URL>();
         for (int i = 0; i < list.length; i++) {
           if (list[i].getName().endsWith(".jar")) vector.add(list[i].toURI().toURL());
         }
         File flib =
             new File(
                 instance.getTangaraPath().getParentFile().getAbsolutePath().replace("\\", "/")
                     + "/objects/lib");
         File[] listflib = flib.listFiles();
         for (int j = 0; j < listflib.length; j++) {
           if (listflib[j].getName().endsWith(".jar")) vector.add(listflib[j].toURI().toURL());
         }
         URL[] listUrl = new URL[vector.size()];
         for (int j = 0; j < vector.size(); j++) listUrl[j] = vector.get(j);
         objectsClassLoader = new URLClassLoader(listUrl);
       }
     } catch (Exception e1) {
       displayError("URL MAL FORMED " + e1);
       return null;
     }
   }
   return objectsClassLoader;
 }
Ejemplo n.º 2
0
 public Properties loadUpdateProperties() {
   File propertiesDirectory;
   Properties updateProperties = new Properties();
   // First we look at local configuration directory
   propertiesDirectory = new File(System.getProperty("user.home"), PROPERTIES_DIRECTORY_NAME);
   if (!propertiesDirectory.exists()) {
     // Second we look at tangara binary path
     propertiesDirectory = getTangaraPath().getParentFile();
   }
   BufferedInputStream input = null;
   try {
     input =
         new BufferedInputStream(
             new FileInputStream(
                 new File(propertiesDirectory, getProperty("checkUpdate.fileName"))));
     updateProperties.load(input);
     input.close();
     return updateProperties;
   } catch (IOException e) {
     LOG.warn("Error trying to load update properties");
   } finally {
     IOUtils.closeQuietly(input);
   }
   return null;
 }
Ejemplo n.º 3
0
 private void initBasePath() {
   // First we look at local configuration directory
   File baseFile = getLocalBasePath();
   if (!baseFile.exists()) {
     // file does not exist, check if base exists in binary path
     File baseFile2 = getBinaryBasePath();
     if (isValidBase(baseFile2)) {
       // base was found and base is valid: we use this one
       baseFile = baseFile2;
     }
   }
   this.basePath = baseFile;
 }
Ejemplo n.º 4
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);
   }
 }
Ejemplo n.º 5
0
  /**
   * Loads the configuration
   *
   * @throws ConfigurationException
   */
  public void load() throws ConfigurationException {
    System.out.println("Loading configuration..."); // $NON-NLS-1$
    properties.clear();
    fixedProperties.clear();

    System.out.println("-> loading default properties");
    loadDefaultCfg();
    System.out.println("-> loading fixed properties");
    loadFixedCfg();
    System.out.println("-> loading system properties");
    loadSystemCfgFile();
    System.out.println("-> loading local properties");
    loadLocalCfgFile();
    // Try to define userHome from the config file
    System.out.println("-> setting user home");
    userHome = new File(System.getProperty("user.home"));
    String confHome = getProperty(USER_HOME_P);
    if ((confHome != null) && !confHome.equals("")) userHome = new File(confHome);
    String myDocString = getProperty(USER_DIRNAME_P);
    if ((myDocString != null) && (!myDocString.equals(""))) {
      File myDocDir = new File(userHome, myDocString);
      if (myDocDir.exists()) userHome = myDocDir;
    }
    // Check if we are in execution mode
    System.out.println("-> checking execution mode");
    testExecutionMode();
    System.out.println("-> loading scripting languages");
    loadScriptingLanguages(fixedProperties);
    System.out.println("-> langage " + getLanguage() + " is used");
    defaultLanguage = (getLanguage().compareTo(getDefaultLanguage()) == 0);
    System.out.println("-> loading localized messages");
    // Load localized messages
    try {
      // loads the language
      Messages.loadLocalizedResource(getLanguage());
      org.colombbus.tangara.net.Messages.loadLocalizedResource(getLanguage());
    } catch (Throwable th) {
      System.err.println("error while loading language configuration: " + th);
    }
    System.out.println("-> loading package info");
    loadPackageInfo(fixedProperties);
    System.out.println("-> loading engine");
    loadEngine(defaultEngineName);
    System.out.println("-> loading objects");
    loadObjects();
    System.out.println("Configuration loaded"); // $NON-NLS-1$
  }
Ejemplo n.º 6
0
 private boolean isValidBase(File basePath) {
   if (basePath.exists()) {
     String baseVersion = JarUtils.getManifestProperty(basePath, BASE_VERSION_PROPERTY);
     if ((baseVersion != null) && (baseVersion.compareTo(getString("tangara.version")) == 0)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 7
0
 public void saveUpdateProperties(Properties updateProperties) {
   File propertiesDirectory;
   propertiesDirectory = new File(System.getProperty("user.home"), PROPERTIES_DIRECTORY_NAME);
   if (!propertiesDirectory.exists()) {
     propertiesDirectory.mkdir();
   }
   BufferedOutputStream outStream = null;
   try {
     outStream =
         new BufferedOutputStream(
             new FileOutputStream(
                 new File(propertiesDirectory, getProperty("checkUpdate.fileName"))));
     updateProperties.store(outStream, "Tangara update properties");
   } catch (Exception ex) {
     LOG.error("Failed to write lastlaunch property", ex);
   } finally {
     IOUtils.closeQuietly(outStream);
   }
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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();
  }
Ejemplo n.º 10
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);
      }
    }
  }