Jess is a tool that enables a targeted compilation of Java programs. By doing so, it provides the abillity to compile specific areas of interest of a program without the need to invoke build scripts, even when only part of its code base is available.
To install Jess you just have to invoke mvn install
.
Jess can be programmaticaly invoked from a Java application in the following way:
- Create a Jess configuration
boolean exitOnCompilationFail = false;
boolean exitOnParsingFail = false;
boolean looseSignatureMatching = true; // if true one only needs to specify parameter types, not names
boolean keepAsteriskImports = true;
boolean failOnAmbiguity = false;
boolean disableStubbing = false;
JessConfiguration config = new JessConfiguration(exitOnCompilationFail, exitOnParsingFail,
looseSignatureMatching, keepAsteriskImports, failOnAmbiguity, disableStubbing);
- Point to Java project for compilation via Jess
String projectPath = "path/to/project";
Set<String> packages = PackageFinder.findPackageRoots(projectPath);
Set<String> jars = Collections.emptyList(); // can specify additional JAR-files here
- Create a Jess instance and point to target file
Jess jess = new Jess(config, packages, jars);
- Specify targets for compilation
String targetFile = "org/example/Target.java";
List<String> targetMethods = Collections.singletonList("method(String, String, boolean)")";
List<String> targetClinit = Collections.emptyList(); // static fields/initializers
List<String> targetInit = Collections.emptyList(); // non-static fields/initializers
- Start targeted compilation
jess.preSlice(targetClass, targetMethods, targetClinit, targetInit);
int compilationResult = jess.parse(targetClass);