On 4 October 2016 at 10:49, Chetan Mehrotra <chetan.mehro...@gmail.com>
wrote:

> On Tue, Oct 4, 2016 at 2:53 PM,  <i...@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
>

Reply via email to