Search in sources :

Example 21 with FileResource

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

the class PermissionUtilsTest method getSetPermissionsWorksForFiles.

@Test
public void getSetPermissionsWorksForFiles() throws IOException {
    File f = File.createTempFile("ant", ".tst");
    f.deleteOnExit();
    Assume.assumeNotNull(Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class));
    Set<PosixFilePermission> s = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ);
    PermissionUtils.setPermissions(new FileResource(f), s, null);
    assertEquals(s, PermissionUtils.getPermissions(new FileResource(f), null));
}
Also used : FileResource(org.apache.tools.ant.types.resources.FileResource) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) File(java.io.File) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView) Test(org.junit.Test)

Example 22 with FileResource

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

the class ChangeLogSyncToTagTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    OutputStreamWriter writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = new OutputStreamWriter(outputFile.getOutputStream(), getOutputEncoding());
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels());
        }
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate sync SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate sync SQL. Error creating output writer.", e);
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to sync change log: " + e.getMessage(), e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) LiquibaseException(liquibase.exception.LiquibaseException) Contexts(liquibase.Contexts)

Example 23 with FileResource

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

the class DatabaseUpdateTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Writer writer = null;
    Liquibase liquibase = getLiquibase();
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = getOutputFileWriter();
            liquibase.update(toTag, new Contexts(getContexts()), getLabels(), writer);
        } else {
            if (dropFirst) {
                liquibase.dropAll();
            }
            liquibase.update(toTag, new Contexts(getContexts()), getLabels());
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to update database: " + e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate update SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate update SQL. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 24 with FileResource

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

the class DatabaseRollbackTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Writer writer = null;
    Liquibase liquibase = getLiquibase();
    try {
        FileResource outputFile = getOutputFile();
        if (rollbackCount != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else if (rollbackTag != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else if (rollbackDate != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else {
            throw new BuildException("Unable to rollback database. No count, tag, or date set.");
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to rollback database: " + e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate rollback SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate rollback SQL. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BuildException(org.apache.tools.ant.BuildException) LiquibaseException(liquibase.exception.LiquibaseException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 25 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)48 File (java.io.File)29 BuildException (org.apache.tools.ant.BuildException)25 Resource (org.apache.tools.ant.types.Resource)23 IOException (java.io.IOException)15 FileProvider (org.apache.tools.ant.types.resources.FileProvider)10 Test (org.junit.Test)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 Liquibase (liquibase.Liquibase)6 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)6 FileSet (org.apache.tools.ant.types.FileSet)6 Contexts (liquibase.Contexts)5 LiquibaseException (liquibase.exception.LiquibaseException)5 BufferedReader (java.io.BufferedReader)4 Reader (java.io.Reader)4 Writer (java.io.Writer)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4