Author: sseifert
Date: Tue Feb 23 00:09:40 2016
New Revision: 1731761
URL: http://svn.apache.org/viewvc?rev=1731761&view=rev
Log:
SLING-5546 Update to Sling API 2.11 and dependencies
Added:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
(with props)
Modified:
sling/trunk/testing/mocks/sling-mock/pom.xml
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
Modified: sling/trunk/testing/mocks/sling-mock/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/pom.xml?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock/pom.xml Tue Feb 23 00:09:40 2016
@@ -28,7 +28,7 @@
</parent>
<artifactId>org.apache.sling.testing.sling-mock</artifactId>
- <version>1.6.3-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Testing Sling Mock</name>
@@ -45,7 +45,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>1.7.2</version>
+ <version>2.0.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -70,81 +70,93 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
- <version>1.1.0</version>
+ <version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
- <version>1.1.0</version>
+ <version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.4.0</version>
+ <version>2.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.resourceresolver</artifactId>
- <version>1.1.0</version>
+ <version>1.4.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.api</artifactId>
- <version>2.2.0</version>
+ <version>2.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.resource</artifactId>
- <version>2.3.6</version>
+ <version>2.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.mime</artifactId>
- <version>2.1.4</version>
+ <version>2.1.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.json</artifactId>
- <version>2.0.6</version>
+ <version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.2.0</version>
+ <version>2.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.classloader</artifactId>
- <version>1.3.0</version>
+ <version>1.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.settings</artifactId>
- <version>1.2.2</version>
+ <version>1.3.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.i18n</artifactId>
- <version>2.2.4</version>
+ <version>2.4.4</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.adapter</artifactId>
+ <version>2.1.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ <version>2.11.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
- <version>3.2.1</version>
+ <version>3.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -204,10 +216,10 @@
</dependency>
<dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
- <scope>compile</scope>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>1.0</version>
+ <scope>compile</scope>
</dependency>
<dependency>
@@ -267,25 +279,4 @@
</plugins>
</build>
- <!-- Profiles to run unit tests against different JCR Resource versions -->
- <profiles>
- <profile>
- <id>jcr.resource-2.5.4</id>
- <dependencies>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.api</artifactId>
- <version>2.9.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.jcr.resource</artifactId>
- <version>2.5.4</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- </profile>
- </profiles>
-
</project>
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
Tue Feb 23 00:09:40 2016
@@ -22,26 +22,34 @@ import static org.apache.sling.api.adapt
import static org.apache.sling.api.adapter.AdapterFactory.ADAPTER_CLASSES;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.felix.scr.annotations.Component;
+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.adapter.Adaption;
+import org.apache.sling.adapter.internal.AdapterFactoryDescriptor;
+import org.apache.sling.adapter.internal.AdapterFactoryDescriptorMap;
+import org.apache.sling.adapter.internal.AdaptionImpl;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
@@ -49,12 +57,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * This is a copy of org.apache.sling.adapter.internal.AdpaterManagerImpl from
Sling Adapter 2.1.0,
+ * This is a copy of org.apache.sling.adapter.internal.AdpaterManagerImpl from
Sling Adapter 2.1.6,
* with all calls to SyntheticResource.setAdapterManager/unsetAdapterManager
disabled, because this would
* break the {@link ThreadsafeMockAdapterManagerWrapper} concept.
+ * Additionally the reference to PackageAdmin is disabled.
*/
@Component(immediate=true)
@Service
+@Properties({
+ @Property(name=Constants.SERVICE_DESCRIPTION, value="Sling Adapter
Manager"),
+ @Property(name=Constants.SERVICE_VENDOR, value="The Apache Software
Foundation")
+
+})
@Reference(name="AdapterFactory", referenceInterface=AdapterFactory.class,
cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
policy=ReferencePolicy.DYNAMIC)
public class MockAdapterManagerImpl implements AdapterManager {
@@ -102,6 +116,12 @@ public class MockAdapterManagerImpl impl
@Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY,
policy=ReferencePolicy.DYNAMIC)
private volatile EventAdmin eventAdmin;
+ // DISABLED IN THIS COPY OF CLASS
+ /*
+ @Reference
+ private PackageAdmin packageAdmin;
+ */
+
// ---------- AdapterManager interface
-------------------------------------
/**
@@ -181,7 +201,6 @@ public class MockAdapterManagerImpl impl
/**
* Bind a new adapter factory.
- * @param reference Service reference
*/
protected void bindAdapterFactory(final ServiceReference reference) {
boolean create = true;
@@ -199,8 +218,7 @@ public class MockAdapterManagerImpl impl
}
/**
- * Unbind an adapter factory.
- * @param reference Service reference
+ * Unbind a adapter factory.
*/
protected void unbindAdapterFactory(final ServiceReference reference) {
unregisterAdapterFactory(reference);
@@ -242,6 +260,21 @@ public class MockAdapterManagerImpl impl
return;
}
+ // DISABLED IN THIS COPY OF CLASS
+ /*
+ for (String clazz : adaptables) {
+ if (!checkPackage(packageAdmin, clazz)) {
+ log.warn("Adaptable class {} in factory service {} is not in
an exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
+ }
+ }
+
+ for (String clazz : adapters) {
+ if (!checkPackage(packageAdmin, clazz)) {
+ log.warn("Adapter class {} in factory service {} is not in an
exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
+ }
+ }
+ */
+
final AdapterFactoryDescriptor factoryDesc = new
AdapterFactoryDescriptor(context,
reference, adapters);
@@ -262,16 +295,51 @@ public class MockAdapterManagerImpl impl
// clear the factory cache to force rebuild on next access
this.factoryCache.clear();
+ // register adaption
+ final Dictionary<String, Object> props = new Hashtable<String,
Object>();
+ props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
+ props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
+
+ ServiceRegistration adaptionRegistration =
this.context.getBundleContext().registerService(
+ Adaption.class.getName(), AdaptionImpl.INSTANCE, props);
+ if (log.isDebugEnabled()) {
+ log.debug("Registered service {} with {} : {} and {} : {}", new
Object[] { Adaption.class.getName(),
+ SlingConstants.PROPERTY_ADAPTABLE_CLASSES,
Arrays.toString(adaptables),
+ SlingConstants.PROPERTY_ADAPTER_CLASSES,
Arrays.toString(adapters) });
+ }
+ factoryDesc.setAdaption(adaptionRegistration);
+
// send event
final EventAdmin localEA = this.eventAdmin;
if ( localEA != null ) {
- final Dictionary<String, Object> props = new Hashtable<String,
Object>();
- props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
- props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
localEA.postEvent(new
Event(SlingConstants.TOPIC_ADAPTER_FACTORY_ADDED,
props));
}
}
+
+ static String getPackageName(String clazz) {
+ final int lastDot = clazz.lastIndexOf('.');
+ return lastDot <= 0 ? "" : clazz.substring(0, lastDot);
+ }
+
+ /**
+ * Check that the package containing the class is exported or is a java.*
+ * class.
+ *
+ * @param packageAdmin the PackageAdmin service
+ * @param clazz the class name
+ * @return true if the package is exported
+ */
+ // DISABLED IN THIS COPY OF CLASS
+ /*
+ static boolean checkPackage(PackageAdmin packageAdmin, String clazz) {
+ final String packageName = getPackageName(clazz);
+ if (packageName.startsWith("java.")) {
+ return true;
+ }
+ return packageAdmin.getExportedPackage(packageName) != null;
+ }
+ */
/**
* Unregisters the {@link AdapterFactory} referred to by the service
@@ -291,13 +359,25 @@ public class MockAdapterManagerImpl impl
boolean factoriesModified = false;
AdapterFactoryDescriptorMap adfMap = null;
+
+ AdapterFactoryDescriptor removedDescriptor = null;
for (final String adaptable : adaptables) {
synchronized ( this.descriptors ) {
adfMap = this.descriptors.get(adaptable);
}
if (adfMap != null) {
synchronized ( adfMap ) {
- factoriesModified |= (adfMap.remove(reference) != null);
+ AdapterFactoryDescriptor factoryDesc =
adfMap.remove(reference);
+ if (factoryDesc != null) {
+ factoriesModified = true;
+ // A single ServiceReference should correspond to a
single Adaption service being registered
+ // Since the code paths above does not fully guarantee
it though, let's keep this check in place
+ if (removedDescriptor != null && removedDescriptor !=
factoryDesc) {
+ log.error("When unregistering reference {} got
duplicate service descriptors {} and {}. Unregistration of {} services may be
incomplete.",
+ new Object[] { reference,
removedDescriptor, factoryDesc, Adaption.class.getName()} );
+ }
+ removedDescriptor = factoryDesc;
+ }
}
}
}
@@ -308,6 +388,16 @@ public class MockAdapterManagerImpl impl
this.factoryCache.clear();
}
+ // unregister adaption
+ if (removedDescriptor != null) {
+ removedDescriptor.getAdaption().unregister();
+ if (log.isDebugEnabled()) {
+ log.debug("Unregistered service {} with {} : {} and {} : {}",
new Object[] { Adaption.class.getName(),
+ SlingConstants.PROPERTY_ADAPTABLE_CLASSES,
Arrays.toString(adaptables),
+ SlingConstants.PROPERTY_ADAPTER_CLASSES,
Arrays.toString(adapters) });
+ }
+ }
+
// send event
final EventAdmin localEA = this.eventAdmin;
if ( localEA != null ) {
@@ -428,64 +518,4 @@ public class MockAdapterManagerImpl impl
}
}
}
-
-
- /**
- * The <code>AdapterFactoryDescriptor</code> is an entry in the
- * {@link AdapterFactoryDescriptorMap} conveying the list of adapter
(target)
- * types and the respective {@link AdapterFactory}.
- */
- private static class AdapterFactoryDescriptor {
-
- private volatile AdapterFactory factory;
-
- private final String[] adapters;
-
- private final ServiceReference reference;
-
- private final ComponentContext context;
-
- public AdapterFactoryDescriptor(
- final ComponentContext context,
- final ServiceReference reference,
- final String[] adapters) {
- this.reference = reference;
- this.context = context;
- this.adapters = adapters;
- }
-
- public AdapterFactory getFactory() {
- if ( factory == null ) {
- factory = (AdapterFactory) context.locateService(
- "AdapterFactory", reference);
- }
- return factory;
- }
-
- public String[] getAdapters() {
- return adapters;
- }
- }
-
- /**
- * The <code>AdapterFactoryDescriptorMap</code> is a sorted map of
- * {@link AdapterFactoryDescriptor} instances indexed (and ordered) by
their
- * {@link ServiceReference}. This map is used to organize the
- * registered {@link org.apache.sling.api.adapter.AdapterFactory} services
for
- * a given adaptable type.
- * <p>
- * Each entry in the map is a {@link AdapterFactoryDescriptor} thus
enabling the
- * registration of multiple factories for the same (adaptable, adapter)
type
- * tuple. Of course only the first entry (this is the reason for having a
sorted
- * map) for such a given tuple is actually being used. If that first
instance is
- * removed the eventual second instance may actually be used instead.
- */
- private static class AdapterFactoryDescriptorMap extends
- TreeMap<ServiceReference, AdapterFactoryDescriptor> {
-
- private static final long serialVersionUID = 2L;
-
- }
-
-
}
Added:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java?rev=1731761&view=auto
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
(added)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
Tue Feb 23 00:09:40 2016
@@ -0,0 +1,33 @@
+/*
+ * 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.testing.mock.sling;
+
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
+
+/**
+ * Mock implementation of {@link DynamicClassLoaderManager}.
+ */
+class MockDynamicClassLoaderManager implements DynamicClassLoaderManager {
+
+ @Override
+ public ClassLoader getDynamicClassLoader() {
+ return MockDynamicClassLoaderManager.class.getClassLoader();
+ }
+
+}
Propchange:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Tue Feb 23 00:09:40 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockDynamicClassLoaderManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrSlingRepository.java
Tue Feb 23 00:09:40 2016
@@ -116,4 +116,10 @@ public final class MockJcrSlingRepositor
return this.repository.login();
}
+ @Override
+ public Session impersonateFromService(String subServiceName, Credentials
credentials, String workspaceName)
+ throws LoginException, RepositoryException {
+ return this.repository.login(credentials);
+ }
+
}
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java
Tue Feb 23 00:09:40 2016
@@ -23,18 +23,17 @@ import java.util.Hashtable;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.query.Query;
-import org.apache.sling.api.resource.QueriableResourceProvider;
-import org.apache.sling.api.resource.ResourceProvider;
-import org.apache.sling.api.resource.ResourceProviderFactory;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.jcr.api.SlingRepository;
-import
org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory;
+import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider;
+import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
+import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.apache.sling.testing.mock.osgi.MockEventAdmin;
import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.osgi.framework.BundleContext;
@@ -66,15 +65,15 @@ class ResourceResolverFactoryInitializer
registerJcrNodeTypes(slingRepository, nodeTypeMode);
// initialize JCR resource provider factory
- ensureJcrResourceProviderFactoryDependencies(bundleContext);
- initializeJcrResourceProviderFactory(bundleContext);
+ ensureJcrResourceProviderDependencies(bundleContext);
+ initializeJcrResourceProvider(bundleContext);
}
// initialize resource resolver factory activator
ensureResourceResolverFactoryActivatorDependencies(bundleContext);
initializeResourceResolverFactoryActivator(bundleContext);
- ServiceReference factoryRef =
bundleContext.getServiceReference(ResourceResolverFactory.class.getName());
+ ServiceReference<ResourceResolverFactory> factoryRef =
bundleContext.getServiceReference(ResourceResolverFactory.class);
if (factoryRef == null) {
throw new IllegalStateException("Unable to get
ResourceResolverFactory.");
}
@@ -85,26 +84,23 @@ class ResourceResolverFactoryInitializer
* Ensure dependencies for JcrResourceProviderFactory are present.
* @param bundleContext Bundle context
*/
- private static void
ensureJcrResourceProviderFactoryDependencies(BundleContext bundleContext) {
+ private static void ensureJcrResourceProviderDependencies(BundleContext
bundleContext) {
+ bundleContext.registerService(DynamicClassLoaderManager.class, new
MockDynamicClassLoaderManager(), null);
// setup PathMapper which is a mandatory service for
JcrProviderFactory (since org.apache.sling.jcr.resource 2.5.4)
// use reflection to not depend on it if running with older version of
org.apache.sling.jcr.resource
- registerServiceIfFoundInClasspath(bundleContext,
"org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper");
+ registerServiceIfFoundInClasspath(bundleContext,
PathMapper.class.getName(), PathMapper.class.getName());
}
/**
* Initialize JCR resource provider factory.
* @param bundleContext Bundle context
*/
- @SuppressWarnings("deprecation")
- private static void initializeJcrResourceProviderFactory(BundleContext
bundleContext) {
+ private static void initializeJcrResourceProvider(BundleContext
bundleContext) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
- config.put(ResourceProvider.ROOTS, new String[] { "/" });
- config.put(QueriableResourceProvider.LANGUAGES, new String[] {
Query.XPATH, Query.SQL, Query.JCR_SQL2 });
-
- JcrResourceProviderFactory factory = new JcrResourceProviderFactory();
+ JcrResourceProvider factory = new JcrResourceProvider();
MockOsgi.injectServices(factory, bundleContext);
MockOsgi.activate(factory, bundleContext, config);
- bundleContext.registerService(ResourceProviderFactory.class.getName(),
factory, config);
+ bundleContext.registerService(ResourceProvider.class, factory, config);
}
/**
@@ -126,8 +122,6 @@ class ResourceResolverFactoryInitializer
*/
private static void
initializeResourceResolverFactoryActivator(BundleContext bundleContext) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
- config.put("resource.resolver.required.providers", new String[0]);
-
ResourceResolverFactoryActivator activator = new
ResourceResolverFactoryActivator();
MockOsgi.injectServices(activator, bundleContext);
MockOsgi.activate(activator, bundleContext, config);
@@ -167,10 +161,11 @@ class ResourceResolverFactoryInitializer
* and if no service with this class is already registered.
* @param className Service class name
*/
- private static void registerServiceIfFoundInClasspath(BundleContext
bundleContext, String className) {
+ private static void registerServiceIfFoundInClasspath(BundleContext
bundleContext, String serviceClassName, String implClassName) {
try {
- Class<?> serviceClass = Class.forName(className);
- Object instance = serviceClass.newInstance();
+ Class<?> serviceClass = Class.forName(serviceClassName);
+ Class<?> implClass = Class.forName(implClassName);
+ Object instance = implClass.newInstance();
registerServiceIfNotPresent(bundleContext, serviceClass, instance);
}
catch (ClassNotFoundException ex) {
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
Tue Feb 23 00:09:40 2016
@@ -87,7 +87,7 @@ class ThreadsafeMockAdapterManagerWrappe
if (bundleContext == null) {
setBundleContext(MockOsgi.newBundleContext());
}
- ServiceReference serviceReference =
bundleContext.getServiceReference(AdapterManager.class.getName());
+ ServiceReference<AdapterManager> serviceReference =
bundleContext.getServiceReference(AdapterManager.class);
if (serviceReference != null) {
return
(AdapterManager)bundleContext.getService(serviceReference);
}
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/ModelAdapterFactoryUtil.java
Tue Feb 23 00:09:40 2016
@@ -18,13 +18,16 @@
*/
package org.apache.sling.testing.mock.sling.context;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.cert.X509Certificate;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
@@ -59,7 +62,6 @@ final class ModelAdapterFactoryUtil {
MockOsgi.sendBundleEvent(bundleContext, event);
}
- @SuppressWarnings("unused")
private static class ModelsPackageBundle implements Bundle {
private final String packageName;
@@ -78,14 +80,14 @@ final class ModelAdapterFactoryUtil {
}
@Override
- public Dictionary getHeaders() {
- Dictionary<String, Object> headers = new Hashtable<String,
Object>();
+ public Dictionary<String,String> getHeaders() {
+ Dictionary<String, String> headers = new Hashtable<String,
String>();
headers.put("Sling-Model-Packages", this.packageName);
return headers;
}
@Override
- public Enumeration findEntries(String path, String filePattern,
boolean recurse) {
+ public Enumeration<URL> findEntries(String path, String filePattern,
boolean recurse) {
Reflections reflections = new Reflections(this.packageName);
Set<Class<?>> types =
reflections.getTypesAnnotatedWith(Model.class);
Vector<URL> urls = new Vector<URL>(); // NOPMD
@@ -100,7 +102,7 @@ final class ModelAdapterFactoryUtil {
}
@Override
- public Class loadClass(String name) throws ClassNotFoundException {
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
return getClass().getClassLoader().loadClass(name);
}
@@ -155,12 +157,12 @@ final class ModelAdapterFactoryUtil {
}
@Override
- public ServiceReference[] getRegisteredServices() { // NOPMD
+ public ServiceReference<?>[] getRegisteredServices() { // NOPMD
return null;
}
@Override
- public ServiceReference[] getServicesInUse() { // NOPMD
+ public ServiceReference<?>[] getServicesInUse() { // NOPMD
return null;
}
@@ -175,7 +177,7 @@ final class ModelAdapterFactoryUtil {
}
@Override
- public Dictionary getHeaders(String locale) {
+ public Dictionary<String,String> getHeaders(String locale) {
return null;
}
@@ -185,12 +187,12 @@ final class ModelAdapterFactoryUtil {
}
@Override
- public Enumeration getResources(String name) throws IOException {
+ public Enumeration<URL> getResources(String name) throws IOException {
return null;
}
@Override
- public Enumeration getEntryPaths(String path) {
+ public Enumeration<String> getEntryPaths(String path) {
return null;
}
@@ -204,16 +206,31 @@ final class ModelAdapterFactoryUtil {
return 0;
}
- // this is part of org.osgi 4.2.0
- public Map getSignerCertificates(int signersType) {
+ @Override
+ public Map<X509Certificate, List<X509Certificate>>
getSignerCertificates(int signersType) {
return null;
}
- // this is part of org.osgi 4.2.0
+ @Override
public Version getVersion() {
return null;
}
+ @Override
+ public int compareTo(Bundle o) {
+ return 0;
+ }
+
+ @Override
+ public <A> A adapt(Class<A> type) {
+ return null;
+ }
+
+ @Override
+ public File getDataFile(String filename) {
+ return null;
+ }
+
}
}
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
Tue Feb 23 00:09:40 2016
@@ -308,9 +308,9 @@ public class SlingContextImpl extends Os
*/
public final void runMode(String... runModes) {
Set<String> newRunModes = ImmutableSet.<String>
builder().add(runModes).build();
- ServiceReference ref =
bundleContext().getServiceReference(SlingSettingsService.class.getName());
+ ServiceReference<SlingSettingsService> ref =
bundleContext().getServiceReference(SlingSettingsService.class);
if (ref != null) {
- MockSlingSettingService slingSettings = (MockSlingSettingService)
bundleContext().getService(ref);
+ MockSlingSettingService slingSettings =
(MockSlingSettingService)bundleContext().getService(ref);
slingSettings.setRunModes(newRunModes);
}
}
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
Tue Feb 23 00:09:40 2016
@@ -603,9 +603,9 @@ public final class ContentLoader {
String mimeType = null;
String fileExtension = StringUtils.substringAfterLast(name, ".");
if (bundleContext != null && StringUtils.isNotEmpty(fileExtension)) {
- ServiceReference ref =
bundleContext.getServiceReference(MimeTypeService.class.getName());
+ ServiceReference<MimeTypeService> ref =
bundleContext.getServiceReference(MimeTypeService.class);
if (ref != null) {
- MimeTypeService mimeTypeService = (MimeTypeService)
bundleContext.getService(ref);
+ MimeTypeService mimeTypeService =
(MimeTypeService)bundleContext.getService(ref);
mimeType = mimeTypeService.getMimeType(fileExtension);
}
}
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/package-info.java
Tue Feb 23 00:09:40 2016
@@ -19,5 +19,5 @@
/**
* Mock implementation of selected Sling APIs.
*/
[email protected]("1.5")
[email protected]("1.6")
package org.apache.sling.testing.mock.sling;
Modified:
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java?rev=1731761&r1=1731760&r2=1731761&view=diff
==============================================================================
---
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
(original)
+++
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/MockSlingHttpServletRequest.java
Tue Feb 23 00:09:40 2016
@@ -84,7 +84,7 @@ public class MockSlingHttpServletRequest
public ResourceBundle getResourceBundle(String baseName, Locale locale) {
// check of ResourceBundleProvider is registered in mock OSGI context
ResourceBundle resourceBundle = null;
- ServiceReference serviceReference =
bundleContext.getServiceReference(ResourceBundleProvider.class.getName());
+ ServiceReference<ResourceBundleProvider> serviceReference =
bundleContext.getServiceReference(ResourceBundleProvider.class);
if (serviceReference != null) {
ResourceBundleProvider provider =
(ResourceBundleProvider)bundleContext.getService(serviceReference);
resourceBundle = provider.getResourceBundle(baseName, locale);