{
final File appsDir = MuleContainerBootstrapUtils.getMuleAppsDir();
File appDir = new File(appsDir, appName);
if (!appDir.exists())
{
throw new MuleRuntimeException(
MessageFactory.createStaticMessage(
String.format("Application directory does not exist: '%s'", appDir)));
}
// list mule-deploy.* files
@SuppressWarnings("unchecked")
Collection<File> deployFiles = FileUtils.listFiles(appDir, new WildcardFileFilter("mule-deploy.*"), null);
if (deployFiles.size() > 1)
{
// TODO need some kind of an InvalidAppFormatException
throw new MuleRuntimeException(
MessageFactory.createStaticMessage(
String.format("More than one mule-deploy descriptors found in application '%s'", appName)));
}
ApplicationDescriptor desc;
// none found, return defaults
if (deployFiles.isEmpty())
{
desc = new EmptyApplicationDescriptor(appName);
}
else
{
// lookup the implementation by extension
final File descriptorFile = deployFiles.iterator().next();
final String ext = FilenameUtils.getExtension(descriptorFile.getName());
final DescriptorParser descriptorParser = parserRegistry.get(ext);
if (descriptorParser == null)
{
// TODO need some kind of an InvalidAppFormatException
throw new MuleRuntimeException(
MessageFactory.createStaticMessage(
String.format("Unsupported deployment descriptor format for app '%s': %s", appName, ext)));
}
desc = descriptorParser.parse(descriptorFile);