GithubHelp home page GithubHelp logo

isabella232 / sling-org-apache-sling-feature-apiregions-model Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apache/sling-org-apache-sling-feature-apiregions-model

0.0 0.0 0.0 30 KB

Apache Sling Feature Model API Regions

Home Page: https://sling.apache.org/

License: Apache License 2.0

Java 100.00%

sling-org-apache-sling-feature-apiregions-model's Introduction

Apache Sling

Build Status Test Status Coverage Sonarcloud Status JavaDoc Maven Central feature License

This small set of APIs aims to provide to Apache Sling users an easy-to-use layer to manipulate api-regions JSON extensions.

Motivation

The api-regions extensions gained popularity via the APIs Jar MOJO that, for each selected Apache Sling Feature Model file, generates multiple Java Archives, one for each declared section in the api-regions extension, containing declared APIs in each region.

During the time, business intelligence on top of api-regions extension will be required, i.e. analyzing the evolution of each region in each Apache Sling Feature Model file, to see what's removed and what's added (just to mention few operations), so having a single APIs set to manipulate api-regions will be helpful avoiding code redundancies across multiple applications.

Quick how-to

api-regions extensions are generally obtained by parsing the JSON content in the api-regions declaration, i.e. given the following sample region:

[
  {
    "name": "base",
    "exports": [
      "org.apache.felix.inventory",
      "org.apache.felix.metatype"
    ]
  },
  {
    "name": "extended",
    "exports": [
      "org.apache.felix.scr.component",
      "org.apache.felix.scr.info"
    ]
  }
]

then obtaining simple APIs will look like:

import org.apache.sling.feature.Feature;
import org.apache.sling.feature.apiregions.model.ApiRegion;
import org.apache.sling.feature.apiregions.model.ApiRegions;
import org.apache.sling.feature.apiregions.model.io.json.ApiRegionsJSONParser;

...

Feature feature = [somehow obtained]
// parseApiRegions method can be invoked also passing a org.apache.sling.feature.Extension instance
// or a String which represents the JSON structure of an api-regions extension.
ApiRegions regions = ApiRegionsJSONParser.parseApiRegions(feature);

for (ApiRegion region : regions) {
    System.out.println("-" + region.getName());

    for (String api : region) {
        System.out.println(" * " + api);
    }

    System.out.println("--------");
}

That code will output:

- base
 * org.apache.felix.inventory
 * org.apache.felix.metatype
--------
- extended
 * org.apache.felix.scr.component
 * org.apache.felix.scr.info
 * org.apache.felix.inventory
 * org.apache.felix.metatype
--------

Note

Pleas take in account that each declared region in api-regions inherits declared APIs from the previous declared region.

APIs to create regions

Users can also use APIs to manually declare their api-regions instances:

omit imports for brevity;

...

ApiRegions apiRegions = new ApiRegions();
ApiRegion granpa = apiRegions.addNew("granpa");
granpa.add("org.apache.sling.feature.apiregions.model");

ApiRegion father = apiRegions.addNew("father");
father.add("org.apache.sling.feature.apiregions.model.io");

ApiRegion child = apiRegions.addNew("child");
child.add("org.apache.sling.feature.apiregions.model.io.json");

for (ApiRegion region : apiRegions) {
    System.out.println("-" + region.getName());

    for (String api : region) {
        System.out.println(" * " + api);
    }

    System.out.println("--------");
}

That code will output:

- granpa
 * org.apache.sling.feature.apiregions.model
--------
- father
 * org.apache.sling.feature.apiregions.model
 * org.apache.sling.feature.apiregions.model.io
--------
- child
 * org.apache.sling.feature.apiregions.model
 * org.apache.sling.feature.apiregions.model.io
 * org.apache.sling.feature.apiregions.model.io.json
--------

JSON serialization is available as well:

import org.apache.sling.feature.apiregions.model.io.json.ApiRegionsJSONSerializer

...

ApiRegionsJSONSerializer.serializeApiRegions(ApiRegions, System.out);

that will output:

[
  {
    "name":"granpa",
    "exports":[
      "org.apache.sling.feature.apiregions.model"
    ]
  },
  {
    "name":"father",
    "exports":[
      "org.apache.sling.feature.apiregions.model.io"
    ]
  },
  {
    "name":"child",
    "exports":[
      "org.apache.sling.feature.apiregions.model.io.json"
    ]
  }
]

sling-org-apache-sling-feature-apiregions-model's People

Contributors

bdelacretaz avatar klcodanr avatar raducotescu avatar simonetripodi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.