Search in sources :

Example 21 with BuildException

use of org.apache.tools.ant.BuildException in project lombok by rzwitserloot.

the class WebUpToDate method eval.

/**
	 * Evaluate (all) target and source file(s) to
	 * see if the target(s) is/are up-to-date.
	 * @return true if the target(s) is/are up-to-date
	 */
public boolean eval() {
    if (sourceFileSets.size() == 0 && sourceResources.size() == 0 && sourceFile == null) {
        throw new BuildException("At least one srcfile or a nested <srcfiles> or <srcresources> element must be set.");
    }
    if ((sourceFileSets.size() > 0 || sourceResources.size() > 0) && sourceFile != null) {
        throw new BuildException("Cannot specify both the srcfile attribute and a nested <srcfiles> or <srcresources> element.");
    }
    if (urlbase == null) {
        throw new BuildException("The urlbase attribute must be set.");
    }
    // if the source file isn't there, throw an exception
    if (sourceFile != null && !sourceFile.exists()) {
        throw new BuildException(sourceFile.getAbsolutePath() + " not found.");
    }
    boolean upToDate = true;
    if (sourceFile != null) {
        Resource fileResource = new FileResource(sourceFile);
        upToDate = isUpToDate(fileResource);
    }
    if (upToDate) {
        Enumeration e = sourceFileSets.elements();
        while (upToDate && e.hasMoreElements()) {
            FileSet fs = (FileSet) e.nextElement();
            Iterator it = fs.iterator();
            while (upToDate && it.hasNext()) {
                Resource r = (Resource) it.next();
                upToDate = isUpToDate(r);
            }
        }
    }
    if (upToDate) {
        Resource[] r = sourceResources.listResources();
        for (int i = 0; upToDate && i < r.length; i++) {
            upToDate = isUpToDate(r[i]);
        }
    }
    return upToDate;
}
Also used : Enumeration(java.util.Enumeration) FileSet(org.apache.tools.ant.types.FileSet) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) URLResource(org.apache.tools.ant.types.resources.URLResource) FileResource(org.apache.tools.ant.types.resources.FileResource) Iterator(java.util.Iterator) BuildException(org.apache.tools.ant.BuildException)

Example 22 with BuildException

use of org.apache.tools.ant.BuildException in project lombok by rzwitserloot.

the class WebUpToDate method isUpToDate.

private boolean isUpToDate(Resource r) throws BuildException {
    String url = urlbase + r.getName();
    Resource urlResource;
    try {
        urlResource = new URLResource(new URL(url));
    } catch (MalformedURLException e) {
        throw new BuildException("url is malformed: " + url, e);
    }
    if (SelectorUtils.isOutOfDate(r, urlResource, 20)) {
        log(r.getName() + " is newer than " + url, Project.MSG_VERBOSE);
        return false;
    } else {
        return true;
    }
}
Also used : URLResource(org.apache.tools.ant.types.resources.URLResource) MalformedURLException(java.net.MalformedURLException) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) URLResource(org.apache.tools.ant.types.resources.URLResource) BuildException(org.apache.tools.ant.BuildException) URL(java.net.URL)

Example 23 with BuildException

use of org.apache.tools.ant.BuildException in project liquibase by liquibase.

the class DatabaseType method createDatabase.

public Database createDatabase(ClassLoader classLoader) {
    logParameters();
    validateParameters();
    try {
        DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
        if (databaseClass != null) {
            Database databaseInstance = (Database) ClasspathUtils.newInstance(databaseClass, classLoader, Database.class);
            databaseFactory.register(databaseInstance);
        }
        DatabaseConnection jdbcConnection;
        if (getUrl().startsWith("offline:")) {
            jdbcConnection = new OfflineConnection(getUrl(), new ClassLoaderResourceAccessor(classLoader));
        } else {
            Driver driver = (Driver) ClasspathUtils.newInstance(getDriver(), classLoader, Driver.class);
            if (driver == null) {
                throw new BuildException("Unable to create Liquibase Database instance. Could not instantiate the JDBC driver.");
            }
            Properties connectionProps = new Properties();
            String user = getUser();
            if (user != null && !user.isEmpty()) {
                connectionProps.setProperty(USER, user);
            }
            String password = getPassword();
            if (password != null && !password.isEmpty()) {
                connectionProps.setProperty(PASSWORD, password);
            }
            ConnectionProperties connectionProperties = getConnectionProperties();
            if (connectionProperties != null) {
                connectionProps.putAll(connectionProperties.buildProperties());
            }
            Connection connection = driver.connect(getUrl(), connectionProps);
            if (connection == null) {
                throw new BuildException("Unable to create Liquibase Database instance. Could not connect to the database.");
            }
            jdbcConnection = new JdbcConnection(connection);
        }
        Database database = databaseFactory.findCorrectDatabaseImplementation(jdbcConnection);
        String schemaName = getDefaultSchemaName();
        if (schemaName != null) {
            database.setDefaultSchemaName(schemaName);
        }
        String catalogName = getDefaultCatalogName();
        if (catalogName != null) {
            database.setDefaultCatalogName(catalogName);
        }
        String currentDateTimeFunction = getCurrentDateTimeFunction();
        if (currentDateTimeFunction != null) {
            database.setCurrentDateTimeFunction(currentDateTimeFunction);
        }
        database.setOutputDefaultSchema(isOutputDefaultSchema());
        database.setOutputDefaultCatalog(isOutputDefaultCatalog());
        String liquibaseSchemaName = getLiquibaseSchemaName();
        if (liquibaseSchemaName != null) {
            database.setLiquibaseSchemaName(liquibaseSchemaName);
        }
        String liquibaseCatalogName = getLiquibaseCatalogName();
        if (liquibaseCatalogName != null) {
            database.setLiquibaseCatalogName(liquibaseCatalogName);
        }
        String databaseChangeLogTableName = getDatabaseChangeLogTableName();
        if (databaseChangeLogTableName != null) {
            database.setDatabaseChangeLogTableName(databaseChangeLogTableName);
        }
        String databaseChangeLogLockTableName = getDatabaseChangeLogLockTableName();
        if (databaseChangeLogLockTableName != null) {
            database.setDatabaseChangeLogLockTableName(databaseChangeLogLockTableName);
        }
        String liquibaseTablespaceName = getLiquibaseTablespaceName();
        if (liquibaseTablespaceName != null) {
            database.setLiquibaseTablespaceName(liquibaseTablespaceName);
        }
        return database;
    } catch (SQLException e) {
        throw new BuildException("Unable to create Liquibase database instance. A JDBC error occurred. " + e.toString(), e);
    } catch (DatabaseException e) {
        throw new BuildException("Unable to create Liquibase database instance. " + e.toString(), e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Driver(java.sql.Driver) JdbcConnection(liquibase.database.jvm.JdbcConnection) OfflineConnection(liquibase.database.OfflineConnection) Properties(java.util.Properties) DatabaseFactory(liquibase.database.DatabaseFactory) Database(liquibase.database.Database) DatabaseConnection(liquibase.database.DatabaseConnection) BuildException(org.apache.tools.ant.BuildException) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) DatabaseException(liquibase.exception.DatabaseException)

Example 24 with BuildException

use of org.apache.tools.ant.BuildException in project flyway by flyway.

the class AbstractFlywayTask method execute.

@Override
public void execute() throws BuildException {
    prepareClassPath();
    try {
        flyway.setClassLoader(Thread.currentThread().getContextClassLoader());
        flyway.setDataSource(createDataSource());
        if (resolvers != null) {
            flyway.setResolversAsClassNames(resolvers);
        }
        if (callbacks != null) {
            flyway.setCallbacksAsClassNames(callbacks);
        }
        Properties projectProperties = new Properties();
        projectProperties.putAll(getProject().getProperties());
        flyway.configure(projectProperties);
        flyway.configure(System.getProperties());
        flyway.setLocations(getLocations());
        addPlaceholdersFromProperties(placeholders, getProject().getProperties());
        flyway.setPlaceholders(placeholders);
        doExecute(flyway);
    } catch (Exception e) {
        throw new BuildException("Flyway Error: " + e.toString(), ExceptionUtils.getRootCause(e));
    }
}
Also used : BuildException(org.apache.tools.ant.BuildException) Properties(java.util.Properties) BuildException(org.apache.tools.ant.BuildException)

Example 25 with BuildException

use of org.apache.tools.ant.BuildException in project hibernate-orm by hibernate.

the class EnhancementTask method writeEnhancedClass.

private void writeEnhancedClass(File javaClassFile, byte[] result) {
    try {
        if (javaClassFile.delete()) {
            if (!javaClassFile.createNewFile()) {
                log("Unable to recreate class file [" + javaClassFile.getName() + "]", Project.MSG_INFO);
            }
        } else {
            log("Unable to delete class file [" + javaClassFile.getName() + "]", Project.MSG_INFO);
        }
        FileOutputStream outputStream = new FileOutputStream(javaClassFile, false);
        try {
            outputStream.write(result);
            outputStream.flush();
        } finally {
            try {
                outputStream.close();
            } catch (IOException ignore) {
            }
        }
    } catch (FileNotFoundException ignore) {
    // should not ever happen because of explicit checks
    } catch (IOException e) {
        throw new BuildException(String.format("Error processing included file [%s]", javaClassFile.getAbsolutePath()), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Aggregations

BuildException (org.apache.tools.ant.BuildException)930 IOException (java.io.IOException)390 File (java.io.File)365 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)75 ArrayList (java.util.ArrayList)65 InputStream (java.io.InputStream)62 Project (org.apache.tools.ant.Project)61 Resource (org.apache.tools.ant.types.Resource)58 FileSet (org.apache.tools.ant.types.FileSet)52 Path (org.apache.tools.ant.types.Path)52 Commandline (org.apache.tools.ant.types.Commandline)51 Properties (java.util.Properties)50 OutputStream (java.io.OutputStream)44 FileOutputStream (java.io.FileOutputStream)42 FileResource (org.apache.tools.ant.types.resources.FileResource)42 FileInputStream (java.io.FileInputStream)41 URL (java.net.URL)40 BufferedReader (java.io.BufferedReader)37 Writer (java.io.Writer)37 MalformedURLException (java.net.MalformedURLException)37