This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.featureflags-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-featureflags.git
commit 1dfd47c24bd44b68748a3c57b8447e539ae8ffa4 Author: Carsten Ziegeler <[email protected]> AuthorDate: Mon Aug 1 16:16:00 2016 +0000 SLING-5939 : Register filter using http whiteboard git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/feature-flags@1754774 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 20 ++---- .../sling/featureflags/ExecutionContext.java | 3 +- .../org/apache/sling/featureflags/Feature.java | 2 +- .../org/apache/sling/featureflags/Features.java | 2 +- .../sling/featureflags/impl/ConfiguredFeature.java | 82 +++++++++++++--------- .../sling/featureflags/impl/FeatureManager.java | 44 ++++++------ .../apache/sling/featureflags/package-info.java | 5 +- 7 files changed, 78 insertions(+), 80 deletions(-) diff --git a/pom.xml b/pom.xml index 6fe29b9..8b245e6 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.apache.sling</groupId> <artifactId>sling</artifactId> - <version>26</version> + <version>27</version> <relativePath/> </parent> @@ -42,10 +42,6 @@ <plugins> <plugin> <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> </plugin> @@ -55,27 +51,23 @@ <dependencies> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> + <artifactId>osgi.core</artifactId> </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.api</artifactId> - <version>2.1.0</version> + <artifactId>org.osgi.service.http.whiteboard</artifactId> + <version>1.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.osgi</artifactId> + <artifactId>org.apache.sling.api</artifactId> <version>2.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> + <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> diff --git a/src/main/java/org/apache/sling/featureflags/ExecutionContext.java b/src/main/java/org/apache/sling/featureflags/ExecutionContext.java index 321a092..5eda911 100644 --- a/src/main/java/org/apache/sling/featureflags/ExecutionContext.java +++ b/src/main/java/org/apache/sling/featureflags/ExecutionContext.java @@ -21,8 +21,7 @@ package org.apache.sling.featureflags; import javax.servlet.http.HttpServletRequest; import org.apache.sling.api.resource.ResourceResolver; - -import aQute.bnd.annotation.ProviderType; +import org.osgi.annotation.versioning.ProviderType; /** * The {@code ExecutionContext} interface provides access to the context for diff --git a/src/main/java/org/apache/sling/featureflags/Feature.java b/src/main/java/org/apache/sling/featureflags/Feature.java index 1d835b9..7faa6a4 100644 --- a/src/main/java/org/apache/sling/featureflags/Feature.java +++ b/src/main/java/org/apache/sling/featureflags/Feature.java @@ -18,7 +18,7 @@ */ package org.apache.sling.featureflags; -import aQute.bnd.annotation.ConsumerType; +import org.osgi.annotation.versioning.ConsumerType; /** * A feature is defined by its name. Features are registered as OSGi services. diff --git a/src/main/java/org/apache/sling/featureflags/Features.java b/src/main/java/org/apache/sling/featureflags/Features.java index a1d2a69..e9b7f7d 100644 --- a/src/main/java/org/apache/sling/featureflags/Features.java +++ b/src/main/java/org/apache/sling/featureflags/Features.java @@ -18,7 +18,7 @@ */ package org.apache.sling.featureflags; -import aQute.bnd.annotation.ProviderType; +import org.osgi.annotation.versioning.ProviderType; /** * The {@code Features} service is the applications access point to the Feature diff --git a/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java b/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java index d79d8cf..266069e 100644 --- a/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java +++ b/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java @@ -22,42 +22,44 @@ import java.util.Map; import javax.servlet.ServletRequest; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.featureflags.ExecutionContext; import org.apache.sling.featureflags.Feature; import org.osgi.framework.Constants; - -@Component( - name = "org.apache.sling.featureflags.Feature", - metatype = true, - configurationFactory = true, - policy = ConfigurationPolicy.REQUIRE, - label = "Apache Sling Configured Feature", - description = "Allows for the definition of statically configured features which are defined and enabled through OSGi configuration") -@Service +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@Designate(ocd = ConfiguredFeature.Config.class, factory = true) +@Component(service = Feature.class, + configurationPolicy = ConfigurationPolicy.REQUIRE) public class ConfiguredFeature implements Feature { - private static final String PROP_FEATURE = "feature"; - - @Property(label = "Name", description = "Short name of this feature. This name is used " - + "to refer to this feature when checking for it to be enabled or not. This " - + "property is required and defaults to a name derived from the feature's class " - + "name and object identity. It is strongly recommended to define a useful and unique for the feature") - private static final String NAME = "name"; + @ObjectClassDefinition(name = "Apache Sling Configured Feature", + description = "Allows for the definition of statically configured features which are defined and enabled through OSGi configuration", + factoryPid = "org.apache.sling.featureflags.Feature") + public static @interface Config { + + @AttributeDefinition(name = "Name", description = "Short name of this feature. This name is used " + + "to refer to this feature when checking for it to be enabled or not. This " + + "property is required and defaults to a name derived from the feature's class " + + "name and object identity. It is strongly recommended to define a useful and unique for the feature") + String name(); + + @AttributeDefinition(name = "Description", description = "Description for the feature. The " + + "intent is to descibe the behaviour of the application if this feature would be " + + "enabled. It is recommended to define this property. The default value is the value of the name property.") + String description(); + + @AttributeDefinition(name = "Enabled", description = "Boolean flag indicating whether the feature is " + + "enabled or not by this configuration") + boolean enabled() default false; + } - @Property(label = "Description", description = "Description for the feature. The " - + "intent is to descibe the behaviour of the application if this feature would be " - + "enabled. It is recommended to define this property. The default value is the value of the name property.") - private static final String DESCRIPTION = "description"; + private static final String PROP_FEATURE = "feature"; - @Property(boolValue = false, label = "Enabled", description = "Boolean flag indicating whether the feature is " - + "enabled or not by this configuration") - private static final String ENABLED = "enabled"; private String name; @@ -66,12 +68,22 @@ public class ConfiguredFeature implements Feature { private boolean enabled; @Activate - private void activate(final Map<String, Object> configuration) { - final String pid = PropertiesUtil.toString(configuration.get(Constants.SERVICE_PID), getClass().getName() + "$" - + System.identityHashCode(this)); - this.name = PropertiesUtil.toString(configuration.get(NAME), pid); - this.description = PropertiesUtil.toString(configuration.get(DESCRIPTION), this.name); - this.enabled = PropertiesUtil.toBoolean(configuration.get(ENABLED), false); + private void activate(final Config config, final Map<String, Object> properties) { + this.name = config.name(); + if ( this.name == null ) { + Object pid = properties.get(Constants.SERVICE_PID); + if ( pid == null ) { + this.name = getClass().getName() + "$" + System.identityHashCode(this); + } else { + this.name = pid.toString(); + } + + } + this.description = config.description(); + if ( this.description == null ) { + this.description = this.name; + } + this.enabled = config.enabled(); } @Override diff --git a/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java b/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java index 9fed787..c8fd473 100644 --- a/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java +++ b/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java @@ -37,18 +37,16 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.ConfigurationPolicy; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.ReferencePolicy; -import org.apache.felix.scr.annotations.Service; import org.apache.sling.api.request.ResponseUtil; import org.apache.sling.featureflags.Feature; import org.apache.sling.featureflags.Features; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.osgi.service.http.whiteboard.HttpWhiteboardConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,20 +54,16 @@ import org.slf4j.LoggerFactory; * This service implements the feature handling. It keeps track of all * {@link Feature} services. */ -@Component(policy = ConfigurationPolicy.IGNORE) -@Service -@Reference( - name = "feature", - cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, - policy = ReferencePolicy.DYNAMIC, - referenceInterface = Feature.class) -@Properties({ - @Property(name = "felix.webconsole.label", value = "features"), - @Property(name = "felix.webconsole.title", value = "Features"), - @Property(name = "felix.webconsole.category", value = "Sling"), - @Property(name = "pattern", value = "/.*"), - @Property(name = "service.ranking", intValue = 0x4000) -}) +@Component(service = {Features.class, Filter.class, Servlet.class}, + configurationPolicy = ConfigurationPolicy.IGNORE, + property = { + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=org.apache.sling)", + HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN + "=/", + "felix.webconsole.label=features", + "felix.webconsole.title=Features", + "felix.webconsole.category=Sling", + Constants.SERVICE_RANKING + ":Integer=16384" + }) public class FeatureManager implements Features, Filter, Servlet { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -84,15 +78,18 @@ public class FeatureManager implements Features, Filter, Servlet { //--- Features + @Override public Feature[] getFeatures() { final Map<String, Feature> activeFeatures = this.activeFeatures; return activeFeatures.values().toArray(new Feature[activeFeatures.size()]); } + @Override public Feature getFeature(final String name) { return this.activeFeatures.get(name); } + @Override public boolean isEnabled(String featureName) { final Feature feature = this.getFeature(featureName); if (feature != null) { @@ -170,7 +167,8 @@ public class FeatureManager implements Features, Filter, Servlet { //--- Feature binding // bind method for Feature services - @SuppressWarnings("unused") + @Reference(cardinality = ReferenceCardinality.MULTIPLE, + policy = ReferencePolicy.DYNAMIC) private void bindFeature(final Feature f, final Map<String, Object> props) { synchronized (this.allFeatures) { final String name = f.getName(); diff --git a/src/main/java/org/apache/sling/featureflags/package-info.java b/src/main/java/org/apache/sling/featureflags/package-info.java index c1803b5..ff01425 100644 --- a/src/main/java/org/apache/sling/featureflags/package-info.java +++ b/src/main/java/org/apache/sling/featureflags/package-info.java @@ -63,8 +63,5 @@ * @version 1.0 * @see <a href="http://sling.apache.org/documentation/the-sling-engine/featureflags.html">Feature Flags</a> */ -@Version("1.0") [email protected]("1.0.1") package org.apache.sling.featureflags; - -import aQute.bnd.annotation.Version; - -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
