in rake-runner-agent/src/jetbrains/buildServer/agent/rakerunner/SharedParamsType.java [74:119]
public RubySdk createSdk(@NotNull final BuildRunnerContext context,
@NotNull final SharedParams sharedParams)
throws RakeTasksBuildService.MyBuildFailureException {
final String sdkName = StringUtil.emptyIfNull(sharedParams.getRVMSdkName());
// at first lets check that it isn't "system" interpreter
if (RVMSupportUtil.isSystemRuby(sdkName)) {
final EnvironmentPatchableMap env = new EnvironmentPatchableMap(context.getBuildParameters().getEnvironmentVariables());
final Map<String, String> patched = RVMSupportUtil.patchEnvForRVMIfNecessary2(sdkName, env);
final RubySdk sdk = new RVMRubySdkImpl(findSystemInterpreterExecutable(patched));
sdk.setup(patched);
return sdk;
}
// build dist/gemsets table, match ref with dist. name
final String gemset = sharedParams.getRVMGemsetName();
final Pair<String, String> suitable = RVMSupportUtil.determineSuitableRVMSdkDist(sdkName, gemset);
if (suitable.first == null) {
throw new RakeTasksBuildService.MyBuildFailureException(String.format("RVM interpreter '%s' doesn't exist " +
"or isn't a file or isn't a valid RVM interpreter name.", sdkName));
} else {
final File home = RVMPathsSettings.getRVMNullSafe().getHomeForVersionName(suitable.first);
if (home == null) {
throw new RakeTasksBuildService.MyBuildFailureException(String.format("Cannot find home path for RVM SDK with name %s", suitable.first));
}
if (suitable.second == null && !StringUtil.isEmptyOrSpaces(gemset)) {
if (sharedParams.isRVMGemsetCreate()) {
// Creating gemset
final ShellScriptRunner scriptRunner = new BashShellScriptRunner();
final ExecResult output = scriptRunner.run(". $rvm_path/scripts/rvm && rvm use --create " + suitable.first + "@" + gemset,
context.getWorkingDirectory().getAbsolutePath(),
context.getBuildParameters().getEnvironmentVariables());
//noinspection ThrowableResultOfMethodCallIgnored
if (output.getExitCode() != 0 || output.getException() != null) {
throw new RakeTasksBuildService.MyBuildFailureException("Failed to create gemset '" + gemset + "':" + output);
}
return new RVMRubySdkImpl(home, suitable.first, gemset);
} else {
throw new RakeTasksBuildService.MyBuildFailureException(String.format("Gemset '%s' isn't defined for RVM interpreter '%s'. " +
"You may enable 'Create gemset if not exist' option in Ruby Environment Configurator build feature.", gemset, sdkName));
}
}
return new RVMRubySdkImpl(home, suitable.first, suitable.second);
}
}