diff --git a/README.md b/README.md index 0a54ba1..3f4cdce 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,24 @@ When running the precessor, some flags may be define. Directives check wether a ## Running the preprocessor + +### With ANT + +You can create a task `sjpp`. +You need to give the input tree structure (`src`) , the destination tree structure (`dest`) and the flag to be defined (`define`). + +Example: + +``` + + + + + +``` + +### On the command line + If you launch the preprocessor without any arguments, you'll get some help: ``` diff --git a/sjpp/build.gradle b/sjpp/build.gradle index be8558e..0fa474f 100644 --- a/sjpp/build.gradle +++ b/sjpp/build.gradle @@ -17,6 +17,9 @@ repositories { } dependencies { + // Ant + compileOnly 'org.apache.ant:ant:1.10.13' + // Use JUnit Jupiter for testing. testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' diff --git a/sjpp/src/main/java/sjpp/SjppAntTask.java b/sjpp/src/main/java/sjpp/SjppAntTask.java new file mode 100644 index 0000000..e55a195 --- /dev/null +++ b/sjpp/src/main/java/sjpp/SjppAntTask.java @@ -0,0 +1,49 @@ +package sjpp; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +public class SjppAntTask extends Task { + + private String src; + private String dest; + private String define; + + @Override + public void execute() throws BuildException { + this.log("Starting SimpleJava PreProcessor."); + this.log("src: " + src); + this.log("dest: " + dest); + this.log("define: " + define); + + final Path root = Paths.get(src); + + final Context context = new Context(ContextMode.REGULAR, root); + context.addDefine(define); + + final Path out = Paths.get(dest); + try { + context.process(out); + } catch (Exception e) { + e.printStackTrace(); + this.log("Error " + e.toString()); + } + + } + + public final void setSrc(String src) { + this.src = src; + } + + public final void setDest(String dest) { + this.dest = dest; + } + + public final void setDefine(String define) { + this.define = define; + } + +}