Skip to content

Commit

Permalink
Separating environment and active profiles terms. (#3)
Browse files Browse the repository at this point in the history
* Separating environment and active profiles terms.
  • Loading branch information
onukristo authored Apr 3, 2024
1 parent d9a8a54 commit acf21fe
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 174 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - 2024-04-02

### Changed

* `wise.environments.active` property was renamed to `wise.profiles.active`.

* "Environment" and "active profile" terms were separated in the code.

* Now defaulting to 'WISE' active profile.

## [0.0.2] - 2024-03-27

Initial version.
### Added

* Initial version.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.0.2
version=0.0.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.wise.common.environment;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CachingWiseActiveProfilesProvider implements WiseActiveProfilesProvider {

private final List<WiseProfile> activeProfiles;

private Map<WiseProfile, Boolean> isActiveCache = new ConcurrentHashMap<>();

public CachingWiseActiveProfilesProvider(List<WiseProfile> activeProfiles) {
this.activeProfiles = activeProfiles;
}

@Override
public List<WiseProfile> getActiveProfiles() {
return activeProfiles;
}

@Override
public boolean isProfileActive(WiseProfile profile) {
return isActiveCache.computeIfAbsent(profile, k -> {
var activeProfiles = getActiveProfiles();

for (var activeProfile : activeProfiles) {
while (activeProfile != null) {
if (activeProfile == profile) {
return true;
}
activeProfile = activeProfile.parent();
}
}

return false;
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class DefaultPropertiesSetterDsl implements PropertiesSetterDsl {

private String source;
private WiseEnvironment wiseEnvironment;
private WiseProfile wiseProfile;

private String keyPrefix;

Expand All @@ -20,8 +20,8 @@ public Dsl0 source(String source) {
class Dsl0Impl implements Dsl0 {

@Override
public Dsl2 environment(WiseEnvironment wiseEnvironment) {
DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment;
public Dsl2 profile(WiseProfile profile) {
DefaultPropertiesSetterDsl.this.wiseProfile = profile;
return dsl2;
}

Expand All @@ -35,17 +35,17 @@ public Dsl1 keyPrefix(String keyPrefix) {
class Dsl1Impl implements Dsl1 {

@Override
public Dsl2 environment(WiseEnvironment wiseEnvironment) {
DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment;
public Dsl2 profile(WiseProfile profile) {
DefaultPropertiesSetterDsl.this.wiseProfile = profile;
return dsl2;
}
}

class Dsl2Impl implements Dsl2 {

@Override
public Dsl2 environment(WiseEnvironment wiseEnvironment) {
DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment;
public Dsl2 profile(WiseProfile profile) {
DefaultPropertiesSetterDsl.this.wiseProfile = profile;
return this;
}

Expand All @@ -57,7 +57,7 @@ public Dsl2 keyPrefix(String keyPrefix) {

@Override
public Dsl2 set(String name, Object value) {
WiseEnvironment.setDefaultProperty(source, wiseEnvironment, keyPrefix == null ? name : keyPrefix + name, value);
WiseEnvironment.setDefaultProperty(source, wiseProfile, keyPrefix == null ? name : keyPrefix + name, value);
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public DefaultWiseEnvironmentDetector(String value) {
}

@Override
public List<WiseEnvironment> detect() {
final var result = new ArrayList<WiseEnvironment>();
public List<WiseProfile> detectActiveProfiles() {
final var result = new ArrayList<WiseProfile>();
final var envs = StringUtils.split(value, ",");
if (envs != null) {
for (var env : envs) {
final var trimmedEnv = StringUtils.trim(env);
result.add(WiseEnvironment.getByName(trimmedEnv));
result.add(WiseProfile.getByName(trimmedEnv));
}
}

if (result.isEmpty()) {
if (isExecutedByIntegrationTest()) {
result.add(WiseEnvironment.INTEGRATION_TEST);
result.add(WiseProfile.INTEGRATION_TEST);
} else if (isExecutedByTest()) {
result.add(WiseEnvironment.UNIT_TEST);
result.add(WiseProfile.UNIT_TEST);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ public interface PropertiesSetterDsl {

interface Dsl0 {

Dsl2 environment(WiseEnvironment environment);
Dsl2 profile(WiseProfile profile);

Dsl1 keyPrefix(String prefix);
}

interface Dsl1 {

Dsl2 environment(WiseEnvironment wiseEnvironment);
Dsl2 profile(WiseProfile profile);

}

interface Dsl2 {

Dsl2 environment(WiseEnvironment environment);
Dsl2 profile(WiseProfile profile);

Dsl2 keyPrefix(String keyPrefix);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ public class PropertyContainer {

private Object value;

private WiseEnvironmentOrigin origin;
private WiseEnvironmentPropertyOrigin origin;

public PropertyContainer(String source, WiseEnvironment environment, Object value) {
public PropertyContainer(String source, WiseProfile profile, Object value) {
Assert.notNull(value, "Value must not be null");
this.origin = new WiseEnvironmentOrigin(source, environment);
this.origin = new WiseEnvironmentPropertyOrigin(source, profile);
this.value = value;
}

@Data
public static class WiseEnvironmentOrigin implements Origin {
public static class WiseEnvironmentPropertyOrigin implements Origin {

private String source;

private WiseEnvironment environment;
private WiseProfile profile;

public WiseEnvironmentOrigin(String source, WiseEnvironment environment) {
public WiseEnvironmentPropertyOrigin(String source, WiseProfile profile) {
Assert.notNull(source, "Source must not be null");
Assert.notNull(environment, "Environment must not be null");
Assert.notNull(profile, "Profile must not be null");
this.source = source;
this.environment = environment;
this.profile = profile;
}

public String toString() {
return "Wise environment: '" + environment + "', source: '" + source + "'";
return "Wise profile: '" + profile + "', source: '" + source + "'";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wise.common.environment;

import java.util.List;

public interface WiseActiveProfilesProvider {

List<WiseProfile> getActiveProfiles();

boolean isProfileActive(WiseProfile profile);
}
Loading

0 comments on commit acf21fe

Please sign in to comment.