If you want to implement your own module, you have to implement the
uniol.apt.module.Module
-interface that is available in APT. Additionally, your
class should be have the @uniol.apt.module.AptModule
annotation so that it is
automatically registered with APT. To make this work, apt.jar
contains an
annotation processor that must be run by your Java compiler. How to ensure this
is explained below.
As an example for a module, you can look at the module that provides the
coverability graph. Its source code is available in
src/module/uniol/apt/analysis/coverability/CoverabilityModule.java
.
The latest Javadoc documentation is always available at:
http://CvO-theory.github.io/apt-javadoc/
Some functionalities need to abort a module after it was already started. For example, the graphical user interface offers an abort button and the JSON-interface supports timeouts on modules. To support this, your module needs to be specially prepared.
If you want to support this, your module has to implement the
InterruptibleModule
-interface instead of the Module
-interface. This marker
interface indicates that your module will regularly call
uniol.apt.util.interrupt.InterrupterRegistry.throwIfInterruptRequestedForCurrentThread()
.
In turn, this method will throw an unchecked exception if your module was
aborted.
To develop a module with Eclipse, follow these steps:
- Create a new Eclipse project
- Get a copy of the file apt.jar, for example from here, and add it as a library to your project.
- Open the project properties and navigate to "Java Compiler/Annotation
Processing".
- Check "Enable project specific settings".
- Check "Enable annotation processing".
- Check "Enable annotation processing in editor".
- Open the project properties and navigate to "Java Compiler/Annotation
Processing/Factory Path".
- Check "Enable project specific settings".
- Add the
apt.jar
as an external jar. - Check that
uniol.apt.compiler.ModuleProcessor
is listed under "Advanced".
- Create a new run configuration of the type "Java Application" and set
uniol.apt.APT
as the main class. Here you can also provide command line arguments (for example, the name of your module as returned by getName() should be the first argument).
The above ensures that APT's annotation processor is run by Eclipse. It creates the needed files so that APT will automatically find your module.
It is not recommended to build APT directly from Eclipse, because of problems
with the project structure. You can however compile APT from Eclipse by
opening APT's build.xml
file and running the jar
target via Ant.
- Create a new Java project.
- Enable annotation processing
- Go to "Settings/Build, Execution, Deployment/Compiler/Annotation Processors".
- Make sure "Enable annotation processing" is enabled.
- Get a copy of the file apt.jar, for example from
here, and add it as a
library to your project.
- Go to "Project Structure/Libraries".
- Add
apt.jar
as a new Java library.
- Make sure a working JAR file is built.
- Go to "Project Structure/Artifacts".
- Add a new "JAR" artifact that is built "From Modules with dependencies", has main class "uniol.apt.APT" and select "Copy to the output directory and link via manifest".
- It is recommended to also select "Include in project build" so the JAR file is updated when the project is build.
The above ensures that any modules that you write is automatically found. Make
sure that your module has the @AptModule
annotation!
It is not recommended to build APT directly from IDEA. You can however compile
APT by executing the jar
target of APT's build.xml
via Ant.
The following assumes that your source code is in a folder called src.
-
Get a copy of the file apt.jar, for example from here.
-
Compile your source code against APT.
mkdir classes javac -d classes -cp apt.jar src/*
-
Run the new module
java -cp apt.jar:classes uniol.apt.APT your_module_name_as_returned_by_getName() example_argument
The above example is for unixoid systems. On Windows, Java uses ;
instead of
:
as separator in the class path argument. This means you have to use -cp apt.jar;classes
instead on Windows.
A JAR file can be built with any of the usual methods. The generated files has
to include the META-INF
directory that is automatically generated next to the
.class
files so that modules can be found. The entry point of the command line
utility should be uniol.apt.APT
.
If you want to use ANT to build your code and generate a JAR file, then the build.xml file of apt-extremal can be a good starting point.