Example usage for org.apache.commons.io.filefilter FileFilterUtils andFileFilter

List of usage examples for org.apache.commons.io.filefilter FileFilterUtils andFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter FileFilterUtils andFileFilter.

Prototype

public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2) 

Source Link

Document

Returns a filter that ANDs the two specified filters.

Usage

From source file:com.liferay.maven.plugins.SassToCssBuilderMojo.java

protected void doExecute() throws Exception {
    FileFilter fileFilter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY,
            FileFilterUtils.andFileFilter(FileFileFilter.FILE, FileFilterUtils.suffixFileFilter(".css")));

    FileUtils.copyDirectory(webappSourceDir, webappDir, fileFilter, true);

    if (Validator.isNull(sassPortalCommonDir)) {
        File file = new File(appServerPortalDir, "html/css/common");

        sassPortalCommonDir = file.getAbsolutePath();
    }//from   www .  j  av a2  s.  co  m

    String[] args = null;

    String[] dirNames = StringUtil.split(sassDirNames);

    if (dirNames.length > 1) {
        if (getPortalMajorVersion() < PORTAL_VERSION_6_2) {
            args = new String[dirNames.length];
        } else {
            args = new String[dirNames.length + 2];

            args[dirNames.length] = "sass.docroot.dir=" + sassDocrootDir;
            args[dirNames.length + 1] = "sass.portal.common.dir=" + sassPortalCommonDir;
        }

        for (int i = 0; i < dirNames.length; i++) {
            if (getPortalMajorVersion() < PORTAL_VERSION_6_2) {
                args[i] = "sass.dir." + i + "=" + dirNames[i];
            }
        }
    } else {
        if (getPortalMajorVersion() < PORTAL_VERSION_6_2) {
            if (sassDirNames.equals("/")) {
                sassDirNames = "";
            }

            args = new String[] { "sass.dir=" + sassDocrootDir + sassDirNames };
        } else {
            args = new String[] { "sass.dir=" + sassDirNames, "sass.docroot.dir=" + sassDocrootDir,
                    "sass.portal.common.dir=" + sassPortalCommonDir };
        }
    }

    executeTool("com.liferay.portal.tools.SassToCssBuilder", getProjectClassLoader(), args);
}

From source file:com.wavemaker.tools.project.upgrade.six_dot_four.RemoveMySQLHBMCatalogUpgradeTask.java

@Override
public void doUpgrade(Project project, UpgradeInfo upgradeInfo) {
    Folder servicesFolder = project.getRootFolder().getFolder("services");
    // Don't bother if we do not have services
    try {//from  w  ww  .  ja  v  a 2s  .  c o m
        if (servicesFolder.exists()) {
            Resource servicesDir = project.getProjectRoot().createRelative("services/");
            ArrayList<String> mySQLServices = new ArrayList<String>();
            try {
                // Find MySQL Services
                IOFileFilter propFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(),
                        FileFilterUtils.suffixFileFilter("properties"));
                List<File> propFiles = new UpgradeFileFinder(propFilter).findFiles(servicesDir.getFile());
                Iterator<File> propIt = propFiles.iterator();
                while (propIt.hasNext()) {
                    File propFile = propIt.next();
                    String propContent = FileUtils.readFileToString(propFile);
                    if (propContent.contains(mySQLStr)) {
                        String propFileName = propFile.getName();
                        int index = propFileName.lastIndexOf(".");
                        if (index > 0 && index <= propFileName.length()) {
                            mySQLServices.add(propFileName.substring(0, index));
                        }
                    }
                }
                // Find HBM files in MySQLServices
                Iterator<String> servIt = mySQLServices.iterator();
                while (servIt.hasNext()) {
                    IOFileFilter hbmFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(),
                            FileFilterUtils.suffixFileFilter("hbm.xml"));
                    String path = servIt.next();
                    Resource mySQLServiceDir = servicesDir
                            .createRelative(path.endsWith("/") ? path : path + "/");
                    List<File> hbmFiles = new UpgradeFileFinder(hbmFilter).findFiles(mySQLServiceDir.getFile());
                    Iterator<File> hbmIt = hbmFiles.iterator();
                    while (hbmIt.hasNext()) {
                        File hbmFile = hbmIt.next();
                        String hbmContent = FileUtils.readFileToString(hbmFile);
                        hbmContent.replaceFirst(catalogStr, replaceStr);
                        FileUtils.writeStringToFile(hbmFile, hbmContent);
                        System.out
                                .println("Project upgrade: Catalog removed from " + hbmFile.getAbsolutePath());
                    }
                }
                if (!mySQLServices.isEmpty()) {
                    upgradeInfo.addMessage("\nMySQL Catalog upgrade task completed. See wm.log for details");
                } else {
                    System.out.println("Project Upgrade: No MySQL Services found");
                }
            } catch (IOException ioe) {
                upgradeInfo
                        .addMessage("\nError removing Catalog from MySQL Services. Check wm.log for details.");
                ioe.printStackTrace();
            }
        } else {
            System.out.println("Project Upgrade: No Services found");
        }
    } catch (IOException e) {
        throw new WMRuntimeException(e);
    }
}

From source file:it.geosolutions.tools.io.file.FileRemover.java

public static List<File> collectOlder(final long time, final int daysAgo, final File root) {
    if (daysAgo < 0) {
        return null;
    }/*from  w  w w.jav a 2 s  .  c  om*/
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);
    int days = cal.get(Calendar.DAY_OF_YEAR);
    if (days >= daysAgo)
        cal.set(Calendar.DAY_OF_YEAR, days - daysAgo);
    else {
        // TODO use getActualMaximum for days
        cal.set(Calendar.DAY_OF_YEAR, (354 + (days - daysAgo)));
        cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) - 1);
    }
    // cal.getTime().toString()
    final Collector coll = new Collector(FileFilterUtils.andFileFilter(FileFilterUtils.directoryFileFilter(),
            FileFilterUtils.ageFileFilter(cal.getTime(), true)), 1);
    return coll.collect(root);
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.io.Files2.java

/**
 * A variation on {@link FileUtils#listFiles(File, IOFileFilter, IOFileFilter) listFiles}
 * that also optionally includes directories matched in the result.
 *//*from   w  w  w  .  j a va2  s .co m*/
public static Collection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter,
        boolean includeDirs) {
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Parameter 'directory' is not a directory");
    }
    if (fileFilter == null) {
        throw new NullPointerException("Parameter 'fileFilter' is null");
    }

    //Setup effective file filter
    IOFileFilter effFileFilter = FileFilterUtils.andFileFilter(fileFilter,
            FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));

    //Setup effective directory filter
    IOFileFilter effDirFilter;
    if (dirFilter == null) {
        effDirFilter = FalseFileFilter.INSTANCE;
    } else {
        effDirFilter = FileFilterUtils.andFileFilter(dirFilter, DirectoryFileFilter.INSTANCE);
    }

    //Find files
    Collection<File> files = new LinkedList<File>();
    innerListFiles(files, directory, FileFilterUtils.orFileFilter(effFileFilter, effDirFilter), includeDirs);
    return files;
}

From source file:ext.deployit.community.cli.plainarchive.io.Files2.java

/**
 * A variation on {@link FileUtils#listFiles(File, IOFileFilter, IOFileFilter) listFiles}
 * that also optionally includes directories matched in the result.
 *///w w w  .j av  a 2s . c o m
public static Collection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter,
        boolean includeDirs) {
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException(format("Parameter '%s' is not a directory", directory));
    }
    if (fileFilter == null) {
        throw new NullPointerException("Parameter 'fileFilter' is null");
    }

    //Setup effective file filter
    IOFileFilter effFileFilter = FileFilterUtils.andFileFilter(fileFilter,
            FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));

    //Setup effective directory filter
    IOFileFilter effDirFilter;
    if (dirFilter == null) {
        effDirFilter = FalseFileFilter.INSTANCE;
    } else {
        effDirFilter = FileFilterUtils.andFileFilter(dirFilter, DirectoryFileFilter.INSTANCE);
    }

    //Find files
    Collection<File> files = new LinkedList<File>();
    innerListFiles(files, directory, FileFilterUtils.orFileFilter(effFileFilter, effDirFilter), includeDirs);
    return files;
}

From source file:com.aionengine.gameserver.dataholders.DataLoader.java

/**
 * This method is supposed to be called from subclass to initialize data loading process.<br>
 * <br>//from   ww w. j  a  va  2 s  . com
 * This method is using file given in the constructor to load the data and there are two possibilities:
 * <ul>
 * <li>Given file is file is in deed the <b>file</b> then it's forwarded to {@link #loadFile(File)} method</li>
 * <li>Given file is a <b>directory</b>, then this method is obtaining list of all visible .txt files in this
 * directory and subdirectiores ( except hidden ones and those named "new" ) and call {@link #loadFile(File)} for
 * each of these files.
 * </ul>
 */
protected void loadData() {
    if (dataFile.isDirectory()) {
        Collection<?> files = FileUtils
                .listFiles(dataFile,
                        FileFilterUtils
                                .andFileFilter(
                                        FileFilterUtils.andFileFilter(
                                                FileFilterUtils
                                                        .notFileFilter(FileFilterUtils.nameFileFilter("new")),
                                                FileFilterUtils.suffixFileFilter(".txt")),
                                        HiddenFileFilter.VISIBLE),
                        HiddenFileFilter.VISIBLE);

        for (Object file1 : files) {
            File f = (File) file1;
            loadFile(f);
        }
    } else {
        loadFile(dataFile);
    }
}

From source file:com.aionemu.gameserver.dataholders.DataLoader.java

/**
 * This method is supposed to be called from subclass to initialize data
 * loading process.<br>/*from  w  w w  . j  av  a 2s . co m*/
 * <br>
 * This method is using file given in the constructor to load the data and
 * there are two possibilities:
 * <ul>
 * <li>Given file is file is in deed the <b>file</b> then it's forwarded to
 * {@link #loadFile(File)} method</li>
 * <li>Given file is a <b>directory</b>, then this method is obtaining list
 * of all visible .txt files in this directory and subdirectiores ( except
 * hidden ones and those named "new" ) and call {@link #loadFile(File)} for
 * each of these files.
 * </ul>
 */
@SuppressWarnings("deprecation")
protected void loadData() {
    if (dataFile.isDirectory()) {
        Collection<?> files = FileUtils
                .listFiles(dataFile,
                        FileFilterUtils
                                .andFileFilter(
                                        FileFilterUtils.andFileFilter(
                                                FileFilterUtils
                                                        .notFileFilter(FileFilterUtils.nameFileFilter("new")),
                                                FileFilterUtils.suffixFileFilter(".txt")),
                                        HiddenFileFilter.VISIBLE),
                        HiddenFileFilter.VISIBLE);

        for (Object file1 : files) {
            File f = (File) file1;
            loadFile(f);
        }
    } else {
        loadFile(dataFile);
    }
}

From source file:net.sf.firemox.xml.XmlConfiguration.java

/**
 * <ul>//  w ww . ja  v a2s.  c o  m
 * 2 modes:
 * <li>Update the a MDB for specified TBS against the XML files (main file,
 * cards and fragments). Arguments are : TBS_NAME</li>
 * <li>Rebuild completely the MDB for specified TBS. Arguments are : -full
 * TBS_NAME</li>
 * </ul>
 * 
 * @param args
 *          main arguments.
 */
public static void main(String... args) {
    options = new Options();
    final CmdLineParser parser = new CmdLineParser(options);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        // Display help
        info(e.getMessage());
        parser.setUsageWidth(80);
        parser.printUsage(System.out);
        System.exit(-1);
        return;
    }

    if (options.isVersion()) {
        // Display version
        info("Version is " + IdConst.VERSION);
        System.exit(-1);
        return;
    }

    if (options.isHelp()) {
        // Display help
        parser.setUsageWidth(80);
        parser.printUsage(System.out);
        System.exit(-1);
        return;
    }

    warning = 0;
    uncompleted = 0;
    error = 0;
    long start = System.currentTimeMillis();
    XmlTools.initHashMaps();
    MToolKit.tbsName = options.getMdb();
    String xmlFile = MToolKit.getFile(IdConst.TBS_DIR + "/" + MToolKit.tbsName + ".xml", false)
            .getAbsolutePath();
    try {
        if (options.isForce()) {
            final File recycledDir = MToolKit.getTbsFile("recycled");
            if (!recycledDir.exists() || !recycledDir.isDirectory()) {
                recycledDir.mkdir();
            }

            parseRules(xmlFile, MToolKit.getTbsFile("recycled").getAbsolutePath(),
                    new FileOutputStream(MToolKit.getTbsFile(MToolKit.tbsName + ".mdb", false)));
        } else {
            // Check the up-to-date state of MDB
            final File file = MToolKit
                    .getFile(IdConst.TBS_DIR + "/" + MToolKit.tbsName + "/" + MToolKit.tbsName + ".mdb");
            final long lastModifiedMdb;
            if (file == null) {
                lastModifiedMdb = 0;
            } else {
                lastModifiedMdb = file.lastModified();
            }
            boolean update = false;
            // Check the up-to-date state of MDB against the main XML file
            if (MToolKit.getFile(xmlFile).lastModified() > lastModifiedMdb) {
                // The main XML file is newer than MDB
                System.out.println("MDB is out of date, " + xmlFile + " is newer");
                update = true;
            } else {
                final File fragmentDir = MToolKit.getTbsFile("");
                for (File frament : fragmentDir.listFiles(
                        (FilenameFilter) FileFilterUtils.andFileFilter(FileFilterUtils.suffixFileFilter("xml"),
                                FileFilterUtils.prefixFileFilter("fragment-")))) {
                    if (frament.lastModified() > lastModifiedMdb) {
                        // One card is newer than MDB
                        System.out.println(
                                "MDB is out of date, at least one fragment found : " + frament.getName());
                        update = true;
                        break;
                    }
                }
                if (!update) {
                    // Check the up-to-date state of MDB against the cards
                    final File recycledDir = MToolKit.getTbsFile("recycled");
                    if (!recycledDir.exists() || !recycledDir.isDirectory()) {
                        recycledDir.mkdir();
                    }
                    if (recycledDir.lastModified() > lastModifiedMdb) {
                        // The recycled XML file is newer than MDB
                        System.out.println("MDB is out of date, the recycled directory is new");
                        update = true;
                    } else {
                        for (File card : recycledDir.listFiles((FilenameFilter) FileFilterUtils.andFileFilter(
                                FileFilterUtils.suffixFileFilter("xml"), FileFilterUtils.notFileFilter(
                                        FileFilterUtils.suffixFileFilter(IdConst.FILE_DATABASE_SAVED))))) {
                            if (card.lastModified() > lastModifiedMdb) {
                                // One card is newer than MDB
                                System.out.println("MDB is out of date, at least one new card found : " + card);
                                update = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!update) {
                return;
            }
            // Need to update the whole MDB
            parseRules(xmlFile, MToolKit.getTbsFile("recycled").getAbsolutePath(),
                    new FileOutputStream(MToolKit.getTbsFile(MToolKit.tbsName + ".mdb", false)));
        }
    } catch (SAXParseException e) {
        // Ignore this error
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (warning > 0) {
        System.out.println("\t" + warning + " warning" + (warning > 1 ? "s" : ""));
    }
    if (error > 0) {
        System.out.println("\t" + error + " error" + (error > 1 ? "s" : ""));
        System.out.println("Some cards have not been built correctly. Fix them.");
    } else {
        System.out.println("\tSuccessfull build");
    }
    System.out.println("\tTime : " + (System.currentTimeMillis() - start) / 1000 + " s");
}

From source file:net.sf.firemox.xml.XmlTbs.java

/**
 * Reads from the tbs directory the existing XML files, parse them, add them
 * to the mdb file in the right order//from w  w  w  . j a va2s . com
 * 
 * @param mdbName
 *          the mdb name used to find the directory containing the XML files.
 * @param out
 *          the outputStream where the cards would written in.
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void updateMdb(String mdbName, OutputStream out) throws IOException {
    final String incomingDir = IdConst.TBS_DIR + "/" + mdbName + "/recycled";

    // Save the first card's code offset
    final long referenceOffset = ((FileOutputStream) out).getChannel().position();
    MToolKit.writeInt24(out, 0);

    // initialize the card pager
    cardPager = new ReferencePager();

    // list the available cards
    final String[] cards = MToolKit.getFile(incomingDir).list(FileFilterUtils.andFileFilter(
            FileFilterUtils.suffixFileFilter("xml"),
            FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(IdConst.FILE_DATABASE_SAVED))));
    final Pair<String, String>[] sortedPair = new Pair[cards.length];
    for (int i = sortedPair.length; i-- > 0;) {
        sortedPair[i] = new Pair<String, String>(cards[i].toLowerCase(), cards[i]);
    }
    Arrays.sort(sortedPair);

    System.out.println("\t" + sortedPair.length + " founds ...");
    for (Pair<String, String> pair : sortedPair) {
        final File file = MToolKit.getFile(incomingDir + "/" + pair.value);
        try {
            referencedAbilities = null;
            referencedTest = null;
            referencedActions = null;
            referencedNonMacroActions = null;
            writeCard(incomingDir, out, file.getAbsolutePath());
        } catch (InternalError e) {
            XmlConfiguration.error(e.getMessage());
        }
    }

    // Save the first card's code offset
    final long curentOffset = ((FileOutputStream) out).getChannel().position();
    ((FileOutputStream) out).getChannel().position(referenceOffset);
    MToolKit.writeInt24(out, (int) curentOffset);
    ((FileOutputStream) out).getChannel().position(curentOffset);

    // Write the card references
    cardPager.write(out);

    System.out.println("Build completed");
    System.out.println("\t" + sortedPair.length + " proceeded card" + (sortedPair.length > 1 ? "s" : ""));
    System.out.println("\t" + XmlConfiguration.uncompleted + " uncompleted card"
            + (XmlConfiguration.uncompleted > 1 ? "s" : ""));
    System.out.println(
            "\tRate : " + (sortedPair.length - XmlConfiguration.uncompleted) * 100. / sortedPair.length + "%");
}

From source file:com.jaxio.celerio.util.IOUtil.java

/**
 * Recurse in the folder to get the list all files and folders
 * <ul>/*from   w  w  w  .  j a  v  a  2s .c o m*/
 * <li>do not recurse in svn folder</li>
 * <li>do not recurse in cvs folder</li>
 * <li>do not match .bak files</li>
 * <li>do not match .old files</li>
 * </ul>
 *
 * @param folder       the folder to parse
 * @param ioFileFilter additionnal IOFilter
 */
@SuppressWarnings("unchecked")
public Collection<String> listFiles(File folder, IOFileFilter ioFileFilter) {
    if (ioFileFilter == null) {
        ioFileFilter = FileFilterUtils.fileFileFilter();
    }
    OrFileFilter oldFilesFilter = new OrFileFilter();
    for (String exclude : DEFAULT_EXCLUDES_SUFFIXES) {
        oldFilesFilter.addFileFilter(FileFilterUtils.suffixFileFilter(exclude));
    }
    IOFileFilter notOldFilesFilter = FileFilterUtils.notFileFilter(oldFilesFilter);

    Collection<File> files = FileUtils.listFiles(folder,
            FileFilterUtils.andFileFilter(ioFileFilter, notOldFilesFilter),
            FileFilterUtils.makeSVNAware(FileFilterUtils.makeCVSAware(null)));
    Collection<String> ret = newArrayList();
    for (File file : files) {
        ret.add(file.getAbsolutePath());
    }
    return ret;
}