Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #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;
 }
Beispiel #4
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$
  }
Beispiel #5
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);
   }
 }
Beispiel #6
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;
 }
Beispiel #7
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);
      }
    }
  }