public class AppKnobYamlParsingProcessor extends AbstractParsingProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit unit = phaseContext.getDeploymentUnit();
TorqueBoxMetaData metaData = null;
File rootFile = null;
ResourceRoot appRoot = null;
try {
VirtualFile appKnobYml = getFile( unit );
if (appKnobYml == null) {
return;
}
GlobalRuby ruby = null;
try {
ruby = (GlobalRuby) phaseContext.getServiceRegistry().getRequiredService( CoreServices.GLOBAL_RUBY ).getValue();
metaData = new TorqueBoxMetaData( ruby.evaluateErb( YAMLUtils.parseYaml( appKnobYml ) ) );
} catch (org.jboss.msc.service.ServiceNotFoundException e) {
log.warn("No GlobalRuby available to parse ERB in deployment descriptor");
metaData = new TorqueBoxMetaData( YAMLUtils.parseYaml( appKnobYml ) );
}
rootFile = metaData.getApplicationRootFile();
if (rootFile != null) {
VirtualFile root = VFS.getChild( rootFile.toURI() );
if (!root.exists()) {
throw new DeploymentUnitProcessingException( "Application root does not exist: " + root.toURL().toExternalForm() );
}
if (root.exists() && !root.isDirectory()) {
// Expand the referenced root if it's not a directory (ie
// .knob archive)
final Closeable closable = VFS.mountZipExpanded( root, root, TempFileProviderService.provider() );
final MountHandle mountHandle = new MountHandle( closable );
appRoot = new ResourceRoot( root, mountHandle );
} else {
appRoot = new ResourceRoot( root, null );
}
appRoot.putAttachment( Attachments.INDEX_RESOURCE_ROOT, false );
unit.putAttachment( Attachments.DEPLOYMENT_ROOT, appRoot );
}
else {
log.infof( "Rootless deployment detected: %s", unit.getName() );
DeploymentUtils.markUnitAsRootless( unit );
}
} catch (YAMLException e) {
throw new DeploymentUnitProcessingException( "Error processing YAML: ", e );
} catch (Exception e) {
throw new DeploymentUnitProcessingException( e );
}
unit.putAttachment( TorqueBoxMetaData.ATTACHMENT_KEY, metaData );
RubyAppMetaData rubyAppMetaData = new RubyAppMetaData( unit.getName() );
rubyAppMetaData.setRoot( rootFile );
rubyAppMetaData.setEnvironmentName( metaData.getApplicationEnvironment() );
rubyAppMetaData.attachTo( unit );
}