This is an automated email from the ASF dual-hosted git repository. anatole pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-extensions.git
commit 6c9a9ff27a859d6f8d528616f229ce957506d31e Author: Anatole Tresch <[email protected]> AuthorDate: Sun Feb 24 19:59:36 2019 +0100 Fixed some checkstyle issues. --- .../tamaya/collections/CollectionConverter.java | 3 + .../org/apache/tamaya/etcd/EtcdBackendConfig.java | 36 ++--- .../org/apache/tamaya/json/JSONPropertySource.java | 1 - .../java/org/apache/tamaya/yaml/YAMLFormat.java | 21 ++- .../apache/tamaya/cdi/ConfigurationProducer.java | 15 ++- .../tamaya/cdi/TamayaCDIInjectionExtension.java | 20 ++- .../inject/internal/DefaultDynamicValue.java | 22 +-- .../tamaya/microprofile/MicroprofileConfig.java | 26 ++-- .../microprofile/MicroprofileConfigBuilder.java | 73 +++++----- .../MicroprofileConfigProviderResolver.java | 12 +- .../tamaya/microprofile/MicroprofileConverter.java | 1 + .../tamaya/microprofile/TamayaConfiguration.java | 4 +- .../microprofile/TamayaPropertyConverter.java | 1 + .../microprofile/cdi/BridgingConfigBean.java | 4 +- .../tamaya/microprofile/cdi/ConfiguredType.java | 11 +- .../cdi/MicroprofileConfigurationProducer.java | 42 +++--- .../microprofile/converter/ProviderConverter.java | 36 +++-- .../MutablePropertiesPropertySource.java | 31 +++-- .../MutableXmlPropertiesPropertySource.java | 34 +++-- .../java/org/apache/tamaya/osgi/Activator.java | 5 +- .../main/java/org/apache/tamaya/osgi/Backups.java | 50 ++++--- .../java/org/apache/tamaya/osgi/ConfigChanger.java | 20 +-- .../java/org/apache/tamaya/osgi/ConfigHistory.java | 112 ++++++++++------ .../org/apache/tamaya/osgi/TamayaConfigPlugin.java | 149 +++++++++++---------- .../apache/tamaya/gogo/shell/BackupCommands.java | 3 + .../apache/tamaya/gogo/shell/ConfigCommands.java | 3 + .../apache/tamaya/gogo/shell/HistoryCommands.java | 3 + .../apache/tamaya/gogo/shell/SettingsCommands.java | 3 + .../apache/tamaya/osgi/injection/Activator.java | 9 +- .../karaf/shell/ApplyTamayaConfigCommand.java | 3 + .../tamaya/karaf/shell/BackupCreateCommand.java | 3 + .../tamaya/karaf/shell/BackupDeleteCommand.java | 3 + .../tamaya/karaf/shell/BackupListCommand.java | 3 + .../tamaya/karaf/shell/BackupRestoreCommand.java | 3 + .../tamaya/karaf/shell/DefaultEnableCommand.java | 6 + .../tamaya/karaf/shell/DefaultEnabledCommand.java | 3 + .../tamaya/karaf/shell/GetPolicyCommand.java | 3 + .../karaf/shell/HistoryDeleteAllCommand.java | 3 + .../tamaya/karaf/shell/HistoryDeleteCommand.java | 7 +- .../tamaya/karaf/shell/HistoryGetCommand.java | 12 +- .../tamaya/karaf/shell/HistoryMaxsizeCommand.java | 6 +- .../karaf/shell/HistoryMaxsizeSetCommand.java | 3 + .../org/apache/tamaya/karaf/shell/InfoCommand.java | 3 + .../tamaya/karaf/shell/OSGIConfigCommand.java | 3 + .../tamaya/karaf/shell/PolicyGetCommand.java | 3 + .../tamaya/karaf/shell/PolicySetCommand.java | 6 + .../karaf/shell/PropagateUpdatesCommand.java | 3 + .../karaf/shell/PropagateUpdatesSetCommand.java | 3 + .../tamaya/karaf/shell/PropertyGetCommand.java | 3 + .../tamaya/karaf/shell/PropertySourceCommand.java | 3 + .../tamaya/karaf/shell/PropertySourcesCommand.java | 3 + .../tamaya/karaf/shell/TamayaConfigCommand.java | 3 + .../org/apache/tamaya/osgi/updater/Activator.java | 4 +- .../apache/tamaya/osgi/updater/EventListener.java | 3 +- 54 files changed, 528 insertions(+), 320 deletions(-) diff --git a/modules/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java b/modules/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java index 577cece..a0180f6 100644 --- a/modules/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java +++ b/modules/collections/src/main/java/org/apache/tamaya/collections/CollectionConverter.java @@ -36,6 +36,9 @@ public final class CollectionConverter implements PropertyConverter<Collection> private static final Logger LOG = Logger.getLogger(CollectionConverter.class.getName()); public static final String VALUE_MAPPING = "collection-mapping"; + /** + * Type of collection mappings supported. + */ private enum MappingType{ /** The list values are identiified by parsing the node value(s) into items. * Hereby only the items of the most significant config entry are considered. */ diff --git a/modules/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java b/modules/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java index 95561c9..696f187 100644 --- a/modules/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java +++ b/modules/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java @@ -29,24 +29,26 @@ import java.util.logging.Logger; */ final class EtcdBackendConfig { - private static final Logger LOG = Logger.getLogger(EtcdBackendConfig.class.getName()); - private static final String TAMAYA_ETCD_SERVER_URLS = "tamaya.etcd.server"; - private static final String TAMAYA_ETCD_TIMEOUT = "tamaya.etcd.timeout"; + private static final Logger LOG = Logger.getLogger(EtcdBackendConfig.class.getName()); + private static final String TAMAYA_ETCD_SERVER_URLS = "tamaya.etcd.server"; + private static final String TAMAYA_ETCD_TIMEOUT = "tamaya.etcd.timeout"; private static final String TAMAYA_ETCD_DIRECTORY = "tamaya.etcd.directory"; - private EtcdBackendConfig(){} + private EtcdBackendConfig() { + } /** * Get the default etcd directory selector, default {@code ""}. + * * @return the default etcd directory selector, never null. */ - public static String getEtcdDirectory(){ + public static String getEtcdDirectory() { String val = System.getProperty(TAMAYA_ETCD_DIRECTORY); - if(val == null){ + if (val == null) { val = System.getenv(TAMAYA_ETCD_DIRECTORY); } - if(val!=null){ + if (val != null) { return val; } return ""; @@ -55,14 +57,15 @@ final class EtcdBackendConfig { /** * Get the etcd connection timeout from system/enfironment property {@code tamaya.etcd.timeout (=seconds)} * (default 2 seconds). + * * @return the etcd connection timeout. */ - public static long getEtcdTimeout(){ + public static long getEtcdTimeout() { String val = System.getProperty(TAMAYA_ETCD_TIMEOUT); - if(val == null){ + if (val == null) { val = System.getenv(TAMAYA_ETCD_TIMEOUT); } - if(val!=null){ + if (val != null) { return TimeUnit.MILLISECONDS.convert(Integer.parseInt(val), TimeUnit.SECONDS); } return 2000L; @@ -70,22 +73,23 @@ final class EtcdBackendConfig { /** * Evaluate the etcd target servers fomr system/environment property {@code tamaya.etcd.server}. + * * @return the servers configured, or {@code http://127.0.0.1:4001} (default). */ - public static List<String> getServers(){ + public static List<String> getServers() { String serverURLs = System.getProperty(TAMAYA_ETCD_SERVER_URLS); - if(serverURLs==null){ + if (serverURLs == null) { serverURLs = System.getenv(TAMAYA_ETCD_SERVER_URLS); } - if(serverURLs==null){ + if (serverURLs == null) { serverURLs = "http://127.0.0.1:4001"; } List<String> servers = new ArrayList<>(); - for(String url:serverURLs.split("\\,")) { - try{ + for (String url : serverURLs.split("\\,")) { + try { servers.add(url.trim()); LOG.info("Using etcd endoint: " + url); - } catch(Exception e){ + } catch (Exception e) { LOG.log(Level.SEVERE, "Error initializing etcd accessor for URL: " + url, e); } } diff --git a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java index bc982ef..39f2b95 100644 --- a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java +++ b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java @@ -25,7 +25,6 @@ import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; diff --git a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java index f7d8102..c1b6038 100644 --- a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java +++ b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java @@ -61,35 +61,34 @@ public class YAMLFormat implements ConfigurationFormat { @Override public ConfigurationData readConfiguration(String resource, InputStream inputStream) { - try{ + try { Yaml yaml = new Yaml(); PropertyValue data; Object config = yaml.load(inputStream); - if(config instanceof Map){ + if (config instanceof Map) { data = PropertyValue.createObject(""); data.setMeta("resource", resource); data.setMeta("format", "yaml"); - addObject((Map)config, (ObjectValue)data); - }else if(config instanceof List){ + addObject((Map) config, (ObjectValue) data); + } else if (config instanceof List) { data = PropertyValue.createList(""); data.setMeta("resource", resource); data.setMeta("format", "yaml"); - addList((List)config, (ListValue)data); - }else { + addList((List) config, (ListValue) data); + } else { throw new ConfigException("Unknown YamlType encountered: " + config.getClass().getName()); } - if(LOG.isLoggable(Level.FINEST)){ + if (LOG.isLoggable(Level.FINEST)) { LOG.finest(String.format("Read data from %s : %s", resource, data.asString())); } return new ConfigurationData(resource, this, data); - } - catch (Throwable t) { + } catch (Throwable t) { throw new ConfigException(format("Failed to read properties from %s", resource), t); } } - private void addObject(Map<String,Object> values, ObjectValue dataNode){ + private void addObject(Map<String, Object> values, ObjectValue dataNode) { values.forEach((key, value) -> { if (value instanceof List) { ListValue list = dataNode.setList(key); @@ -115,7 +114,7 @@ public class YAMLFormat implements ConfigurationFormat { } else if (val instanceof Map) { ObjectValue ov = dataNode.addObject(); addObject((Map) val, ov); - } else{ + } else { dataNode.setValue(String.valueOf(val)); } }); diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java index a5b5cf8..986b7a4 100644 --- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java +++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java @@ -16,9 +16,18 @@ */ package org.apache.tamaya.cdi; -import org.apache.tamaya.*; -import org.apache.tamaya.inject.api.*; -import org.apache.tamaya.spi.*; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.inject.api.Config; +import org.apache.tamaya.inject.api.ConfigSection; +import org.apache.tamaya.inject.api.DynamicValue; +import org.apache.tamaya.inject.api.WithConfigOperator; +import org.apache.tamaya.inject.api.WithPropertyConverter; +import org.apache.tamaya.spi.ConfigurationBuilder; +import org.apache.tamaya.spi.ConfigurationContext; +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Instance; diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java index fbbd3c9..d1b2430 100644 --- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java +++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java @@ -28,11 +28,25 @@ import org.apache.tamaya.spi.PropertyConverter; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.event.Observes; import javax.enterprise.inject.Instance; -import javax.enterprise.inject.spi.*; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.ProcessBean; +import javax.enterprise.inject.spi.ProcessProducerMethod; import javax.inject.Provider; import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.UnaryOperator; import java.util.logging.Logger; diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java index f9a16eb..450ed4d 100644 --- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java +++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java @@ -84,7 +84,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { this.propertyConverter = propertyConverter; this.loadPolicy = Objects.requireNonNull(loadPolicy); setUpdatePolicy(updatePolicy); - if(loadPolicy == LoadPolicy.INITIAL){ + if (loadPolicy == LoadPolicy.INITIAL) { this.value = evaluateValue(); } } @@ -101,8 +101,8 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { return of(owner, annotatedField, configuration, LoadPolicy.ALWAYS, updatePolicy); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static DynamicValue<?> of(Object owner, Field annotatedField, Configuration configuration, + @SuppressWarnings({"rawtypes", "unchecked"}) + public static DynamicValue<?> of(Object owner, Field annotatedField, Configuration configuration, LoadPolicy loadPolicy, UpdatePolicy updatePolicy) { // Check for adapter/filter Type targetType = annotatedField.getGenericType(); @@ -148,7 +148,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { } @SuppressWarnings("unchecked") - public static DynamicValue<?> of(Object owner, Method method, Configuration configuration, + public static DynamicValue<?> of(Object owner, Method method, Configuration configuration, LoadPolicy loadPolicy, UpdatePolicy updatePolicy) { // Check for adapter/filter Type targetType = method.getGenericReturnType(); @@ -181,7 +181,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { loadPolicy, updatePolicy); } - protected PropertyConverter getCustomConverter(){ + protected PropertyConverter getCustomConverter() { return this.propertyConverter; } @@ -195,13 +195,13 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { */ public T get() { T newLocalValue; - if(loadPolicy!=LoadPolicy.INITIAL) { + if (loadPolicy != LoadPolicy.INITIAL) { newLocalValue = evaluateValue(); if (this.value == null) { this.value = newLocalValue; } - if(!Objects.equals(this.value, newLocalValue)){ - switch (getUpdatePolicy()){ + if (!Objects.equals(this.value, newLocalValue)) { + switch (getUpdatePolicy()) { case IMMEDEATE: case IMMEDIATE: commit(); @@ -234,7 +234,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { * {@link UpdatePolicy} in place. */ public boolean updateValue() { - if(this.value==null && this.newValue==null){ + if (this.value == null && this.newValue == null) { this.value = evaluateValue(); return false; } @@ -290,8 +290,8 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> { * @throws IOException */ @SuppressWarnings("unchecked") - private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { - setUpdatePolicy((UpdatePolicy)ois.readObject()); + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { + setUpdatePolicy((UpdatePolicy) ois.readObject()); if (isPresent()) { this.value = (T) ois.readObject(); } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java index c38d38f..a351a7d 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java @@ -35,14 +35,14 @@ import java.util.*; */ public class MicroprofileConfig implements Config, Serializable { - private static final long serialVersionUID = -2811635734899431816L; - private Configuration delegate; + private static final long serialVersionUID = -2811635734899431816L; + private Configuration delegate; - public MicroprofileConfig(Configuration delegate){ + public MicroprofileConfig(Configuration delegate) { this.delegate = Objects.requireNonNull(delegate); } - public Configuration getConfiguration(){ + public Configuration getConfiguration() { return this.delegate; } @@ -50,14 +50,14 @@ public class MicroprofileConfig implements Config, Serializable { @Override public <T> T getValue(String propertyName, Class<T> propertyType) { T value = null; - try{ + try { value = delegate.get(propertyName, propertyType); - }catch(ConfigException e){ - if(e.toString().contains("Unparseable")){ + } catch (ConfigException e) { + if (e.toString().contains("Unparseable")) { throw new IllegalArgumentException("Invalid type: " + propertyType.getName()); } } - if(value == null){ + if (value == null) { throw new NoSuchElementException("No such config property: " + propertyName); } return value; @@ -85,16 +85,16 @@ public class MicroprofileConfig implements Config, Serializable { '}'; } - private void writeObject(ObjectOutputStream out) throws IOException{ - if(!(this.delegate instanceof Serializable)){ + private void writeObject(ObjectOutputStream out) throws IOException { + if (!(this.delegate instanceof Serializable)) { out.writeObject(this.delegate.getSnapshot()); - }else { + } else { out.writeObject(this.delegate); } } - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{ - this.delegate = (Configuration)in.readObject(); + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + this.delegate = (Configuration) in.readObject(); } } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java index 816878c..419829b 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java @@ -37,15 +37,16 @@ import org.eclipse.microprofile.config.spi.Converter; * Created by atsticks on 23.03.17. */ final class MicroprofileConfigBuilder implements ConfigBuilder { - - private ConfigurationBuilder configurationBuilder; - MicroprofileConfigBuilder(ConfigurationBuilder configurationBuilder){ + private ConfigurationBuilder configurationBuilder; + + MicroprofileConfigBuilder(ConfigurationBuilder configurationBuilder) { this.configurationBuilder = Objects.requireNonNull(configurationBuilder); configurationBuilder.addDefaultPropertyConverters(); } + public ConfigurationBuilder getConfigurationBuilder() { - return configurationBuilder; + return configurationBuilder; } /** @@ -61,31 +62,32 @@ final class MicroprofileConfigBuilder implements ConfigBuilder { */ @Override public ConfigBuilder addDefaultSources() { - - configurationBuilder.addPropertySources( + + configurationBuilder.addPropertySources( new SystemPropertySource(400), // new EnvironmentPropertySource(300), // new MicroprofileDefaultProperties() // - ); - configurationBuilder.sortPropertySources(PropertySourceComparator.getInstance()); + ); + configurationBuilder.sortPropertySources(PropertySourceComparator.getInstance()); return this; } /** * Add ConfigSources registered using the ServiceLoader. + * * @return the ConfigBuilder with the added configuration sources */ @Override public ConfigBuilder addDiscoveredSources() { - for(ConfigSource configSource: ServiceContextManager.getServiceContext( - configurationBuilder.getClassLoader()).getServices(ConfigSource.class)){ - configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(configSource)); + for (ConfigSource configSource : ServiceContextManager.getServiceContext( + configurationBuilder.getClassLoader()).getServices(ConfigSource.class)) { + configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(configSource)); } - for(ConfigSourceProvider configSourceProvider: ServiceContextManager.getServiceContext( + for (ConfigSourceProvider configSourceProvider : ServiceContextManager.getServiceContext( configurationBuilder.getClassLoader() - ).getServices(ConfigSourceProvider.class)){ - configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySources(configSourceProvider.getConfigSources( + ).getServices(ConfigSourceProvider.class)) { + configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySources(configSourceProvider.getConfigSources( Thread.currentThread().getContextClassLoader() ))); } @@ -95,17 +97,18 @@ final class MicroprofileConfigBuilder implements ConfigBuilder { /** * Add Converters registered using the ServiceLoader. + * * @return the ConfigBuilder with the added configuration converters */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override public ConfigBuilder addDiscoveredConverters() { - for(Converter<?> converter: ServiceContextManager.getServiceContext( + for (Converter<?> converter : ServiceContextManager.getServiceContext( configurationBuilder.getClassLoader() - ).getServices(Converter.class)){ - TypeLiteral targetType = TypeLiteral.of( - TypeLiteral.getGenericInterfaceTypeParameters(converter.getClass(),Converter.class)[0]); - + ).getServices(Converter.class)) { + TypeLiteral targetType = TypeLiteral.of( + TypeLiteral.getGenericInterfaceTypeParameters(converter.getClass(), Converter.class)[0]); + configurationBuilder.addPropertyConverters(targetType, MicroprofileAdapter.toPropertyConverter(converter)); } @@ -120,19 +123,19 @@ final class MicroprofileConfigBuilder implements ConfigBuilder { @Override public ConfigBuilder withSources(ConfigSource... sources) { - for(ConfigSource source:sources){ + for (ConfigSource source : sources) { configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(source)); } return this; } - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override public ConfigBuilder withConverters(Converter<?>... converters) { - for(Converter<?> converter:converters){ + for (Converter<?> converter : converters) { TypeLiteral lit = TypeLiteral.of(converter.getClass()); TypeLiteral target = TypeLiteral.of(lit.getType()); - + configurationBuilder.removePropertyConverters(target); configurationBuilder.addPropertyConverters(target, MicroprofileAdapter.toPropertyConverter(converter)); @@ -140,18 +143,18 @@ final class MicroprofileConfigBuilder implements ConfigBuilder { return this; } - @SuppressWarnings("unchecked") - @Override - public <T> ConfigBuilder withConverter(Class<T> type, int priority, Converter<T> converter) { - configurationBuilder.addPropertyConverters(TypeLiteral.of(type), MicroprofileAdapter.toPropertyConverter(converter)); - return this; - } - + @SuppressWarnings("unchecked") + @Override + public <T> ConfigBuilder withConverter(Class<T> type, int priority, Converter<T> converter) { + configurationBuilder.addPropertyConverters(TypeLiteral.of(type), MicroprofileAdapter.toPropertyConverter(converter)); + return this; + } + @Override public Config build() { Configuration config = getConfigurationBuilder().build(); - Configuration.setCurrent(config); - + Configuration.setCurrent(config); + return MicroprofileAdapter.toConfig(config); } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java index 33da10a..ac92aa6 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java @@ -43,9 +43,9 @@ public class MicroprofileConfigProviderResolver extends ConfigProviderResolver { @Override public Config getConfig(ClassLoader loader) { Config config = this.configs.get(loader); - if(config==null){ - ConfigurationBuilder builder = Configuration.createConfigurationBuilder(); - builder.setClassLoader(loader); + if (config == null) { + ConfigurationBuilder builder = Configuration.createConfigurationBuilder(); + builder.setClassLoader(loader); builder.addDefaultPropertyConverters(); MicroprofileConfigBuilder microConfigBuilder = new MicroprofileConfigBuilder(builder); microConfigBuilder.addDefaultSources(); @@ -63,7 +63,7 @@ public class MicroprofileConfigProviderResolver extends ConfigProviderResolver { @Override public void registerConfig(Config config, ClassLoader classLoader) { - if(configs.containsKey(classLoader)){ + if (configs.containsKey(classLoader)) { Logger.getLogger(getClass().getName()) .warning("Replacing existing config for classloader: " + classLoader); // throw new IllegalArgumentException("Already a config registered with classloader: " + classLoader); @@ -73,8 +73,8 @@ public class MicroprofileConfigProviderResolver extends ConfigProviderResolver { @Override public void releaseConfig(Config config) { - for(Map.Entry<ClassLoader, Config> en: this.configs.entrySet()){ - if(en.getValue().equals(config)){ + for (Map.Entry<ClassLoader, Config> en : this.configs.entrySet()) { + if (en.getValue().equals(config)) { this.configs.remove(en.getKey()); return; } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java index e1ac08d..b351d80 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java @@ -29,6 +29,7 @@ import java.util.Objects; /** * Property source implementation that wraps a Microprofile {@link ConfigSource} instance. + * @param <T> the target type. */ public class MicroprofileConverter<T> implements Converter<T> { diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java index 469deba..cfc0ead 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java @@ -18,7 +18,9 @@ */ package org.apache.tamaya.microprofile; -import org.apache.tamaya.*; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationSnapshot; +import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spisupport.DefaultConfigurationSnapshot; import org.eclipse.microprofile.config.Config; diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java index a83008a..a5088d4 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java @@ -28,6 +28,7 @@ import java.util.Objects; /** * Property source implementation that wraps a Microprofile {@link ConfigSource} instance. + * @param <T> the target type. */ public class TamayaPropertyConverter<T> implements PropertyConverter<T> { diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java index e6f90c8..ae8f883 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java @@ -32,8 +32,8 @@ final class BridgingConfigBean implements Bean<Object> { private final Bean<Object> delegate; private final Set<Type> types; - @SuppressWarnings({ "unchecked", "rawtypes" }) - public BridgingConfigBean(final Bean delegate, final Set<Type> types) { + @SuppressWarnings({"unchecked", "rawtypes"}) + public BridgingConfigBean(final Bean delegate, final Set<Type> types) { this.types = types; this.delegate = Objects.requireNonNull(delegate); } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java index 92b535e..fb13911 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java @@ -37,12 +37,12 @@ public final class ConfiguredType { private final List<ConfiguredMethod> methods = new ArrayList<>(); private final List<ConfiguredField> fields = new ArrayList<>(); - public ConfiguredType(Class<?> type){ + public ConfiguredType(Class<?> type) { this.type = Objects.requireNonNull(type); } @SuppressWarnings("rawtypes") - public Class getType() { + public Class getType() { return type; } @@ -64,14 +64,15 @@ public final class ConfiguredType { /** * Used to build up during injection point processing. + * * @param injectionPoint the CDI injection point, not null. - * @param key the possible configuration key, not null. + * @param key the possible configuration key, not null. */ void addConfiguredMember(InjectionPoint injectionPoint, String key) { Member member = injectionPoint.getMember(); - if(member instanceof Field){ + if (member instanceof Field) { this.fields.add(new ConfiguredField(injectionPoint, key)); - } else if(member instanceof Method){ + } else if (member instanceof Method) { this.methods.add(new ConfiguredMethod(injectionPoint, key)); } } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java index e3afea5..cca7f26 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java @@ -52,10 +52,10 @@ public class MicroprofileConfigurationProducer { @Produces @ConfigProperty public Object resolveAndConvert(final InjectionPoint injectionPoint) { - LOGGER.finest( () -> "Inject: " + injectionPoint); + LOGGER.finest(() -> "Inject: " + injectionPoint); final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class); String key = annotation.name(); - if(key.isEmpty()){ + if (key.isEmpty()) { key = getDefaultKey(injectionPoint); } @@ -75,7 +75,7 @@ public class MicroprofileConfigurationProducer { } @SuppressWarnings("rawtypes") - static String getDefaultKey(InjectionPoint injectionPoint) { + static String getDefaultKey(InjectionPoint injectionPoint) { Class declaringType = injectionPoint.getMember().getDeclaringClass(); return declaringType.getCanonicalName() + "." + injectionPoint.getMember().getName(); } @@ -85,24 +85,24 @@ public class MicroprofileConfigurationProducer { Configuration config = Configuration.current(); ConversionContext.Builder builder = new ConversionContext.Builder(config, key, TypeLiteral.of(targetType)); - if(targetType instanceof ParameterizedType){ - ParameterizedType pt = (ParameterizedType)targetType; - if(pt.getRawType().equals(Provider.class)) { + if (targetType instanceof ParameterizedType) { + ParameterizedType pt = (ParameterizedType) targetType; + if (pt.getRawType().equals(Provider.class)) { builder = new ConversionContext.Builder(config, key, TypeLiteral.of(pt.getActualTypeArguments()[0])); } } if (injectionPoint.getMember() instanceof AnnotatedElement) { - AnnotatedElement annotated = (AnnotatedElement)injectionPoint.getMember(); - if(annotated.isAnnotationPresent(ConfigProperty.class)) { + AnnotatedElement annotated = (AnnotatedElement) injectionPoint.getMember(); + if (annotated.isAnnotationPresent(ConfigProperty.class)) { builder.setAnnotatedElement(annotated); } - }else if(injectionPoint.getMember() instanceof Method){ - Method method = (Method)injectionPoint.getMember(); - for(Type type:method.getParameterTypes()){ - if(type instanceof AnnotatedElement){ - AnnotatedElement annotated = (AnnotatedElement)type; - if(annotated.isAnnotationPresent(ConfigProperty.class)) { + } else if (injectionPoint.getMember() instanceof Method) { + Method method = (Method) injectionPoint.getMember(); + for (Type type : method.getParameterTypes()) { + if (type instanceof AnnotatedElement) { + AnnotatedElement annotated = (AnnotatedElement) type; + if (annotated.isAnnotationPresent(ConfigProperty.class)) { builder.setAnnotatedElement(annotated); } } @@ -111,18 +111,18 @@ public class MicroprofileConfigurationProducer { return builder.build(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) static Object resolveValue(String defaultTextValue, ConversionContext context, InjectionPoint injectionPoint) { Config config = ConfigProviderResolver.instance().getConfig(); String textValue = config.getOptionalValue(context.getKey(), String.class).orElse(defaultTextValue); - if(String.class.equals(context.getTargetType().getRawType())){ + if (String.class.equals(context.getTargetType().getRawType())) { return textValue; } Object value = null; if (textValue != null || Optional.class.equals(context.getTargetType().getRawType())) { - LOGGER.log(Level.FINEST, () -> "Converting KEY: " + context.getKey() + "("+context.getTargetType()+"), textValue: " + textValue); - List<PropertyConverter> converters = Configuration.current().getContext() - .getPropertyConverters((TypeLiteral)context.getTargetType()); + LOGGER.log(Level.FINEST, () -> "Converting KEY: " + context.getKey() + "(" + context.getTargetType() + "), textValue: " + textValue); + List<PropertyConverter> converters = Configuration.current().getContext() + .getPropertyConverters((TypeLiteral) context.getTargetType()); for (PropertyConverter<Object> converter : converters) { try { value = converter.convert(textValue, context); @@ -141,12 +141,12 @@ public class MicroprofileConfigurationProducer { } @Produces - public Config getConfiguration(){ + public Config getConfiguration() { return ConfigProvider.getConfig(); } @Produces - public ConfigBuilder getConfigBuilder(){ + public ConfigBuilder getConfigBuilder() { return ConfigProviderResolver.instance().getBuilder(); } diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java index f15dd38..6907503 100644 --- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java +++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java @@ -34,6 +34,9 @@ import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; +/** + * Allows injection of {@link Provider} instances. + */ @SuppressWarnings("rawtypes") @Priority(-1) public class ProviderConverter implements PropertyConverter<Provider> { @@ -41,30 +44,35 @@ public class ProviderConverter implements PropertyConverter<Provider> { private static final Logger LOG = Logger.getLogger(ProviderConverter.class.getName()); @SuppressWarnings({"unchecked"}) - @Override + @Override public Provider convert(String value, ConversionContext context) { return () -> { - try{ + try { Type targetType = context.getTargetType().getType(); - ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(targetType)); + ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(targetType)); return context.getConfiguration().adapt(converter); - }catch(Exception e){ + } catch (Exception e) { throw new ConfigException("Error evaluating configuration createValue.", e); } }; } @Override - public boolean equals(Object o){ + public boolean equals(Object o) { return getClass().equals(o.getClass()); } @Override - public int hashCode(){ + public int hashCode() { return getClass().hashCode(); } - private static final class ConvertQuery<T> implements Function<Configuration,T> { + /** + * Query for getting the sub converter required. + * + * @param <T> the type. + */ + private static final class ConvertQuery<T> implements Function<Configuration, T> { private String rawValue; private TypeLiteral<T> type; @@ -79,18 +87,18 @@ public class ProviderConverter implements PropertyConverter<Provider> { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setConfiguration(config).setKey(ConvertQuery.class.getName()).build(); - for(PropertyConverter<?> conv: converters) { - try{ - if(conv instanceof ProviderConverter){ + for (PropertyConverter<?> conv : converters) { + try { + if (conv instanceof ProviderConverter) { continue; } @SuppressWarnings("unchecked") - T result = (T)conv.convert(rawValue, context); - if(result!=null){ + T result = (T) conv.convert(rawValue, context); + if (result != null) { return result; } - }catch(Exception e){ - LOG.log(Level.FINEST, e, () -> "Converter "+ conv +" failed to convert to " + type); + } catch (Exception e) { + LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java index 3a0e06b..2c6c66d 100644 --- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java +++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java @@ -41,7 +41,7 @@ import java.util.logging.Logger; * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .properties files. */ public class MutablePropertiesPropertySource extends BasePropertySource -implements MutablePropertySource{ + implements MutablePropertySource { /** * The logger. @@ -71,8 +71,8 @@ implements MutablePropertySource{ * Creates a new Properties based PropertySource based on the given URL. * * @param propertiesLocation the URL encoded location, not null. - * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property - * source's properties. + * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property + * source's properties. */ public MutablePropertiesPropertySource(File propertiesLocation, int defaultOrdinal) { super(propertiesLocation.toString(), defaultOrdinal); @@ -87,7 +87,7 @@ implements MutablePropertySource{ @Override public PropertyValue get(String key) { - Map<String,PropertyValue> properties = getProperties(); + Map<String, PropertyValue> properties = getProperties(); return properties.get(key); } @@ -118,46 +118,45 @@ implements MutablePropertySource{ @Override public void applyChange(ConfigChangeRequest change) { - if(change.isEmpty()){ + if (change.isEmpty()) { LOG.info("Nothing to commit for transaction: " + change.getTransactionID()); return; } - if(!file.exists()){ + if (!file.exists()) { try { - if(!file.createNewFile()){ + if (!file.createNewFile()) { throw new ConfigException("Failed to createObject config file " + file); } } catch (IOException e) { throw new ConfigException("Failed to createObject config file " + file, e); } } - for(Map.Entry<String,String> en:change.getAddedProperties().entrySet()){ + for (Map.Entry<String, String> en : change.getAddedProperties().entrySet()) { int index = en.getKey().indexOf('?'); - if(index>0){ + if (index > 0) { this.properties.put(en.getKey().substring(0, index), en.getValue()); - }else{ + } else { this.properties.put(en.getKey(), en.getValue()); } } - for(String rmKey:change.getRemovedProperties()){ + for (String rmKey : change.getRemovedProperties()) { this.properties.remove(rmKey); } - try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){ + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) { Properties props = new Properties(); - for (Map.Entry<String,String> en : this.properties.entrySet()) { + for (Map.Entry<String, String> en : this.properties.entrySet()) { props.setProperty(en.getKey(), en.getValue()); } props.store(bos, "Properties written from Tamaya on " + new Date()); bos.flush(); - } - catch(Exception e){ + } catch (Exception e) { throw new ConfigException("Failed to write config to " + file, e); } } @Override protected String toStringValues() { - return super.toStringValues() + + return super.toStringValues() + " file=" + file + '\n'; } diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java index 99d7097..510ba81 100644 --- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java +++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java @@ -41,7 +41,7 @@ import java.util.logging.Logger; * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .xml properties files. */ public class MutableXmlPropertiesPropertySource extends BasePropertySource -implements MutablePropertySource{ + implements MutablePropertySource { /** * The logger. @@ -72,8 +72,8 @@ implements MutablePropertySource{ * Creates a new Properties based PropertySource based on the given URL. * * @param propertiesLocation the URL encoded location, not null. - * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property - * source's properties. + * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property + * source's properties. */ public MutableXmlPropertiesPropertySource(File propertiesLocation, int defaultOrdinal) { super(propertiesLocation.toString(), defaultOrdinal); @@ -86,11 +86,10 @@ implements MutablePropertySource{ } - @Override public PropertyValue get(String key) { String val = this.properties.get(key); - if(val!=null) { + if (val != null) { return PropertyValue.createValue(key, val).setMeta("source", getName()); } return null; @@ -98,7 +97,7 @@ implements MutablePropertySource{ @Override public Map<String, PropertyValue> getProperties() { - return PropertyValue.map(this.properties,getName()); + return PropertyValue.map(this.properties, getName()); } /** @@ -124,46 +123,45 @@ implements MutablePropertySource{ @Override public void applyChange(ConfigChangeRequest configChange) { - if(configChange.isEmpty()){ + if (configChange.isEmpty()) { LOG.info("Nothing to commit for transaction: " + configChange.getTransactionID()); return; } - if(!file.exists()){ + if (!file.exists()) { try { - if(!file.createNewFile()){ + if (!file.createNewFile()) { throw new ConfigException("Failed to createObject config file " + file); } } catch (IOException e) { throw new ConfigException("Failed to createObject config file " + file, e); } } - for(Map.Entry<String,String> en:configChange.getAddedProperties().entrySet()){ + for (Map.Entry<String, String> en : configChange.getAddedProperties().entrySet()) { int index = en.getKey().indexOf('?'); - if(index>0){ + if (index > 0) { this.properties.put(en.getKey().substring(0, index), en.getValue()); - }else{ + } else { this.properties.put(en.getKey(), en.getValue()); } } - for(String rmKey:configChange.getRemovedProperties()){ + for (String rmKey : configChange.getRemovedProperties()) { this.properties.remove(rmKey); } - try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){ + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) { Properties props = new Properties(); - for (Map.Entry<String,String> en : this.properties.entrySet()) { + for (Map.Entry<String, String> en : this.properties.entrySet()) { props.setProperty(en.getKey(), en.getValue()); } props.storeToXML(bos, "Properties written from Tamaya on " + new Date()); bos.flush(); - } - catch(Exception e){ + } catch (Exception e) { throw new ConfigException("Failed to write config to " + file, e); } } @Override protected String toStringValues() { - return super.toStringValues() + + return super.toStringValues() + " file=" + file + '\n'; } diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java index 9a7a404..3c42d87 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java @@ -19,7 +19,10 @@ package org.apache.tamaya.osgi; import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.*; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceRegistration; import org.osgi.service.cm.ConfigurationAdmin; import java.util.Dictionary; diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java index eca0c98..57e94a0 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java @@ -36,21 +36,24 @@ final class Backups { private static final Logger LOG = Logger.getLogger(Backups.class.getName()); public static final String TAMAYA_BACKUP = "tamaya.backup"; - private static Map<String, Hashtable<String,?>> initialConfigState = new ConcurrentHashMap<>(); + private static Map<String, Hashtable<String, ?>> initialConfigState = new ConcurrentHashMap<>(); - private Backups(){} + private Backups() { + } /** * Sets the given backup for a PID. - * @param pid the PID, not null. + * + * @param pid the PID, not null. * @param config the config to store. */ - public static void set(String pid, Dictionary<String,?> config){ + public static void set(String pid, Dictionary<String, ?> config) { initialConfigState.put(pid, toHashtable(config)); } /** * Converts the dictionary to a hash table to enable serialization. + * * @param dictionary the config, not null. * @return the corresponding Hashtable */ @@ -58,8 +61,8 @@ final class Backups { if (dictionary == null) { return null; } - if(dictionary instanceof Hashtable){ - return (Hashtable<String,?>) dictionary; + if (dictionary instanceof Hashtable) { + return (Hashtable<String, ?>) dictionary; } Hashtable<String, Object> map = new Hashtable<>(dictionary.size()); Enumeration<String> keys = dictionary.keys(); @@ -72,83 +75,90 @@ final class Backups { /** * Removes a backup. + * * @param pid the PID, not null. * @return the removed dictionary or null if unknown */ - public static Dictionary<String,?> remove(String pid){ + public static Dictionary<String, ?> remove(String pid) { return initialConfigState.remove(pid); } /** * Removes all backups. */ - public static void removeAll(){ + public static void removeAll() { initialConfigState.clear(); } /** * Get a backup for a PID. + * * @param pid the PID, not null. * @return the backup found, or null. */ - public static Dictionary<String,?> get(String pid){ + public static Dictionary<String, ?> get(String pid) { return initialConfigState.get(pid); } /** * Get all current stored backups. + * * @return The backups stored, by PID. */ - public static Map<String,Dictionary<String,?>> get(){ + public static Map<String, Dictionary<String, ?>> get() { return new HashMap<>(initialConfigState); } /** * Get all currently known PIDs. + * * @return the PIDs, never null. */ - public static Set<String> getPids(){ + public static Set<String> getPids() { return initialConfigState.keySet(); } /** * Checks if a backup exists for a given PID. + * * @param pid the pid, not null. * @return {@code true} if there is a backup for the given PID, {@code false} otherwise. */ - public static boolean contains(String pid){ + public static boolean contains(String pid) { return initialConfigState.containsKey(pid); } /** * Saves the backups into the given config. + * * @param config the config, not null. */ - public static void save(Dictionary<String,Object> config){ - try{ + public static void save(Dictionary<String, Object> config) { + try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(initialConfigState); oos.flush(); Base64.getEncoder().encode(bos.toByteArray()); config.put(TAMAYA_BACKUP, Base64.getEncoder().encodeToString(bos.toByteArray())); - }catch(Exception e){ + } catch (Exception e) { LOG.log(Level.SEVERE, "Failed to restore OSGI Backups.", e); } } /** * Restores the backups into the given config. + * * @param config the config, not null. */ @SuppressWarnings("unchecked") - public static void restore(Dictionary<String,Object> config){ - try{ - String serialized = (String)config.get(TAMAYA_BACKUP); - if(serialized!=null) { + public static void restore(Dictionary<String, Object> config) { + try { + String serialized = (String) config.get(TAMAYA_BACKUP); + if (serialized != null) { ByteArrayInputStream bis = new ByteArrayInputStream(Base64.getDecoder().decode(serialized)); ObjectInputStream ois = new ObjectInputStream(bis); - initialConfigState = (Map<String, Hashtable<String,?>>) ois.readObject(); + initialConfigState = (Map<String, Hashtable<String, ?>>) ois.readObject(); ois.close(); } } catch (Exception e) { diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java index 28aaa55..0bbc526 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java @@ -153,8 +153,6 @@ final class ConfigChanger { continue; } switch (opMode) { - case EXTEND: - break; case OVERRIDE: LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue); ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue()); @@ -164,6 +162,9 @@ final class ConfigChanger { LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue); ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue()); dictionary.put(dictEntry.getKey(), configuredValue); + case EXTEND: + default: + break; } } } @@ -173,13 +174,6 @@ final class ConfigChanger { continue; } switch (opMode) { - case EXTEND: - if(dictValue==null){ - LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue()); - ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null); - dictionary.put(configEntry.getKey(), configEntry.getValue()); - } - break; case OVERRIDE: LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue()); ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null); @@ -192,6 +186,14 @@ final class ConfigChanger { dictionary.put(configEntry.getKey(), configEntry.getValue()); } break; + case EXTEND: + default: + if(dictValue==null){ + LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue()); + ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null); + dictionary.put(configEntry.getKey(), configEntry.getValue()); + } + break; } } } diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java index 4256a55..d8a4fa0 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java @@ -27,51 +27,74 @@ import java.util.logging.Logger; * Class storing the history of changes applied to the OSGI configuration by Tamaya. * This class can be used in the future to restore the previous state, if needed. */ -public final class ConfigHistory implements Serializable{ +public final class ConfigHistory implements Serializable { private static final long serialVersionUID = 1L; private static final Logger LOG = Logger.getLogger(ConfigHistory.class.getName()); - /** The key of the plugin OSGI configuration, where the history is stored/retrieved. */ + /** + * The key of the plugin OSGI configuration, where the history is stored/retrieved. + */ private static final String HISTORY_KEY = "tamaya.history"; - public enum TaskType{ + /** + * History entry type. + */ + public enum TaskType { PROPERTY, BEGIN, END, } - /** The max number of changes tracked. */ + + /** + * The max number of changes tracked. + */ private static int maxHistory = 10000; - /** The overall history. */ + /** + * The overall history. + */ private static List<ConfigHistory> history = new LinkedList<>(); - /** The entry timestamp. */ + /** + * The entry timestamp. + */ private long timestamp = System.currentTimeMillis(); - /** The entry type. */ + /** + * The entry type. + */ private TaskType type; - /** The previous createValue. */ + /** + * The previous createValue. + */ private Object previousValue; - /** The current createValue. */ + /** + * The current createValue. + */ private Object value; - /** The key. */ + /** + * The key. + */ private String key; - /** The target PID. */ + /** + * The target PID. + */ private String pid; - private ConfigHistory(TaskType taskType, String pid){ + private ConfigHistory(TaskType taskType, String pid) { this.type = Objects.requireNonNull(taskType); this.pid = Objects.requireNonNull(pid); } /** * Creates and registers an entry when starting to configure a bundle. - * @param pid the PID + * + * @param pid the PID * @param info any info. * @return the entry, never null. */ - public static ConfigHistory configuring(String pid, String info){ + public static ConfigHistory configuring(String pid, String info) { ConfigHistory h = new ConfigHistory(TaskType.BEGIN, pid) .setValue(info); - synchronized (history){ + synchronized (history) { history.add(h); checkHistorySize(); } @@ -80,14 +103,15 @@ public final class ConfigHistory implements Serializable{ /** * Creates and registers an entry when finished to configure a bundle. - * @param pid the PID + * + * @param pid the PID * @param info any info. * @return the entry, never null. */ - public static ConfigHistory configured(String pid, String info){ + public static ConfigHistory configured(String pid, String info) { ConfigHistory h = new ConfigHistory(TaskType.END, pid) .setValue(info); - synchronized (history){ + synchronized (history) { history.add(h); checkHistorySize(); } @@ -96,18 +120,19 @@ public final class ConfigHistory implements Serializable{ /** * Creates and registers an entry when a property has been changed. - * @param pid the PID - * @param key the key, not null. + * + * @param pid the PID + * @param key the key, not null. * @param previousValue the previous createValue. - * @param value the new createValue. + * @param value the new createValue. * @return the entry, never null. */ - public static ConfigHistory propertySet(String pid, String key, Object value, Object previousValue){ + public static ConfigHistory propertySet(String pid, String key, Object value, Object previousValue) { ConfigHistory h = new ConfigHistory(TaskType.PROPERTY, pid) .setKey(key) .setPreviousValue(previousValue) .setValue(value); - synchronized (history){ + synchronized (history) { history.add(h); checkHistorySize(); } @@ -116,44 +141,48 @@ public final class ConfigHistory implements Serializable{ /** * Sets the maximum history getNumChilds. + * * @param maxHistory the getNumChilds */ - static void setMaxHistory(int maxHistory){ + static void setMaxHistory(int maxHistory) { ConfigHistory.maxHistory = maxHistory; } /** * Get the max history getNumChilds. + * * @return the max getNumChilds */ - static int getMaxHistory(){ + static int getMaxHistory() { return maxHistory; } /** * Access the current history. + * * @return the current history, never null. */ - static List<ConfigHistory> getHistory(){ + static List<ConfigHistory> getHistory() { return getHistory(null); } /** * Clears the history. */ - static void clearHistory(){ + static void clearHistory() { clearHistory(null); } /** * Clears the history for a PID. + * * @param pid the pid, null clears the full history. */ - static void clearHistory(String pid){ - synchronized (history){ - if("*".equals(pid)) { + static void clearHistory(String pid) { + synchronized (history) { + if ("*".equals(pid)) { history.clear(); - }else{ + } else { history.removeAll(getHistory(pid)); } } @@ -161,11 +190,12 @@ public final class ConfigHistory implements Serializable{ /** * Get the history for a PID. + * * @param pid the pid, null returns the full history. * @return the history, never null. */ public static List<ConfigHistory> getHistory(String pid) { - if(pid==null || pid.isEmpty()){ + if (pid == null || pid.isEmpty()) { return new ArrayList<>(history); } synchronized (history) { @@ -179,7 +209,7 @@ public final class ConfigHistory implements Serializable{ } } - public TaskType getType(){ + public TaskType getType() { return type; } @@ -228,9 +258,10 @@ public final class ConfigHistory implements Serializable{ /** * This method saves the (serialized) history in the plugin's OSGI configuration using * the key {@link #HISTORY_KEY}. + * * @param osgiConfig the plugin config, not null. */ - static void save(Dictionary<String,Object> osgiConfig){ + static void save(Dictionary<String, Object> osgiConfig) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); @@ -244,13 +275,14 @@ public final class ConfigHistory implements Serializable{ /** * Restores the history from the plugin's OSGI configuration. + * * @param osgiConfig THE OSGI dictionary, not null. */ @SuppressWarnings("unchecked") - static void restore(Dictionary<String,Object> osgiConfig){ - try{ - String serialized = (String)osgiConfig.get(HISTORY_KEY); - if(serialized!=null) { + static void restore(Dictionary<String, Object> osgiConfig) { + try { + String serialized = (String) osgiConfig.get(HISTORY_KEY); + if (serialized != null) { ByteArrayInputStream bis = new ByteArrayInputStream(Base64.getDecoder().decode(serialized)); ObjectInputStream ois = new ObjectInputStream(bis); ConfigHistory.history = (List<ConfigHistory>) ois.readObject(); @@ -261,8 +293,8 @@ public final class ConfigHistory implements Serializable{ } } - private static void checkHistorySize(){ - while(history.size() > maxHistory){ + private static void checkHistorySize() { + while (history.size() > maxHistory) { history.remove(0); } } diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java index a22c7b5..b35166e 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java @@ -19,7 +19,13 @@ package org.apache.tamaya.osgi; import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.*; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; @@ -32,9 +38,11 @@ import java.util.logging.Logger; * Tamaya plugin that updates/extends the component configurations managed * by {@link ConfigurationAdmin}, based on the configured {@link Policy}. */ -public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, ServiceListener{ +public class TamayaConfigPlugin implements TamayaConfigService, BundleListener, ServiceListener { static final String COMPONENTID = "TamayaConfigPlugin"; - /** the logger. */ + /** + * the logger. + */ private static final Logger LOG = Logger.getLogger(TamayaConfigPlugin.class.getName()); public static final String TAMAYA_POLICY_PROP = "tamaya-policy"; @@ -54,7 +62,7 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S @Override public void serviceChanged(ServiceEvent event) { - switch(event.getType()){ + switch (event.getType()) { case ServiceEvent.REGISTERED: case ServiceEvent.MODIFIED: configureService(event); @@ -62,17 +70,20 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S case ServiceEvent.UNREGISTERING: // unconfigure...? Currently nothing here. break; + default: + break; } } /** * Create a new getConfig. + * * @param context the OSGI context */ public TamayaConfigPlugin(BundleContext context) { configChanger = new ConfigChanger(context); - Dictionary<String,Object> props = getPluginConfig(); + Dictionary<String, Object> props = getPluginConfig(); Backups.restore(props); ConfigHistory.restore(props); initDefaultEnabled(props); @@ -82,47 +93,49 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } @Override - public void setAutoUpdateEnabled(boolean enabled){ + public void setAutoUpdateEnabled(boolean enabled) { this.autoUpdateEnabled = enabled; setConfigValue(TAMAYA_AUTO_UPDATE_ENABLED_PROP, enabled); } @Override - public void setTamayaEnabledByDefault(boolean enabledByDefault){ + public void setTamayaEnabledByDefault(boolean enabledByDefault) { this.enabledByDefault = enabledByDefault; setConfigValue(TAMAYA_ENABLED_PROP, enabledByDefault); } @Override - public boolean isTamayaEnabledByDefault(){ + public boolean isTamayaEnabledByDefault() { return enabledByDefault; } @Override - public Policy getDefaultPolicy(){ + public Policy getDefaultPolicy() { return defaultPolicy; } @Override - public void setDefaultPolicy(Policy mode){ + public void setDefaultPolicy(Policy mode) { this.defaultPolicy = Objects.requireNonNull(mode); setConfigValue(Policy.class.getSimpleName(), defaultPolicy.toString()); } @Override public void bundleChanged(BundleEvent event) { - switch(event.getType()){ + switch (event.getType()) { case BundleEvent.STARTING: case BundleEvent.LAZY_ACTIVATION: configureBundle(event.getBundle()); break; + default: + break; } } private void initConfigs() { // Check for matching bundles already installed... - for(Bundle bundle:configChanger.getContext().getBundles()){ - switch(bundle.getState()){ + for (Bundle bundle : configChanger.getContext().getBundles()) { + switch (bundle.getState()) { case Bundle.ACTIVE: configureBundle(bundle); break; @@ -133,39 +146,39 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S private void configureService(ServiceEvent event) { // Optional MANIFEST entries Bundle bundle = event.getServiceReference().getBundle(); - if(!isBundleEnabled(bundle)){ + if (!isBundleEnabled(bundle)) { return; } - String pid = (String)event.getServiceReference().getProperty(Constants.SERVICE_PID); - if(pid==null){ + String pid = (String) event.getServiceReference().getProperty(Constants.SERVICE_PID); + if (pid == null) { LOG.finest("No service pid for: " + event.getServiceReference()); return; } configChanger.configure(pid, event.getServiceReference().getBundle(), defaultPolicy, false, false); - Dictionary<String,Object> props = getPluginConfig(); + Dictionary<String, Object> props = getPluginConfig(); Backups.save(props); ConfigHistory.save(props); setPluginConfig(props); } @Override - public Dictionary<String,Object> updateConfig(String pid) { + public Dictionary<String, Object> updateConfig(String pid) { return updateConfig(pid, defaultPolicy, false, false); } @Override - public Dictionary<String,Object> updateConfig(String pid, boolean dryRun) { + public Dictionary<String, Object> updateConfig(String pid, boolean dryRun) { return updateConfig(pid, defaultPolicy, false, dryRun); } @Override - public Dictionary<String,Object> updateConfig(String pid, Policy opMode, boolean explicitMode, boolean dryRun) { - if(dryRun){ + public Dictionary<String, Object> updateConfig(String pid, Policy opMode, boolean explicitMode, boolean dryRun) { + if (dryRun) { return configChanger.configure(pid, null, opMode, explicitMode, true); - }else { + } else { LOG.fine("Updating getConfig for pid...: " + pid); - Dictionary<String,Object> result = configChanger.configure(pid, null, opMode, explicitMode, false); - Dictionary<String,Object> props = getPluginConfig(); + Dictionary<String, Object> result = configChanger.configure(pid, null, opMode, explicitMode, false); + Dictionary<String, Object> props = getPluginConfig(); Backups.save(props); ConfigHistory.save(props); setPluginConfig(props); @@ -174,38 +187,38 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } private void configureBundle(Bundle bundle) { - if(!isBundleEnabled(bundle)){ + if (!isBundleEnabled(bundle)) { return; } String tamayaPid = bundle.getHeaders().get(TAMAYA_CUSTOM_ROOT_MANIFEST); - String pid = tamayaPid!=null?tamayaPid:bundle.getSymbolicName(); - if(pid==null){ + String pid = tamayaPid != null ? tamayaPid : bundle.getSymbolicName(); + if (pid == null) { pid = bundle.getLocation(); } - if(pid==null){ - LOG.finest(() -> "No PID/location for bundle " + bundle.getSymbolicName() + '('+bundle.getBundleId()+')'); + if (pid == null) { + LOG.finest(() -> "No PID/location for bundle " + bundle.getSymbolicName() + '(' + bundle.getBundleId() + ')'); return; } configChanger.configure(pid, bundle, defaultPolicy, false, false); - Dictionary<String,Object> props = getPluginConfig(); + Dictionary<String, Object> props = getPluginConfig(); Backups.save(props); ConfigHistory.save(props); setPluginConfig(props); } @Override - public boolean isBundleEnabled(Bundle bundle){ + public boolean isBundleEnabled(Bundle bundle) { // Optional MANIFEST entries String bundleEnabledVal = bundle.getHeaders().get(TAMAYA_ENABLED_MANIFEST); - if(bundleEnabledVal==null && !enabledByDefault){ + if (bundleEnabledVal == null && !enabledByDefault) { LOG.finest("tamaya.enabled=false: not configuring bundle: " + bundle.getSymbolicName()); return false; } - if(bundleEnabledVal != null && !Boolean.parseBoolean(bundleEnabledVal)){ + if (bundleEnabledVal != null && !Boolean.parseBoolean(bundleEnabledVal)) { LOG.finest("Bundle is explcitly disabled for Tamaya: " + bundle.getSymbolicName()); return false; } - if(bundleEnabledVal != null && Boolean.parseBoolean(bundleEnabledVal)){ + if (bundleEnabledVal != null && Boolean.parseBoolean(bundleEnabledVal)) { LOG.finest("Bundle is explicitly enabled for Tamaya: " + bundle.getSymbolicName()); return true; } @@ -213,62 +226,62 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } // REVIEW is this method still needed at all? - private boolean isAutoUpdateEnabled(Bundle bundle, Dictionary<String,Object> props) { + private boolean isAutoUpdateEnabled(Bundle bundle, Dictionary<String, Object> props) { Object enabledVal = props.get(TAMAYA_AUTO_UPDATE_ENABLED_PROP); - if(enabledVal!=null){ + if (enabledVal != null) { return Boolean.parseBoolean(enabledVal.toString()); } - if(bundle!=null){ + if (bundle != null) { enabledVal = bundle.getHeaders().get(TAMAYA_AUTO_UPDATE_ENABLED_MANIFEST); - if(enabledVal!=null){ + if (enabledVal != null) { return Boolean.parseBoolean(enabledVal.toString()); } } return this.autoUpdateEnabled; } - private void initAutoUpdateEnabled(Dictionary<String,Object> props) { + private void initAutoUpdateEnabled(Dictionary<String, Object> props) { Object enabledVal = props.get(TAMAYA_AUTO_UPDATE_ENABLED_PROP); - if(enabledVal==null && System.getProperty(TAMAYA_AUTO_UPDATE_ENABLED_PROP)!=null){ + if (enabledVal == null && System.getProperty(TAMAYA_AUTO_UPDATE_ENABLED_PROP) != null) { enabledVal = Boolean.parseBoolean(System.getProperty(TAMAYA_AUTO_UPDATE_ENABLED_PROP)); } - if(enabledVal!=null){ + if (enabledVal != null) { this.autoUpdateEnabled = Boolean.parseBoolean(enabledVal.toString()); } - if(this.autoUpdateEnabled) { + if (this.autoUpdateEnabled) { LOG.info("Tamaya Automatic Config Update is enabled by default."); - }else{ + } else { LOG.info("Tamaya Automatic Config Update is disabled by default."); } } - private void initDefaultEnabled(Dictionary<String,Object> props) { + private void initDefaultEnabled(Dictionary<String, Object> props) { Object enabledVal = props.get(TAMAYA_ENABLED_PROP); - if(enabledVal==null && System.getProperty(TAMAYA_ENABLED_PROP)!=null){ + if (enabledVal == null && System.getProperty(TAMAYA_ENABLED_PROP) != null) { enabledVal = Boolean.parseBoolean(System.getProperty(TAMAYA_ENABLED_PROP)); } - if(enabledVal!=null){ + if (enabledVal != null) { this.enabledByDefault = Boolean.parseBoolean(enabledVal.toString()); } - if(this.enabledByDefault) { + if (this.enabledByDefault) { LOG.info("Tamaya Config is enabled by default. Add Tamaya-Enabled to your bundle manifests to enable it."); - }else{ + } else { LOG.info("Tamaya Config is not enabled by default. Add Tamaya-Disabled to your bundle manifests to disable it."); } } - private void initDefaultOpMode(Dictionary<String,Object> props) { - String opVal = (String)props.get(Policy.class.getSimpleName()); - if(opVal!=null){ - try{ + private void initDefaultOpMode(Dictionary<String, Object> props) { + String opVal = (String) props.get(Policy.class.getSimpleName()); + if (opVal != null) { + try { defaultPolicy = Policy.valueOf(opVal); - }catch(Exception e){ - LOG.warning("Invalid Policy: " + opVal +", using default: " + defaultPolicy); + } catch (Exception e) { + LOG.warning("Invalid Policy: " + opVal + ", using default: " + defaultPolicy); } } } - Dictionary<String, Object> getPluginConfig(){ + Dictionary<String, Object> getPluginConfig() { Configuration config; try { config = configChanger.getConfigurationAdmin().getConfiguration(COMPONENTID); @@ -285,7 +298,7 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } } - void setPluginConfig(Dictionary<String, Object> props){ + void setPluginConfig(Dictionary<String, Object> props) { Configuration config; try { config = configChanger.getConfigurationAdmin().getConfiguration(COMPONENTID); @@ -297,10 +310,10 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } } - void setConfigValue(String key, Object value){ + void setConfigValue(String key, Object value) { try { Dictionary<String, Object> props = getPluginConfig(); - if(props!=null) { + if (props != null) { props.put(key, value); setPluginConfig(props); LOG.finest("Updated Tamaya Plugin createValue: " + key + "=" + value); @@ -310,10 +323,10 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } } - Object getConfigValue(String key){ + Object getConfigValue(String key) { try { Dictionary<String, Object> props = getPluginConfig(); - if(props!=null){ + if (props != null) { return props.get(key); } } catch (Exception e) { @@ -343,10 +356,10 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S } @Override - public boolean restoreBackup(String pid){ + public boolean restoreBackup(String pid) { @SuppressWarnings("unchecked") - Dictionary<String,Object> config = (Dictionary<String,Object>) Backups.get(pid); - if(config==null){ + Dictionary<String, Object> config = (Dictionary<String, Object>) Backups.get(pid); + if (config == null) { return false; } try { @@ -360,7 +373,7 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S @Override public boolean createBackup(String pid) { - if(!Backups.contains(pid)) { + if (!Backups.contains(pid)) { Backups.set(pid, getOSGIConfiguration(pid, null)); return true; } @@ -369,7 +382,7 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S @Override public boolean deleteBackup(String pid) { - if(Backups.contains(pid)) { + if (Backups.contains(pid)) { Backups.remove(pid); return true; } @@ -416,7 +429,7 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S return null; } props = config.getProperties(); - if(section!=null){ + if (section != null) { return filter(props, section); } return props; @@ -434,9 +447,9 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S private Dictionary<String, Object> filter(Dictionary<String, Object> props, String section) { Hashtable<String, Object> result = new Hashtable<>(); Enumeration<String> keys = props.keys(); - while(keys.hasMoreElements()){ + while (keys.hasMoreElements()) { String key = keys.nextElement(); - if(key.startsWith(section)){ + if (key.startsWith(section)) { result.put(key, props.get(key)); } } diff --git a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java index 93f3dea..9b87077 100644 --- a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java +++ b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java @@ -28,6 +28,9 @@ import org.osgi.service.cm.ConfigurationAdmin; import java.io.IOException; import java.util.Objects; +/** + * A Felix shell commands provider. + */ public class BackupCommands { private BundleContext context; diff --git a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java index 5b26b4c..de47ae6 100644 --- a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java +++ b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java @@ -28,6 +28,9 @@ import org.osgi.framework.ServiceReference; import java.io.IOException; import java.util.Objects; +/** + * A Felix shell commands provider. + */ public class ConfigCommands { private BundleContext context; diff --git a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java index a0d6959..8463ac3 100644 --- a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java +++ b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java @@ -27,6 +27,9 @@ import org.osgi.framework.ServiceReference; import java.io.IOException; import java.util.Objects; +/** + * A Felix shell commands provider. + */ public class HistoryCommands { private BundleContext context; diff --git a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java index cf79f0a..cf38662 100644 --- a/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java +++ b/modules/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java @@ -29,6 +29,9 @@ import org.osgi.framework.ServiceReference; import java.io.IOException; import java.util.Objects; +/** + * A Felix shell commands provider. + */ public class SettingsCommands { private BundleContext context; diff --git a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java index 57b8010..8d55b3d 100644 --- a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java +++ b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/Activator.java @@ -18,7 +18,11 @@ */ package org.apache.tamaya.osgi.injection; -import org.osgi.framework.*; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; import java.util.Dictionary; import java.util.Hashtable; @@ -58,6 +62,9 @@ public class Activator implements BundleActivator { injector.stop(); } + /** + * Tamaya injector service. + */ static final class TamayaConfigInjectionService implements ConfigInjectionService{ private TamayaOSGIInjector injector; diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ApplyTamayaConfigCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ApplyTamayaConfigCommand.java index 9864ecc..c43e92a 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ApplyTamayaConfigCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ApplyTamayaConfigCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_apply_config", description="Show the current Tamaya configuration.") @Service public class ApplyTamayaConfigCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java index dda367a..20ed420 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java @@ -30,6 +30,9 @@ import org.osgi.service.cm.ConfigurationAdmin; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_backup_create", description="Creates a backup of a current OSGI configuration.") @Service public class BackupCreateCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java index f8fe5fe..55d0d97 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_backup_delete", description="Deletes the OSGI configuration backup of Tamya.") @Service public class BackupDeleteCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java index edc5e88..68a8355 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_backup_list", description="List the backed-up OSGI configuration before Tamya applied changes.") @Service public class BackupListCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupRestoreCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupRestoreCommand.java index e053bd2..9e600a2 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupRestoreCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupRestoreCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_backup_restore", description="Restores the OSGI configuration backup of Tamya and disabled the PID for Tamaya configuration.") @Service public class BackupRestoreCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnableCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnableCommand.java index a667224..45ce97e 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnableCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnableCommand.java @@ -34,6 +34,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; import java.util.List; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_enable", description="Enables or disable Tamaya by default for all bundles/services (default: enabled=false)." + " Disabling still allows to explicitly enable bundles using 'tamaya-enable' manifest or OSGI config entries.") @Service @@ -51,6 +54,9 @@ public class DefaultEnableCommand implements Action{ return(ConfigCommands.setDefaultEnabled(configPlugin, enabled)); } + /** + * Karaf code completion. + */ @Service public static final class OperationModeCompleter implements Completer { diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnabledCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnabledCommand.java index 7b29af7..f5ce13c 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnabledCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultEnabledCommand.java @@ -33,6 +33,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; import java.util.List; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_enabled", description="Check if Tamaya is currently by default enabled for all bundles/services (default: enabled=false)." + " If disabled still Tamaya allows to explicitly enable bundles using 'tamaya-enable' manifest or OSGI config entries.") @Service diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java index 71830ca..c393418 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_policy", description="Get the current Tamaya overriding policy.") @Service public class GetPolicyCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteAllCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteAllCommand.java index 2e816dd..e1dc4be 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteAllCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteAllCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_history_delete_all", description="Deletes the full getHistory of changes Tamaya applied to the OSGI configuration.") @Service public class HistoryDeleteAllCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java index d9df7e0..c7fa3a0 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java @@ -18,7 +18,9 @@ */ package org.apache.tamaya.karaf.shell; -import org.apache.karaf.shell.api.action.*; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.HistoryCommands; @@ -26,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_history_delete", description="Deletes the getHistory of changes Tamaya applied to the OSGI configuration.") @Service public class HistoryDeleteCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java index ec221fc..1a2e324 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java @@ -18,7 +18,11 @@ */ package org.apache.tamaya.karaf.shell; -import org.apache.karaf.shell.api.action.*; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.karaf.shell.api.console.CommandLine; @@ -32,6 +36,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; import java.util.List; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_history", description="Gets the getHistory of changes Tamaya applied to the OSGI configuration.") @Service public class HistoryGetCommand implements Action{ @@ -53,6 +60,9 @@ public class HistoryGetCommand implements Action{ return HistoryCommands.getHistory(configPlugin, pid, eventTypes); } + /** + * Karaf completer action. + */ @Service public static final class FilterCompleter implements Completer { diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java index 4add8f6..2555a59 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java @@ -18,7 +18,8 @@ */ package org.apache.tamaya.karaf.shell; -import org.apache.karaf.shell.api.action.*; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.HistoryCommands; @@ -26,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_history_maxsize", description="Gets the maximal getNumChilds of stored getHistory entries.") @Service public class HistoryMaxsizeCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeSetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeSetCommand.java index ae4cca4..960bfd7 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeSetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeSetCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_history_maxsize_set", description="Sets the maximal getNumChilds of Tamaya getHistory entries.") @Service public class HistoryMaxsizeSetCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java index cb8f826..94d7278 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java @@ -27,6 +27,9 @@ import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.ConfigCommands; import org.apache.tamaya.osgi.commands.TamayaConfigService; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_info", description="Show he current Tamaya status.") @Service public class InfoCommand implements Action { diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/OSGIConfigCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/OSGIConfigCommand.java index 128aa78..334c31f 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/OSGIConfigCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/OSGIConfigCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_osgi_config", description="Show the current OSGI configuration.") @Service public class OSGIConfigCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java index e38e017..107f30b 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_policy", description="Gets the current Tamaya operation policy.") @Service public class PolicyGetCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java index 10e317f..cb67a3d 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java @@ -35,6 +35,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; import java.util.List; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_policy_set", description="Sets the current Tamaya operation policy.") @Service public class PolicySetCommand implements Action{ @@ -52,6 +55,9 @@ public class PolicySetCommand implements Action{ return(ConfigCommands.setDefaultOpPolicy(configPlugin, policy)); } + /** + * Completer command. + */ @Service public static final class OperationModeCompleter implements Completer { diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesCommand.java index 129e9fc..5a2dcc5 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesCommand.java @@ -26,6 +26,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_propagate_updates", description="Flag if Tamaya is automatically triggering OSGI config updates, when according " + "Tamaya configuration changes.") diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesSetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesSetCommand.java index ff5dc95..c018204 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesSetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropagateUpdatesSetCommand.java @@ -28,6 +28,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_propagate_updates_set", description="Configure if Tamaya is automatically triggering OSGI config updates, when according " + "Tamaya configuration changes.") diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java index b4e62f0..d141d8e 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_property", description="Get a Tamaya property.") @Service public class PropertyGetCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java index 97ff4ae..4dea80b 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java @@ -26,6 +26,9 @@ import org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_propertysource", description="Show the current Tamaya entries of a propertysource.") @Service public class PropertySourceCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java index 8301914..b2167f4 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java @@ -25,6 +25,9 @@ import org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_propertysources", description="Get a createList of currently registered propertysources.") @Service public class PropertySourcesCommand implements Action{ diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/TamayaConfigCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/TamayaConfigCommand.java index e66d27b..8b673b7 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/TamayaConfigCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/TamayaConfigCommand.java @@ -27,6 +27,9 @@ import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; +/** + * A Karaf shell command. + */ @Command(scope = "tamaya", name = "tm_config", description="Show the current Tamaya configuration.") @Service public class TamayaConfigCommand implements Action{ diff --git a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java index a97e8f3..20fe0ab 100644 --- a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java +++ b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java @@ -21,7 +21,9 @@ package org.apache.tamaya.osgi.updater; import org.apache.tamaya.events.ConfigEventManager; import org.apache.tamaya.events.ConfigurationChange; import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.*; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; import org.osgi.service.cm.ConfigurationAdmin; import java.util.Timer; diff --git a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java index 68e9bcb..a7d648f 100644 --- a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java +++ b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java @@ -23,7 +23,8 @@ import org.apache.tamaya.events.ConfigEventListener; import org.apache.tamaya.events.ConfigurationChange; import org.apache.tamaya.osgi.Policy; import org.apache.tamaya.osgi.commands.TamayaConfigService; -import org.osgi.framework.*; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; import org.osgi.service.cm.ConfigurationAdmin; import java.beans.PropertyChangeEvent;
