public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit unit = phaseContext.getDeploymentUnit();
if (DeploymentUtils.isUnitRootless( unit )) {
return;
}
RubyAppMetaData rubyAppMetaData = unit.getAttachment( RubyAppMetaData.ATTACHMENT_KEY );
RackMetaData rackAppMetaData = unit.getAttachment( RackMetaData.ATTACHMENT_KEY );
RailsMetaData railsAppMetaData = unit.getAttachment( RailsMetaData.ATTACHMENT_KEY );
if ( rubyAppMetaData == null || rackAppMetaData == null || railsAppMetaData == null ) {
return;
}
RubyRuntimeMetaData runtimeMetaData = unit.getAttachment( RubyRuntimeMetaData.ATTACHMENT_KEY );
if ( runtimeMetaData != null && runtimeMetaData.getRuntimeType() != null ) {
return;
}
if (runtimeMetaData == null) {
runtimeMetaData = new RubyRuntimeMetaData();
unit.putAttachment( RubyRuntimeMetaData.ATTACHMENT_KEY, runtimeMetaData );
}
runtimeMetaData.setBaseDir( rubyAppMetaData.getRoot() );
runtimeMetaData.setEnvironment( rubyAppMetaData.getEnvironmentVariables() );
runtimeMetaData.setRuntimeType( RubyRuntimeMetaData.RuntimeType.RAILS );
runtimeMetaData.appendLoadPath( new RubyLoadPathMetaData( rubyAppMetaData.getRoot() ) );
runtimeMetaData.appendLoadPath( new RubyLoadPathMetaData( new File( rubyAppMetaData.getRoot(), "lib" ) ) );
RuntimeInitializer initializer = new RailsRuntimeInitializer( rubyAppMetaData, rackAppMetaData, railsAppMetaData );
RuntimePreparer preparer = new BundlerAwareRuntimePreparer( rubyAppMetaData );
runtimeMetaData.setRuntimeInitializer( initializer );
runtimeMetaData.setRuntimePreparer( preparer );