Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gastaldi/reflections-addon

Forge 2 Addon using Reflections library
https://github.com/gastaldi/reflections-addon

Last synced: 2 days ago
JSON representation

Forge 2 Addon using Reflections library

Awesome Lists containing this project

README

        

== reflections
:idprefix: id_
This addon *exports services* for use in other addons.
It enables the usage of the Reflections (https://github.com/ronmamo/reflections) libraries as Facets in Forge projects.
Reflections scans your classpath, indexes the metadata, allows you to query it on runtime and may save and collect that information for many modules within your project.

Using Reflections you can query your metadata such as:

* get all subtypes of some type
* all types/members annotated with some annotation, optionally with annotation parameters matching
* get all resources matching a regular expression
* get all methods with specific signature including parameters, parameter annotations and return type

=== Depends on
[options="header"]
|===
|Addon |Exported |Optional
|projects
|yes
|no

|facets
|yes
|no
|===

== Setup
This Addon requires the following installation steps.

=== Add configuration to pom.xml
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact:
[source,xml]
----

me.gastaldi.forge
reflections
forge-addon
${version}

----
== Features
ReflectionsFacet::
Provides a Reflections object from the project classloader.
+
[source,java]
----
ReflectionsFacet facet = project.getFacet(ReflectionsFacet.class);
Reflections reflections = facet.getReflections();

//Returns all classes in the project (including its dependencies) annotated with @Entity
Set> entities = reflections.getTypesAnnotatedWith(Entity.class);

//Returns all classes in the project (including its dependencies) that is a sub-type of Exception
Set> subTypes = reflections.getSubTypesOf(Exception.class);

----

ClassLoaderFacet::
This addon introduces a ClassLoaderFacet that provides a URLClassLoader from the project dependencies.
+
[source,java]
----
ClassLoaderFacet facet = project.getFacet(ClassLoaderFacet.class);
// This classloader contains all the project classes and their dependencies
URLClassLoader classLoader = facet.getClassLoader();
----