This doc contains information relevant to people contributing to Workcraft. Read the README.md first if you have not done it yet.
Testing includes a collection of JUnit tests and checkstyle to enforce a sane code style throughout the Java codebase (see below). The tests should be run before proposing your changes for the merge into the master repo as follows:
./gradlew check
The code style is configured via checkstyle.xml.
The style is similar to Google's Java style, but it is more lax and indents with four spaces.
To give a quick overview of it, here is a code snippet showing the basics:
class Foo {
public static final int CONSTANT = 1;
private boolean myField = true;
public static void barMethod(int someInt,
String someString) {
if (someInt > 3 || someInt < 0) {
someFunc(someInt);
} else {
someString = "value is " + someInt;
}
List<String> myList = new ArrayList<>();
}
}Eclipse IDE is a convenient environment for developing and debugging Workcraft.
-
Clone the Workcraft git repo and set it as the current directory:
git clone https://github.com/tuura/workcraft.git cd workcraft -
Generate Java parser classes from JavaCC grammar files:
./gradlew compileJavacc -
Generate Eclipse projects from Gradle config files:
./gradlew eclipse -
Start Eclipse and select
workcraftas the currentWorkspacedirectory. -
Import all
workcraftprojects via theFile->Import...as aGeneral->Existing Projects into Workspaceitem. -
Create a
Java Applicationrunner with the following configuration:
- Name: Workcraft
- Project: WorkcraftRunner
- Main class: org.workcraft.Console
The default code style of eclipse uses tabs for indentation. This contradicts to the checkstyle that requires 4 spaces for each level of indentation. Therefore Eclipse settings need to be modified as follows:
-
Select
Windows->Preferencesmenu. -
Go to the
Java->Code Style->Formattersection. -
Edit the indentation policy of
Eclipse [built-in]profile by changing its tab policy toSpaces only. -
Save the modified profile under a new name and select it as the active profile.
-
Create symbolic link pointing to the location of the backend tools for your platform, e.g. for Linux:
ln -s dist-template/linux/tools -
Choose
Run->Run Configurations...menu and edit the Workcraft runner underJava Applicationsection (the one created in the previous section): on theArgumentstab modify theWorking directoryso it points to${workspace_loc}.
This will set workcraft as the current directory when Workcraft is
started from Eclipse and the tools directory will be in the right place
to locate the backend tools.
Note: Workcraft requires Java 1.7 or newer for a successful build. You
may have several versions of Java installed with Java 1.7 being active
system-wide. However, Eclipse may have a different version of Java set
as its default. Check this under Windows->Preferences->Java->Compiler
section.
If Gradle complains about a missing JAVA_HOME env var even though it
is set properly, the following may help in Debian-like systems:
sudo ln -s /usr/lib/jvm/your-jdk /usr/lib/jvm/default-java