Skip to content

Commit

Permalink
use default profile if nothing is set
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Wiedemann <wistefan@googlemail.com>
  • Loading branch information
wistefan committed May 2, 2024
1 parent 2092848 commit c737bb0
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -191,15 +192,17 @@ private void checkAnnotatedElementForFeatureAnnotations(AnnotatedElement annotat
private Set<UpdateFeature> getUpdateFeaturesSet(AnnotatedElement annotatedElement, State state) {
Set<UpdateFeature> ret = new HashSet<>();

Profile activeProfile = Optional.ofNullable(Profile.getInstance()).orElse(Profile.defaults());

ret.addAll(Arrays.stream(annotatedElement.getAnnotationsByType(EnableFeature.class))
.map(annotation -> {
if (state == State.BEFORE) {
return new UpdateFeature(annotation.value(), annotation.skipRestart(),FeatureAction.ENABLE, annotatedElement);
} else if (Profile.getInstance().getDisabledFeatures().contains(annotation.value())) {
return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.ENABLE, annotatedElement);
} else if (activeProfile.getDisabledFeatures().contains(annotation.value())) {
// only disable if it should be
return new UpdateFeature(annotation.value(), annotation.skipRestart(),FeatureAction.DISABLE_AND_RESET, annotatedElement);
return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE_AND_RESET, annotatedElement);
} else {
return new UpdateFeature(annotation.value(), annotation.skipRestart(),FeatureAction.ENABLE, annotatedElement);
return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.ENABLE, annotatedElement);
}
})
.collect(Collectors.toSet()));
Expand All @@ -208,7 +211,7 @@ private Set<UpdateFeature> getUpdateFeaturesSet(AnnotatedElement annotatedElemen
.map(annotation -> {
if (state == State.BEFORE) {
return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE, annotatedElement);
} else if (Profile.getInstance().getDisabledFeatures().contains(annotation.value())) {
} else if (activeProfile.getDisabledFeatures().contains(annotation.value())) {
// we do not want to enable features that should be disabled by default
return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE_AND_RESET, annotatedElement);
} else {
Expand Down

0 comments on commit c737bb0

Please sign in to comment.