// get associated metadata file
String filePath =
folder.getProjectRelativePath().toPortableString() + Constants.DEFAULT_METADATA_FILE_EXTENSION;
IFile folderMetadataFile = folder.getProject().getFile(filePath);
Component component = null;
if (folderMetadataFile != null && folderMetadataFile.exists()) {
component = getComponentFromFile(folderMetadataFile, true);
if (component == null) {
logger.warn("Unable to get component metadata from file '"
+ folderMetadataFile.getProjectRelativePath().toPortableString() + "'");
return null;
}
} else if (folder.getParent() != null && folder.getParent().getType() == IResource.FOLDER
&& folder.getParent().exists()) {
logger.warn("Unable to get folder's component metadata file '"
+ folderMetadataFile.getProjectRelativePath().toPortableString() + "'");
IFolder parent = (IFolder) folder.getParent();
component = getComponentByFolderName(parent.getName());
if (component == null) {
logger.warn("Unable to get component from parent '" + parent.getName() + "'");
return null;
}
component.setName(folder.getName());
component.setFilePath(folderMetadataFile.getProjectRelativePath().toPortableString());
component.setSecondaryComponentType(component.getComponentType());
component.setComponentType(Constants.FOLDER);
component.setDisplayName(Constants.FOLDER);
String packageName = getProjectService().getPackageName(folder.getProject());
component.setPackageName(packageName);
} else {
logger.warn("Unable to get folder's component metadata file '"
+ folderMetadataFile.getProjectRelativePath().toPortableString() + "' or derive from parent");
return null;
}
// get empty component for the folder's sub-type to load defaults, if applicable
setFolderComponentDefaults(component);
if (logger.isDebugEnabled()) {
logger.debug("Loaded " + component.getFullDisplayName() + " from folder '" + folder.getName() + "'");
}
return component;
}