You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2016/07/29 13:12:05 UTC
svn commit: r1754513 - in
/sling/trunk/contrib/extensions/context-aware-config: api/ impl/ impl/src/
impl/src/main/ impl/src/main/java/ impl/src/main/java/org/
impl/src/main/java/org/apache/ impl/src/main/java/org/apache/sling/
impl/src/main/java/org/a...
Author: cziegeler
Date: Fri Jul 29 13:12:04 2016
New Revision: 1754513
URL: http://svn.apache.org/viewvc?rev=1754513&view=rev
Log:
SLING-5886 : Add dummy implementation
Added:
sling/trunk/contrib/extensions/context-aware-config/impl/
sling/trunk/contrib/extensions/context-aware-config/impl/README.txt (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/
sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java (with props)
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/
sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java (with props)
Modified:
sling/trunk/contrib/extensions/context-aware-config/api/pom.xml
Modified: sling/trunk/contrib/extensions/context-aware-config/api/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/api/pom.xml?rev=1754513&r1=1754512&r2=1754513&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/api/pom.xml (original)
+++ sling/trunk/contrib/extensions/context-aware-config/api/pom.xml Fri Jul 29 13:12:04 2016
@@ -27,7 +27,7 @@
<relativePath />
</parent>
- <artifactId>org.apache.sling.config.api</artifactId>
+ <artifactId>org.apache.sling.contextaware.config.api</artifactId>
<packaging>bundle</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Apache Sling Context-Aware-Config API</name>
Added: sling/trunk/contrib/extensions/context-aware-config/impl/README.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/README.txt?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/README.txt (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/README.txt Fri Jul 29 13:12:04 2016
@@ -0,0 +1,25 @@
+Apache Sling Configuration Implementation
+
+
+Getting Started
+===============
+
+This component uses a Maven 3 (http://maven.apache.org/) build
+environment. It requires a Java 7 JDK (or higher) and Maven (http://maven.apache.org/)
+3.3.9 or later. We recommend to use the latest Maven version.
+
+If you have Maven 3 installed, you can compile and
+package the jar using the following command:
+
+ mvn package
+
+See the Maven 3 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+ svn checkout https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/config/impl
+
+See the Subversion documentation for other source control features.
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/README.txt
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml Fri Jul 29 13:12:04 2016
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>27</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.contextaware.config.impl</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache Sling Context-Aware Config Implementation</name>
+ <description>Apache Sling Context Aware Config Implementation</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/impl</connection>
+ <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/context-aware-config/impl</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl</url>
+ </scm>
+
+ <properties>
+ <!-- Java 8 as minimum requirement -->
+ <sling.java.version>8</sling.java.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <executions>
+ <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
+ <execution>
+ <id>scr-metadata</id>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ <configuration>
+ <supportIncrementalBuild>true</supportIncrementalBuild>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- Export SCR metadata to classpath to have them available in unit tests -->
+ <exportScr>true</exportScr>
+ <instructions>
+ <Embed-Dependency>
+ org.apache.felix.scr;inline="org/apache/felix/scr/impl/inject/Annotations*|org/apache/felix/scr/impl/helper/Coercions*"
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+ <version>2.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock</artifactId>
+ <version>1.7.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.contextaware.config.api</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.4.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.osgi</artifactId>
+ <version>2.2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.3.2</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- The required classes o.a.f.scr.impl.helper.Annotations and o.a.f.scr.impl.helper.Coercions are inlined -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.0.87-beta</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.config.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.contextaware.config.ConfigurationResolver;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+
+@Component(service = AdapterFactory.class)
+public class ConfigAdapterFactory implements AdapterFactory {
+
+ private BundleTracker<ServiceRegistration<?>[]> bundleTracker;
+
+ @Reference
+ private ConfigurationResolver configurationResolver;
+
+ private ConcurrentMap<String, ClassMapping> classMappings = new ConcurrentHashMap<>();
+
+ @Activate
+ private void activate(BundleContext bundleContext) {
+ BundleTrackerCustomizer<ServiceRegistration<?>[]> bundlerTrackerCustomizer = new ConfigPackageBundleListener(bundleContext, this);
+ bundleTracker = new BundleTracker<ServiceRegistration<?>[]>(bundleContext, Bundle.ACTIVE, bundlerTrackerCustomizer);
+ bundleTracker.open();
+ }
+
+ @Deactivate
+ private void deactivate() {
+ bundleTracker.close();
+ bundleTracker = null;
+ }
+
+ @Override
+ public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+ if (!(adaptable instanceof Resource)) {
+ return null;
+ }
+ ClassMapping classMapping = classMappings.get(type.getName());
+ if (classMapping == null) {
+ return null;
+ }
+
+ // TODO: optimize class mapping to support default values and make it more efficient during runtime
+ Resource resource = (Resource)adaptable;
+ return configurationResolver.get(resource).as(type);
+ }
+
+ void addClassMapping(Class<?> configClass) {
+ classMappings.put(configClass.getName(), new ClassMapping(configClass));
+ }
+
+ void removeClassMapping(String configClassName) {
+ classMappings.remove(configClassName);
+ }
+
+ private static class ClassMapping {
+
+ @SuppressWarnings("unused")
+ private final Class<?> clazz;
+
+ public ClassMapping(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+
+ }
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigAdapterFactory.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.config.impl;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ConfigPackageBundleListener implements BundleTrackerCustomizer<ServiceRegistration<?>[]> {
+
+ static final String HEADER = "Sling-Config-Packages";
+
+ private static final Logger log = LoggerFactory.getLogger(ConfigPackageBundleListener.class);
+
+ private final BundleContext bundleContext;
+ private final ConfigAdapterFactory adapterFactory;
+
+ public ConfigPackageBundleListener(BundleContext bundleContext, ConfigAdapterFactory adapterFactory) {
+ this.bundleContext = bundleContext;
+ this.adapterFactory = adapterFactory;
+ }
+
+ @Override
+ public ServiceRegistration<?>[] addingBundle(Bundle bundle, BundleEvent event) {
+ Dictionary<String, String> headers = bundle.getHeaders();
+ String packageList = headers.get(HEADER);
+ if (packageList == null) {
+ return null;
+ }
+
+ List<ServiceRegistration<?>> regs = new ArrayList<ServiceRegistration<?>>();
+
+ packageList = StringUtils.deleteWhitespace(packageList);
+ String[] packages = StringUtils.split(packageList, ",");
+ for (String singlePackage : packages) {
+ Enumeration<URL> classUrls = bundle.findEntries("/" + singlePackage.replace('.', '/'), "*.class", true);
+
+ if (classUrls == null) {
+ log.warn("No configuration classes found in package {}, ignoring.", singlePackage);
+ continue;
+ }
+
+ while (classUrls.hasMoreElements()) {
+ String className = toClassName(classUrls.nextElement());
+ try {
+ Class<?> configType = bundle.loadClass(className);
+
+ // TODO: check for specific annotation on config class
+ if (configType.isAnnotation()) {
+ log.debug("{}: Add configuration class {}", bundle.getSymbolicName(), className);
+
+ adapterFactory.addClassMapping(configType);
+ ServiceRegistration reg = registerAdapterFactory(Resource.class, configType);
+ regs.add(reg);
+ }
+ }
+ catch (ClassNotFoundException ex) {
+ log.warn("Unable to load class: " + className, ex);
+ }
+
+ }
+ }
+ return regs.toArray(new ServiceRegistration[regs.size()]);
+ }
+
+ /**
+ * Convert class URL to class name.
+ */
+ private String toClassName(URL url) {
+ final String f = url.getFile();
+ final String cn = f.substring(1, f.length() - ".class".length());
+ return cn.replace('/', '.');
+ }
+
+ /**
+ * Registers an adapter factory for a annotated sling models class.
+ * @param adapterTypes Adapter (either the class itself, or interface or superclass of it)
+ * @param adaptableTypes Classes to adapt from
+ * @param implType Type of the implementation class
+ * @param condition Condition (optional)
+ * @return Service registration
+ */
+ private ServiceRegistration registerAdapterFactory(Class<?> adaptableType, Class<?> adapterType) {
+ Dictionary<String, Object> registrationProps = new Hashtable<String, Object>();
+ registrationProps.put(AdapterFactory.ADAPTABLE_CLASSES, adaptableType.getName());
+ registrationProps.put(AdapterFactory.ADAPTER_CLASSES, adapterType.getName());
+ return bundleContext.registerService(AdapterFactory.SERVICE_NAME, adapterFactory, registrationProps);
+ }
+
+ @Override
+ public void modifiedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] serviceRegistrations) {
+ // nothing to do
+ }
+
+ @Override
+ public void removedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] serviceRegistrations) {
+ for (ServiceRegistration reg : serviceRegistrations) {
+ ServiceReference ref = reg.getReference();
+ String adapterTypeName = PropertiesUtil.toString(ref.getProperty(AdapterFactory.ADAPTER_CLASSES), null);
+ adapterFactory.removeClassMapping(adapterTypeName);
+ reg.unregister();
+ }
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigPackageBundleListener.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.config.impl;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.felix.scr.impl.inject.Annotations;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.contextaware.config.ConfigurationBuilder;
+import org.apache.sling.contextaware.resource.ConfigurationResourceResolver;
+import org.osgi.framework.Bundle;
+
+class ConfigurationBuilderImpl implements ConfigurationBuilder {
+
+ private final Resource resource;
+ private final ConfigurationResourceResolver configurationResourceResolver;
+ private final Bundle bundle;
+
+ private String configName;
+
+ public ConfigurationBuilderImpl(Resource resource,
+ ConfigurationResourceResolver configurationResourceResolver, Bundle bundle) {
+ this.resource = resource;
+ this.configurationResourceResolver = configurationResourceResolver;
+ this.bundle = bundle;
+ }
+
+ @Override
+ public ConfigurationBuilder name(String configName) {
+ this.configName = configName;
+ return this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T as(Class<T> clazz) {
+ // TODO: this is only a dummy implementation
+ String name = StringUtils.defaultString(configName, clazz.getName());
+ ValueMap props = getValueMap(configurationResourceResolver, resource, name);
+ if (clazz == ValueMap.class) {
+ return (T)props;
+ }
+ return Annotations.toObject(clazz, props, bundle, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> Collection<T> asCollection(Class<T> clazz) {
+ // TODO: this is only a dummy implementation
+ String name = StringUtils.defaultString(configName, clazz.getName());
+ Collection<ValueMap> propsList = getValueMapCollection(configurationResourceResolver, resource, name);
+ if (clazz == ValueMap.class) {
+ return (Collection<T>)propsList;
+ }
+ return propsList.stream()
+ .map(props -> Annotations.toObject(clazz, props, bundle, true))
+ .collect(Collectors.toList());
+ }
+
+ private static ValueMap getValueMap(ConfigurationResourceResolver resolver, Resource resource, String configName) {
+ // TODO: this is only a dummy implementation
+ Resource configResource = resolver.getResource(resource, configName);
+ return ResourceUtil.getValueMap(configResource);
+ }
+
+ private static Collection<ValueMap> getValueMapCollection(ConfigurationResourceResolver resolver, Resource resource, String configName) {
+ // TODO: this is only a dummy implementation
+ Collection<Resource> configResources = resolver.getResourceList(resource, configName);
+ return configResources.stream()
+ .map(res -> ResourceUtil.getValueMap(res))
+ .collect(Collectors.toList());
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationBuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.config.impl;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.contextaware.config.ConfigurationBuilder;
+import org.apache.sling.contextaware.config.ConfigurationResolver;
+import org.apache.sling.contextaware.resource.ConfigurationResourceResolver;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(service=ConfigurationResolver.class)
+public class ConfigurationResolverImpl implements ConfigurationResolver {
+
+ @Reference
+ private ConfigurationResourceResolver configurationResourceResolver;
+
+ private BundleContext bundleContext;
+
+ @Activate
+ private void activate(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ @Override
+ public ConfigurationBuilder get(Resource resource) {
+ return new ConfigurationBuilderImpl(resource,
+ configurationResourceResolver, bundleContext.getBundle());
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.resource.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.contextaware.resource.ConfigurationResourceResolver;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=ConfigurationResourceResolver.class)
+public class ConfigurationResourceResolverImpl implements ConfigurationResourceResolver {
+
+ @Override
+ public Resource getResource(Resource resource, String configName) {
+ // TODO: this is only a dummy implementation
+ String configPath = "/conf" + getContextPath(resource) + "/" + configName;
+ return resource.getResourceResolver().getResource(configPath);
+ }
+
+ @Override
+ public Collection<Resource> getResourceList(Resource resource, String configName) {
+ // TODO: this is only a dummy implementation
+ String configPath = "/conf" + getContextPath(resource) + "/" + configName;
+ Resource configResource = resource.getResourceResolver().getResource(configPath);
+ if (configResource != null) {
+ return StreamSupport.stream(configResource.getChildren().spliterator(), false)
+ .collect(Collectors.toList());
+ }
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getContextPath(Resource resource) {
+ // TODO: this is only a dummy implementation
+ String[] pathParts = resource.getPath().split("/");
+ return "/" + pathParts[1] + "/" + pathParts[2];
+ }
+
+ @Override
+ public List<String> getAllContextPaths(Resource resource) {
+ // TODO: this is only a dummy implementation
+ List<String> items = new ArrayList<String>();
+ items.add(getContextPath(resource));
+ return items;
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/main/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.example;
+
+import static org.apache.sling.config.example.AllTypesDefaults.BOOL_DEFAULT;
+import static org.apache.sling.config.example.AllTypesDefaults.BOOL_DEFAULT_2;
+import static org.apache.sling.config.example.AllTypesDefaults.DOUBLE_DEFAULT;
+import static org.apache.sling.config.example.AllTypesDefaults.DOUBLE_DEFAULT_2;
+import static org.apache.sling.config.example.AllTypesDefaults.INT_DEFAULT;
+import static org.apache.sling.config.example.AllTypesDefaults.INT_DEFAULT_2;
+import static org.apache.sling.config.example.AllTypesDefaults.LONG_DEFAULT;
+import static org.apache.sling.config.example.AllTypesDefaults.LONG_DEFAULT_2;
+import static org.apache.sling.config.example.AllTypesDefaults.STRING_DEFAULT;
+import static org.apache.sling.config.example.AllTypesDefaults.STRING_DEFAULT_2;
+
+public @interface AllTypesConfig {
+
+ String stringParam();
+
+ String stringParamWithDefault() default STRING_DEFAULT;
+
+ int intParam();
+
+ int intParamWithDefault() default INT_DEFAULT;
+
+ long longParam();
+
+ long longParamWithDefault() default LONG_DEFAULT;
+
+ double doubleParam();
+
+ double doubleParamWithDefault() default DOUBLE_DEFAULT;
+
+ boolean boolParam();
+
+ boolean boolParamWithDefault() default BOOL_DEFAULT;
+
+ String[] stringArrayParam();
+
+ String[] stringArrayParamWithDefault() default { STRING_DEFAULT, STRING_DEFAULT_2 };
+
+ int[] intArrayParam();
+
+ int[] intArrayParamWithDefault() default { INT_DEFAULT, INT_DEFAULT_2 };
+
+ long[] longArrayParam();
+
+ long[] longArrayParamWithDefault() default { LONG_DEFAULT, LONG_DEFAULT_2 };
+
+ double[] doubleArrayParam();
+
+ double[] doubleArrayParamWithDefault() default { DOUBLE_DEFAULT, DOUBLE_DEFAULT_2 };
+
+ boolean[] boolArrayParam();
+
+ boolean[] boolArrayParamWithDefault() default { BOOL_DEFAULT, BOOL_DEFAULT_2 };
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesConfig.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.example;
+
+public final class AllTypesDefaults {
+
+ private AllTypesDefaults() {
+ // constants only
+ }
+
+ public static final String STRING_DEFAULT = "myDefault";
+
+ public static final String STRING_DEFAULT_2 = "myDefault2";
+
+ public static final int INT_DEFAULT = 12345;
+
+ public static final int INT_DEFAULT_2 = 23456;
+
+ public static final long LONG_DEFAULT = 1234567890L;
+
+ public static final long LONG_DEFAULT_2 = 2345678901L;
+
+ public static final double DOUBLE_DEFAULT = 123.456d;
+
+ public static final double DOUBLE_DEFAULT_2 = 234.567d;
+
+ public static final boolean BOOL_DEFAULT = true;
+
+ public static final boolean BOOL_DEFAULT_2 = false;
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/AllTypesDefaults.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.example;
+
+public @interface ListConfig {
+
+ String stringParam();
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/ListConfig.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.example;
+
+public @interface NestedConfig {
+
+ String stringParam();
+
+ SimpleConfig subConfig();
+
+ ListConfig[] subListConfig();
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/NestedConfig.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.config.example;
+
+public @interface SimpleConfig {
+
+ String stringParam();
+
+ int intParam();
+
+ boolean boolParam();
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/config/example/SimpleConfig.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.config.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.config.example.AllTypesConfig;
+import org.apache.sling.config.example.ListConfig;
+import org.apache.sling.config.example.NestedConfig;
+import org.apache.sling.config.example.SimpleConfig;
+import org.apache.sling.contextaware.config.ConfigurationResolver;
+import org.apache.sling.contextaware.resource.impl.ConfigurationResourceResolverImpl;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class ConfigurationResolverImplTest {
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ private ConfigurationResolver underTest;
+
+ private Resource site1Page1;
+ private Resource site2Page1;
+
+ @Before
+ public void setUp() {
+ context.registerInjectActivateService(new ConfigurationResourceResolverImpl());
+ underTest = context.registerInjectActivateService(new ConfigurationResolverImpl());
+
+ // config resources
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.SimpleConfig", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue1")
+ .put("intParam", 111)
+ .put("boolParam", true)
+ .build());
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.AllTypesConfig", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue2")
+ .put("intParam", 222)
+ .put("longParam", 3456L)
+ .put("doubleParam", 0.123d)
+ .put("boolParam", true)
+ .build());
+
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.NestedConfig", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue3")
+ .build());
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.NestedConfig/subConfig", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue4")
+ .put("intParam", 444)
+ .put("boolParam", true)
+ .build());
+
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.ListConfig/1", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue1.1")
+ .build());
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.ListConfig/2", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue1.2")
+ .build());
+ context.create().resource("/conf/content/site2/org.apache.sling.config.example.ListConfig/3", ImmutableMap.<String, Object>builder()
+ .put("stringParam", "configValue1.3")
+ .build());
+
+ // content resources
+ site1Page1 = context.create().resource("/content/site1/page1");
+ site2Page1 = context.create().resource("/content/site2/page1");
+ }
+
+ @Test
+ public void testNonExistingConfig_Simple() {
+ SimpleConfig cfg = underTest.get(site1Page1).as(SimpleConfig.class);
+
+ assertNull(cfg.stringParam());
+ assertEquals(0, cfg.intParam());
+ assertEquals(false, cfg.boolParam());
+ }
+
+ @Test
+ public void testNonExistingConfig_AllTypes() {
+ AllTypesConfig cfg = underTest.get(site1Page1).as(AllTypesConfig.class);
+
+ assertNull(cfg.stringParam());
+ //FIXME: assertEquals(STRING_DEFAULT, cfg.stringArrayParamWithDefault());
+ assertEquals(0, cfg.intParam());
+ //FIXME: assertEquals(INT_DEFAULT, cfg.intParamWithDefault());
+ assertEquals(0L, cfg.longParam());
+ //FIXME: assertEquals(LONG_DEFAULT, cfg.longParamWithDefault());
+ assertEquals(0d, cfg.doubleParam(), 0.001d);
+ //FIXME: assertEquals(DOUBLE_DEFAULT, cfg.doubleParamWithDefault(), 0.001d);
+ assertEquals(false, cfg.boolParam());
+ //FIXME: assertEquals(BOOL_DEFAULT, cfg.boolParamWithDefault());
+
+ assertNull(cfg.stringArrayParam());
+ //FIXME: assertArrayEquals(new String[] { STRING_DEFAULT, STRING_DEFAULT_2 }, cfg.stringArrayParamWithDefault());
+ assertNull(cfg.intArrayParam());
+ //FIXME: assertArrayEquals(new int[] { INT_DEFAULT, INT_DEFAULT_2 }, cfg.intArrayParamWithDefault());
+ assertNull(cfg.longArrayParam());
+ //FIXME: assertArrayEquals(new long[] { LONG_DEFAULT, LONG_DEFAULT_2 }, cfg.longArrayParamWithDefault());
+ assertNull(cfg.doubleArrayParam());
+ //FIXME: assertArrayEquals(new double[] { DOUBLE_DEFAULT, DOUBLE_DEFAULT_2 }, cfg.doubleArrayParamWithDefault(), 0.001d);
+ assertNull(cfg.boolArrayParam());
+ //FIXME: assertArrayEquals(new boolean[] { BOOL_DEFAULT, BOOL_DEFAULT_2 }, cfg.boolArrayParamWithDefault());
+ }
+
+ @Test
+ public void testNonExistingConfig_List() {
+ Collection<ListConfig> cfgList = underTest.get(site1Page1).asCollection(ListConfig.class);
+ assertTrue(cfgList.isEmpty());
+ }
+
+ @Test
+ public void testNonExistingConfig_Nested() {
+ NestedConfig cfg = underTest.get(site1Page1).as(NestedConfig.class);
+
+ assertNull(cfg.stringParam());
+ assertNull(cfg.subConfig());
+ assertEquals(0, cfg.subListConfig().length);
+ }
+
+
+ @Test
+ public void testConfig_Simple() {
+ SimpleConfig cfg = underTest.get(site2Page1).as(SimpleConfig.class);
+
+ assertEquals("configValue1", cfg.stringParam());
+ assertEquals(111, cfg.intParam());
+ assertEquals(true, cfg.boolParam());
+ }
+
+ @Test
+ public void testConfig_AllTypes() {
+ AllTypesConfig cfg = underTest.get(site2Page1).as(AllTypesConfig.class);
+
+ assertEquals("configValue2", cfg.stringParam());
+ //FIXME: assertEquals(STRING_DEFAULT, cfg.stringArrayParamWithDefault());
+ assertEquals(222, cfg.intParam());
+ //FIXME: assertEquals(INT_DEFAULT, cfg.intParamWithDefault());
+ assertEquals(3456L, cfg.longParam());
+ //FIXME: assertEquals(LONG_DEFAULT, cfg.longParamWithDefault());
+ assertEquals(0.123d, cfg.doubleParam(), 0.001d);
+ //FIXME: assertEquals(DOUBLE_DEFAULT, cfg.doubleParamWithDefault(), 0.001d);
+ assertEquals(true, cfg.boolParam());
+ //FIXME: assertEquals(BOOL_DEFAULT, cfg.boolParamWithDefault());
+
+ //FIXME: assertArrayEquals(new String[0], cfg.stringArrayParam());
+ //FIXME: assertArrayEquals(new String[] { STRING_DEFAULT, STRING_DEFAULT_2 }, cfg.stringArrayParamWithDefault());
+ //FIXME: assertArrayEquals(new int[0], cfg.intArrayParam());
+ //FIXME: assertArrayEquals(new int[] { INT_DEFAULT, INT_DEFAULT_2 }, cfg.intArrayParamWithDefault());
+ //FIXME: assertArrayEquals(new long[0], cfg.longArrayParam());
+ //FIXME: assertArrayEquals(new long[] { LONG_DEFAULT, LONG_DEFAULT_2 }, cfg.longArrayParamWithDefault());
+ //FIXME: assertArrayEquals(new double[0], cfg.doubleArrayParam(), 0.001d);
+ //FIXME: assertArrayEquals(new double[] { DOUBLE_DEFAULT, DOUBLE_DEFAULT_2 }, cfg.doubleArrayParamWithDefault(), 0.001d);
+ //FIXME: assertArrayEquals(new boolean[0], cfg.boolArrayParam());
+ //FIXME: assertArrayEquals(new boolean[] { BOOL_DEFAULT, BOOL_DEFAULT_2 }, cfg.boolArrayParamWithDefault());
+ }
+
+ @Test
+ public void testConfig_List() {
+ Collection<ListConfig> cfgList = underTest.get(site2Page1).asCollection(ListConfig.class);
+
+ assertEquals(3, cfgList.size());
+ Iterator<ListConfig> cfgIterator = cfgList.iterator();
+ assertEquals("configValue1.1", cfgIterator.next().stringParam());
+ assertEquals("configValue1.2", cfgIterator.next().stringParam());
+ assertEquals("configValue1.3", cfgIterator.next().stringParam());
+ }
+
+ @Test
+ public void testConfig_Nested() {
+ NestedConfig cfg = underTest.get(site2Page1).as(NestedConfig.class);
+
+ assertEquals("configValue3", cfg.stringParam());
+
+ // FIXME: nested configurations do not work currently
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/config/impl/ConfigurationResolverImplTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java?rev=1754513&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java (added)
+++ sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java Fri Jul 29 13:12:04 2016
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.contextaware.resource.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.contextaware.resource.ConfigurationResourceResolver;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class ConfigurationResourceResolverImplTest {
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ private ConfigurationResourceResolver underTest;
+
+ private Resource site1Page1;
+ private Resource site2Page1;
+
+ @Before
+ public void setUp() {
+ underTest = context.registerInjectActivateService(new ConfigurationResourceResolverImpl());
+
+ // content resources
+ site1Page1 = context.create().resource("/content/site1/page1");
+ site2Page1 = context.create().resource("/content/site2/page1");
+ }
+
+ @Test
+ public void testGetValueMapContextPath() {
+ assertEquals("/content/site1", underTest.getContextPath(site1Page1));
+ assertEquals("/content/site2", underTest.getContextPath(site2Page1));
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/context-aware-config/impl/src/test/java/org/apache/sling/contextaware/resource/impl/ConfigurationResourceResolverImplTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url