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);
}
}
}
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;
}
}
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;
}
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));
}
}
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]);
}
Aggregations