Skip to content

kordamp/jipsy

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
etc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Jipsy

jipsy logo

Build Status Download


Configurable Java Annotation Processor to simplify the use of the Service Provider Interface.

Introduction

JDK6 added a neat facility named ServiceLoader that enables library authors to hook in implementations using an SPI. As explained at the service loader documentation, services must follow certain rules in order to be considered as such; they also must be registered using an standard location based on a naming convention. The following rules apply to classes that may be considered services

  1. The class must implement at least one target interface (the service interface).

  2. The class must provide a no-args constructor.

  3. The class must be public.

  4. The class name should be added to a file named META-INF/services/<target_interface_name>

This library provides a mechanism for enforcing those rules by simply adding an annotation on each service implementation, for example say there exists the following Calculator service interface

package com.acme;

public interface Calculator {
    double add(double a, double b);
}

A basic implementation of such service may be as follows

package com.acme;

@org.kordamp.jipsy.annotations.ServiceProviderFor(Calculator.class)
public class BasicCalculator implements Calculator {
    public double add(double a, double b) { return a + b; }
}

Compile your code. If you look closely at your project’s output you’ll see a file named META-INF/services/com.acme.Calculator whose contents should look similar to

# Generated by org.kordamp.jipsy.processor.service.ServiceProviderProcessor (1.1.1)
com.acme.BasicCalculator

Et voilà! There are no additional sources to be touched nor files to be created; Jipsy will take care of the boiler plate.

Installing

Jipsy is packaged as a standalone jars with no additional dependencies. Jipsy requires JDK8 as a minimum as it relies on the Annotation Processor facility to do its work. You must enable annotation processing on your IDE if you want Jipsy to work correctly.

Jipsy can be downloaded directly from Maven Central, configure it via Maven or Gradle.

Maven
<dependency>
    <groupId>org.kordamp.jipsy</groupId>
    <artifactId>jipsy-processor</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>
Gradle
dependencies {
    annotationProcessor 'org.kordamp.jipsy:jipsy-processor:1.1.1'
    compileOnly 'org.kordamp.jipsy:jipsy-annotations:1.1.1'
}
Note
For Maven, use the provided scope in order to mark Jipsy as a compile-only dependency; this also avoids exposing Jipsy to consumers of your library.

Origin

Jipsy is a re-implementation of the org.mangosdk.spi project, original by Roel Spilker and Bart Enkelaar; copyrighted by TOPdesk; source distributed under Apache Software License 2.0

Creating Your Own Processors

TBD

About

Configurable Java Annotation Processor to simplify the use of the Service Provider Interface.

Resources

License

Stars

Watchers

Forks

Languages