Search in sources :

Example 1 with SuffixFileFilter

use of org.apache.commons.io.filefilter.SuffixFileFilter in project gocd by gocd.

the class JobResourceImporter method getArtifactFilesOfType.

File[] getArtifactFilesOfType(String artifactsPathFromRoot, String jobArtifactPath, final String fileExtension) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("getArtifactFilesOfType(" + artifactsPathFromRoot + ", " + jobArtifactPath + ", " + fileExtension + ")");
    }
    File jobArtifactFile = new File(artifactBaseDir, artifactsPathFromRoot + File.separator + jobArtifactPath);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Artifact directory calculated to be " + jobArtifactFile.getAbsolutePath());
    }
    if (!jobArtifactFile.exists() || !jobArtifactFile.isDirectory()) {
        return new File[0];
    }
    Collection collection = FileUtils.listFiles(jobArtifactFile, new SuffixFileFilter(fileExtension, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("" + collection.size() + " artifact files found.");
    }
    return (File[]) collection.toArray(new File[0]);
}
Also used : Collection(java.util.Collection) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) File(java.io.File)

Example 2 with SuffixFileFilter

use of org.apache.commons.io.filefilter.SuffixFileFilter in project stanbol by apache.

the class ManagedIndexMetadata method loadIndexConfigs.

/**
     * Loads the configurations of uninitialised Solr Indexes
     * 
     * @return the map with the index name as key and the properties as values
     * @throws IOException
     *             on any error while loading the configurations
     */
private Map<String, IndexMetadata> loadIndexConfigs() throws IOException {
    File uninstalledConfigDir = getIndexConfigDirectory(false);
    Map<String, IndexMetadata> configs = new HashMap<String, IndexMetadata>();
    synchronized (pid) {
        if (uninstalledConfigDir.exists()) {
            for (String file : uninstalledConfigDir.list(new SuffixFileFilter(ConfigUtils.SOLR_INDEX_ARCHIVE_EXTENSION + ".ref"))) {
                String indexName = file.substring(0, file.indexOf('.'));
                File configFile = new File(uninstalledConfigDir, file);
                IndexMetadata props = new IndexMetadata();
                InputStream is = null;
                try {
                    is = new FileInputStream(configFile);
                    props.load(is);
                    //validate Index-Name and Server-Name properties!
                    if (!indexName.equals(props.getIndexName())) {
                        throw new IOException("The IndexName '" + props.getIndexName() + "within the IndexConfig file does not correspond to the file name '" + file + "'!");
                    }
                    if (!serverName.equals(props.getServerName())) {
                        throw new IOException("The Name of the Referenced Solr server '" + serverName + " does not correspond with the Server-Name value '" + props.getServerName() + "' within the property file '" + file + "'!");
                    }
                    configs.put(indexName, props);
                } finally {
                    IOUtils.closeQuietly(is);
                }
            }
        }
    }
    return configs;
}
Also used : HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) IOException(java.io.IOException) IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with SuffixFileFilter

use of org.apache.commons.io.filefilter.SuffixFileFilter in project robovm by robovm.

the class IOSTarget method packageApplication.

private void packageApplication(File appDir) throws IOException {
    File ipaFile = new File(config.getInstallDir(), getExecutable() + ".ipa");
    config.getLogger().info("Packaging IPA %s from %s", ipaFile.getName(), appDir.getName());
    File tmpDir = new File(config.getInstallDir(), "ipabuild");
    FileUtils.deleteDirectory(tmpDir);
    tmpDir.mkdirs();
    File payloadDir = new File(tmpDir, "Payload");
    payloadDir.mkdir();
    config.getLogger().info("Copying %s to %s", appDir.getName(), payloadDir);
    new Executor(config.getLogger(), "cp").args("-Rp", appDir, payloadDir).exec();
    File frameworksDir = new File(appDir, "Frameworks");
    if (frameworksDir.exists()) {
        String[] swiftLibs = frameworksDir.list(new AndFileFilter(new PrefixFileFilter("libswift"), new SuffixFileFilter(".dylib")));
        if (swiftLibs.length > 0) {
            File swiftSupportDir = new File(tmpDir, "SwiftSupport");
            swiftSupportDir.mkdir();
            copySwiftLibs(Arrays.asList(swiftLibs), swiftSupportDir);
        }
    }
    config.getLogger().info("Zipping %s to %s", tmpDir, ipaFile);
    new Executor(Logger.NULL_LOGGER, "zip").wd(tmpDir).args("--symlinks", "--recurse-paths", ipaFile, ".").exec();
    config.getLogger().info("Deleting temp dir %s", tmpDir);
    FileUtils.deleteDirectory(tmpDir);
}
Also used : Executor(org.robovm.compiler.util.Executor) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) NSString(com.dd.plist.NSString) File(java.io.File) PrefixFileFilter(org.apache.commons.io.filefilter.PrefixFileFilter)

Example 4 with SuffixFileFilter

use of org.apache.commons.io.filefilter.SuffixFileFilter in project robovm by robovm.

the class InterfaceBuilderClassesPlugin method buildClassToUrlMap.

private Map<String, URL> buildClassToUrlMap(List<File> paths) {
    // Reverse the list since classes in the first paths should take
    // precedence over classes in latter paths.
    Collections.reverse(paths);
    Map<String, URL> classToUrlMap = new HashMap<>();
    for (File path : paths) {
        if (isJarFile(path)) {
            try (ZipFile zipFile = new ZipFile(path)) {
                for (ZipEntry entry : Collections.list(zipFile.entries())) {
                    if (!entry.isDirectory()) {
                        if (FilenameUtils.isExtension(entry.getName(), CLASS_EXTENSION)) {
                            String className = FilenameUtils.removeExtension(entry.getName()).replace('/', '.');
                            URL url = new URL("jar", null, -1, path.toURI().toString() + "!/" + entry.getName());
                            classToUrlMap.put(className, url);
                        }
                    }
                }
            } catch (IOException e) {
                logger.warn("Failed to read JAR/ZIP file %s: %s", path.getAbsolutePath(), e.getMessage());
            }
        } else if (path.isDirectory()) {
            path = path.getAbsoluteFile();
            for (File f : FileUtils.listFiles(path, new SuffixFileFilter("." + CLASS_EXTENSION), new PackageNameFilter(path.getAbsolutePath()))) {
                String className = FilenameUtils.removeExtension(f.getAbsolutePath());
                className = className.substring(path.getAbsolutePath().length() + 1);
                className = className.replace(File.separatorChar, '.');
                try {
                    classToUrlMap.put(className, f.toURI().toURL());
                } catch (MalformedURLException e) {
                    throw new Error(e);
                }
            }
        }
    }
    return classToUrlMap;
}
Also used : MalformedURLException(java.net.MalformedURLException) ZipFile(java.util.zip.ZipFile) HashMap(java.util.HashMap) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL)

Example 5 with SuffixFileFilter

use of org.apache.commons.io.filefilter.SuffixFileFilter in project ddf by codice.

the class ConfigurationFilesPoller method register.

public void register(ChangeListener listener) {
    notNull(listener, "ChangeListener cannot be null");
    changeListener = listener;
    fileAlterationObserver = new FileAlterationObserver(configurationDirectoryPath.toAbsolutePath().toString(), new SuffixFileFilter(fileExtension));
    fileAlterationObserver.addListener(this);
    watchService = new FileAlterationMonitor(POLLING_INTERVAL, fileAlterationObserver);
    try {
        watchService.start();
    } catch (Exception e) {
        logStackAndMessageSeparately(e, "Failed to start, 'Platform :: Migration' must be restarted: ");
    }
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileAlterationMonitor(org.apache.commons.io.monitor.FileAlterationMonitor) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter)

Aggregations

SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)5 File (java.io.File)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 NSString (com.dd.plist.NSString)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)1 PrefixFileFilter (org.apache.commons.io.filefilter.PrefixFileFilter)1 FileAlterationMonitor (org.apache.commons.io.monitor.FileAlterationMonitor)1 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)1 IndexMetadata (org.apache.stanbol.commons.solr.managed.IndexMetadata)1 Executor (org.robovm.compiler.util.Executor)1