Skip to content

Commit

Permalink
feat: add Ant task
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Mar 14, 2023
1 parent 55518e2 commit cea452d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
<taskdef name="sjpp" classname="sjpp.SjppAntTask" />
<target name="dist">
<sjpp src="src-folder" dest="src-generated" define="__MIT__" />
</target>
```

### On the command line

If you launch the preprocessor without any arguments, you'll get some help:

```
Expand Down
3 changes: 3 additions & 0 deletions sjpp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
49 changes: 49 additions & 0 deletions sjpp/src/main/java/sjpp/SjppAntTask.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit cea452d

Please sign in to comment.