DeployTask.java

package org.docascode.ant;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.docascode.ant.types.Artifacts;
import org.docascode.api.DeployCommand;
import org.docascode.api.DocAsCode;
import org.docascode.api.core.errors.DocAsCodeException;
import org.docascode.api.event.Event;
import org.docascode.api.listener.EventListener;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DeployTask extends Task implements EventListener {
    private Artifacts artifacts = new Artifacts();
    public void add(Artifacts artifacts){
        this.artifacts = artifacts;
    }

    private List<String> ids = new ArrayList<>();
    public void setIds(String ids){
        if (!ids.equals("")) {
            this.ids = Arrays.asList(ids.split(","));
        }
    }

    private String profile;
    public void setProfile(String profile){
        this.profile = profile;
    }

    @Override
    public void execute() {
        try (DocAsCode docascode = DocAsCode.open()){
            ((DeployCommand) docascode.deploy().addListener(this))
                .addArtifacts(artifacts.toArtifacts())
                .addIds(this.ids)
                .setProfile(this.profile)
                .call();
        } catch (DocAsCodeException e) {
            throw new BuildException(e);
        }
    }

    @Override
    public void fireEvent(Event event) {
        log(event.getMessage());
    }
}