kordamp / gipsy

Groovy version of Jipsy, a configurable AST Transformation to simplify the use of the Service Provider Interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gipsy

gipsy logo

Build Status Download


Groovy version of Jipsy, a configurable AST Transformation to simplify the use of the Service Provider Interface.

Introduction

Gipsy delivers the same functionality that Jipsy does but uses Groovy’s AST Transformations instead of JDK6' Annotation Processor.

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

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 BasicCalculator implements Calculator {
    double add(double a, double b) { a + b }
}

Notice that Gipsy reuses the same annotations from Jipsy. 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.gipsy.transform.service.ServiceProviderProcessor (1.2.0)
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

Gipsy requires the following dependencies

  • jipsy-processor-1.2.0

  • groovy-all-3.0.7

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

Maven

<dependency>
    <groupId>org.kordamp.gipsy</groupId>
    <artifactId>gipsy</artifactId>
    <version>1.2.0</version>
    <scope>provided</scope>
</dependency>

Gradle

dependencies {
    annotationProcessor 'org.kordamp.gipsy:gipsy:1.2.0'
    compileOnly 'org.kordamp.jipsy:jipsy-annotations:1.2.0'
}

Creating Your Own AST Transformations

TBD

About

Groovy version of Jipsy, a configurable AST Transformation to simplify the use of the Service Provider Interface.

License:Apache License 2.0


Languages

Language:Java 91.6%Language:Groovy 8.4%