Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/nullability' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 14, 2018
2 parents 1df1f91 + 877bc04 commit 62208d8
Show file tree
Hide file tree
Showing 49 changed files with 177 additions and 82 deletions.
6 changes: 6 additions & 0 deletions commons/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.2.2" date="not released">
<action type="update" dev="sseifert">
Add Jetbrains NotNull/Nullable annotations to API.
</action>
</release>

<release version="1.2.0" date="2018-03-14">
<action type="add" dev="sseifert">
Add QueryStringBuilder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.wcm.sling.commons.adapter;

import org.apache.sling.api.adapter.Adaptable;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -40,7 +41,7 @@ private AdaptTo() {
* @return Adaption result (not null)
* @throws UnableToAdaptException if the adaption was not successful
*/
public static <T> T notNull(Adaptable adaptable, Class<T> type) {
public static <T> @NotNull T notNull(@NotNull Adaptable adaptable, @NotNull Class<T> type) {
T object = adaptable.adaptTo(type);
if (object == null) {
throw new UnableToAdaptException(adaptable, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.wcm.sling.commons.adapter;

import org.apache.sling.api.adapter.Adaptable;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -30,14 +31,14 @@ public final class UnableToAdaptException extends RuntimeException {

private static final long serialVersionUID = 1L;

private final Adaptable adaptable;
private final Class<?> type;
private final @NotNull Adaptable adaptable;
private final @NotNull Class<?> type;

/**
* @param adaptable Adaptable object instance
* @param type Interface to adapt to
*/
public UnableToAdaptException(Adaptable adaptable, Class<?> type) {
public UnableToAdaptException(@NotNull Adaptable adaptable, @NotNull Class<?> type) {
super("Unable to adapt " + adaptable + " to " + type.getName());
this.adaptable = adaptable;
this.type = type;
Expand All @@ -46,14 +47,14 @@ public UnableToAdaptException(Adaptable adaptable, Class<?> type) {
/**
* @return Adaptable object instance
*/
public Adaptable getAdaptable() {
public @NotNull Adaptable getAdaptable() {
return adaptable;
}

/**
* @return Interface to adapt to
*/
public Class<?> getType() {
public @NotNull Class<?> getType() {
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Helper classes around the Sling {@link org.apache.sling.api.adapter.Adaptable} concept.
*/
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.versioning.Version("1.0.1")
package io.wcm.sling.commons.adapter;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package io.wcm.sling.commons.caservice;

import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ConsumerType;

/**
Expand Down Expand Up @@ -50,6 +51,7 @@ public interface ContextAwareService {
* Only if the path is matching the service is considered as candidate.
* If the property is not set all resource paths are accepted.
*/
@NotNull
String PROPERTY_CONTEXT_PATH_PATTERN = "Wcmio-CAService-ContextPathRegex";

/**
Expand All @@ -58,6 +60,7 @@ public interface ContextAwareService {
* If the path is matching the service is not considered as candidate.
* If the property is not set no resource paths are blacklisted.
*/
@NotNull
String PROPERTY_CONTEXT_PATH_BLACKLIST_PATTERN = "Wcmio-CAService-ContextPathBlacklistRegex";

/**
Expand All @@ -66,6 +69,7 @@ public interface ContextAwareService {
* be considered as candidate if no context resource exists and thus the context path is empty (null).
* If the property is not set the implementation is not considered as candidate for empty resource paths.
*/
@NotNull
String PROPERTY_ACCEPTS_CONTEXT_PATH_EMPTY = "Wcmio-CASService-AcceptsContextPathEmpty";

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -44,7 +46,7 @@ public interface ContextAwareServiceResolver {
* @param <T> Service interface or class
* @return Service implementation or null if no match found.
*/
<T extends ContextAwareService> T resolve(Class<T> serviceClass, Adaptable adaptable);
<T extends ContextAwareService> @Nullable T resolve(@NotNull Class<T> serviceClass, @NotNull Adaptable adaptable);

/**
* Resolves all matching service implementations for the given resource context.
Expand All @@ -58,7 +60,7 @@ public interface ContextAwareServiceResolver {
* @param <T> Service interface or class
* @return Collection of all matching services
*/
<T extends ContextAwareService> ResolveAllResult<T> resolveAll(Class<T> serviceClass, Adaptable adaptable);
<T extends ContextAwareService> @NotNull ResolveAllResult<T> resolveAll(@NotNull Class<T> serviceClass, @NotNull Adaptable adaptable);

/**
* Result of the {@link ContextAwareServiceResolver#resolveAll(Class, Adaptable)} method.
Expand All @@ -71,6 +73,7 @@ interface ResolveAllResult<T extends ContextAwareService> {
* Gets all matching services
* @return Context-Aware services
*/
@NotNull
Stream<T> getServices();

/**
Expand All @@ -82,6 +85,7 @@ interface ResolveAllResult<T extends ContextAwareService> {
* services always the same result as long as they are registered.
* @return Key string
*/
@NotNull
String getCombinedKey();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.wcm.sling.commons.caservice;

import org.apache.sling.api.resource.ResourceResolver;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ConsumerType;

/**
Expand All @@ -35,6 +36,7 @@ public interface PathPreprocessor {
* @param resourceResolver Resource resolver
* @return Processed path or same path
*/
String apply(String path, ResourceResolver resourceResolver);
@NotNull
String apply(@NotNull String path, @NotNull ResourceResolver resourceResolver);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -69,6 +70,7 @@ private void activate(BundleContext context) {
this.bundleContext = context;
this.serviceTrackerCache = CacheBuilder.newBuilder()
.removalListener(new RemovalListener<String, ContextAwareServiceTracker>() {
@SuppressWarnings("null")
@Override
public void onRemoval(RemovalNotification<String, ContextAwareServiceTracker> notification) {
notification.getValue().dispose();
Expand All @@ -90,7 +92,7 @@ private void deactivate(BundleContext context) {

@SuppressWarnings("unchecked")
@Override
public <T extends ContextAwareService> T resolve(Class<T> serviceClass, Adaptable adaptable) {
public <T extends ContextAwareService> T resolve(@NotNull Class<T> serviceClass, @NotNull Adaptable adaptable) {
Resource resource = getResource(adaptable);
if (log.isTraceEnabled()) {
log.trace("Resolve {} for resource {}", serviceClass.getName(), (resource != null ? resource.getPath() : "null"));
Expand All @@ -103,7 +105,7 @@ public <T extends ContextAwareService> T resolve(Class<T> serviceClass, Adaptabl

@SuppressWarnings("unchecked")
@Override
public <T extends ContextAwareService> ResolveAllResult<T> resolveAll(Class<T> serviceClass, Adaptable adaptable) {
public <T extends ContextAwareService> @NotNull ResolveAllResult<T> resolveAll(@NotNull Class<T> serviceClass, @NotNull Adaptable adaptable) {
Resource resource = getResource(adaptable);
if (log.isTraceEnabled()) {
log.trace("Resolve all {} for resource {}", serviceClass.getName(), (resource != null ? resource.getPath() : "null"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public Stream<ServiceInfo> resolve(Resource resource) {
.filter(serviceInfo -> matchesResource(serviceInfo, resource));
}

@SuppressWarnings("null")
private boolean matchesResource(ServiceInfo serviceInfo, Resource resource) {
String path = null;
if (resource != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.jetbrains.annotations.NotNull;

import io.wcm.sling.commons.caservice.ContextAwareService;
import io.wcm.sling.commons.caservice.ContextAwareServiceResolver.ResolveAllResult;

@SuppressWarnings("null")
class ResolveAllResultImpl<T extends ContextAwareService> implements ResolveAllResult<T> {

private final Stream<T> services;
Expand All @@ -36,12 +39,12 @@ class ResolveAllResultImpl<T extends ContextAwareService> implements ResolveAllR
}

@Override
public Stream<T> getServices() {
public @NotNull Stream<T> getServices() {
return services;
}

@Override
public String getCombinedKey() {
public @NotNull String getCombinedKey() {
return combinedKey.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Context-Aware services.
*/
@org.osgi.annotation.versioning.Version("1.1.0")
@org.osgi.annotation.versioning.Version("1.1.1")
package io.wcm.sling.commons.caservice;
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

import io.wcm.sling.commons.util.Escape;
Expand All @@ -47,7 +49,7 @@ public final class QueryStringBuilder {
* @return this
*/
@SuppressWarnings("unchecked")
public QueryStringBuilder param(String name, Object value) {
public @NotNull QueryStringBuilder param(@NotNull String name, @Nullable Object value) {
if (value instanceof Iterable) {
Iterable<Object> valueItems = (Iterable)value;
for (Object valueItem : valueItems) {
Expand All @@ -73,7 +75,8 @@ else if (isArray(value)) {
* If a value is an array or {@link Iterable} the value items will be added as separate parameters.
* @return this
*/
public QueryStringBuilder params(Map<String, Object> values) {
@SuppressWarnings("null")
public @NotNull QueryStringBuilder params(@NotNull Map<String, Object> values) {
for (Map.Entry<String, Object> entry : values.entrySet()) {
param(entry.getKey(), entry.getValue());
}
Expand All @@ -84,7 +87,7 @@ public QueryStringBuilder params(Map<String, Object> values) {
* Build query string.
* @return Query string or null if query string contains no parameters at all.
*/
public String build() {
public @Nullable String build() {
StringBuilder queryString = new StringBuilder();

for (NameValuePair param : params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.wcm.sling.commons.request;

import org.apache.sling.api.SlingHttpServletRequest;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -33,6 +34,7 @@ public interface RequestContext {
* The request is stored in a threadlocal set by a servlet filter.
* @return Sling request or null if none is associated.
*/
@Nullable
SlingHttpServletRequest getThreadRequest();

}

0 comments on commit 62208d8

Please sign in to comment.