* Load default platform (qualitative) capabilities
*/
ProcessorArchitecture processor = new ProcessorArchitecture();
platforms.add(processor);
PlatformCapability operatingSystem = new OperatingSystem();
platforms.add(operatingSystem);
PlatformCapability tcpIP = new TCPConnectivity();
platforms.add(tcpIP);
PlatformCapability j2se = new J2SESupport();
platforms.add(j2se);
List<PlatformCapability> platformCapabilityList = new ArrayList<PlatformCapability>();
PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT,
"platformCapabilities",
PlatformCapability[].class,
new PlatformCapability[0]);
platformCapabilityList.addAll(Arrays.asList(pCaps));
PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT,
"addPlatformCapabilities",
PlatformCapability[].class,
new PlatformCapability[0]);
platformCapabilityList.addAll(Arrays.asList(addCaps));
/*
* Load the default capabilities
*/
PlatformLoader loader = new PlatformLoader();
pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome()));
platformCapabilityList.addAll(Arrays.asList(pCaps));
/*
* Get additional platform configurations
*/
String platformDir = getPlatformConfigurationDirectory(config);
if(platformDir!=null) {
PlatformCapability[] caps = parsePlatformConfig(loader, platformDir);
platformCapabilityList.addAll(Arrays.asList(caps));
} else {
logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set.");
}
/*
* Get the final array of PlatformCapability instances
*/
pCaps = platformCapabilityList.toArray(new PlatformCapability[platformCapabilityList.size()]);
for (PlatformCapability pCap : pCaps) {
if (pCap.getClass().getName().equals(RIO)) {
if (getRioHome() != null) {
pCap.setPath(getRioHome());
}
}
platforms.add(pCap);
}
/* Find out if we have loaded a StorageCapability class */
PlatformCapability storage = findCapability(platforms, STORAGE);
if(storage==null) {
storage = getPlatformCapability(STORAGE);
platforms.add(storage);
}
/* Find out if we have loaded a Memory class */
PlatformCapability memory = findCapability(platforms, MEMORY);
if(memory == null) {
memory = getPlatformCapability(MEMORY);
platforms.add(memory);
}
/* Find out if we have loaded a SystemMemory class */
PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY);
if(systemMemory == null) {
systemMemory = getPlatformCapability(SYSTEM_MEMORY);
platforms.add(systemMemory);
}
/* Create NativeLibrarySupport objects */
String nativeLibDirs = System.getProperty(NATIVE_LIBS);
List<File> dirList = new ArrayList<File>();
if(nativeLibDirs!=null && nativeLibDirs.length()>0) {
StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" ");
while(st.hasMoreTokens()) {
String dirName = st.nextToken();
File dir = new File(dirName);
if(dir.isDirectory() && dir.canRead()) {
dirList.add(dir);
if(logger.isDebugEnabled())
logger.debug("Adding directory [{}] to check for native libraries", dirName);
} else {
logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...",
dirName);
}
}
final String[] libExtensions = getLibExtensions();
File[] dirs = dirList.toArray(new File[dirList.size()]);
for (File dir : dirs) {
File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File pathName) {
try {
if(FileUtils.isSymbolicLink(pathName)) {
return false;
}
} catch (IOException e) {
logger.warn( "Trying to determine whether the file is a symbolic link", e);
}
boolean matches = false;
for(String libExtension : libExtensions) {
if(pathName.getName().endsWith(libExtension)) {
matches = true;
break;
}
}
return matches;
}
});
for (File file : files) {
String fileName = file.getName();
int index = fileName.lastIndexOf(".");
if (index != -1) {
if (logger.isDebugEnabled())
logger.debug("Create NativeLibrarySupport object for [{}]", fileName);
PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS);
String name;
/*if (!OperatingSystemType.isWindows()) {
name = fileName.substring(3, index);
} else {*/
name = fileName.substring(0, index);
//}
nLib.define(NativeLibrarySupport.NAME, name);
nLib.define(NativeLibrarySupport.FILENAME, fileName);
nLib.setPath(dir.getCanonicalPath());
platforms.add(nLib);
} else {
logger.warn("Illegal Shared Library name="+fileName);
}
}