Search in sources :

Example 1 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project maven-plugins by apache.

the class ScmPublishPublishScmMojo method update.

/**
 * Update scm checkout directory with content.
 *
 * @param checkout        the scm checkout directory
 * @param dir             the content to put in scm (can be <code>null</code>)
 * @param doNotDeleteDirs directory names that should not be deleted from scm even if not in new content:
 *                        used for modules, which content is available only when staging
 * @throws IOException
 */
private void update(File checkout, File dir, List<String> doNotDeleteDirs) throws IOException {
    String scmSpecificFilename = scmProvider.getScmSpecificFilename();
    String[] files = scmSpecificFilename != null ? checkout.list(new NotFileFilter(new NameFileFilter(scmSpecificFilename))) : checkout.list();
    Set<String> checkoutContent = new HashSet<String>(Arrays.asList(files));
    List<String> dirContent = (dir != null) ? Arrays.asList(dir.list()) : Collections.<String>emptyList();
    Set<String> deleted = new HashSet<String>(checkoutContent);
    deleted.removeAll(dirContent);
    MatchPatterns ignoreDeleteMatchPatterns = null;
    List<String> pathsAsList = new ArrayList<String>(0);
    if (ignorePathsToDelete != null && ignorePathsToDelete.length > 0) {
        ignoreDeleteMatchPatterns = MatchPatterns.from(ignorePathsToDelete);
        pathsAsList = Arrays.asList(ignorePathsToDelete);
    }
    for (String name : deleted) {
        if (ignoreDeleteMatchPatterns != null && ignoreDeleteMatchPatterns.matches(name, true)) {
            getLog().debug(name + " match one of the patterns '" + pathsAsList + "': do not add to deleted files");
            continue;
        }
        getLog().debug("file marked for deletion: " + name);
        File file = new File(checkout, name);
        if ((doNotDeleteDirs != null) && file.isDirectory() && (doNotDeleteDirs.contains(name))) {
            // ignore directory not available
            continue;
        }
        if (file.isDirectory()) {
            update(file, null, null);
        }
        this.deleted.add(file);
    }
    for (String name : dirContent) {
        File file = new File(checkout, name);
        File source = new File(dir, name);
        if (source.isDirectory()) {
            directories++;
            if (!checkoutContent.contains(name)) {
                this.added.add(file);
                file.mkdir();
            }
            update(file, source, null);
        } else {
            if (checkoutContent.contains(name)) {
                this.updated.add(file);
            } else {
                this.added.add(file);
            }
            copyFile(source, file);
        }
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) MatchPatterns(org.codehaus.plexus.util.MatchPatterns) ArrayList(java.util.ArrayList) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project druid by druid-io.

the class LocalInputSource method getDirectoryListingIterator.

private Iterator<File> getDirectoryListingIterator() {
    if (baseDir == null) {
        return Collections.emptyIterator();
    } else {
        final IOFileFilter fileFilter;
        if (files == null) {
            fileFilter = new WildcardFileFilter(filter);
        } else {
            fileFilter = new AndFileFilter(new WildcardFileFilter(filter), new NotFileFilter(new NameFileFilter(files.stream().map(File::getName).collect(Collectors.toList()), IOCase.SENSITIVE)));
        }
        Iterator<File> fileIterator = FileUtils.iterateFiles(baseDir.getAbsoluteFile(), fileFilter, TrueFileFilter.INSTANCE);
        if (!fileIterator.hasNext()) {
            // base dir & filter are guaranteed to be non-null here
            // (by construction and non-null check of baseDir a few lines above):
            log.info("Local inputSource filter [%s] for base dir [%s] did not match any files", filter, baseDir);
        }
        return fileIterator;
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File)

Example 3 with NameFileFilter

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

the class JobDetailPresentationModel method getIndexPageURL.

public String getIndexPageURL() {
    try {
        File testOutputFolder = artifactsService.findArtifact(job.getIdentifier(), TEST_OUTPUT_FOLDER);
        if (testOutputFolder.exists()) {
            Collection<File> files = FileUtils.listFiles(testOutputFolder, new NameFileFilter("index.html"), TrueFileFilter.TRUE);
            if (files.isEmpty()) {
                return null;
            }
            File testIndexPage = files.iterator().next();
            return getRestfulUrl(testIndexPage.getPath().substring(testIndexPage.getPath().indexOf(TEST_OUTPUT_FOLDER)));
        }
    } catch (Exception ignore) {
    }
    return null;
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) File(java.io.File) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)

Example 4 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project pentaho-platform by pentaho.

the class SystemPathXmlPluginProvider method processDirectory.

protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session) throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    // $NON-NLS-1$
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE);
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;
    }
    boolean hasLib = false;
    // $NON-NLS-1$
    filter = new NameFileFilter("lib", IOCase.SENSITIVE);
    kids = folder.listFiles(filter);
    if (kids != null && kids.length > 0) {
        hasLib = kids[0].exists() && kids[0].isDirectory();
    }
    // we have found a plugin.xml file
    // get the file from the repository
    // $NON-NLS-1$ //$NON-NLS-2$
    String path = "system" + RepositoryFile.SEPARATOR + folder.getName() + RepositoryFile.SEPARATOR + "plugin.xml";
    Document doc = null;
    try {
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            doc = reader.read(ActionSequenceResource.getInputStream(path, LocaleHelper.getLocale()));
        } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
        }
        if (doc != null) {
            plugins.add(createPlugin(doc, session, folder.getName(), hasLib));
        }
    } catch (Exception e) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path), // $NON-NLS-1$
        e);
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", // $NON-NLS-1$
        path));
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) Document(org.dom4j.Document) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver) FilenameFilter(java.io.FilenameFilter) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 5 with NameFileFilter

use of org.apache.commons.io.filefilter.NameFileFilter in project tutorials by eugenp.

the class CommonsIOUnitTest method whenGetFilewithNameFileFilter_thenFindfileTesttxt.

@Test
public void whenGetFilewithNameFileFilter_thenFindfileTesttxt() throws IOException {
    final String testFile = "fileTest.txt";
    String path = getClass().getClassLoader().getResource(testFile).getPath();
    File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));
    String[] possibleNames = { "NotThisOne", testFile };
    Assert.assertEquals(testFile, dir.list(new NameFileFilter(possibleNames, IOCase.INSENSITIVE))[0]);
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)7 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)7 FilenameFilter (java.io.FilenameFilter)2 ArrayList (java.util.ArrayList)2 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)2 Document (org.dom4j.Document)2 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)2 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 MatchPatterns (org.codehaus.plexus.util.MatchPatterns)1 SAXReader (org.dom4j.io.SAXReader)1 Test (org.junit.Test)1 MagicCollection (org.magic.api.beans.MagicCollection)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 SolutionURIResolver (org.pentaho.platform.engine.services.SolutionURIResolver)1