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;
}
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;
}
}
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);
}
}
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));
}
}
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);
}
}
Aggregations