Loading the properties file, which is a combination of the jobProps file and sysProps file

@return a Property file, which is the combination of the jobProps file and sysProps file
423194
@SuppressWarnings("DefaultCharset")
  public static Properties loadAzkabanProps() throws IOException {
    String propsFile = System.getenv(ProcessJob.JOB_PROP_ENV);
    Properties props = new Properties();
    props.load(new BufferedReader(new FileReader(propsFile)));
    return props;
  }
1309628
public File getPropertiesFile() {
        final String path = line.getOptionValue(ARGUMENT.PROP);
        if (path != null) {
            return new File(path);
        }
        return null;
    }
837806
public static Properties loadProperties(String propertyFilePath){
		Properties prop = new Properties();
		InputStream is = null;
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		try {
			is = cl.getResourceAsStream(propertyFilePath);
			Assert.notNull(is, "Failed to obtain InputStream for " + propertyFilePath);
			prop.load(is);
			resolveSystemPropertyPlaceholders(prop);
		} 
		catch (Exception e) {
			throw new IllegalStateException("Failed to load configuration properties: " + propertyFilePath, e);
		} 
		finally {
			try {
				is.close();
			} catch (Exception e2) {
				// ignore
			}
		}
		return prop;
	}
1235061
private void loadAndCheckPropertyFile() {
        final String methodName = "loadAndCheckPropertyFile()";
        final File f = new File(htodPropertyFileName);
        final File swapDirPathFile = new File(swapDirPath);
        final CacheOnDisk cod = this;
        traceDebug(methodName, "cacheName=" + this.cacheName);
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                cod.propertyFileStatus = PROPERTY_FILE_OK;
                String[] files = swapDirPathFile.list();
                if (files != null && files.length > 0) {
                    for (int i = 0; i < files.length; i++) {
                        if (files[i].startsWith(HTOD_PREF + HTODDynacache.object_suffix)) {
                            cod.dataFiles++;
                        } else if (files[i].startsWith(HTOD_PREF + HTODDynacache.dependency_suffix)) {
                            cod.dependencyIdFiles++;
                        } else if (files[i].startsWith(HTOD_PREF + HTODDynacache.template_suffix)) {
                            cod.templateFiles++;
                        }
                    }
                } else {
                    traceDebug(methodName, "cacheName=" + cod.cacheName + " no disk cache files exist");
                    cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_NO_FILES);
                    return null;
                }
                if (f.exists()) {
                    FileInputStream fis = null;
                    try {
                        fis = new FileInputStream(f);
                        Properties htodProp = new Properties();
                        htodProp.load(fis);

                        String sTemp = (String) htodProp.get(DISABLE_DEPENDENCY_ID);
                        if (sTemp != null) {
                            cod.disableDependencyIdFromPropertyFile = (Boolean.valueOf(sTemp)).booleanValue();
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_DISABLE_DEPID);
                        }
                        sTemp = (String) htodProp.get(DISABLE_TEMPLATE_SUPPORT);
                        if (sTemp != null) {
                            cod.disableTemplatesSupprotFromPropertyFile = (Boolean.valueOf(sTemp)).booleanValue();
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_DISABLE_TEMPLATE);
                        }
                        sTemp = (String) htodProp.get(CACHE_SIZE_IN_BYTES);
                        long currentCacheSizeInBytes = 0;
                        if (sTemp != null) {
                            currentCacheSizeInBytes = Long.parseLong(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_CACHE_SIZE);
                            return null;
                        }
                        byte[] b = sTemp.getBytes("UTF-8");
                        int fieldCheck = 0;
                        for (int i = 0; i < b.length; i++) {
                            fieldCheck += (int) b[i];
                        }
                        fieldCheck = fieldCheck * 3;
                        sTemp = (String) htodProp.get(FIELD_CHECK);
                        if (sTemp != null) {
                            int expFieldCheck = Integer.parseInt(sTemp);
                            if (fieldCheck != expFieldCheck) {
                                cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FIELD_CHECK);
                                return null;
                            }
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FIELD_CHECK);
                            return null;
                        }

                        sTemp = (String) htodProp.get(DATA_GB);
                        int dataGB = 0;
                        if (sTemp != null) {
                            dataGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        sTemp = (String) htodProp.get(DEPID_GB);
                        int dependencyIdGB = 0;
                        if (sTemp != null) {
                            dependencyIdGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        sTemp = (String) htodProp.get(TEMPLATE_GB);
                        int templateGB = 0;
                        if (sTemp != null) {
                            templateGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        cod.currentCacheSizeInBytes = currentCacheSizeInBytes;
                        cod.dataGB = dataGB;
                        cod.dependencyIdGB = dependencyIdGB;
                        cod.templateGB = templateGB;

                        traceDebug(methodName, "cacheName=" + cod.cacheName + " htod.properties exist with status=" + cod.propertyFileStatus
                                               + " disableDependencyIdFromProperty=" + cod.disableDependencyIdFromPropertyFile
                                               + " disableTemplatesSupportFromProperty=" + cod.disableTemplatesSupprotFromPropertyFile + " cacheSizeInBytes="
                                               + cod.currentCacheSizeInBytes + " dataGB=" + cod.dataGB + " dependencyIdGB=" + cod.dependencyIdGB + " templateGB="
                                               + cod.templateGB);
                    } catch (Throwable t) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.cache.CacheOnDisk.loadAndCheckPropertyFile", "782", cod);
                        traceDebug(methodName, "cacheName=" + cod.cacheName + "\nException: " + ExceptionUtility.getStackTrace(t));
                        cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FILE_CORRUPT);
                    } finally {
                        try {
                            if (fis != null) {
                                fis.close();
                            }
                        } catch (Throwable t) {
                            com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.cache.CacheOnDisk.loadAndCheckPropertyFile", "791", cod);
                            traceDebug(methodName, "cacheName=" + cod.cacheName + "\nException: " + ExceptionUtility.getStackTrace(t));
                        }
                    }

                } else {
                    cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FILE_NOT_EXIST);
                    traceDebug(methodName, "cacheName=" + cod.cacheName + " htod.properties not exist" + " dependencyIdFiles="
                                           + cod.dependencyIdFiles + " templateFiles=" + cod.templateFiles);
                }
                return null;
            }
        });
    }
1042278
private String getMainPropertyFileName() throws StartupException {
        String configLoc = getConfigLocation();
        File file = new File(configLoc == null ? MDW_PROPERTIES_FILE_NAME : (configLoc+MDW_PROPERTIES_FILE_NAME));
        if (file.exists())
            return MDW_PROPERTIES_FILE_NAME;
        URL url = this.getClass().getClassLoader().getResource(MDW_PROPERTIES_FILE_NAME);
        if (url != null)
            return MDW_PROPERTIES_FILE_NAME;
        return null;
    }
1093284
private synchronized void loadProperties()
	{
		// If multiple threads are waiting to invoke this method only allow
		// the first one to do so. The rest should just return since the first
		// thread through took care of loading the properties.
		try
		{
			
			this.file = null;
			
			boolean alwaysReload = this.isAlwaysReload();

			boolean useFormatting = this.isUseFormatting();
	
			String filePath = getSystemPropertyFile();
			if (filePath != null && filePath.length() > 0)
			{
				// System.out.println("CONFIG: LOADING CONFIG properties from "+
				// file);
				this.file = Paths.get(filePath).toFile();
				FileInputStream fis = new FileInputStream(file);

				try
				{
					properties = new Properties();
					// Load the properties object from the properties file
					properties.load(fis);
					// System.out.println("CONFIG: FINISHED LOADING CONFIG
					// properties from "+
					// file);

					configSourceLocation = file.getAbsolutePath();
				}
				catch (Exception e)
				{
					e.printStackTrace();
					throw new ConfigException(e.toString());
				}
				finally
				{
					if (fis != null)
						fis.close(); // Always close the file, even on exception

				}

			}
			else
			{
				properties = new Properties();

				try
				{
					String bundleName = getBundleName();

					// try to get properties from resource bundle
					ResourceBundle rb = ResourceBundle.getBundle(bundleName);

					URL url = Config.class.getResource(bundleName + ".properties");

					if (url != null)
						configSourceLocation = url.toString();
					else
						configSourceLocation = bundleName + ".properties";

					Enumeration<?> keys = rb.getKeys();

					Object k = null;

					while (keys.hasMoreElements())
					{

						k = keys.nextElement();

						properties.put(k, rb.getString(k + ""));

					}
				} // end els load from resource bundle
				catch (MissingResourceException e)
				{
				}
			}//end else
			
			

			//Determine global settings
			String reloadBool = properties.getProperty(Config.class.getName() + ".alwaysReload");

			if (reloadBool == null || reloadBool.length() == 0)
			{

				// throw new ConfigException("System property
				// "+Constants.ALWAY_RELOAD_PROP+" is not set.");

				alwaysReload = false;

			}
			else
			{
				alwaysReload = Boolean.valueOf(reloadBool).booleanValue();
			}

			this.setAlwaysReload(alwaysReload);

			// Merge SystemProperteis
			mergeSystemProperties = Boolean
					.valueOf(properties.getProperty(Config.class.getName() + ".mergeSystemProperties", "true"))
					.booleanValue();

			if (mergeSystemProperties)
			{
				// add system properties
				properties.putAll((Properties)System.getProperties().clone());
			}

			// Envinronment SystemProperteis
			mergeEnvProperties = Boolean
					.valueOf(properties.getProperty(Config.class.getName() + ".mergeEnvProperties", "true"))
					.booleanValue();

			if (mergeEnvProperties)
			{
				// add env properties
				properties.putAll(System.getenv());
			}

			// process formatting
			String propName = Config.class.getName() + ".useFormatting";
			String useFormattingText = properties.getProperty(propName);

			// System.out.println("CONFIG:
			// "+propName+"="+useFormattingText);

			if (useFormattingText == null || useFormattingText.length() == 0)
			{

				// throw new ConfigException("System property
				// "+Constants.ALWAY_RELOAD_PROP+" is not set.");

				useFormatting = false;

			}
			else
			{
				useFormatting = Boolean.valueOf(useFormattingText).booleanValue();
			}

			if (useFormatting)
			{
				// System.out.println("CONFIG: FORMATTING MAP CONFIG
				// properties ");
				// format map (note this can be an expensive operation)

				Text.formatMap(properties);
				// System.out.println("CONFIG: FORMATTED MAP CONFIG
				// properties ");
			}

			propName = Config.class.getName() + ".setSystemProperties";
			setSystemProperties = Boolean.valueOf(properties.getProperty(propName, "false")).booleanValue();

			// Set system properties with values from configuration
			if (setSystemProperties)
			{
				Set<Object> keySet = properties.keySet();
				String key;
				String sysProp;
				for (Iterator<Object> i = keySet.iterator(); i.hasNext();)
				{
					key = (String) i.next();
					sysProp = System.getProperty(key);

					if (sysProp != null && sysProp.length() > 0)
						continue; // do not override values

					// set system property
					System.setProperty(key, properties.getProperty(key));
				}
			}
			
			
			
		}
		catch (ConfigException e)
		{
			throw e;
		}
		catch (FileNotFoundException e)
		{
			throw new ConfigException(e.getMessage(), e);
		}
		catch (Exception e)
		{
			throw new ConfigException(e.getMessage(), e);
		}
		
		try
		{
			this.registry.notify(this.getClass().getName(), this);
		}
		catch(Exception e)
		{
			Debugger.printWarn(e);
		}
	}
945249
private ProfilesConfigFile getProfilesConfigFile() {
        if (configFile == null) {
            synchronized (this) {
                if (configFile == null) {
                    try {
                        configFile = new ProfilesConfigFile(configFileLocationProvider.getLocation());
                    } catch (Exception e) {
                        throw new SdkClientException("Unable to load config file", e);
                    }
                }
            }
        }
        return configFile;
    }
844331
public SSLConfig[] loadPropertiesFile(final String propertiesURL, final boolean multiConfigURL) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "loadPropertiesFile", new Object[] { propertiesURL, Boolean.valueOf(multiConfigURL) });
        // sslConfigs is used when multiConfigURL=true;
        SSLConfig[] sslConfigs = null;

        if (propertiesURL == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(tc, "loadPropertiesFile (null props file)");
            return null;
        }
        try {
            sslConfigs = AccessController.doPrivileged(
                                                       new PrivilegedExceptionAction<SSLConfig[]>() {
                                                           @Override
                                                           public SSLConfig[] run() throws Exception {

                                                               InputStream istream = null;
                                                               BufferedReader in = null;

                                                               try {
                                                                   URL url = new URL(propertiesURL);
                                                                   istream = url.openStream();

                                                                   if (!multiConfigURL) {
                                                                       load(istream);
                                                                   } else {
                                                                       String s = null;
                                                                       in = new BufferedReader(new InputStreamReader(istream));
                                                                       List<SSLConfig> sslConfigList = new ArrayList<SSLConfig>();
                                                                       SSLConfig currentSSLConfig = new SSLConfig();
                                                                       currentSSLConfig.clear(); // clear the default properties

                                                                       while ((s = in.readLine()) != null) {
                                                                           if (!(s.trim().startsWith("#") || s.trim().length() <= 0)) {
                                                                               if (s.trim().startsWith("com.ibm.ssl.alias")) {
                                                                                   if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                                                                       Tr.debug(tc, "Saving SSL configuration...");
                                                                                   sslConfigList.add(currentSSLConfig);

                                                                                   // now start a new one.
                                                                                   currentSSLConfig = new SSLConfig();

                                                                                   int index = s.indexOf('=');
                                                                                   String name = s.substring(0, index);
                                                                                   String value = s.substring(index + 1);
                                                                                   if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                                                                       Tr.debug(tc, "Parsing SSL configuration with alias: " + value);
                                                                                   currentSSLConfig.setProperty(name, value, true);
                                                                               } else if (s.trim().indexOf('=') != -1) {
                                                                                   int index = s.indexOf('=');
                                                                                   String name = s.substring(0, index);
                                                                                   String value = null;
                                                                                   if (name != null)
                                                                                       value = System.getProperty(name);
                                                                                   if (value == null)
                                                                                       value = s.substring(index + 1);
                                                                                   if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                                                                       Tr.debug(tc, "Parsing SSL property: " + name + " = " + value);
                                                                                   currentSSLConfig.setProperty(name, value, true);
                                                                               }
                                                                           }
                                                                       }

                                                                       if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                                                           Tr.debug(tc, "Saving SSL configuration...");
                                                                       sslConfigList.add(currentSSLConfig);
                                                                       return sslConfigList.toArray(new SSLConfig[sslConfigList.size()]);
                                                                   }
                                                               } finally {
                                                                   if (null != in) {
                                                                       in.close();
                                                                   }
                                                                   if (istream != null)
                                                                       istream.close();
                                                               }
                                                               return null;
                                                           }
                                                       });

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(tc, "loadPropertiesFile");
            return sslConfigs;
        } catch (PrivilegedActionException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "loadPropertiesFile exception; " + e.getException());
            FFDCFilter.processException(e.getException(), getClass().getName(), "loadPropertiesFile", this);
            // TODO shouldn't this be throwing the error?
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "loadPropertiesFile");
        return null;
    }
308242
public static Properties loadProperties(final File file) {
        checkNotNull("file", file);
        checkValidFile(file);
        final Properties props = new Properties();
        try (final InputStream inStream = new FileInputStream(file)) {
            props.load(inStream);
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
        return props;
    }
1130630
public static void loadUserConfigProps() {
        userProps = new Properties();
        try {
            LOG.info("Loading the properties as proj root /src:");
            loadProps(userProps, mRunPropertiesFile);
        } catch (IOException e) {
            LOG.info("context", e);
            try {
                LOG.info("No prop file found, trying load the properties as proj root /src:");
                loadProps(userProps, iRunPropertiesFile);
            } catch (IOException e1) {
                LOG.error("IOException", e1);
            }
        }
    }
1295564
public Properties<JobXMLDescriptor> getOrCreateProperties()
   {
      Node node = model.getOrCreate("properties");
      Properties<JobXMLDescriptor> properties = new PropertiesImpl<JobXMLDescriptor>(this, "properties", model, node);
      return properties;
   }
786558
public static Properties loadProperties(String filename) throws ConfigurableException {
        log.info("Loading properties from " + filename);
        Properties properties = new Properties();
        FileInputStream input = null;
        try {
            input = new FileInputStream(filename);
            properties.load(input);
        } catch (IOException e) {
            final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
            log.error(errMessage, e);
            throw new ConfigurableException(errMessage, e);
        } finally {
            if (null != input) {
                try {
                    input.close();
                } catch (IOException e) {
                    final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
                    log.error(errMessage, e);
                }
            }
        }

        return properties;
    }
580697
public static PropertiesLoader getPropertiesLoader() {
		synchronized (PropertiesLoader.class) {
			final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
			PropertiesLoader loader = clMap.get(classLoader);
			if (loader == null) {
				try {
					loader = new PropertiesLoader(MASTER_PLUGIN_FILE, EXTRA_PLUGIN_FILE);
					clMap.put(classLoader, loader);
				} catch (final IOException ex) {
					throw new RuntimeException(ex);
				}
			}
			return loader;
		}
	}
270333
private void getPfile() throws ConfigException {
    if (pfile != null) {
      return;
    }

    String pfileUri = System.getProperty(pfilePname);

    if (pfileUri == null) {
      throw new ConfigException("No property with name \"" +
                                        pfilePname + "\"");
    }

    try {
/*
      URI uri;
      uri = new URI(pfileUri);

      String scheme = uri.getScheme();

      if ((scheme == null) || (scheme.equals("file"))) {
        */
      String path = pfileUri;
      File f = new File(path);
      if (!f.exists()) {
        throw new ConfigException("No configuration pfile at " + path);
      }

      if (!f.isFile()) {
        throw new ConfigException(path + " is not a file");
      }

      final Util.PropertiesPropertyFetcher ppf =
              new Util.PropertiesPropertyFetcher(System.getProperties());

        synchronized (pfileLock) {
          if (pfile != null) {
            // Someone beat us to it
            return;
          }

          pfile = new Properties();
          pfile.load(new FileReader(f));

          /* Do any property replacement on values */
          Set pfileNames = pfile.keySet();

          for (Object o: pfileNames) {
            pfile.put(o, Util.propertyReplace(pfile.getProperty((String)o),
                                              ppf));
          }

          configBase = pfile.getProperty(configBasePname);

          URI uri = new URI(configBase);
          String scheme = uri.getScheme();

          if ((scheme == null) || (scheme.equals("file"))) {
            configBase = uri.getPath();
            configBaseIsFile = true;
          } else if (httpSchemes.contains(scheme)) {
            configBaseIsHttp = true;
          } else {
            throw new ConfigException("Unsupported scheme in " + uri);
          }
        }

/*        return;
      }

      throw new ConfigException("Unsupported configuration pfile: " + uri);
      */
    } catch (ConfigException ce) {
      throw ce;
    } catch (Throwable t) {
      throw new ConfigException(t);
    }
  }
1199586
private Properties loadProperties() {

    props = new Properties();

    try {
      InputStream in = VersionProperties.class.getResourceAsStream("/META-INF/version.properties");
      props.load(in);
      in.close();
    }
    catch (Exception e) {
      // failed to load version properties. go with defaults
      props.put("vendor", "Mobicents");
      props.put("version", "UN.DEFINED");
    }

    return props;
  }
518238
private Map<String, String> getOptionsFromPropertiesFile(String newPropertiesFile) throws MojoExecutionException {

        this.getLog().debug("Using search path at: " + this.basedir.getAbsolutePath());
        this.resourceManager.addSearchPath(FileResourceLoader.ID, this.basedir.getAbsolutePath());

        Properties properties = new Properties();
        try {
            properties.load(this.resourceManager.getResourceAsInputStream(newPropertiesFile));
        } catch (ResourceNotFoundException e) {
            getLog().debug("Property file [" + newPropertiesFile + "] cannot be found", e);
            return new HashMap<>();
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot read config file [" + newPropertiesFile + "]", e);
        }

        final Map<String, String> map = new HashMap<>();
        for (final String name : properties.stringPropertyNames()) {
            map.put(name, properties.getProperty(name));
        }
        return map;
    }
558463
public static Properties getPropertiesFromPath(String fileName)
      throws PropertiesFileNotFoundException {

    Properties props = new Properties();
    FileInputStream fis;
    try {
      fis = new FileInputStream(fileName);
      props.load(fis);
      fis.close();
    } catch (Exception e) {
      throw new PropertiesFileNotFoundException(
          "ERROR LOADING PROPERTIES FROM PATH >" + fileName + "< !!!", e);
    }
    return props;
  }