Example usage for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY

List of usage examples for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY

Introduction

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

Prototype

IOFileFilter DIRECTORY

To view the source code for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY.

Click Source Link

Document

Singleton instance of directory filter.

Usage

From source file:com.hp.test.framework.Utlis.java

public static void main(String ar[]) throws IOException {

    ArrayList<String> runs_list = new ArrayList<String>();
    String basepath = replacelogs();
    String path = basepath + "ATU Reports\\Results";
    File directory = new File(path);
    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    for (File dir : subdirs) {
        log.info("Directory: " + dir.getName());
        runs_list.add(dir.getName());//from ww w  .jav a2s  . c om
    }

    Map<String, List<String>> runCounts = GetCountsrunsWise(runs_list, path);

    int success = replaceCounts(runCounts, path);

    if (success == 0) {
        File SourceFile = new File(path + "\\lineChart_temp.js");
        File RenameFile = new File(path + "\\lineChart.js");

        renameOriginalFile(SourceFile, RenameFile);

        File SourceFile1 = new File(path + "\\barChart_temp.js");
        File RenameFile1 = new File(path + "\\barChart.js");

        renameOriginalFile(SourceFile1, RenameFile1);

        String Reports_path = basepath + "ATU Reports\\";
        int LatestRun = Utlis.getLastRun(Reports_path);
        Utlis.getpaths(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun));
        try {
            Utlis.replaceMainTable(false, new File(Reports_path + "index.html"));
            Utlis.replaceMainTable(true, new File(Reports_path + "results\\" + "ConsolidatedPage.html"));
            Utlis.replaceMainTable(true,
                    new File(Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));

            fileList.add(
                    new File(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));
            for (File f : fileList) {
                Utlis.replaceMainTable(true, f);
            }

        } catch (Exception ex) {
            log.error("Error in updating Report format" + ex.getMessage());
        }
    }

}

From source file:com.nuance.expertassistant.ContentCrawler.java

public static void main(String args[]) {
    if (args.length == 0) {
        ContentExtractor.startDocument("Test3", "/Users/abhishek_rohatgi/" + "Test3" + ".xml");
        ContentExtractor.extract("http://www.audihelp.com/auda-147-tyre_repairs.html");
        ContentExtractor.endDocument();/*from ww  w.ja v  a 2 s.com*/
    } else {
        final ContentCrawlerOptions options = new ContentCrawlerOptions(args);
        final ContentCrawlerInputTypes inputType = ContentCrawlerOptions.getInputType();
        if (ContentCrawlerInputTypes.FILE.equals(inputType)) {
            final File outputFile = new File(getOutput());
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }
            translateFile(getInput(), getOutput());
        } else if (ContentCrawlerInputTypes.FOLDER.equals(inputType)) {
            final File outputFolder = new File(getOutput());
            final Collection<File> inputFiles = FileUtils.listFiles(new File(getInput()),
                    new RegexFileFilter("^(.*\\.(html)?)"), DirectoryFileFilter.DIRECTORY);
            for (final File inputFile : inputFiles) {
                final String outputFileName = inputFile.getAbsolutePath().substring(getInput().length())
                        + ".xml";
                final File outputFile = new File(outputFolder, outputFileName);
                if (!outputFile.getParentFile().exists()) {
                    outputFile.getParentFile().mkdirs();
                }
                translateFile(inputFile.getAbsolutePath(), outputFile.getAbsolutePath());
            }

        } else {
            ContentExtractor.startDocument(getInput(), getOutput());
            ContentExtractor.extract(getInput());
            ContentExtractor.endDocument();
        }
    }
}

From source file:com.makkajai.ObjCToCpp.java

/**
 * Main Method/*  www.j a va2 s.c  o m*/
 *
 * @param args - First argument is the input directory to scan and second is the output directory to write files to.
 * @throws IOException
 */
public static void main(String[] args) throws IOException {

    if (args.length < 2) {
        System.out.println("Invalid Arguments!");
        System.out.println(
                "Usage: java com.makkajai.ObjCToCpp \"<directory to scan for .h and .m files>\" \"<directory to write .h and .cpp files>\"");
        return;
    }

    String inputDirectory = args[0];
    String outputDirectory = args[1];
    //     String inputDirectory = "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/scenes";
    //     String outputDirectory = "/Users/administrator/playground/projarea/monster-math-cross-platform/monster-math-2/Classes/Makkajai/scenes";

    List<String> exceptFiles = new ArrayList<String>();

    if (args.length == 3) {
        BufferedReader bufferedInputStream = new BufferedReader(new FileReader(args[2]));
        String exceptFile = null;
        while ((exceptFile = bufferedInputStream.readLine()) != null) {
            if (exceptFile.equals(""))
                continue;
            exceptFiles.add(exceptFile);
        }
    }

    //Getting all the files from the input directory.
    final List<File> files = new ArrayList<File>(FileUtils.listFiles(new File(inputDirectory),
            new RegexFileFilter(FILE_NAME_WITH_H_OR_M), DirectoryFileFilter.DIRECTORY));

    //        String fileName =
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Utils/MakkajaiEnum"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Utils/MakkajaiUtil"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Home"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Activities/gnumchmenu/PlayStrategy"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Characters/Character"
    //                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/Activities/gnumchmenu/GnumchScene"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/ParentScene"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/BaseSkillView"
    ////                "/Users/administrator/playground/projarea/math-monsters-2/makkajai-number-muncher/makkajai-ios/Makkajai/Makkajai/YDLayerBase"
    //                ;
    //The instance of the translator.
    ObjCToCppTranslator visitor = new ObjCToCppTranslator();

    for (int i = 0; i < files.size();) {
        File currentFile = files.get(i);
        String filePathRelativeToInput = currentFile.getAbsolutePath().replace(inputDirectory, "");
        Date startTime = new Date();
        try {
            final TranslateFileInput translateFileInput = new TranslateFileInput(inputDirectory,
                    outputDirectory, filePathRelativeToInput, false);
            if (nextFileIsM(currentFile, files, i)) {
                try {
                    if (isIgnoredFile(filePathRelativeToInput, exceptFiles))
                        continue;
                    translateFileInput.dryRun = true;
                    visitor.translateFile(translateFileInput);
                    Date stopTime = new Date();
                    System.out.println("Dry run File: " + translateFileInput.filePathRelativeToInput
                            + " Time Taken: " + getDelta(startTime, stopTime));

                    Date startTime1 = new Date();
                    translateFileInput.filePathRelativeToInput = filePathRelativeToInput.replace(H, M);
                    translateFileInput.dryRun = false;
                    visitor.translateFile(translateFileInput);
                    stopTime = new Date();
                    System.out.println("Processed File: " + translateFileInput.filePathRelativeToInput
                            + " Time Taken: " + getDelta(startTime1, stopTime));

                    Date startTime2 = new Date();
                    translateFileInput.filePathRelativeToInput = filePathRelativeToInput;
                    translateFileInput.dryRun = false;
                    visitor.translateFile(translateFileInput);
                    stopTime = new Date();
                    System.out.println("Processed File: " + translateFileInput.filePathRelativeToInput
                            + " Time Taken: " + getDelta(startTime2, stopTime));
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("###########################Error Processing: " + filePathRelativeToInput
                            + ", Continuing with next set of tiles");
                } finally {
                    i += 2;
                }
                continue;
            }
            if (!isIgnoredFile(filePathRelativeToInput, exceptFiles))
                visitor.translateFile(translateFileInput);
            i++;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("###########################Error Processing: " + filePathRelativeToInput
                    + ", Continuing with next set of tiles");
        } finally {
            Date stopTime = new Date();
            //                System.out.println("Processed File(s): " + filePathRelativeToInput.replaceAll(H_OR_M, "") + " Time Taken: " + getDelta(startTime, stopTime));
        }
    }
}

From source file:com.hp.test.framework.Reporting.Utlis.java

public static void main(String ar[]) throws IOException {

    ArrayList<String> runs_list = new ArrayList<String>();
    String basepath = replacelogs();
    String path = basepath + "ATU Reports\\Results";
    File directory = new File(path);
    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    String htmlReport = basepath + "HTML_Design_Files\\CSS\\HtmlReport.html";
    for (File dir : subdirs) {

        runs_list.add(dir.getName());/*from   www . j a  v  a  2s . c  om*/
    }
    String Reports_path = basepath + "ATU Reports\\";
    int LatestRun = Utlis.getLastRun(Reports_path);
    String Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\";

    HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html"));
    HtmlParse.replaceCountsinJSFile(new File("HTML_Design_Files/JS/3dChart.js"), Last_run_path);
    UpdateTestCaseDesciption.basepath = Last_run_path;
    UpdateTestCaseDesciption.getTestCaseHtmlPath(Last_run_path + "/CurrentRun.html");
    UpdateTestCaseDesciption.replaceDetailsTable(Last_run_path + "/CurrentRun.html");
    //   GenerateFailReport.genarateFailureReport(new File(htmlReport), Reports_path + "Results\\Run_" + String.valueOf(LatestRun));
    genarateFailureReport(new File(htmlReport), Reports_path + "Results\\");
    Map<String, List<String>> runCounts = GetCountsrunsWise(runs_list, path);

    int success = replaceCounts(runCounts, path);

    if (success == 0) {
        File SourceFile = new File(path + "\\lineChart_temp.js");
        File RenameFile = new File(path + "\\lineChart.js");

        renameOriginalFile(SourceFile, RenameFile);

        File SourceFile1 = new File(path + "\\barChart_temp.js");
        File RenameFile1 = new File(path + "\\barChart.js");

        renameOriginalFile(SourceFile1, RenameFile1);

        Utlis.getpaths(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun));
        try {
            Utlis.replaceMainTable(false, new File(Reports_path + "index.html"));
            Utlis.replaceMainTable(true, new File(Reports_path + "results\\" + "ConsolidatedPage.html"));
            Utlis.replaceMainTable(true,
                    new File(Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));

            fileList.add(
                    new File(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));
            for (File f : fileList) {
                Utlis.replaceMainTable(true, f);
            }

        } catch (Exception ex) {
            log.info("Error in updating Report format" + ex.getMessage());
        }

        Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\";

        //   HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html"));
        //   HtmlParse.replaceCountsinJSFile(new File("../HTML_Design_Files/JS/3dChart.js"), Last_run_path);
        ArrayList<String> to_list = new ArrayList<String>();
        ReportingProperties reportingproperties = new ReportingProperties();
        String temp_eml = reportingproperties.getProperty("TOLIST");
        String JenkinsURL = reportingproperties.getProperty("JENKINSURL");

        String ScreenShotsDir = reportingproperties.getProperty("ScreenShotsDirectory");
        Boolean cleanScreenshotsDir = Boolean.valueOf(reportingproperties.getProperty("CleanPreScreenShots"));
        Boolean generatescreenshots = Boolean.valueOf(reportingproperties.getProperty("GenerateScreenShots"));
        String HtmlreportFilePrefix = reportingproperties.getProperty("HtmlreportFilePrefix");

        if (cleanScreenshotsDir) {
            if (!CleanFilesinDir(ScreenShotsDir)) {
                log.error("Not able to Clean the Previous Run Details in the paht" + ScreenShotsDir);
            } else {
                log.info("Cleaning Previous Run Details in the paht" + ScreenShotsDir + "Sucess");
            }
        }
        List<String> scr_fileList;
        List<String> html_fileList;
        if (generatescreenshots) {
            scr_fileList = GetFileListinDir(ScreenShotsDir, "png");

            int len = scr_fileList.size();
            len = len + 1;

            screenshot.generatescreenshot(Last_run_path + "CurrentRun.html",
                    ScreenShotsDir + "screenshot_" + len + ".png");
            File source = new File(Reports_path + "Results\\HtmlReport.html");
            File dest = new File(ScreenShotsDir + HtmlreportFilePrefix + "_HtmlReport.html");
            //  Files.copy(f.toPath(), (new File((ScreenShotsDir+HtmlreportFilePrefix+"_HtmlReport.html").toPath(),StandardCopyOption.REPLACE_EXISTING);
            FileUtils.copyFile(source, dest);
            scr_fileList.clear();

        }

        scr_fileList = GetFileListinDir(ScreenShotsDir, "png");
        html_fileList = GetFileListinDir(ScreenShotsDir, "html");

        if (temp_eml.length() > 1) {
            String[] to_list_temp = temp_eml.split(",");

            if (to_list_temp.length > 0) {
                for (String to_list_temp1 : to_list_temp) {
                    to_list.add(to_list_temp1);
                }
            }
            if (to_list.size() > 0) {
                screenshot.generatescreenshot(Last_run_path + "CurrentRun.html",
                        Last_run_path + "screenshot.png");

                //    cleanTempDir.cleanandCreate(Reports_path, LatestRun);
                // ZipUtils.ZipFolder(Reports_path + "temp", Reports_path + "ISTF_Reports.zip");
                if (generatescreenshots) {
                    SendingEmail.sendmail(to_list, JenkinsURL, scr_fileList, html_fileList);
                } else {
                    SendingEmail.sendmail(to_list, JenkinsURL, Reports_path + "/Results/HtmlReport.html",
                            Last_run_path + "screenshot.png");
                }

                //  FileUtils.deleteQuietly(new File(Reports_path + "ISTF_Reports.zip"));
                // FileUtils.deleteDirectory(new File(Reports_path + "temp"));
            }
        }
    }
}

From source file:com.ontotext.s4.SBTDemo.Main.java

public static void main(String[] args) {
    /*//from ww  w.ja  v a  2 s . c  o m
     * Read log4j properties file.
     */
    org.apache.log4j.PropertyConfigurator.configure(args.length >= 1 ? args[1] : DEFAULT_LOG4J_FILE);

    /*
     * Read properties file  List all annotated files. We should
     * use absolute path to the files
     */
    init(args);

    ProcessingDocuments processingDocuments = new ProcessingDocuments(
            programProperties.getProperty(PropertiesNames.S4_API_KEY),
            programProperties.getProperty(PropertiesNames.S4_API_PASS),
            programProperties.getProperty(PropertiesNames.RAW_FOLDER),
            programProperties.getProperty(PropertiesNames.ANNOTATED_FOLDER),
            programProperties.getProperty(PropertiesNames.SERVICE),
            programProperties.getProperty(PropertiesNames.MIME_TYPE),
            programProperties.getProperty(PropertiesNames.RESPONSE_FORMAT),
            Integer.parseInt(programProperties.getProperty(PropertiesNames.NUMBER_OF_THREADS)));

    processingDocuments.ProcessData();

    File directory = new File(programProperties.getProperty(PropertiesNames.ANNOTATED_FOLDER));
    listOfAllAnnotatedFiles = FileUtils.listFiles(directory, new RegexFileFilter("^(.*?)"),
            DirectoryFileFilter.DIRECTORY);

    RepoManager repoManager = new RepoManager(programProperties.getProperty(PropertiesNames.REPOSITORY_URL));
    JsonToRDF jsonToRdfParser = new JsonToRDF(programProperties.getProperty(PropertiesNames.MIME_TYPE),
            programProperties.getProperty(PropertiesNames.RDFIZE_FOLDER));

    for (File file : listOfAllAnnotatedFiles) {
        String fileContent = null;
        try {
            fileContent = FileUtils.readFileToString(file, "UTF-8");
        } catch (IOException e) {
            logger.error(e);
        }

        Model graph = jsonToRdfParser.wirteDataToRDF(fileContent, file.getName(),
                programProperties.getProperty(PropertiesNames.RDFIZE_FOLDER));
        try {
            repoManager.sendDataTOGraphDB(graph);
        } catch (RepositoryException e) {
            logger.error(e);
        }

    }

    repoManager.close();
}

From source file:licenseUtil.LicenseUtil.java

public static void main(String[] args) throws IOException, IncompleteLicenseObjectException {
    if (args.length == 0) {
        logger.error("Missing parameters. Use --help to get a list of the possible options.");
    } else if (args[0].equals("--addPomToTsv")) {
        if (args.length < 4)
            logger.error(/*from  w w  w. j a  v  a  2s. c  o  m*/
                    "Missing arguments for option --addPomToTsv. Please specify <pomFileName> <licenses.stub.tsv> <currentVersion> or use the option --help for further information.");
        String pomFN = args[1];
        String spreadSheetFN = args[2];
        String currentVersion = args[3];

        MavenProject project = null;
        try {
            project = Utils.readPom(new File(pomFN));
        } catch (XmlPullParserException e) {
            logger.error("Could not parse pom file: \"" + pomFN + "\"");
        }
        LicensingList licensingList = new LicensingList();
        File f = new File(spreadSheetFN);
        if (f.exists() && !f.isDirectory()) {
            licensingList.readFromSpreadsheet(spreadSheetFN);
        }

        licensingList.addMavenProject(project, currentVersion);
        licensingList.writeToSpreadsheet(spreadSheetFN);
    } else if (args[0].equals("--writeLicense3rdParty")) {
        if (args.length < 4)
            logger.error(
                    "Missing arguments for option --writeLicense3rdParty. Please provide <licenses.enhanced.tsv> <processModule> <currentVersion> [and <targetDir>] or use the option --help for further information.");
        String spreadSheetFN = args[1];
        String processModule = args[2];
        String currentVersion = args[3];

        HashMap<String, String> targetDirs = new HashMap<>();
        if (args.length > 4) {
            File targetDir = new File(args[4]);
            logger.info("scan pom files in direct subdirectories of \"" + targetDir.getPath()
                    + "\" to obtain target locations for 3rd party license files...");
            File[] subdirs = targetDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
            for (File subdir : subdirs) {
                File pomFile = new File(subdir.getPath() + File.separator + POM_FN);
                if (!pomFile.exists())
                    continue;
                MavenProject mavenProject;
                try {
                    mavenProject = Utils.readPom(pomFile);
                } catch (Exception e) {
                    logger.warn("Could not read from pom file: \"" + pomFile.getPath() + "\" because of "
                            + e.getMessage());
                    continue;
                }
                targetDirs.put(mavenProject.getModel().getArtifactId(), subdir.getAbsolutePath());
            }
        }

        LicensingList licensingList = new LicensingList();
        licensingList.readFromSpreadsheet(spreadSheetFN);
        if (processModule.toUpperCase().equals("ALL")) {
            for (String module : licensingList.getNonFixedHeaders()) {
                try {
                    writeLicense3rdPartyFile(module, licensingList, currentVersion, targetDirs.get(module));
                } catch (NoLicenseTemplateSetException e) {
                    logger.error("Could not write file for module \"" + module
                            + "\". There is no template specified for \"" + e.getLicensingObject()
                            + "\". Please add an existing template filename to the column \""
                            + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN
                            + "\".");
                }
            }
        } else {
            try {
                writeLicense3rdPartyFile(processModule, licensingList, currentVersion,
                        targetDirs.get(processModule));
            } catch (NoLicenseTemplateSetException e) {
                logger.error("Could not write file for module \"" + processModule
                        + "\". There is no template specified for \"" + e.getLicensingObject()
                        + "\". Please add an existing template filename to the column \""
                        + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN
                        + "\".");
            }
        }
    } else if (args[0].equals("--buildEffectivePom")) {
        Utils.writeEffectivePom(new File(args[1]), (new File(EFFECTIVE_POM_FN)).getAbsolutePath());
    } else if (args[0].equals("--updateTsvWithProjectsInFolder")) {
        if (args.length < 4)
            logger.error(
                    "Missing arguments for option --processProjectsInFolder. Please provide <superDirectory> <licenses.stub.tsv> and <currentVersion> or use the option --help for further information.");
        File directory = new File(args[1]);
        String spreadSheetFN = args[2];
        String currentVersion = args[3];
        LicensingList licensingList = new LicensingList();
        File f = new File(spreadSheetFN);
        if (f.exists() && !f.isDirectory()) {
            licensingList.readFromSpreadsheet(spreadSheetFN);
        }
        licensingList.addAll(processProjectsInFolder(directory, currentVersion, false));
        licensingList.writeToSpreadsheet(spreadSheetFN);

    } else if (args[0].equals("--purgeTsv")) {
        if (args.length < 3)
            logger.error(
                    "Missing arguments for option --purgeTsv. Please provide <spreadSheetIN.tsv>, <spreadSheetOUT.tsv> and <currentVersion> or use the option --help for further information.");
        String spreadSheetIN = args[1];
        String spreadSheetOUT = args[2];
        String currentVersion = args[3];

        LicensingList licensingList = new LicensingList();
        licensingList.readFromSpreadsheet(spreadSheetIN);
        licensingList.purge(currentVersion);
        licensingList.writeToSpreadsheet(spreadSheetOUT);

    } else if (args[0].equals("--help")) {
        InputStream in = LicenseUtil.class.getClassLoader().getResourceAsStream(README_PATH);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } else {
        logger.error("Unknown parameter: " + args[0] + ". Use --help to get a list of the possible options.");
    }
}

From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {

    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);

    String workDir = System.getProperty("workDir", ".");
    LOGGER.debug("Work dir: {}", workDir);
    String configDir = System.getProperty("configDir", ".");
    LOGGER.debug("Config dir: {}", configDir);

    File seedDir = new File(workDir, SEED_DIR);
    LOGGER.debug("Seed dir: {}", seedDir);
    File currentDir = new File(workDir, CURRENT_DIR);
    LOGGER.debug("Current dir: {}", currentDir);
    File backupDir = new File(workDir, BACKUP_DIR);
    LOGGER.debug("Backup dir: {}", backupDir);

    String initialMinTimeString = System.getProperty("minTime");
    LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
    Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
    LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));

    String absoluteMaxTimeString = System.getProperty("maxTime");
    LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
    Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
            : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
    LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));

    String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
    String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();

    LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
    FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);

    // get point limit
    int pointLimit = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
    LOGGER.debug("Print limit: {}", pointLimit);

    // get backups to keep
    int backupsToKeep = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
    LOGGER.debug("Backups to keep: {}", pointLimit);

    LOGGER.debug("Initializing process components (manager and limiter).");
    IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
    IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);

    LOGGER.debug("Starting incremental loop.");
    while (true) { // break as soon as no new points are available

        // cleanup --- just in case
        LOGGER.debug("Deleting \"current\" dir.");
        FileUtils.deleteDirectory(currentDir);

        // copy from seed to current
        LOGGER.debug("Copying seed.");
        seedDir.mkdirs();//from   w  w w .j a v a  2s. com
        FileUtils.copyDirectory(seedDir, currentDir);

        // get min time
        LOGGER.debug("Getting minimal time ...");
        Date minTime = initialMinTime;
        ProcessManagerEntry entry = processManager.getEntry();
        if (entry != null && entry.getMaxTime() != null) {
            minTime = entry.getMaxTime();
        }
        LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
        if (minTime.getTime() >= absoluteMaxTime.getTime()) {
            LOGGER.debug("Processed all points.");
            break;
        }

        // get the maximal time
        LOGGER.debug("Get maximal time.");

        // get the time from the newest point in our point range (pointMaxTime) ...
        Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);

        // ... and possibly break the loop if no new points are available
        if (pointMaxTime == null)
            break;

        // set the max time and make sure we are not taking to many points 
        // (set max time to the minimum of pointMaxTime and absoluteMaxTime)
        Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;

        LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        // start process
        processManager.start(minTime);

        System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);

        IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);

        ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);

        heatmap.processTiles(tileProcessor);

        tileProcessor.close();
        heatmapContext.close();

        // finish process
        processManager.finish(maxTime);

        // move old seed
        if (backupsToKeep > 0) {
            FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed

            // cleanup backups
            String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
            File oldestBackup = null;
            if (backups.length > backupsToKeep) {
                for (String bs : backups) {
                    File b = new File(backupDir, bs);
                    if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
                        oldestBackup = b;
                    }
                }
                FileUtils.deleteDirectory(oldestBackup);
            }

        } else {
            FileUtils.deleteDirectory(seedDir);
        }

        // move new seed
        FileUtils.moveDirectory(currentDir, seedDir);

    }

    incrementalContext.close();

}

From source file:io.proscript.jlight.SourcesLocator.java

public static Collection<File> locateRecursive(File directory) {
    return FileUtils.listFiles(directory, new SuffixFileFilter(".java"), DirectoryFileFilter.DIRECTORY);
}

From source file:naftoreiclag.villagefive.addon.AddonManager.java

public static void reloadAddons() {
    addonCollection.clear();/* w ww.  ja  va  2 s.  c om*/

    File[] pluginRoots = (new File(SAM.ADDON_DIR)).listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);

    // 
    for (File pluginRoot : pluginRoots) {
        System.out.println(pluginRoot);
        String addon_root = pluginRoot.getPath().replace('\\', '/') + "/";

        Globals globals = JsePlatform.standardGlobals();
        globals.set("ADDON_ROOT", addon_root);
        globals.loadfile("lua/globals.lua").call();

        LuaTable data = globals.loadfile(addon_root + "addon.lua").call().checktable();

        LuaAddon addon = new LuaAddon(pluginRoot.getName() + "\\", data);

        addonCollection.put(addon.id, addon);
    }

    for (Map.Entry<String, LuaAddon> pair : addonCollection.entrySet()) {
        LuaAddon addon = pair.getValue();

        System.out.println(addon.id);
        for (LuaEntity entity : addon.entities) {
            System.out.println(entity.parent.id + ":" + entity.id);
            EntityRegistry.register(entity);
        }
    }
}

From source file:hoot.services.utils.FileUtils.java

public static File getSubFolderFromFolder(String targetFolder, String subFolderName) {
    File ret = null;/*from  w  w  w  .j a v  a 2  s  . com*/

    File folder = new File(targetFolder);
    List<File> files = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(folder,
            new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY);

    for (File file : files) {
        if (file.getName().equals(subFolderName)) {
            ret = file;
            break;
        }
    }

    return ret;
}