This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch properties in repository https://gitbox.apache.org/repos/asf/camel.git
commit 171ec389e3cff54e04e25cedbf87712be92c72b0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jul 4 11:33:08 2019 +0200 CAMEL-13708: Properties component should have API to make it easier to lookup a property on-demand or from all pre-loaded properties. --- .../AbstractLocationPropertiesSource.java | 6 ++-- .../properties/DefaultPropertiesLookup.java | 7 ----- .../properties/LocationPropertiesSource.java | 3 -- .../component/properties/PropertiesComponent.java | 32 ++++------------------ .../component/properties/RefPropertiesSource.java | 1 - 5 files changed, 9 insertions(+), 40 deletions(-) diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java index 94a10c4c..abb08df 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java @@ -57,8 +57,10 @@ public abstract class AbstractLocationPropertiesSource extends ServiceSupport im super.doInit(); Properties prop = loadPropertiesFromLocation(propertiesComponent, location); - prop = prepareLoadedProperties(prop); - properties.putAll(prop); + if (prop != null) { + prop = prepareLoadedProperties(prop); + properties.putAll(prop); + } } @Override diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java index 1d9a065..45737fb 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java @@ -44,13 +44,6 @@ public class DefaultPropertiesLookup implements PropertiesLookup { answer = it2.next().getProperty(name); } } - if (answer == null) { - // then try till first found location source - Iterator<LocationPropertiesSource> it = component.getLocationSources().iterator(); - while (answer == null && it.hasNext()) { - answer = it.next().getProperty(name); - } - } // initial properties are last if (answer == null && component.getInitialProperties() != null) { answer = component.getInitialProperties().getProperty(name); diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/LocationPropertiesSource.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/LocationPropertiesSource.java index 7ec3f89..bcfddb0 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/LocationPropertiesSource.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/LocationPropertiesSource.java @@ -21,9 +21,6 @@ package org.apache.camel.component.properties; */ public interface LocationPropertiesSource extends PropertiesSource { - // TODO: We can make some special for this and remove this interface - // as this is an implementation details only internally - /** * Gets the location of the properties */ diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java index 8695c6f..be22fc8 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java @@ -52,7 +52,6 @@ import org.slf4j.LoggerFactory; public class PropertiesComponent extends DefaultComponent implements org.apache.camel.spi.PropertiesComponent, StaticService { // TODO: PropertySource / LoadablePropertySource to camel-api - // TODO: Remove LocationPropertiesSource // TODO: API on PropertiesComponent in SPI to Optional<String> lookupProperty(String name); // TODO: Add docs about `PropertiesSource` @@ -106,7 +105,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private PropertiesParser propertiesParser = new DefaultPropertiesParser(this); private final PropertiesLookup propertiesLookup = new DefaultPropertiesLookup(this); private final List<PropertiesSource> sources = new ArrayList<>(); - private final List<LocationPropertiesSource> locationSources = new ArrayList<>(); private List<PropertiesLocation> locations = Collections.emptyList(); @@ -181,15 +179,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. prop.putAll(initialProperties); } - if (!locationSources.isEmpty()) { - for (PropertiesSource ps : locationSources) { - if (ps instanceof LoadablePropertiesSource) { - LoadablePropertiesSource lps = (LoadablePropertiesSource) ps; - Properties p = lps.loadProperties(); - prop.putAll(p); - } - } - } if (!sources.isEmpty()) { for (PropertiesSource ps : sources) { if (ps instanceof LoadablePropertiesSource) { @@ -241,8 +230,8 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. locations = parseLocations(locations); this.locations = Collections.unmodifiableList(locations); - // we need to reset them as sources as well - this.locationSources.clear(); + // we need to re-create the property sources which may have already been created from locations + this.sources.removeIf(s -> s instanceof LocationPropertiesSource); for (PropertiesLocation loc : locations) { addPropertiesLocationsAsPropertiesSource(loc); } @@ -475,11 +464,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. if (propertiesSource instanceof CamelContextAware) { ((CamelContextAware) propertiesSource).setCamelContext(getCamelContext()); } - if (propertiesSource instanceof LocationPropertiesSource) { - locationSources.add((LocationPropertiesSource) propertiesSource); - } else { - sources.add(propertiesSource); - } + sources.add(propertiesSource); if (isInit()) { // if we are already initialized we need to init the properties source also ServiceHelper.initService(propertiesSource); @@ -490,10 +475,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. return sources; } - public List<LocationPropertiesSource> getLocationSources() { - return locationSources; - } - @Override protected void doInit() throws Exception { super.doInit(); @@ -518,16 +499,13 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. LOG.debug("Error discovering and using custom PropertiesSource due to " + e.getMessage() + ". This exception is ignored", e); } - ServiceHelper.initService(locationSources); ServiceHelper.initService(sources); } @Override protected void doStart() throws Exception { - // sort the sources - locationSources.sort(OrderedComparator.get()); sources.sort(OrderedComparator.get()); - ServiceHelper.startService(locationSources, sources); + ServiceHelper.startService(sources); if (systemPropertiesMode != SYSTEM_PROPERTIES_MODE_NEVER && systemPropertiesMode != SYSTEM_PROPERTIES_MODE_FALLBACK @@ -548,7 +526,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. @Override protected void doStop() throws Exception { - ServiceHelper.stopAndShutdownServices(locationSources, sources); + ServiceHelper.stopAndShutdownServices(sources); } private void addPropertiesLocationsAsPropertiesSource(PropertiesLocation location) { diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java index fb4155c..e2c5a68 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java @@ -38,7 +38,6 @@ public class RefPropertiesSource implements LocationPropertiesSource { return "RefPropertiesSource[" + getLocation().getPath() + "]"; } - @Override public PropertiesLocation getLocation() { return location; }