Search in sources :

Example 1 with SetupException

use of liquibase.exception.SetupException in project liquibase by liquibase.

the class DatabaseChangeLog method includeAll.

public void includeAll(String pathName, boolean isRelativeToChangelogFile, IncludeAllFilter resourceFilter, boolean errorIfMissingOrEmpty, Comparator<String> resourceComparator, ResourceAccessor resourceAccessor, ContextExpression includeContexts) throws SetupException {
    try {
        if (pathName == null) {
            throw new SetupException("No path attribute for includeAll");
        }
        pathName = pathName.replace('\\', '/');
        if (!(pathName.endsWith("/"))) {
            pathName = pathName + '/';
        }
        Logger log = LogFactory.getInstance().getLog();
        log.debug("includeAll for " + pathName);
        log.debug("Using file opener for includeAll: " + resourceAccessor.toString());
        String relativeTo = null;
        if (isRelativeToChangelogFile) {
            relativeTo = this.getPhysicalFilePath();
        }
        Set<String> unsortedResources = null;
        try {
            unsortedResources = resourceAccessor.list(relativeTo, pathName, true, false, true);
        } catch (FileNotFoundException e) {
            if (errorIfMissingOrEmpty) {
                throw e;
            }
        }
        SortedSet<String> resources = new TreeSet<String>(resourceComparator);
        if (unsortedResources != null) {
            for (String resourcePath : unsortedResources) {
                if (resourceFilter == null || resourceFilter.include(resourcePath)) {
                    resources.add(resourcePath);
                }
            }
        }
        if (resources.size() == 0 && errorIfMissingOrEmpty) {
            throw new SetupException("Could not find directory or directory was empty for includeAll '" + pathName + "'");
        }
        for (String path : resources) {
            include(path, false, resourceAccessor, includeContexts);
        }
    } catch (Exception e) {
        throw new SetupException(e);
    }
}
Also used : SetupException(liquibase.exception.SetupException) FileNotFoundException(java.io.FileNotFoundException) Logger(liquibase.logging.Logger) ParsedNodeException(liquibase.parser.core.ParsedNodeException) SetupException(liquibase.exception.SetupException) UnknownChangelogFormatException(liquibase.exception.UnknownChangelogFormatException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ValidationFailedException(liquibase.exception.ValidationFailedException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 2 with SetupException

use of liquibase.exception.SetupException in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_setupException.

@Test
public void visit_setupException() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public void finishInitialization() throws SetupException {
            throw new SetupException("Test message");
        }
    });
    ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getSetupExceptions().size());
    assertEquals("Test message", handler.getSetupExceptions().get(0).getMessage());
    assertFalse(handler.validationPassed());
}
Also used : SetupException(liquibase.exception.SetupException) CreateTableChange(liquibase.change.core.CreateTableChange) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Aggregations

SetupException (liquibase.exception.SetupException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 CreateTableChange (liquibase.change.core.CreateTableChange)1 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)1 RanChangeSet (liquibase.changelog.RanChangeSet)1 LiquibaseException (liquibase.exception.LiquibaseException)1 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)1 UnknownChangelogFormatException (liquibase.exception.UnknownChangelogFormatException)1 ValidationFailedException (liquibase.exception.ValidationFailedException)1 Logger (liquibase.logging.Logger)1 ParsedNodeException (liquibase.parser.core.ParsedNodeException)1 Test (org.junit.Test)1