Author: cziegeler
Date: Mon Aug 1 16:16:00 2016
New Revision: 1754774
URL: http://svn.apache.org/viewvc?rev=1754774&view=rev
Log:
SLING-5939 : Register filter using http whiteboard
Modified:
sling/trunk/bundles/extensions/feature-flags/pom.xml
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ExecutionContext.java
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Features.java
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/package-info.java
Modified: sling/trunk/bundles/extensions/feature-flags/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/pom.xml?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/feature-flags/pom.xml (original)
+++ sling/trunk/bundles/extensions/feature-flags/pom.xml Mon Aug 1 16:16:00
2016
@@ -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>
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ExecutionContext.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ExecutionContext.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ExecutionContext.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ExecutionContext.java
Mon Aug 1 16:16:00 2016
@@ -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
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
Mon Aug 1 16:16:00 2016
@@ -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.
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Features.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Features.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Features.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Features.java
Mon Aug 1 16:16:00 2016
@@ -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
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ConfiguredFeature.java
Mon Aug 1 16:16:00 2016
@@ -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 {
+ @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;
+ }
+
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";
-
- @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";
-
- @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 implement
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
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
Mon Aug 1 16:16:00 2016
@@ -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 F
//--- 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 F
//--- 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();
Modified:
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/package-info.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/package-info.java?rev=1754774&r1=1754773&r2=1754774&view=diff
==============================================================================
---
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/package-info.java
(original)
+++
sling/trunk/bundles/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/package-info.java
Mon Aug 1 16:16:00 2016
@@ -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;
-