You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2016/10/04 09:49:54 UTC

Re: svn commit: r1763255 - in /sling/trunk/contrib/commons/mom: ./ jobs/core/ jobs/core/src/main/java/org/apache/sling/jobs/impl/ jobs/it/ jobs/it/src/test/java/org/apache/sling/jobs/it/ jobs/it/src/test/resources/provisioning-model/

On Tue, Oct 4, 2016 at 2:53 PM,  <ie...@apache.org> wrote:
> +        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[]");
> +        }

Another way to avoid runtime dependency is inline just the
PropertiesUtils class. It does not have any dependency. That way you
get to do code reuse and avoid runtime dependency. See [1] for example

<Embed-Dependency>
org.apache.sling.commons.osgi;inline=
org/apache/sling/commons/osgi/PropertiesUtil*.class
</Embed-Dependency>

Chetan Mehrotra
[1] https://github.com/apache/felix/blob/trunk/jaas/pom.xml#L115

Re: svn commit: r1763255 - in /sling/trunk/contrib/commons/mom: ./ jobs/core/ jobs/core/src/main/java/org/apache/sling/jobs/impl/ jobs/it/ jobs/it/src/test/java/org/apache/sling/jobs/it/ jobs/it/src/test/resources/provisioning-model/

Posted by Ian Boston <ie...@tfd.co.uk>.
On 4 October 2016 at 10:49, Chetan Mehrotra <ch...@gmail.com>
wrote:

> On Tue, Oct 4, 2016 at 2:53 PM,  <ie...@apache.org> wrote:
> > +        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[]");
> > +        }
>
> Another way to avoid runtime dependency is inline just the
> PropertiesUtils class. It does not have any dependency. That way you
> get to do code reuse and avoid runtime dependency. See [1] for example
>
> <Embed-Dependency>
> org.apache.sling.commons.osgi;inline=
> org/apache/sling/commons/osgi/PropertiesUtil*.class
> </Embed-Dependency>
>


In this instance, I wanted a better error message to prevent/detect an
empty set of JobTypes breaking a JobConsumer so PropertiesUtil was not
suitable any more. Doing this reduces the dependencies to run this bundle,
by 1. Incidentally, org.apache.sling.commons.osgi wasn't in the
provisioning model used by the IT tests, which was failing.

Build time inlining can create as many maintenance problems as manual
inlining once a bundle is released.

Best Regards
Ian



> Chetan Mehrotra
> [1] https://github.com/apache/felix/blob/trunk/jaas/pom.xml#L115
>