Example usage for org.apache.commons.io.filefilter TrueFileFilter TRUE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter TRUE

Introduction

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

Prototype

IOFileFilter TRUE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter TRUE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:com.thoughtworks.go.server.service.BackupServiceIntegrationTest.java

@Test
public void shouldNotSendEmailToAdminWhenTheBackupFailsAndEmailConfigIsNotSet() throws Exception {
    GoConfigService configService = mock(GoConfigService.class);
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setBackupConfig(new BackupConfig(null, null, false, false));
    when(configService.serverConfig()).thenReturn(serverConfig);
    when(configService.adminEmail()).thenReturn("mail@admin.com");

    GoMailSender goMailSender = mock(GoMailSender.class);
    when(configService.getMailSender()).thenReturn(goMailSender);
    when(configService.isUserAdmin(admin)).thenReturn(true);

    DateTime now = new DateTime();
    TimeProvider timeProvider = mock(TimeProvider.class);
    when(timeProvider.currentDateTime()).thenReturn(now);

    Database databaseStrategyMock = mock(Database.class);
    doThrow(new RuntimeException("Oh no!")).when(databaseStrategyMock).backup(any(File.class));
    BackupService service = new BackupService(artifactsDirHolder, configService, timeProvider,
            backupInfoRepository, systemEnvironment, configRepository, databaseStrategyMock, null);
    ServerBackup backup = service.startBackup(admin);

    assertThat(backup.isSuccessful(), is(false));
    assertThat(backup.getMessage(), is("Failed to perform backup. Reason: Oh no!"));
    verifyNoMoreInteractions(goMailSender);

    assertThat(FileUtils.listFiles(backupsDirectory, TrueFileFilter.TRUE, TrueFileFilter.TRUE).isEmpty(),
            is(true));/*from   w w  w.  j a  v a  2 s  . c  o m*/
}

From source file:com.cheusov.Jrep.java

private static String[] handleOptions(String[] args) throws ParseException, IOException {
    if (args.length == 0) {
        printHelp(options);//from   w  w  w . j  a v a  2s  .  c o  m
        System.exit(1);
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    inverseMatch = cmd.hasOption("v");
    outputFilename = cmd.hasOption("l");
    opt_O = cmd.getOptionValue("O");
    opt_o = cmd.hasOption("o") || (opt_O != null);
    wholeContent = cmd.hasOption("8");
    opt_L = cmd.hasOption("L");
    opt_i = cmd.hasOption("i");
    opt_h = cmd.hasOption("h");
    opt_H = cmd.hasOption("H");
    opt_F = cmd.hasOption("F");
    opt_c = cmd.hasOption("c");
    opt_n = cmd.hasOption("n");
    opt_x = cmd.hasOption("x");

    boolean optBool = cmd.hasOption("R");
    opt_directories = (optBool || cmd.hasOption("r") ? Directories.RECURSE : Directories.READ);
    if (!optBool)
        orExcludeFileFilter.addFileFilter(new SymLinkFileFilter());

    opt_s = cmd.hasOption("s");
    opt_q = cmd.hasOption("q") || cmd.hasOption("silent");
    opt_w = cmd.hasOption("w");
    opt_line_buffered = cmd.hasOption("line-buffered");

    String[] optArray = cmd.getOptionValues("e");
    if (optArray != null && optArray.length != 0) {
        for (String regexp : optArray)
            regexps.add(regexp);
    }

    optArray = cmd.getOptionValues("include");
    if (optArray != null && optArray.length != 0) {
        for (String globPattern : optArray)
            orIncludeFileFilter.addFileFilter(new WildcardFileFilter(globPattern));
    } else {
        orIncludeFileFilter.addFileFilter(TrueFileFilter.TRUE);
    }

    optArray = cmd.getOptionValues("exclude");
    if (optArray != null && optArray.length != 0) {
        for (String globPattern : optArray) {
            if (globPattern.startsWith(".") || globPattern.startsWith("/"))
                orExcludeFileFilter.addFileFilter(new PathFileFilter(globPattern));
            else
                orExcludeFileFilter.addFileFilter(new WildcardFileFilter(globPattern));
        }
    }

    String optStr = cmd.getOptionValue("exclude-from");
    if (optStr != null) {
        Iterator<String> it = IOUtils.lineIterator(new FileInputStream(optStr), encoding);
        while (it.hasNext()) {
            String globPattern = it.next();

            if (globPattern.startsWith(".") || globPattern.startsWith("/"))
                orExcludeFileFilter.addFileFilter(new PathFileFilter(globPattern));
            else
                orExcludeFileFilter.addFileFilter(new WildcardFileFilter(globPattern));
        }
    }

    optStr = cmd.getOptionValue("f");
    if (optStr != null) {
        Iterator<String> it = IOUtils.lineIterator(new FileInputStream(optStr), encoding);
        while (it.hasNext()) {
            regexps.add(it.next());
        }
    }

    optStr = cmd.getOptionValue("m");
    if (optStr != null)
        opt_m = Integer.valueOf(optStr);

    optStr = cmd.getOptionValue("label");
    if (optStr != null)
        label = optStr;

    optStr = cmd.getOptionValue("marker-start");
    if (optStr != null)
        colorEscStart = optStr;
    optStr = cmd.getOptionValue("marker-end");
    if (optStr != null)
        colorEscEnd = optStr;

    optStr = cmd.getOptionValue("A");
    if (optStr != null)
        opt_A = Integer.valueOf(optStr);

    optStr = cmd.getOptionValue("B");
    if (optStr != null)
        opt_B = Integer.valueOf(optStr);

    optStr = cmd.getOptionValue("C");
    if (optStr != null)
        opt_A = opt_B = Integer.valueOf(optStr);

    optStr = cmd.getOptionValue("color");
    if (optStr == null)
        optStr = cmd.getOptionValue("colour");

    if (optStr == null || optStr.equals("auto")) {
        if (!isStdoutTTY)
            colorEscStart = null;
    } else if (optStr.equals("always")) {
    } else if (optStr.equals("never")) {
        colorEscStart = null;
    } else {
        throw new IllegalArgumentException("Illegal argument `" + optStr + "` for option --color");
    }

    optStr = cmd.getOptionValue("re-engine");
    if (optStr == null) {
    } else if (optStr.equals("java")) {
        opt_re_engine = JrepPattern.RE_ENGINE_TYPE.JAVA;
    } else if (optStr.equals("re2j")) {
        opt_re_engine = JrepPattern.RE_ENGINE_TYPE.RE2J;
    } else {
        throw new IllegalArgumentException("Illegal argument `" + optStr + "` for option --re-engine");
    }

    optStr = cmd.getOptionValue("directories");
    if (optStr == null) {
    } else if (optStr.equals("skip")) {
        opt_directories = Directories.SKIP;
    } else if (optStr.equals("read")) {
        opt_directories = Directories.READ;
    } else if (optStr.equals("recurse")) {
        opt_directories = Directories.RECURSE;
    } else {
        throw new IllegalArgumentException("Illegal argument `" + optStr + "` for option --directories");
    }

    if (cmd.hasOption("2"))
        opt_re_engine = JrepPattern.RE_ENGINE_TYPE.RE2J;

    if (cmd.hasOption("help")) {
        printHelp(options);
        System.exit(0);
    }

    if (cmd.hasOption("V")) {
        System.out.println("jrep-" + System.getenv("JREP_VERSION"));
        System.exit(0);
    }

    return cmd.getArgs();
}

From source file:com.github.mjdetullio.jenkins.plugins.multibranch.AbstractMultiBranchProject.java

/**
 * Migrates <code>SyncBranchesTrigger</code> to {@link hudson.triggers.TimerTrigger} and copies the
 * template's {@link hudson.security.AuthorizationMatrixProperty} to the parent as a
 * {@link com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty}.
 *//*  www  . j a va  2  s .  c om*/
@SuppressWarnings(UNUSED)
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void migrate() throws IOException {
    final String projectAmpStartTag = "<hudson.security.AuthorizationMatrixProperty>";

    final File projectsDir = new File(Jenkins.getActiveInstance().getRootDir(), "jobs");

    if (!projectsDir.getCanonicalFile().isDirectory()) {
        return;
    }

    Collection<File> configFiles = FileUtils.listFiles(projectsDir, new NameFileFilter("config.xml"),
            TrueFileFilter.TRUE);

    for (final File configFile : configFiles) {
        String xml = FileUtils.readFileToString(configFile);

        // Rename and wrap trigger open tag
        xml = xml.replaceFirst("(?m)^  <syncBranchesTrigger>(\r?\n)    <spec>",
                "  <triggers>\n    <hudson.triggers.TimerTrigger>\n      <spec>");

        // Rename and wrap trigger close tag
        xml = xml.replaceFirst("(?m)^  </syncBranchesTrigger>",
                "    </hudson.triggers.TimerTrigger>\n  </triggers>");

        // Copy AMP from template if parent does not have a properties tag
        if (!xml.matches("(?ms).+(\r?\n)  <properties.+")
                // Long line is long
                && xml.matches(
                        "(?ms).*<((freestyle|maven)-multi-branch-project|com\\.github\\.mjdetullio\\.jenkins\\.plugins\\.multibranch\\.(FreeStyle|Maven)MultiBranchProject)( plugin=\".*?\")?.+")) {

            File templateConfigFile = new File(new File(configFile.getParentFile(), TEMPLATE), "config.xml");

            if (templateConfigFile.isFile()) {
                String templateXml = FileUtils.readFileToString(templateConfigFile);

                int start = templateXml.indexOf(projectAmpStartTag);
                int end = templateXml.indexOf("</hudson.security.AuthorizationMatrixProperty>");

                if (start != -1 && end != -1) {
                    String ampSettings = templateXml.substring(start + projectAmpStartTag.length(), end);

                    xml = xml.replaceFirst("(?m)^  ", "  <properties>\n    "
                            + "<com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + ampSettings
                            + "</com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + "\n  </properties>\n  ");
                }
            }
        }

        FileUtils.writeStringToFile(configFile, xml);
    }
}

From source file:com.jayway.maven.plugins.android.AbstractAndroidMojo.java

/**
 * Copies the files contained within the source folder to the target folder.
 * <p>/*from   w w w.  j a v a2  s  .  c  o  m*/
 * The the target folder doesn't exist it will be created.
 * </p>
 *
 * @param sourceFolder      Folder from which to copy the resources.
 * @param targetFolder      Folder to which to copy the files.
 * @throws MojoExecutionException if the files cannot be copied.
 */
protected final void copyFolder(File sourceFolder, File targetFolder) throws MojoExecutionException {
    copyFolder(sourceFolder, targetFolder, TrueFileFilter.TRUE);
}

From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java

public SVNCommitInfo deleteDirectoryInSubversion(RepoDetail repodetail, String subVersionedDirectory)
        throws SVNException, IOException {
    if (debugEnabled) {
        S_LOGGER.debug("Entering Method  SCMManagerImpl.commitDirectoryContentToSubversion()");
    }//from ww  w.  j  a va2s  . c om
    setupLibrary();

    File subVerDir = new File(subVersionedDirectory);
    final SVNClientManager cm = SVNClientManager.newInstance(new DefaultSVNOptions(), repodetail.getUserName(),
            repodetail.getPassword());

    SVNWCClient wcClient = cm.getWCClient();
    //wcClient.doDelete(subVerDir, true, false);
    FileUtils.listFiles(subVerDir, TrueFileFilter.TRUE, FileFilterUtils.makeSVNAware(null));
    for (File child : subVerDir.listFiles()) {
        if (!(DOT + SVN).equals(child.getName())) {
            wcClient.doDelete(child, true, true, false);
        }
    }

    return cm.getCommitClient().doCommit(new File[] { subVerDir }, false, repodetail.getCommitMessage(), null,
            null, false, true, SVNDepth.INFINITY);
}

From source file:ome.services.scripts.ScriptRepoHelper.java

@SuppressWarnings("unchecked")
public Iterator<File> iterate() {
    return FileUtils.iterateFiles(dir, SCRIPT_FILTER, TrueFileFilter.TRUE);
}

From source file:org.ado.musicdroid.view.AppPresenter.java

private List<File> getSelectedSongs() {
    final List<File> songList = new ArrayList<>();
    for (Object item : artistListView.getSelectionModel().getSelectedItems().stream()
            .sorted((i1, i2) -> i1.getFile().getName().compareTo(i2.getFile().getName()))
            .collect(Collectors.toList())) {
        songList.addAll(FileUtils//from   ww  w.j  a v  a2s .c om
                .listFiles(((AlbumDirectory) item).getFile(), TrueFileFilter.TRUE, TrueFileFilter.TRUE).stream()
                .sorted((i1, i2) -> i1.getName().compareTo(i2.getName())).collect(Collectors.toList()));
    }
    return songList;
}

From source file:org.apache.accumulo.minicluster.impl.MiniAccumuloClusterGCTest.java

@Ignore
public void test() throws Exception {
    ZooKeeperInstance inst = new ZooKeeperInstance(accumulo.getClientConfig());
    Connector c = inst.getConnector("root", new PasswordToken(passwd));

    final String table = "foobar";
    c.tableOperations().create(table);/* w w w  . j  a  va2 s  .co  m*/

    final String tableId = c.tableOperations().tableIdMap().get(table);

    BatchWriter bw = null;

    // Add some data
    try {
        bw = c.createBatchWriter(table, new BatchWriterConfig().setMaxMemory(100000l)
                .setMaxLatency(100, TimeUnit.MILLISECONDS).setMaxWriteThreads(1));
        Mutation m = new Mutation("a");
        for (int i = 0; i < 500; i++) {
            m.put("colf", Integer.toString(i), "");
        }

        bw.addMutation(m);
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    File accumuloDir = new File(testDir, "accumulo");
    File tables = new File(accumuloDir.getAbsolutePath(), "tables");
    File myTable = new File(tables, tableId);

    log.trace("Files before compaction: "
            + FileUtils.listFiles(myTable, new SuffixFileFilter(".rf"), TrueFileFilter.TRUE));

    final boolean flush = true, wait = true;

    // Compact the tables to get some rfiles which we can gc
    c.tableOperations().compact(table, null, null, flush, wait);

    Collection<File> filesAfterCompaction = FileUtils.listFiles(myTable, new SuffixFileFilter(".rf"),
            TrueFileFilter.TRUE);
    int fileCountAfterCompaction = filesAfterCompaction.size();

    log.trace("Files after compaction: " + filesAfterCompaction);

    // Sleep for 10s to let the GC do its thing
    for (int i = 1; i < 10; i++) {
        Thread.sleep(1000);
        filesAfterCompaction = FileUtils.listFiles(myTable, new SuffixFileFilter(".rf"), TrueFileFilter.TRUE);

        log.trace("Files in loop: " + filesAfterCompaction);

        int fileCountAfterGCWait = filesAfterCompaction.size();

        if (fileCountAfterGCWait < fileCountAfterCompaction) {
            return;
        }
    }

    Assert.fail("Expected to find less files after compaction and pause for GC");
}

From source file:org.apache.accumulo.minicluster.MiniAccumuloClusterGCTest.java

@Test(timeout = 20000)
public void testFilesAreGarbageCollected() throws Exception {
    ZooKeeperInstance inst = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
    Connector c = inst.getConnector("root", new PasswordToken(passwd));

    final String table = "foobar";
    c.tableOperations().create(table);/*  ww w  .ja  v  a 2 s.  c o  m*/

    BatchWriter bw = null;

    // Add some data
    try {
        bw = c.createBatchWriter(table, new BatchWriterConfig().setMaxMemory(1000l)
                .setMaxLatency(100, TimeUnit.MILLISECONDS).setMaxWriteThreads(1));
        Mutation m = new Mutation("a");
        for (int i = 0; i < 50; i++) {
            m.put("colf", Integer.toString(i), "");
        }

        bw.addMutation(m);
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    final boolean flush = true, wait = true;

    // Compact the tables to get some rfiles which we can gc
    c.tableOperations().compact(table, null, null, flush, wait);
    c.tableOperations().compact(MetadataTable.NAME, null, null, flush, wait);

    File accumuloDir = new File(testDir, "accumulo");
    File tables = new File(accumuloDir.getAbsolutePath(), "tables");

    int fileCountAfterCompaction = FileUtils.listFiles(tables, new SuffixFileFilter(".rf"), TrueFileFilter.TRUE)
            .size();

    // Sleep for 4s to let the GC do its thing
    for (int i = 1; i < 5; i++) {
        Thread.sleep(1000);
        int fileCountAfterGCWait = FileUtils.listFiles(tables, new SuffixFileFilter(".rf"), TrueFileFilter.TRUE)
                .size();

        if (fileCountAfterGCWait < fileCountAfterCompaction) {
            return;
        }
    }

    Assert.fail("Expected to find less files after compaction and pause for GC");
}

From source file:org.bonitasoft.engine.bdm.AbstractBDMJarBuilder.java

private byte[] generateJar(final File directory, final IOFileFilter fileFilter) throws IOException {
    final Collection<File> files = FileUtils.listFiles(directory, fileFilter, TrueFileFilter.TRUE);
    final Map<String, byte[]> resources = new HashMap<String, byte[]>();
    for (final File file : files) {
        final String relativeName = directory.toURI().relativize(file.toURI()).getPath();
        final byte[] content = FileUtils.readFileToByteArray(file);
        resources.put(relativeName, content);
    }//from  w ww.j  ava2s .c o  m
    return IOUtil.generateJar(resources);
}