Search in sources :

Example 86 with FileFilter

use of java.io.FileFilter in project spring-boot by spring-projects.

the class SampleAntApplicationIT method runJar.

@Test
public void runJar() throws Exception {
    File target = new File("target");
    File[] jarFiles = target.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.getName().endsWith(".jar");
        }
    });
    assertThat(jarFiles).hasSize(1);
    Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
    process.waitFor(5, TimeUnit.MINUTES);
    assertThat(process.exitValue()).isEqualTo(0);
    String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
    assertThat(output).contains("Spring Boot Ant Example");
}
Also used : InputStreamReader(java.io.InputStreamReader) FileFilter(java.io.FileFilter) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 87 with FileFilter

use of java.io.FileFilter in project ceylon-compiler by ceylon.

the class MiscTests method compileRuntime.

@Test
public void compileRuntime() {
    cleanCars("build/classes-runtime");
    java.util.List<File> sourceFiles = new ArrayList<File>();
    String ceylonSourcePath = "../ceylon.language/src";
    String javaSourcePath = "../ceylon.language/runtime";
    String[] ceylonPackages = { "ceylon.language", "ceylon.language.meta", "ceylon.language.impl", "ceylon.language.meta.declaration", "ceylon.language.meta.model", "ceylon.language.serialization" };
    // Native files
    FileFilter exceptions = new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            String filename = pathname.getName();
            filename = filename.substring(0, filename.lastIndexOf('.'));
            for (String s : new String[] { "Boolean", "Integer", "Float", "Character", "String", "Byte", "Array", "Tuple", "Exception", "AssertionError", "Callable", "flatten", "className", "integerRangeByIterable", "modules", "printStackTrace", "process", "Throwable", "type", "typeLiteral", "classDeclaration", "reach", "unflatten", "serialization", "PartialImpl" }) {
                if (s.equals(filename)) {
                    return true;
                }
            }
            if (filename.equals("annotations") && pathname.getParentFile().getName().equals("meta")) {
                return true;
            }
            return false;
        }
    };
    String[] extras = new String[] { "true", "false" };
    String[] modelExtras = new String[] { "classDeclaration", "annotations", "modules", "type", "typeLiteral" };
    String[] s11nExtras = new String[] { "PartialImpl" };
    for (String pkg : ceylonPackages) {
        File pkgDir = new File(ceylonSourcePath, pkg.replaceAll("\\.", "/"));
        File javaPkgDir = new File(javaSourcePath, pkg.replaceAll("\\.", "/"));
        File[] files = pkgDir.listFiles();
        if (files != null) {
            for (File src : files) {
                if (src.isFile() && src.getName().toLowerCase().endsWith(".ceylon")) {
                    String baseName = src.getName().substring(0, src.getName().length() - 7);
                    if (!exceptions.accept(src)) {
                        sourceFiles.add(src);
                    } else {
                        addJavaSourceFile(baseName, sourceFiles, javaPkgDir, false);
                    }
                }
            }
        }
    }
    // add extra files that are in Java
    File javaPkgDir = new File(javaSourcePath, "ceylon/language");
    for (String extra : extras) addJavaSourceFile(extra, sourceFiles, javaPkgDir, true);
    File javaModelPkgDir = new File(javaSourcePath, "ceylon/language/meta");
    for (String extra : modelExtras) addJavaSourceFile(extra, sourceFiles, javaModelPkgDir, true);
    File javaS11nPkgDir = new File(javaSourcePath, "ceylon/language/serialization");
    for (String extra : s11nExtras) addJavaSourceFile(extra, sourceFiles, javaS11nPkgDir, true);
    File javaS11nEPkgDir = new File(javaSourcePath, "ceylon/language/impl");
    for (String extra : new String[] { "reach" }) addJavaSourceFile(extra, sourceFiles, javaS11nEPkgDir, true);
    String[] javaPackages = { "com/redhat/ceylon/compiler/java", "com/redhat/ceylon/compiler/java/language", "com/redhat/ceylon/compiler/java/metadata", "com/redhat/ceylon/compiler/java/runtime/ide", "com/redhat/ceylon/compiler/java/runtime/metamodel", "com/redhat/ceylon/compiler/java/runtime/model", "com/redhat/ceylon/compiler/java/runtime/metamodel/decl", "com/redhat/ceylon/compiler/java/runtime/metamodel/meta", "com/redhat/ceylon/compiler/java/runtime/serialization" };
    for (String pkg : javaPackages) {
        File pkgDir = new File(javaSourcePath, pkg.replaceAll("\\.", "/"));
        File[] files = pkgDir.listFiles();
        if (files != null) {
            for (File src : files) {
                if (src.isFile() && src.getName().toLowerCase().endsWith(".java")) {
                    sourceFiles.add(src);
                }
            }
        }
    }
    CeyloncTool compiler;
    try {
        compiler = new CeyloncTool();
    } catch (VerifyError e) {
        System.err.println("ERROR: Cannot run tests! Did you maybe forget to configure the -Xbootclasspath/p: parameter?");
        throw e;
    }
    CeyloncFileManager fileManager = (CeyloncFileManager) compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
    String compilerSourcePath = ceylonSourcePath + File.pathSeparator + javaSourcePath;
    CeyloncTaskImpl task = (CeyloncTaskImpl) compiler.getTask(null, fileManager, null, Arrays.asList("-sourcepath", compilerSourcePath, "-d", "build/classes-runtime", "-Xbootstrapceylon", "-cp", getClassPathAsPathExcludingLanguageModule(), "-suppress-warnings", "ceylonNamespace"), null, compilationUnits1);
    Boolean result = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, result);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(com.redhat.ceylon.compiler.java.tools.CeyloncTool) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) FileFilter(java.io.FileFilter) File(java.io.File) CeyloncFileManager(com.redhat.ceylon.compiler.java.tools.CeyloncFileManager) Test(org.junit.Test)

Example 88 with FileFilter

use of java.io.FileFilter in project spark-dataflow by cloudera.

the class NumShardsTest method testText.

@Test
public void testText() throws Exception {
    SparkPipelineOptions options = SparkPipelineOptionsFactory.create();
    options.setRunner(SparkPipelineRunner.class);
    Pipeline p = Pipeline.create(options);
    PCollection<String> inputWords = p.apply(Create.of(WORDS)).setCoder(StringUtf8Coder.of());
    PCollection<String> output = inputWords.apply(new WordCount.CountWords()).apply(MapElements.via(new WordCount.FormatAsTextFn()));
    output.apply(TextIO.Write.to(outputDir.getAbsolutePath()).withNumShards(3).withSuffix(".txt"));
    EvaluationResult res = SparkPipelineRunner.create().run(p);
    res.close();
    int count = 0;
    Set<String> expected = Sets.newHashSet("hi: 5", "there: 1", "sue: 2", "bob: 2");
    for (File f : tmpDir.getRoot().listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.getName().matches("out-.*\\.txt");
        }
    })) {
        count++;
        for (String line : Files.readLines(f, Charsets.UTF_8)) {
            assertTrue(line + " not found", expected.remove(line));
        }
    }
    assertEquals(3, count);
    assertTrue(expected.isEmpty());
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File) Pipeline(com.google.cloud.dataflow.sdk.Pipeline) Test(org.junit.Test)

Example 89 with FileFilter

use of java.io.FileFilter in project android_frameworks_base by crdroidandroid.

the class SQLiteDatabase method deleteDatabase.

/**
     * Deletes a database including its journal file and other auxiliary files
     * that may have been created by the database engine.
     *
     * @param file The database file path.
     * @return True if the database was successfully deleted.
     */
public static boolean deleteDatabase(File file) {
    if (file == null) {
        throw new IllegalArgumentException("file must not be null");
    }
    boolean deleted = false;
    deleted |= file.delete();
    deleted |= new File(file.getPath() + "-journal").delete();
    deleted |= new File(file.getPath() + "-shm").delete();
    deleted |= new File(file.getPath() + "-wal").delete();
    File dir = file.getParentFile();
    if (dir != null) {
        final String prefix = file.getName() + "-mj";
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File candidate) {
                return candidate.getName().startsWith(prefix);
            }
        });
        if (files != null) {
            for (File masterJournal : files) {
                deleted |= masterJournal.delete();
            }
        }
    }
    return deleted;
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File)

Example 90 with FileFilter

use of java.io.FileFilter 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.xdi.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)

Aggregations

FileFilter (java.io.FileFilter)281 File (java.io.File)267 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)53 JarFile (java.util.jar.JarFile)22 URL (java.net.URL)17 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 FileNotFoundException (java.io.FileNotFoundException)11 FilenameFilter (java.io.FilenameFilter)11 HashSet (java.util.HashSet)11 FileInputStream (java.io.FileInputStream)10 Pattern (java.util.regex.Pattern)10 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)10 MalformedURLException (java.net.MalformedURLException)9 URI (java.net.URI)9 Map (java.util.Map)7 Path (org.apache.hadoop.fs.Path)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6