UpdateTask.java
package org.docascode.ant;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.docascode.api.DocAsCode;
import org.docascode.api.UpdateCommand;
import org.docascode.api.core.errors.DocAsCodeException;
import org.docascode.api.event.Event;
import org.docascode.api.listener.EventListener;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UpdateTask extends Task implements EventListener {
private File file;
public void setFile(File file){
this.file = file;
}
private List<Property> properties = new ArrayList<>();
public void addProperty (Property property){
this.properties.add(property);
}
@Override
public void execute() {
Map<String, String> map = new HashMap<>();
for (Property p : properties){
map.put(p.name,p.value);
}
try {
((UpdateCommand) DocAsCode.update().addListener(this))
.setFile(file)
.setProperties(map)
.call();
} catch (DocAsCodeException e) {
throw new BuildException(e);
}
}
@Override
public void fireEvent(Event event) {
log(event.getMessage());
}
public static class Property{
private String name;
public void setName(String name){
this.name = name;
}
private String value;
public void setValue(String value){
this.value = value;
}
}
}