Search in sources :

Example 6 with FileResource

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.toString(), e);
        } finally {
            FileUtils.close(printStream);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileResource(org.apache.tools.ant.types.resources.FileResource) DiffOutputControl(liquibase.diff.output.DiffOutputControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) JsonChangeLogSerializer(liquibase.serializer.core.json.JsonChangeLogSerializer) YamlChangeLogSerializer(liquibase.serializer.core.yaml.YamlChangeLogSerializer) StringChangeLogSerializer(liquibase.serializer.core.string.StringChangeLogSerializer) XMLChangeLogSerializer(liquibase.serializer.core.xml.XMLChangeLogSerializer) IOException(java.io.IOException) ChangeLogOutputFile(liquibase.integration.ant.type.ChangeLogOutputFile) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) BuildException(org.apache.tools.ant.BuildException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DatabaseException(liquibase.exception.DatabaseException)

Example 7 with FileResource

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.toString(), e);
        } finally {
            FileUtils.close(printStream);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileResource(org.apache.tools.ant.types.resources.FileResource) DiffOutputControl(liquibase.diff.output.DiffOutputControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonChangeLogSerializer(liquibase.serializer.core.json.JsonChangeLogSerializer) StringChangeLogSerializer(liquibase.serializer.core.string.StringChangeLogSerializer) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) YamlChangeLogSerializer(liquibase.serializer.core.yaml.YamlChangeLogSerializer) XMLChangeLogSerializer(liquibase.serializer.core.xml.XMLChangeLogSerializer) IOException(java.io.IOException) CatalogAndSchema(liquibase.CatalogAndSchema) ChangeLogOutputFile(liquibase.integration.ant.type.ChangeLogOutputFile) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) BuildException(org.apache.tools.ant.BuildException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DatabaseException(liquibase.exception.DatabaseException)

Example 8 with FileResource

use of org.apache.tools.ant.types.resources.FileResource in project liquibase by liquibase.

the class MarkNextChangeSetRanTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    Writer writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = getOutputFileWriter();
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels());
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to mark next changeset as ran. " + e.toString(), e);
    } catch (IOException e) {
        throw new BuildException("Unable to mark next changeset as ran. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 9 with FileResource

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());
    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);
    }
}
Also used : InvalidFormatOptionException(lombok.delombok.Delombok.InvalidFormatOptionException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) FileResource(org.apache.tools.ant.types.resources.FileResource) Delombok(lombok.delombok.Delombok) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File)

Example 10 with FileResource

use of org.apache.tools.ant.types.resources.FileResource in project lucene-solr by apache.

the class GetMavenDependenciesTask method traverseIvyXmlResources.

private static void traverseIvyXmlResources(Resources ivyXmlResources, Consumer<File> ivyXmlFileConsumer) {
    @SuppressWarnings("unchecked") Iterator<Resource> iter = (Iterator<Resource>) ivyXmlResources.iterator();
    while (iter.hasNext()) {
        final Resource resource = iter.next();
        if (!resource.isExists()) {
            throw new BuildException("Resource does not exist: " + resource.getName());
        }
        if (!(resource instanceof FileResource)) {
            throw new BuildException("Only filesystem resources are supported: " + resource.getName() + ", was: " + resource.getClass().getName());
        }
        File ivyXmlFile = ((FileResource) resource).getFile();
        try {
            ivyXmlFileConsumer.accept(ivyXmlFile);
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException("Exception reading file " + ivyXmlFile.getPath() + ": " + e, e);
        }
    }
}
Also used : Iterator(java.util.Iterator) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) XPathExpressionException(javax.xml.xpath.XPathExpressionException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

FileResource (org.apache.tools.ant.types.resources.FileResource)12 BuildException (org.apache.tools.ant.BuildException)11 IOException (java.io.IOException)9 File (java.io.File)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 Liquibase (liquibase.Liquibase)5 Iterator (java.util.Iterator)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Contexts (liquibase.Contexts)4 LiquibaseException (liquibase.exception.LiquibaseException)4 Resource (org.apache.tools.ant.types.Resource)4 Writer (java.io.Writer)3 PrintStream (java.io.PrintStream)2 DiffOutputControl (liquibase.diff.output.DiffOutputControl)2 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)2 DatabaseException (liquibase.exception.DatabaseException)2 ChangeLogOutputFile (liquibase.integration.ant.type.ChangeLogOutputFile)2 ChangeLogSerializer (liquibase.serializer.ChangeLogSerializer)2 JsonChangeLogSerializer (liquibase.serializer.core.json.JsonChangeLogSerializer)2 StringChangeLogSerializer (liquibase.serializer.core.string.StringChangeLogSerializer)2