Skip to content

Commit

Permalink
chargement fichier properties
Browse files Browse the repository at this point in the history
  • Loading branch information
khergalant committed Sep 5, 2024
1 parent 4f1bce2 commit c3fc150
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/main/java/fr/univlorraine/ecandidat/utils/MethodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1371,12 +1371,33 @@ public static Boolean checkFileExists(final String path) {
*/
public static Properties loadPropertieFile() {
final Properties properties = new Properties();
/* On essaye de lire dans les property du system le fichier de properties */
try {
final String systemFilePropertiesPath = System.getProperty(ConstanteUtils.PROPERTY_FILE_PATH);
System.out.println("loadPropertieFile " + systemFilePropertiesPath);
if (StringUtils.isNotBlank(systemFilePropertiesPath)) {
final File fileConfig = new File(systemFilePropertiesPath);
System.out.println("loadPropertieFile " + fileConfig);
readConfigFile(systemFilePropertiesPath, properties);
if (!properties.isEmpty()) {
return properties;
}
} catch (final Exception e) {
}
/* On essaye de lire dans les variables d'env le fichier de properties */
try {
final String envFilePropertiesPath = System.getenv(ConstanteUtils.PROPERTY_FILE_PATH);
readConfigFile(envFilePropertiesPath, properties);
} catch (final Exception e) {
}
return properties;
}

/**
* Lit un fichier de config
* @param path
* @param properties
*/
private static void readConfigFile(final String path, final Properties properties) {
try {
if (StringUtils.isNotBlank(path)) {
final File fileConfig = new File(path);
if (fileConfig.exists() && fileConfig.isFile()) {
try (FileInputStream file = new FileInputStream(fileConfig)) {
properties.load(file);
Expand All @@ -1385,6 +1406,6 @@ public static Properties loadPropertieFile() {
}
} catch (final Exception e) {
}
return properties;

}
}

0 comments on commit c3fc150

Please sign in to comment.