From cad056ab89076f5e4ffd32c6063c9914af8d54d4 Mon Sep 17 00:00:00 2001 From: Adrien LAUER Date: Fri, 12 Jan 2018 12:25:12 +0100 Subject: [PATCH] Fixes #239: @CliCommand inheritance bug Also disable config watch by default --- CHANGELOG.md | 5 +++-- .../org/seedstack/seed/cli/AbstractCliHandler.java | 11 +++++++++++ .../seed/cli/SampleCommandLineHandler.java | 2 +- .../seed/core/internal/cli/CliTypeListener.java | 6 +++--- .../internal/configuration/PrioritizedProvider.java | 13 ++++++++++++- .../main/java/org/seedstack/seed/ConfigConfig.java | 2 +- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 cli/src/it/java/org/seedstack/seed/cli/AbstractCliHandler.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 342a504f7..88d7b888a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cli/src/it/java/org/seedstack/seed/cli/AbstractCliHandler.java b/cli/src/it/java/org/seedstack/seed/cli/AbstractCliHandler.java new file mode 100644 index 000000000..09ee07a4d --- /dev/null +++ b/cli/src/it/java/org/seedstack/seed/cli/AbstractCliHandler.java @@ -0,0 +1,11 @@ +/* + * Copyright © 2013-2017, The SeedStack authors + * + * 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 { +} diff --git a/cli/src/it/java/org/seedstack/seed/cli/SampleCommandLineHandler.java b/cli/src/it/java/org/seedstack/seed/cli/SampleCommandLineHandler.java index 12e56ee40..676543acd 100644 --- a/cli/src/it/java/org/seedstack/seed/cli/SampleCommandLineHandler.java +++ b/cli/src/it/java/org/seedstack/seed/cli/SampleCommandLineHandler.java @@ -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") diff --git a/core/src/main/java/org/seedstack/seed/core/internal/cli/CliTypeListener.java b/core/src/main/java/org/seedstack/seed/core/internal/cli/CliTypeListener.java index 888e810d1..41cde8535 100644 --- a/core/src/main/java/org/seedstack/seed/core/internal/cli/CliTypeListener.java +++ b/core/src/main/java/org/seedstack/seed/core/internal/cli/CliTypeListener.java @@ -40,9 +40,9 @@ public void hear(TypeLiteral typeLiteral, TypeEncounter 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); } diff --git a/core/src/main/java/org/seedstack/seed/core/internal/configuration/PrioritizedProvider.java b/core/src/main/java/org/seedstack/seed/core/internal/configuration/PrioritizedProvider.java index 62eeb1a49..bda44c112 100644 --- a/core/src/main/java/org/seedstack/seed/core/internal/configuration/PrioritizedProvider.java +++ b/core/src/main/java/org/seedstack/seed/core/internal/configuration/PrioritizedProvider.java @@ -19,8 +19,11 @@ 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 providers = new CopyOnWriteArrayList<>(); private final AtomicBoolean dirty = new AtomicBoolean(true); @@ -28,11 +31,19 @@ public class PrioritizedProvider implements ConfigurationProvider { 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; } diff --git a/specs/src/main/java/org/seedstack/seed/ConfigConfig.java b/specs/src/main/java/org/seedstack/seed/ConfigConfig.java index 7a1239580..56d1cfda2 100644 --- a/specs/src/main/java/org/seedstack/seed/ConfigConfig.java +++ b/specs/src/main/java/org/seedstack/seed/ConfigConfig.java @@ -12,7 +12,7 @@ @Config("config") public class ConfigConfig { - private boolean watch = true; + private boolean watch = false; public boolean isWatch() { return watch;