Search in sources :

Example 66 with FilenameFilter

use of java.io.FilenameFilter in project graphdb by neo4j-attic.

the class ProvisionerTest method shouldProvisionMavenArtifact.

@Test
public void shouldProvisionMavenArtifact() throws MalformedURLException {
    final String EXPECTED_DIRECTORY = "prove_dir";
    Provisioner prover = new Provisioner();
    prover.setProvisionDirectory(EXPECTED_DIRECTORY);
    prover.include("mvn:org.neo4j/neo4j-kernel/1.1", "neo4j-kernel.jar");
    prover.provision();
    File actualDirectory = new File(EXPECTED_DIRECTORY);
    String[] foundJars = actualDirectory.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith("jar");
        }
    });
    assertThat(foundJars.length, is(equalTo(1)));
    FileUtils.delete(actualDirectory);
}
Also used : FilenameFilter(java.io.FilenameFilter) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 67 with FilenameFilter

use of java.io.FilenameFilter in project intellij-leiningen-plugin by derkork.

the class LeiningenRunnerSettings method getRealLeiningenJar.

/**
     * Returns the real leiningen jar.
     * @return the real leiningen jar
     */
@NotNull
public String getRealLeiningenJar() {
    if (overrideLeiningenJar) {
        return leiningenJar;
    }
    // first check LEIN_JAR env variable
    String env = System.getenv("LEIN_JAR");
    if (!StringUtil.isEmpty(env)) {
        return env;
    }
    // ok it's not set, look for a file below the lein home
    File leinHome = new File(getRealLeiningenHome());
    if (leinHome.exists() && leinHome.isDirectory()) {
        File selfInstalls = new File(leinHome, "self-installs");
        if (selfInstalls.exists() && selfInstalls.isDirectory()) {
            File[] files = selfInstalls.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.startsWith("leiningen-") && name.endsWith("-standalone.jar");
                }
            });
            if (files.length > 0) {
                return files[0].getPath();
            }
        }
    }
    // fallback
    return "leiningen-standalone.jar";
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with FilenameFilter

use of java.io.FilenameFilter in project druid by druid-io.

the class AppenderatorImpl method bootstrapSinksFromDisk.

/**
   * Populate "sinks" and "sinkTimeline" with committed segments, and announce them with the segmentAnnouncer.
   *
   * @return persisted commit metadata
   */
private Object bootstrapSinksFromDisk() {
    Preconditions.checkState(sinks.isEmpty(), "Already bootstrapped?!");
    final File baseDir = tuningConfig.getBasePersistDirectory();
    if (!baseDir.exists()) {
        return null;
    }
    final File[] files = baseDir.listFiles();
    if (files == null) {
        return null;
    }
    final File commitFile = computeCommitFile();
    final Committed committed;
    try {
        if (commitFile.exists()) {
            committed = objectMapper.readValue(commitFile, Committed.class);
        } else {
            committed = Committed.nil();
        }
    } catch (Exception e) {
        throw new ISE(e, "Failed to read commitFile: %s", commitFile);
    }
    log.info("Loading sinks from[%s]: %s", baseDir, committed.getHydrants().keySet());
    for (File sinkDir : files) {
        final File identifierFile = new File(sinkDir, IDENTIFIER_FILE_NAME);
        if (!identifierFile.isFile()) {
            // No identifier in this sinkDir; it must not actually be a sink directory. Skip it.
            continue;
        }
        try {
            final SegmentIdentifier identifier = objectMapper.readValue(new File(sinkDir, "identifier.json"), SegmentIdentifier.class);
            final int committedHydrants = committed.getCommittedHydrants(identifier.getIdentifierAsString());
            if (committedHydrants <= 0) {
                log.info("Removing uncommitted sink at [%s]", sinkDir);
                FileUtils.deleteDirectory(sinkDir);
                continue;
            }
            // To avoid reading and listing of "merged" dir and other special files
            final File[] sinkFiles = sinkDir.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String fileName) {
                    return !(Ints.tryParse(fileName) == null);
                }
            });
            Arrays.sort(sinkFiles, new Comparator<File>() {

                @Override
                public int compare(File o1, File o2) {
                    return Ints.compare(Integer.parseInt(o1.getName()), Integer.parseInt(o2.getName()));
                }
            });
            List<FireHydrant> hydrants = Lists.newArrayList();
            for (File hydrantDir : sinkFiles) {
                final int hydrantNumber = Integer.parseInt(hydrantDir.getName());
                if (hydrantNumber >= committedHydrants) {
                    log.info("Removing uncommitted segment at [%s]", hydrantDir);
                    FileUtils.deleteDirectory(hydrantDir);
                } else {
                    log.info("Loading previously persisted segment at [%s]", hydrantDir);
                    if (hydrantNumber != hydrants.size()) {
                        throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
                    }
                    hydrants.add(new FireHydrant(new QueryableIndexSegment(identifier.getIdentifierAsString(), indexIO.loadIndex(hydrantDir)), hydrantNumber));
                }
            }
            // Make sure we loaded enough hydrants.
            if (committedHydrants != hydrants.size()) {
                throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
            }
            Sink currSink = new Sink(identifier.getInterval(), schema, identifier.getShardSpec(), identifier.getVersion(), tuningConfig.getMaxRowsInMemory(), tuningConfig.isReportParseExceptions(), hydrants);
            sinks.put(identifier, currSink);
            sinkTimeline.add(currSink.getInterval(), currSink.getVersion(), identifier.getShardSpec().createChunk(currSink));
            segmentAnnouncer.announceSegment(currSink.getSegment());
        } catch (IOException e) {
            log.makeAlert(e, "Problem loading sink[%s] from disk.", schema.getDataSource()).addData("sinkDir", sinkDir).emit();
        }
    }
    // Make sure we loaded all committed sinks.
    final Set<String> loadedSinks = Sets.newHashSet(Iterables.transform(sinks.keySet(), new Function<SegmentIdentifier, String>() {

        @Override
        public String apply(SegmentIdentifier input) {
            return input.getIdentifierAsString();
        }
    }));
    final Set<String> missingSinks = Sets.difference(committed.getHydrants().keySet(), loadedSinks);
    if (!missingSinks.isEmpty()) {
        throw new ISE("Missing committed sinks [%s]", Joiner.on(", ").join(missingSinks));
    }
    return committed.getMetadata();
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) IOException(java.io.IOException) IndexSizeExceededException(io.druid.segment.incremental.IndexSizeExceededException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FilenameFilter(java.io.FilenameFilter) Function(com.google.common.base.Function) Sink(io.druid.segment.realtime.plumber.Sink) ISE(io.druid.java.util.common.ISE) FireHydrant(io.druid.segment.realtime.FireHydrant) File(java.io.File)

Example 69 with FilenameFilter

use of java.io.FilenameFilter in project che by eclipse.

the class InstallExtension method main.

public static void main(String[] args) throws IOException {
    for (String arg : args) {
        if (arg.startsWith(EXT_DIR_PARAMETER)) {
            extDirPath = Paths.get(arg.substring(EXT_DIR_PARAMETER.length()));
        } else if (arg.startsWith(EXT_RESOURCES_DIR_PARAMETER)) {
            final Path extResourcesDirPath = Paths.get(arg.substring(EXT_RESOURCES_DIR_PARAMETER.length()));
            final String tempDirName = "temp";
            extResourcesWorkDirPath = extResourcesDirPath.resolve(tempDirName);
            // delete working directory from previous build if it exist
            IoUtil.deleteRecursive(extResourcesWorkDirPath.toFile());
            Files.createDirectory(extResourcesWorkDirPath);
            IoUtil.copy(extResourcesDirPath.toFile(), extResourcesWorkDirPath.toFile(), new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return !(tempDirName.equals(name));
                }
            });
        } else {
            System.err.println("Unknown flag: " + arg);
            System.exit(1);
        }
    }
    List<Extension> extensions = findExtensionsByPath(extDirPath);
    for (Extension extension : extensions) {
        final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile();
        final Model model = Model.readFrom(pom);
        model.dependencies().add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion));
        model.writeTo(pom);
        // Add GWT module if there is one
        if (extension.gwtModuleName != null) {
            final Path ideGwtXmlPath = IoUtil.findFile(IDE_GWT_XML_FILE_NAME, extResourcesWorkDirPath.toFile()).toPath();
            GwtXmlUtils.inheritGwtModule(ideGwtXmlPath, extension.gwtModuleName);
        }
    }
}
Also used : Path(java.nio.file.Path) FilenameFilter(java.io.FilenameFilter) Model(org.eclipse.che.ide.maven.tools.Model) Dependency(org.eclipse.che.ide.maven.tools.Dependency) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 70 with FilenameFilter

use of java.io.FilenameFilter in project neo4j by neo4j.

the class StoreFilesTest method deleteMustNotDeleteFilesInIgnoredDirectories.

@Test
public void deleteMustNotDeleteFilesInIgnoredDirectories() throws Exception {
    File dir = getBaseDir();
    File ignore = new File(dir, "ignore");
    File a = new File(dir, "a");
    File b = new File(dir, "b");
    File c = new File(ignore, "c");
    File d = new File(ignore, "d");
    createOnFileSystem(a);
    createOnFileSystem(c);
    createOnPageCache(b);
    createOnPageCache(d);
    FilenameFilter filter = (directory, name) -> !name.startsWith("ignore");
    storeFiles = new StoreFiles(fs, pageCache, filter);
    storeFiles.delete(dir);
    assertFalse(fs.fileExists(a));
    assertFalse(pc.fileExists(b));
    assertTrue(fs.fileExists(c));
    assertTrue(pc.fileExists(d));
}
Also used : FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Before(org.junit.Before) PageCache(org.neo4j.io.pagecache.PageCache) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) StoreId(org.neo4j.causalclustering.identity.StoreId) RuleChain(org.junit.rules.RuleChain) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) List(java.util.List) Rule(org.junit.Rule) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FilenameFilter(java.io.FilenameFilter) File(java.io.File) Test(org.junit.Test)

Aggregations

FilenameFilter (java.io.FilenameFilter)402 File (java.io.File)398 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)72 Test (org.junit.Test)60 URL (java.net.URL)22 List (java.util.List)22 RandomAccessFile (java.io.RandomAccessFile)19 HashSet (java.util.HashSet)17 FileOutputStream (java.io.FileOutputStream)14 JarFile (java.util.jar.JarFile)14 FileNotFoundException (java.io.FileNotFoundException)13 MalformedURLException (java.net.MalformedURLException)13 HashMap (java.util.HashMap)13 FileFilter (java.io.FileFilter)11 FileWriter (java.io.FileWriter)11 ZipFile (java.util.zip.ZipFile)11 TestClient (org.syncany.tests.util.TestClient)11 FileReader (java.io.FileReader)10 Pattern (java.util.regex.Pattern)10