Skip to content

Commit

Permalink
feat(GH-213): enhance getSystemProperty to also check environment var…
Browse files Browse the repository at this point in the history
…iables
  • Loading branch information
nicdard committed Feb 1, 2024
1 parent cf036b0 commit 3f7f81a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.adobe.aio.event.management.model.EventsOfInterestInputModel;
import com.adobe.aio.event.management.model.Registration;
import com.adobe.aio.event.management.model.RegistrationCreateModel;
import com.adobe.aio.event.management.model.RegistrationUpdateModel;
import com.adobe.aio.util.WorkspaceUtil;
import com.adobe.aio.workspace.Workspace;
import java.net.MalformedURLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
*/
package com.adobe.aio.event.management;

import com.adobe.aio.event.management.model.ProviderInputModel;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import com.adobe.aio.event.management.feign.ConflictException;
import com.adobe.aio.event.management.model.EventMetadata;
import com.adobe.aio.event.management.model.Provider;
import com.adobe.aio.util.WorkspaceUtil;
Expand Down
27 changes: 21 additions & 6 deletions ims/src/main/java/com/adobe/aio/util/WorkspaceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,30 @@ public static String getSystemProperty(String key) {
return getSystemProperty(key,DEFAULT_TEST_PROPERTIES);
}

/**
* Loads a property from either one of the following sources, probing it first to
* check that the required property is given, in order:
* <ol>
* <li>System Properties</li>
* <li>Environment Variables</li>
* <li>classpath:{@code propertyClassPath}</li>
* </ol>
*
* @param key the property name
* @param propertyClassPath the classpath of the property file
* @return the value of the property
*/
public static String getSystemProperty(String key, String propertyClassPath) {
String value = System.getProperty(key);
if (StringUtils.isBlank(value)) {
logger.debug("loading property `{}` from classpath `{}`", key, propertyClassPath);
value = FileUtil.readPropertiesFromClassPath(propertyClassPath).getProperty(key);
} else {
if (StringUtils.isNotBlank(System.getProperty(key))) {
logger.debug("loading property `{}`from JVM System Properties", key);
return System.getProperty(key);
} if (StringUtils.isNotBlank(System.getenv(key))) {
logger.debug("loading property `{}` from Environment Variables", key);
return System.getenv(key);
} else {
logger.debug("loading property `{}` from classpath `{}`", key, propertyClassPath);
return FileUtil.readPropertiesFromClassPath(propertyClassPath).getProperty(key);
}
return value;
}

private static Workspace.Builder getWorkspaceBuilder(String propertyFileClassPath) {
Expand Down

0 comments on commit 3f7f81a

Please sign in to comment.