use of java.io.FileFilter in project superCleanMaster by joyoyao.
the class AppUtil method getNumCores.
/**
* Gets the number of cores available in this device, across all processors.
* Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
*
* @return The number of cores, or 1 if failed to get result
*/
public static int getNumCores() {
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
// number
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
}
});
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
e.printStackTrace();
return 1;
}
}
use of java.io.FileFilter in project hudson-2.x by hudson.
the class MatrixProject method rebuildConfigurations.
/**
* Rebuilds the {@link #configurations} list and {@link #activeConfigurations}.
*/
void rebuildConfigurations() throws IOException {
// backward compatibility check to see if there's any data in the old structure
// if so, bring them to the newer structure.
File[] oldDirs = getConfigurationsDir().listFiles(new FileFilter() {
public boolean accept(File child) {
return child.isDirectory() && !child.getName().startsWith("axis-");
}
});
//TODO seems oldDir is always null and old matrix configuration is not cleared.
if (oldDirs != null) {
// rename the old directory to the new one
for (File dir : oldDirs) {
try {
Combination c = Combination.fromString(dir.getName());
dir.renameTo(getRootDirFor(c));
} catch (IllegalArgumentException e) {
// it's not a configuration dir. Just ignore.
}
}
}
CopyOnWriteMap.Tree<Combination, MatrixConfiguration> configurations = new CopyOnWriteMap.Tree<Combination, MatrixConfiguration>();
loadConfigurations(getConfigurationsDir(), configurations, Collections.<String, String>emptyMap());
this.configurations = configurations;
// find all active configurations
Set<MatrixConfiguration> active = new LinkedHashSet<MatrixConfiguration>();
AxisList axes = getAxes();
if (!CollectionUtils.isEmpty(axes)) {
for (Combination c : axes.list()) {
String combinationFilter = getCombinationFilter();
if (c.evalGroovyExpression(axes, combinationFilter)) {
LOGGER.fine("Adding configuration: " + c);
MatrixConfiguration config = configurations.get(c);
if (config == null) {
config = new MatrixConfiguration(this, c);
config.save();
configurations.put(config.getCombination(), config);
}
active.add(config);
}
}
}
this.activeConfigurations = active;
}
use of java.io.FileFilter in project hudson-2.x by hudson.
the class MatrixProject method loadConfigurations.
/**
* Recursively search for configuration and put them to the map
*
* <p>
* The directory structure would be <tt>axis-a/b/axis-c/d/axis-e/f</tt> for
* combination [a=b,c=d,e=f]. Note that two combinations [a=b,c=d] and [a=b,c=d,e=f]
* can both co-exist (where one is an archived record and the other is live, for example)
* so search needs to be thorough.
*
* @param dir
* Directory to be searched.
* @param result
* Receives the loaded {@link MatrixConfiguration}s.
* @param combination
* Combination of key/values discovered so far while traversing the directories.
* Read-only.
*/
private void loadConfigurations(File dir, CopyOnWriteMap.Tree<Combination, MatrixConfiguration> result, Map<String, String> combination) {
File[] axisDirs = dir.listFiles(new FileFilter() {
public boolean accept(File child) {
return child.isDirectory() && child.getName().startsWith("axis-");
}
});
if (axisDirs == null)
return;
for (File subdir : axisDirs) {
// axis name
String axis = subdir.getName().substring(5);
File[] valuesDir = subdir.listFiles(new FileFilter() {
public boolean accept(File child) {
return child.isDirectory();
}
});
// no values here
if (valuesDir == null)
continue;
for (File v : valuesDir) {
Map<String, String> c = new HashMap<String, String>(combination);
c.put(axis, TokenList.decode(v.getName()));
try {
XmlFile config = Items.getConfigFile(v);
if (config.exists()) {
Combination comb = new Combination(c);
// if we already have this in memory, just use it.
// otherwise load it
MatrixConfiguration item = null;
if (this.configurations != null)
item = this.configurations.get(comb);
if (item == null) {
item = (MatrixConfiguration) config.read();
item.setCombination(comb);
item.onLoad(this, v.getName());
}
result.put(item.getCombination(), item);
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load matrix configuration " + v, e);
}
loadConfigurations(v, result, c);
}
}
}
use of java.io.FileFilter in project hudson-2.x by hudson.
the class ItemGroupMixIn method loadChildren.
/*
* The rest is the methods that provide meat.
*/
/**
* Loads all the child {@link Item}s.
*
* @param modulesDir
* Directory that contains sub-directories for each child item.
*/
public static <K, V extends Item> Map<K, V> loadChildren(ItemGroup parent, File modulesDir, Function1<? extends K, ? super V> key) {
// make sure it exists
modulesDir.mkdirs();
File[] subdirs = modulesDir.listFiles(new FileFilter() {
public boolean accept(File child) {
return child.isDirectory();
}
});
CopyOnWriteMap.Tree<K, V> configurations = new CopyOnWriteMap.Tree<K, V>();
for (File subdir : subdirs) {
try {
V item = (V) Items.load(parent, subdir);
configurations.put(key.call(item), item);
} catch (IOException e) {
// TODO: logging
e.printStackTrace();
}
}
return configurations;
}
use of java.io.FileFilter in project pinot by linkedin.
the class CrcUtils method forAllFilesInFolder.
public static CrcUtils forAllFilesInFolder(File dir) {
final File[] allFiles = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.getName().equals(V1Constants.SEGMENT_CREATION_META)) {
return false;
}
return true;
}
});
Arrays.sort(allFiles);
final List<File> files = new ArrayList<File>();
for (final File f : allFiles) {
files.add(f);
}
return new CrcUtils(files);
}
Aggregations