Skip to content
Closed
48 changes: 22 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<!-- ======================================================================= -->
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
<version>26</version>
<artifactId>sling-bundle-parent</artifactId>
<version>38</version>
<relativePath />
</parent>

Expand All @@ -34,7 +34,6 @@
<!-- ======================================================================= -->
<artifactId>org.apache.sling.distribution.api</artifactId>
<version>0.4.1-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>Apache Sling Distribution API</name>
<description>
Expand All @@ -54,22 +53,8 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>org.apache.sling.distribution.api</Bundle-SymbolicName>
</instructions>
</configuration>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -93,27 +78,38 @@
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<artifactId>osgi.cmpn</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.2</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;
import javax.annotation.Nonnull;

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

/**
* A {@link org.apache.sling.distribution.DistributionRequest} represents the need from the caller to have
Expand All @@ -35,15 +35,15 @@ public interface DistributionRequest {
*
* @return the type of the request as a {@link DistributionRequestType}
*/
@NotNull
@Nonnull
DistributionRequestType getRequestType();

/**
* Get the root paths for this distribution request
*
* @return an array of paths
*/
@NotNull
@Nonnull
public String[] getPaths();

/**
Expand All @@ -52,7 +52,7 @@ public interface DistributionRequest {
* @param path the path to be checked
* @return <code>true</code> if the paths are deep
*/
public boolean isDeep(@NotNull String path);
public boolean isDeep(String path);



Expand All @@ -65,6 +65,6 @@ public interface DistributionRequest {
* @param path the path to get applicable filters for
* @return an array of filters
*/
@NotNull
@Nonnull
public String[] getFilters(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;
import org.osgi.annotation.versioning.ProviderType;

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;
import javax.annotation.Nullable;

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

/**
* <p>
Expand Down Expand Up @@ -66,7 +66,7 @@ public enum DistributionRequestType {
* @return the type or {@code null}
*/
@Nullable
public static DistributionRequestType fromName(String n) {
public static DistributionRequestType fromName(@Nullable String n) {
if (n == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

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

/**
* A {@link org.apache.sling.distribution.DistributionResponse} represents the outcome of a
Expand All @@ -47,7 +47,7 @@ public interface DistributionResponse {
*
* @return the state of the associated request
*/
@NotNull
@Nonnull
DistributionRequestState getState();

/**
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/apache/sling/distribution/Distributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;
import javax.annotation.Nonnull;

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

/**
* <p>
Expand Down Expand Up @@ -49,9 +50,9 @@ public interface Distributor {
* @param resourceResolver the resource resolver used for authorizing the request,
* @return a {@link org.apache.sling.distribution.DistributionResponse}
*/
@NotNull
DistributionResponse distribute(@NotNull String agentName, @NotNull ResourceResolver resourceResolver,
@NotNull DistributionRequest distributionRequest);
@Nonnull
DistributionResponse distribute(String agentName, ResourceResolver resourceResolver,
DistributionRequest distributionRequest);


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/
package org.apache.sling.distribution;

import aQute.bnd.annotation.ProviderType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

import org.osgi.annotation.versioning.ProviderType;

/**
* A {@link SimpleDistributionRequest} is a {@link DistributionRequest} where all paths are either "deep" or "shallow".
Expand All @@ -45,7 +46,7 @@ public final class SimpleDistributionRequest implements DistributionRequest {
* @param isDeep is <code>true</code> if all paths are "deep" and is <code>false</code> if all paths are "shallow"
* @param paths the array of paths to be distributed
*/
public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, boolean isDeep, @NotNull String... paths) {
public SimpleDistributionRequest(DistributionRequestType requestType, boolean isDeep, String... paths) {
this(requestType, paths, isDeep? new HashSet<String>(Arrays.asList(paths)) : new HashSet<String>());
}

Expand All @@ -54,7 +55,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, b
* @param requestType the request type
* @param paths the array of paths to be distributed
*/
public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String... paths) {
public SimpleDistributionRequest(DistributionRequestType requestType, String... paths) {
this(requestType, false, paths);
}

Expand All @@ -65,7 +66,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @
* @param paths the array of paths to be distributed
* @param deepPaths the set of paths that are to be distributed in depth (with all their children)
*/
public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String[] paths, @NotNull Set<String> deepPaths) {
public SimpleDistributionRequest(DistributionRequestType requestType, String[] paths, Set<String> deepPaths) {
this(requestType, paths, deepPaths, new HashMap<String, String[]>());
}

Expand All @@ -77,7 +78,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @
* @param deepPaths the set of paths that are to be distributed in depth (with all their children)
* @param pathFilters the filters applicable for each path
*/
public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String[] paths, @NotNull Set<String> deepPaths, @NotNull Map<String, String[]> pathFilters) {
public SimpleDistributionRequest(DistributionRequestType requestType, String[] paths, Set<String> deepPaths, Map<String, String[]> pathFilters) {
this.requestType = requestType;
this.paths = paths;
this.deepPaths = deepPaths;
Expand All @@ -89,7 +90,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @
*
* @return the type of the request as a {@link DistributionRequestType}
*/
@NotNull
@Nonnull
public DistributionRequestType getRequestType() {
return requestType;
}
Expand All @@ -108,11 +109,11 @@ public String[] getPaths() {
* Returns whether the a path is covering the entire subtree (deep) or just the specified nodes (shallow)
* @return <code>true</code> if the path is deep
*/
public boolean isDeep(@NotNull String path) {
public boolean isDeep(String path) {
return deepPaths.contains(path);
}

@NotNull
@Nonnull
public String[] getFilters(String path) {
String[] filters = pathFilters.get(path);
return filters != null ? filters : new String[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.distribution.event;

import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND;
import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME;
import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_PACKAGE_ID;
import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_PATHS;
import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_TYPE;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.service.event.Event;

public class DistributionEvent {

private final String packageId;
private final String componentName;
private final String componentKind;
private final String distType;
private final String[] distPaths;

public DistributionEvent(
String packageId,
String componentName,
String componentKind,
String distType,
String[] distPaths) {
this.packageId = packageId;
this.componentName = componentName;
this.componentKind = componentKind;
this.distType = distType;
this.distPaths = distPaths;
}

public String getPackageId() {
return packageId;
}

public String getComponentName() {
return componentName;
}

public String getComponentKind() {
return componentKind;
}

public String getDistType() {
return distType;
}

public String[] getDistPaths() {
return distPaths;
}

public Event toEvent(String topic) {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(DISTRIBUTION_PACKAGE_ID, packageId);
props.put(DISTRIBUTION_COMPONENT_NAME, componentName);
props.put(DISTRIBUTION_COMPONENT_KIND, componentKind);
props.put(DISTRIBUTION_TYPE, distType);
props.put(DISTRIBUTION_PATHS, distPaths);
return new Event(topic, props);
}

public static DistributionEvent fromEvent(Event event) {
return new DistributionEvent(
event.getProperty(DISTRIBUTION_PACKAGE_ID).toString(),
event.getProperty(DISTRIBUTION_COMPONENT_NAME).toString(),
event.getProperty(DISTRIBUTION_COMPONENT_KIND).toString(),
event.getProperty(DISTRIBUTION_TYPE).toString(),
(String[])event.getProperty(DISTRIBUTION_PATHS));
}
}
Loading