DeployCommand.java

package org.docascode.api;

import org.docascode.api.core.DocAsCodeRepository;
import org.docascode.api.core.errors.DocAsCodeException;
import org.docascode.api.core.mvn.MvnRepository;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.deployment.DeployResult;

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

public class DeployCommand extends DocAsCodeCommand<DeployResult> {
    public DeployCommand(DocAsCodeRepository repo) {
        super(repo);
    }

    private List<Artifact> artifacts = new ArrayList<>();
    public DeployCommand addArtifacts(List<Artifact> artifacts) {
        this.artifacts.addAll(artifacts);
        return this;
    }

    public DeployCommand addIds(List<String> ids) throws DocAsCodeException {
        this.artifacts.addAll(
                ((DocAsCodeRepository)getRepository().addListener(this)).chrono().toArtifacts(ids).values());
        return this;
    }

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

    @Override
    public DeployResult call() throws DocAsCodeException {
        MvnRepository mvnRepo =
                ((DocAsCodeRepository) getRepository().addListener(this)).mvn();
        mvnRepo.deploy(artifacts,mvnRepo.getRemoteRepositories(profile));
        return null;
    }


}