use of org.apache.tools.ant.types.resources.FileResource in project liquibase by liquibase.
the class DiffDatabaseToChangeLogTask method executeWithLiquibaseClassloader.
@Override
protected void executeWithLiquibaseClassloader() throws BuildException {
for (ChangeLogOutputFile changeLogOutputFile : changeLogOutputFiles) {
PrintStream printStream = null;
String encoding = getOutputEncoding(changeLogOutputFile);
try {
FileResource outputFile = changeLogOutputFile.getOutputFile();
ChangeLogSerializer changeLogSerializer = changeLogOutputFile.getChangeLogSerializer();
printStream = new PrintStream(outputFile.getOutputStream(), true, encoding);
DiffResult diffResult = getDiffResult();
DiffOutputControl diffOutputControl = getDiffOutputControl();
DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, diffOutputControl);
diffToChangeLog.print(printStream, changeLogSerializer);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to diff databases to change log file. Encoding [" + encoding + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to diff databases to change log file. Error creating output stream.", e);
} catch (ParserConfigurationException e) {
throw new BuildException("Unable to diff databases to change log file. Error configuring parser.", e);
} catch (DatabaseException e) {
throw new BuildException("Unable to diff databases to change log file: " + e.getMessage(), e);
} finally {
FileUtils.close(printStream);
}
}
}
use of org.apache.tools.ant.types.resources.FileResource in project liquibase by liquibase.
the class GenerateChangeLogTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
Database database = liquibase.getDatabase();
CatalogAndSchema catalogAndSchema = buildCatalogAndSchema(database);
DiffOutputControl diffOutputControl = getDiffOutputControl();
DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffOutputControl);
for (ChangeLogOutputFile changeLogOutputFile : changeLogOutputFiles) {
String encoding = getOutputEncoding(changeLogOutputFile);
PrintStream printStream = null;
try {
FileResource outputFile = changeLogOutputFile.getOutputFile();
ChangeLogSerializer changeLogSerializer = changeLogOutputFile.getChangeLogSerializer();
log("Writing change log file " + outputFile.toString(), Project.MSG_INFO);
printStream = new PrintStream(outputFile.getOutputStream(), true, encoding);
liquibase.generateChangeLog(catalogAndSchema, diffToChangeLog, printStream, changeLogSerializer);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate a change log. Encoding [" + encoding + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate a change log. Error creating output stream.", e);
} catch (ParserConfigurationException e) {
throw new BuildException("Unable to generate a change log. Error configuring parser.", e);
} catch (DatabaseException e) {
throw new BuildException("Unable to generate a change log: " + e.getMessage(), e);
} finally {
FileUtils.close(printStream);
}
}
}
use of org.apache.tools.ant.types.resources.FileResource in project lombok by rzwitserloot.
the class DelombokTaskImpl method execute.
public void execute(Location location) throws BuildException {
if (fromDir == null && path == null)
throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required.");
if (fromDir != null && path != null)
throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other.");
if (toDir == null)
throw new BuildException("The to attribute is required.");
Delombok delombok = new Delombok();
if (verbose)
delombok.setVerbose(true);
try {
if (encoding != null)
delombok.setCharset(encoding);
} catch (UnsupportedCharsetException e) {
throw new BuildException("Unknown charset: " + encoding, location);
}
if (classpath != null)
delombok.setClasspath(classpath.toString());
if (sourcepath != null)
delombok.setSourcepath(sourcepath.toString());
if (modulepath != null)
delombok.setModulepath(modulepath.toString());
try {
delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));
} catch (InvalidFormatOptionException e) {
throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help.");
}
delombok.setOutput(toDir);
try {
if (fromDir != null)
delombok.addDirectory(fromDir);
else {
Iterator<?> it = path.iterator();
while (it.hasNext()) {
FileResource fileResource = (FileResource) it.next();
File baseDir = fileResource.getBaseDir();
if (baseDir == null) {
File file = fileResource.getFile();
delombok.addFile(file.getParentFile(), file.getName());
} else {
delombok.addFile(baseDir, fileResource.getName());
}
}
}
delombok.delombok();
} catch (IOException e) {
throw new BuildException("I/O problem during delombok", e, location);
}
}
Aggregations