Skip to content

Commit

Permalink
Fixes #239: @CliCommand inheritance bug
Browse files Browse the repository at this point in the history
Also disable config watch by default
  • Loading branch information
adrienlauer committed Jan 12, 2018
1 parent a94f431 commit 4a42527
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Version 3.4.2 (2017-12-15)
# Version 3.4.2 (2018-01-12)

* [new] Add configuration watching for local files and automatic refresh after change.
* [new] Add configuration watching for local files and automatic refresh after change (enable by setting config property `config.watch` to true).
* [fix] Fix `config` tool NullPointerException when dumping a config tree with generics and no null value.
* [fix] Fix exception when a `@CliCommand`-annotated class inherits from a base class.

# Version 3.4.1 (2017-11-29)

Expand Down
11 changes: 11 additions & 0 deletions cli/src/it/java/org/seedstack/seed/cli/AbstractCliHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2013-2017, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.cli;

class AbstractCliHandler {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Map;

@CliCommand("test")
public class SampleCommandLineHandler implements CommandLineHandler {
public class SampleCommandLineHandler extends AbstractCliHandler implements CommandLineHandler {
static boolean called = false;

@CliOption(name = "a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter)
for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
if (cliCommand == null) {
cliCommand = c.getAnnotation(CliCommand.class);
} else {
throw SeedException.createNew(CliErrorCode.CONFLICTING_COMMAND_ANNOTATIONS).put("class",
c.getCanonicalName());
} else if (c.isAnnotationPresent(CliCommand.class)) {
throw SeedException.createNew(CliErrorCode.CONFLICTING_COMMAND_ANNOTATIONS)
.put("class", c.getCanonicalName());
}
Arrays.stream(c.getDeclaredFields()).filter(this::isCandidate).forEach(fields::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,31 @@
import org.seedstack.coffig.spi.ConfigurationComponent;
import org.seedstack.coffig.spi.ConfigurationProvider;
import org.seedstack.coffig.spi.ConfigurationWatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PrioritizedProvider implements ConfigurationProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(PrioritizedProvider.class);
private final List<PrioritizedConfigurationProvider> providers = new CopyOnWriteArrayList<>();
private final AtomicBoolean dirty = new AtomicBoolean(true);

@Override
public MapNode provide() {
MapNode mapNode = providers.stream()
.sorted(Comparator.comparingInt(o -> o.priority))
.map(PrioritizedConfigurationProvider::getConfigurationProvider)
.map(prioritizedConfigurationProvider -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fetching configuration from provider {} at priority {}",
prioritizedConfigurationProvider.getConfigurationProvider().name(),
prioritizedConfigurationProvider.getPriority());
}
return prioritizedConfigurationProvider.getConfigurationProvider();
})
.map(ConfigurationProvider::provide)
.reduce((conf1, conf2) -> (MapNode) conf1.merge(conf2))
.orElse(new MapNode());
dirty.set(false);
LOGGER.debug("Configuration fetching complete");
return mapNode;
}

Expand Down
2 changes: 1 addition & 1 deletion specs/src/main/java/org/seedstack/seed/ConfigConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Config("config")
public class ConfigConfig {
private boolean watch = true;
private boolean watch = false;

public boolean isWatch() {
return watch;
Expand Down

0 comments on commit 4a42527

Please sign in to comment.