All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.integration.ant.DBDocTask Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.integration.ant;

import liquibase.Liquibase;
import liquibase.exception.LiquibaseException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.resources.FileResource;

import java.io.File;

public class DBDocTask extends BaseLiquibaseTask {
    private FileResource outputDirectory;
    private String changeLog;
    private String contexts;

    @Override
    public void executeWithLiquibaseClassloader() throws BuildException {
        File outputDirFile = outputDirectory.getFile();
        if(!outputDirFile.exists()) {
            boolean success = outputDirFile.mkdirs();
            if(!success) {
                throw new BuildException("Unable to create output directory.");
            }
        }
        if(!outputDirFile.isDirectory()) {
            throw new BuildException("Output path is not a directory.");
        }

        Liquibase liquibase = getLiquibase();
        try {
            if (contexts != null) {
                liquibase.generateDocumentation(outputDirectory.toString(), contexts);
            } else {
                liquibase.generateDocumentation(outputDirectory.toString());
            }
        } catch (LiquibaseException e) {
            throw new BuildException("Liquibase encountered an error while creating database documentation. " + e
            .toString(), e);
        }
    }

    @Override
    protected void validateParameters() {
        super.validateParameters();

        if(changeLog == null) {
            throw new BuildException("Change log is required.");
        }
        if(outputDirectory == null) {
            throw new BuildException("Output directory is required.");
        }
    }

    @Override
    protected String getChangeLogFile() {
        return changeLog;
    }

    public void setChangeLogFile(String changeLog) {
        this.changeLog = changeLog;
    }

    public FileResource getOutputDirectory() {
        return outputDirectory;
    }

    public void setOutputDirectory(FileResource outputDirectory) {
        this.outputDirectory = outputDirectory;
    }

    public void setContexts(String contexts) {
        this.contexts = contexts;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy