SLING-5645 Improved IT tests, improved config checking and reduced dependency footprint
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 08a38ad..43b2911 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,11 +116,6 @@
<!-- Use the version being used in Sling -->
<version>15.0</version>
</dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.4.0</version>
- </dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java b/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
index ef3123b..1be6a00 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
@@ -28,8 +28,14 @@
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.commons.osgi.PropertiesUtil;
-import org.apache.sling.jobs.*;
+import org.apache.sling.jobs.Job;
+import org.apache.sling.jobs.JobBuilder;
+import org.apache.sling.jobs.JobCallback;
+import org.apache.sling.jobs.JobConsumer;
+import org.apache.sling.jobs.JobManager;
+import org.apache.sling.jobs.JobTypeValve;
+import org.apache.sling.jobs.JobUpdateListener;
+import org.apache.sling.jobs.Types;
import org.apache.sling.jobs.impl.spi.JobStorage;
import org.apache.sling.jobs.impl.storage.InMemoryJobStorage;
import org.apache.sling.mom.QueueManager;
@@ -41,7 +47,8 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Closeable;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -180,10 +187,34 @@
if ( consumer instanceof JobTypeValve) {
jobTypes = ImmutableSet.of();
} else {
- jobTypes = Types.jobType(PropertiesUtil.toStringArray(properties.get(JobConsumer.JOB_TYPES)));
+ jobTypes = getJobTypes(properties);
}
}
+ public Set<Types.JobType> getJobTypes(Map<Object, Object> properties) {
+ Object types = properties.get(JobConsumer.JOB_TYPES);
+ if (types instanceof String) {
+ return Types.jobType(new String[]{(String) types});
+
+ } else if (types instanceof String[]) {
+ return Types.jobType((String[]) types);
+
+ } else if (types instanceof Iterable) {
+ List<String> l = new ArrayList<String>();
+ for (Object o : (Iterable<?>) types) {
+ l.add(String.valueOf(o));
+ }
+ return Types.jobType((String[]) l.toArray(new String[l.size()]));
+ }
+ throw new IllegalArgumentException("For the JobConsumer to work, the job consumer must either " +
+ "implement a JobTypeValve or define a list of JobTypes, neither were specified. " +
+ "Please check the implementation or OSGi configuration, was expecting " +
+ JobConsumer.JOB_TYPES + " property to be set to a String[]");
+ }
+
+
+
+
@Override
public boolean accept(@Nonnull Types.JobType jobType) {
if ( consumer instanceof JobTypeValve) {