/* * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.agent.rakerunner.scripting; import com.intellij.openapi.diagnostic.Logger; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; import jetbrains.buildServer.ExecResult; import jetbrains.buildServer.agent.rakerunner.utils.RunnerUtil; import jetbrains.buildServer.agent.ruby.rvm.InstalledRVM; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.ruby.rvm.RVMPathsSettings; /** * Run shell script under rvm-shell. * Produces special .sh script file and runs it. *
* RVM required. * Unix/Linux only. * * @author Vladislav.Rassokhin */ public class RvmShellRunner implements ShellScriptRunner { private static final Logger LOG = Logger.getInstance(RvmShellRunner.class.getName()); private static RvmShellRunner ourRvmShellRunner; private final InstalledRVM myRVM; public InstalledRVM getRVM() { return myRVM; } public RvmShellRunner(@NotNull final InstalledRVM rvm) { myRVM = rvm; } @NotNull static RvmShellRunner getRvmShellRunner() { final InstalledRVM rvm = RVMPathsSettings.getRVMNullSafe(); if (ourRvmShellRunner == null || !ourRvmShellRunner.getRVM().equals(rvm)) { ourRvmShellRunner = new RvmShellRunner(rvm); } return ourRvmShellRunner; } /** * Run script. * * * @param script script * @param workingDirectory directory where .rvmrc exists * @return script output */ @NotNull public ExecResult run(@NotNull final String script, @NotNull final String workingDirectory, @Nullable final Map