Search in sources :

Example 1 with AndFileFilter

use of org.apache.commons.io.filefilter.AndFileFilter in project robovm by robovm.

the class IOSTarget method copyToIndexedDir.

/**
     * Copies the dSYM and the executable to {@code ~/Library/Developer/Xcode/
     * DerivedData/RoboVM/Build/Products/<appname>_<timestamp>/}.
     */
private void copyToIndexedDir(File dir, String executable, File dsymDir, File exePath) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    final File indexedDir = new File(System.getProperty("user.home"), "Library/Developer/Xcode/DerivedData/RoboVM/Build/Products/" + FilenameUtils.removeExtension(dir.getName()) + "_" + sdf.format(new Date()));
    indexedDir.mkdirs();
    File indexedDSymDir = new File(indexedDir, dsymDir.getName());
    File indexedAppDir = new File(indexedDir, dir.getName());
    indexedAppDir.mkdirs();
    try {
        // No need to copy the whole .app folder. Just the exe
        // is enough to make symbolication happy.
        FileUtils.copyFile(exePath, new File(indexedAppDir, executable));
    } catch (IOException e) {
        config.getLogger().error("Failed to copy %s to indexed dir %s: %s", exePath.getAbsolutePath(), indexedAppDir.getAbsolutePath(), e.getMessage());
    }
    try {
        FileUtils.copyDirectory(dsymDir, indexedDSymDir);
    } catch (IOException e) {
        config.getLogger().error("Failed to copy %s to indexed dir %s: %s", dsymDir.getAbsolutePath(), indexedDir.getAbsolutePath(), e.getMessage());
    }
    // Now do some cleanup and delete all but the 3 most recent dirs
    List<File> dirs = new ArrayList<>(Arrays.asList(indexedDir.getParentFile().listFiles((FileFilter) new AndFileFilter(new PrefixFileFilter(FilenameUtils.removeExtension(dir.getName())), new RegexFileFilter(".*_\\d{14}")))));
    Collections.sort(dirs, new Comparator<File>() {

        public int compare(File o1, File o2) {
            return Long.compare(o1.lastModified(), o2.lastModified());
        }
    });
    if (dirs.size() > 3) {
        for (File f : dirs.subList(0, dirs.size() - 3)) {
            try {
                FileUtils.deleteDirectory(f);
            } catch (IOException e) {
                config.getLogger().error("Failed to delete diretcory %s", f.getAbsolutePath(), e.getMessage());
            }
        }
    }
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) ArrayList(java.util.ArrayList) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) PrefixFileFilter(org.apache.commons.io.filefilter.PrefixFileFilter)

Example 2 with AndFileFilter

use of org.apache.commons.io.filefilter.AndFileFilter in project tutorials by eugenp.

the class CommonsIOUnitTest method whenGetFilewith_ANDFileFilter_thenFindsampletxt.

@Test
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt() throws IOException {
    String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
    File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));
    Assert.assertEquals("sample.txt", dir.list(new AndFileFilter(new WildcardFileFilter("*ple*", IOCase.INSENSITIVE), new SuffixFileFilter("txt")))[0]);
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) Test(org.junit.Test)

Example 3 with AndFileFilter

use of org.apache.commons.io.filefilter.AndFileFilter in project druid by druid-io.

the class LocalInputSource method getDirectoryListingIterator.

private Iterator<File> getDirectoryListingIterator() {
    if (baseDir == null) {
        return Collections.emptyIterator();
    } else {
        final IOFileFilter fileFilter;
        if (files == null) {
            fileFilter = new WildcardFileFilter(filter);
        } else {
            fileFilter = new AndFileFilter(new WildcardFileFilter(filter), new NotFileFilter(new NameFileFilter(files.stream().map(File::getName).collect(Collectors.toList()), IOCase.SENSITIVE)));
        }
        Iterator<File> fileIterator = FileUtils.iterateFiles(baseDir.getAbsoluteFile(), fileFilter, TrueFileFilter.INSTANCE);
        if (!fileIterator.hasNext()) {
            // base dir & filter are guaranteed to be non-null here
            // (by construction and non-null check of baseDir a few lines above):
            log.info("Local inputSource filter [%s] for base dir [%s] did not match any files", filter, baseDir);
        }
        return fileIterator;
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File)

Example 4 with AndFileFilter

use of org.apache.commons.io.filefilter.AndFileFilter in project oxTrust by GluuFederation.

the class ViewLogFileAction method prepareLogFiles.

private Map<Integer, String> prepareLogFiles() {
    Map<Integer, String> logFiles = new HashMap<Integer, String>();
    int fileIndex = 0;
    for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) {
        String logTemplatePattern = logTemplate.getValue2();
        if (StringHelper.isEmpty(logTemplatePattern)) {
            continue;
        }
        String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern);
        String logTemplateFile = FilenameUtils.getName(logTemplatePattern);
        File logTemplateBaseDir = new File(logTemplatePath);
        FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile));
        File[] files = logTemplateBaseDir.listFiles(fileFilter);
        if (files == null) {
            continue;
        }
        for (int i = 0; i < files.length; i++) {
            logFiles.put(fileIndex++, files[i].getPath());
        }
    }
    return logFiles;
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) HashMap(java.util.HashMap) SimpleCustomProperty(org.gluu.model.SimpleCustomProperty) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) FileFileFilter(org.apache.commons.io.filefilter.FileFileFilter) FileFilter(java.io.FileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Example 5 with AndFileFilter

use of org.apache.commons.io.filefilter.AndFileFilter in project robovm by robovm.

the class IOSTarget method packageApplication.

private void packageApplication(File appDir) throws IOException {
    File ipaFile = new File(config.getInstallDir(), getExecutable() + ".ipa");
    config.getLogger().info("Packaging IPA %s from %s", ipaFile.getName(), appDir.getName());
    File tmpDir = new File(config.getInstallDir(), "ipabuild");
    FileUtils.deleteDirectory(tmpDir);
    tmpDir.mkdirs();
    File payloadDir = new File(tmpDir, "Payload");
    payloadDir.mkdir();
    config.getLogger().info("Copying %s to %s", appDir.getName(), payloadDir);
    new Executor(config.getLogger(), "cp").args("-Rp", appDir, payloadDir).exec();
    File frameworksDir = new File(appDir, "Frameworks");
    if (frameworksDir.exists()) {
        String[] swiftLibs = frameworksDir.list(new AndFileFilter(new PrefixFileFilter("libswift"), new SuffixFileFilter(".dylib")));
        if (swiftLibs.length > 0) {
            File swiftSupportDir = new File(tmpDir, "SwiftSupport");
            swiftSupportDir.mkdir();
            copySwiftLibs(Arrays.asList(swiftLibs), swiftSupportDir);
        }
    }
    config.getLogger().info("Zipping %s to %s", tmpDir, ipaFile);
    new Executor(Logger.NULL_LOGGER, "zip").wd(tmpDir).args("--symlinks", "--recurse-paths", ipaFile, ".").exec();
    config.getLogger().info("Deleting temp dir %s", tmpDir);
    FileUtils.deleteDirectory(tmpDir);
}
Also used : Executor(org.robovm.compiler.util.Executor) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) NSString(com.dd.plist.NSString) File(java.io.File) PrefixFileFilter(org.apache.commons.io.filefilter.PrefixFileFilter)

Aggregations

AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)7 File (java.io.File)5 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)4 PrefixFileFilter (org.apache.commons.io.filefilter.PrefixFileFilter)3 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)3 ArrayList (java.util.ArrayList)2 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)2 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)2 NSString (com.dd.plist.NSString)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 lombok.val (lombok.val)1 FileFileFilter (org.apache.commons.io.filefilter.FileFileFilter)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 OrFileFilter (org.apache.commons.io.filefilter.OrFileFilter)1 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)1 SimpleCustomProperty (org.gluu.model.SimpleCustomProperty)1