jetbrains.buildServer.RunBuildException Java Examples

The following examples show how to use jetbrains.buildServer.RunBuildException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQRBuildService.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private String getExecutablePath() throws RunBuildException {
    final String path = getSonarScannerRoot();

    final String execName = myOsType == WINDOWS ? "sonar-runner.bat" : "sonar-runner";

    final File exec = new File(path + File.separatorChar + "bin" + File.separatorChar + execName);

    if (!exec.exists()) {
        throw new RunBuildException("SonarQube executable doesn't exist: " + exec.getAbsolutePath());
    }
    if (!exec.isFile()) {
        throw new RunBuildException("SonarQube executable is not a file: " + exec.getAbsolutePath());
    }
    return exec.getAbsolutePath();
}
 
Example #2
Source File: TryFinallyBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_fail_on_finally_error() {
  TryFinallyBuildProcessImpl bp = create();

  bp.addFinishProcess(new RecordingBuildProcess("finally-1", BuildFinishedStatus.FINISHED_SUCCESS) {
    {
      setFinishException(new RunBuildException("ppp"));
    }
  });
  bp.addFinishProcess(new RecordingBuildProcess("finally-2", BuildFinishedStatus.FINISHED_SUCCESS));

  //TODO: error status is not propagated here.
  //TODO: The only changes is we report error on that from the runner
  assertRunSuccessfully(bp.asBuildProcess(), BuildFinishedStatus.FINISHED_SUCCESS);
  assertLog("start-finally-1",
          "waitFor-finally-1",
          "error-ppp",
          "start-finally-2",
          "waitFor-finally-2");
}
 
Example #3
Source File: SSHDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
                                          @NotNull final String username,
                                          @NotNull final String password,
                                          @NotNull final String target,
                                          @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException {

  final SSHSessionProvider provider = new SSHSessionProvider(context, myInternalProperties, mySshKeyManager);
  final String transport = context.getRunnerParameters().get(SSHRunnerConstants.PARAM_TRANSPORT);
  if (SSHRunnerConstants.TRANSPORT_SCP.equals(transport)) {
    return new ScpProcessAdapter(context, artifactsCollections, provider);
  } else if (SSHRunnerConstants.TRANSPORT_SFTP.equals(transport)) {
    return new SftpBuildProcessAdapter(context, artifactsCollections, provider);
  } else {
    throw new RunBuildException("Unknown ssh transport [" + transport + "]");
  }
}
 
Example #4
Source File: BaseVM.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public static BuildProcess block(@NotNull final BuildProgressLogger logger,
                                 @NotNull final String blockName,
                                 @NotNull final String blockText,
                                 @NotNull final BuildProcess proc) {
  return new DelegatingBuildProcess(new DelegatingBuildProcess.Action() {
    @NotNull
    @Override
    public BuildProcess startImpl() throws RunBuildException {
      logger.activityStarted(blockName, blockText, "vm");
      return proc;
    }

    @Override
    public void finishedImpl() {
      logger.activityFinished(blockName, "vm");
    }
  });
}
 
Example #5
Source File: FtpDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
                                          @NotNull final String username,
                                          @NotNull final String password,
                                          @NotNull final String target,
                                          @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException {
  final Map<String, String> runnerParameters = context.getRunnerParameters();
  final String authMethod = runnerParameters.get(FTPRunnerConstants.PARAM_AUTH_METHOD);

  if (FTPRunnerConstants.AUTH_METHOD_USER_PWD.equals(authMethod)) {
    return new FtpBuildProcessAdapter(context, target, username, password, artifactsCollections);
  } else if (FTPRunnerConstants.AUTH_METHOD_ANONYMOUS.equals(authMethod)) {
    return new FtpBuildProcessAdapter(context, target, "anonymous", " ", artifactsCollections);
  } else {
    throw new RunBuildException("Unknown FTP authentication method: [" + authMethod + "]");
  }

}
 
Example #6
Source File: AnsibleRunService.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
private String getCustomScriptExecutable(AnsibleRunConfig config) throws RunBuildException {
    String content = null;
    File scriptFile = null;
    if (config.getSourceCode() != null) {
        content = config.getSourceCode().replace("\r\n", "\n").replace("\r", "\n");
    }
    if (StringUtil.isEmptyOrSpaces(content)) {
        throw new RunBuildException("Custom script source code cannot be empty");
    }
    try {
        scriptFile = File.createTempFile("ansible_custom_exe", null, getBuildTempDirectory());
        FileUtil.writeFileAndReportErrors(scriptFile, content);
    } catch (IOException e) {
        throw new RunBuildException("Failed to create a tmp file for custom ansible execution script");
    }
    boolean executable = scriptFile.setExecutable(true, true);
    if (!executable) {
        throw new RunBuildException("Failed to set executable permissions to " + scriptFile.getAbsolutePath());
    }
    return scriptFile.getAbsolutePath();
}
 
Example #7
Source File: BaseDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild,
                                       @NotNull final BuildRunnerContext context) throws RunBuildException {

  final Map<String, String> runnerParameters = context.getRunnerParameters();
  final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME));
  final String password = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_PASSWORD));
  final String target = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_TARGET_URL));
  final String sourcePaths = runnerParameters.get(DeployerRunnerConstants.PARAM_SOURCE_PATH);

  final Collection<ArtifactsPreprocessor> preprocessors = myExtensionHolder.getExtensions(ArtifactsPreprocessor.class);

  final ArtifactsBuilder builder = new ArtifactsBuilder();
  builder.setPreprocessors(preprocessors);
  builder.setBaseDir(runningBuild.getCheckoutDirectory());
  builder.setArtifactsPaths(sourcePaths);

  final List<ArtifactsCollection> artifactsCollections = builder.build();

  return getDeployerProcess(context, username, password, target, artifactsCollections);
}
 
Example #8
Source File: DelegatingBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interrupted_in_process_finish() {
  final AtomicReference<BuildProcess> bp = new AtomicReference<BuildProcess>();
  DelegatingBuildProcess aaa = new DelegatingBuildProcess(new LoggingActionBase(){
    @Override
    protected RecordingBuildProcess createSub() {
      return new RecordingBuildProcess("i", BuildFinishedStatus.FINISHED_SUCCESS){
        @NotNull
        @Override
        public BuildFinishedStatus waitFor() throws RunBuildException {
          bp.get().interrupt();
          return super.waitFor();
        }
      };
    }
  });
  bp.set(aaa);

  assertRunSuccessfully(aaa, INTERRUPTED);
  assertLog("start-impl","start-i","interrupt-i","waitFor-i","finish-impl");
  Assert.assertTrue(aaa.isFinished());
  Assert.assertTrue(aaa.isInterrupted());
}
 
Example #9
Source File: DelegatingBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interrupted_in_process_start() {
  final AtomicReference<BuildProcess> bp = new AtomicReference<BuildProcess>();
  DelegatingBuildProcess aaa = new DelegatingBuildProcess(new LoggingActionBase(){
    @Override
    protected RecordingBuildProcess createSub() {
      return new RecordingBuildProcess("i", BuildFinishedStatus.FINISHED_SUCCESS){
        @Override
        public void start() throws RunBuildException {
          super.start();
          bp.get().interrupt();
        }
      };
    }
  });
  bp.set(aaa);

  assertRunSuccessfully(aaa, INTERRUPTED);
  assertLog("start-impl","start-i","interrupt-i","waitFor-i","finish-impl");
  Assert.assertTrue(aaa.isFinished());
  Assert.assertTrue(aaa.isInterrupted());
}
 
Example #10
Source File: AnsibleRunService.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
private ProgramCommandLine makeExecutableCommand(AnsibleRunConfig config)
        throws RunBuildException {
    String workingDir = getWorkingDirectory().getPath();
    StringBuilder args = new StringBuilder("");
    if (!StringUtil.isEmptyOrSpaces(config.getInventory())) {
        args.append("-i ").append(config.getInventory());
    }
    if (StringUtil.isEmptyOrSpaces(config.getPlaybook())) {
        throw new RunBuildException("Ansible playbook should be specified");
    }
    args.append(" ").append(config.getPlaybook());
    if (!StringUtil.isEmptyOrSpaces(config.getOptions())) {
        args.append(" ").append(config.getOptions());
    }
    return new SimpleProgramCommandLine(getProvidedEnvironmetVariables(),
            workingDir,
           config.getExecutable(), CommandLineArgumentsUtil.extractArguments(args.toString()));
}
 
Example #11
Source File: DelegatingBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interrupted_in_startImpl() {
  final AtomicReference<BuildProcess> bp = new AtomicReference<BuildProcess>();
  DelegatingBuildProcess aaa = new DelegatingBuildProcess(new LoggingAction(FINISHED_SUCCESS){
    @NotNull
    @Override
    public BuildProcess startImpl() throws RunBuildException {
      bp.get().interrupt();
      return super.startImpl();
    }
  });
  bp.set(aaa);

  assertRunSuccessfully(aaa, INTERRUPTED);
  assertLog("start-impl","finish-impl");
  Assert.assertTrue(aaa.isFinished());
  Assert.assertTrue(aaa.isInterrupted());
}
 
Example #12
Source File: AllureBuildServiceAdapter.java    From allure-teamcity with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {

    BuildProgressLogger buildLogger = getLogger();

    Map<String, String> envVariables = new HashMap<>(getRunnerContext()
            .getBuildParameters()
            .getEnvironmentVariables());
    Optional.ofNullable(getRunnerContext().getRunnerParameters().get(JavaRunnerConstants.TARGET_JDK_HOME))
            .ifPresent(javaHome -> envVariables.put("JAVA_HOME", javaHome));

    String programPath = getProgramPath();
    List<String> programArgs = getProgramArgs();

    buildLogger.message("Program environment variables: " + envVariables.toString());
    buildLogger.message("Program working directory: " + workingDirectory);
    buildLogger.message("Program path: " + programPath);
    buildLogger.message("Program args: " + programArgs.toString());

    return new SimpleProgramCommandLine(envVariables, workingDirectory, programPath, programArgs);
}
 
Example #13
Source File: CompositeBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interruptCalledForTwo_WaitFor() {
  final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();
  i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS));
  i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {
    @NotNull
    @Override
    public BuildFinishedStatus waitFor() throws RunBuildException {
      i.interrupt();
      return super.waitFor();
    }
  });
  i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));

  assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);
  assertLog("start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");
}
 
Example #14
Source File: CompositeBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interruptCalledForTwo() {
  final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();
  i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS));
  i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {
    @Override
    public void start() throws RunBuildException {
      super.start();
      i.interrupt();
    }
  });
  i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));

  assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);
  assertLog("start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");
}
 
Example #15
Source File: CompositeBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interruptCalledForFirst_WaitFor() {
  final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();
  i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {
    @NotNull
    @Override
    public BuildFinishedStatus waitFor() throws RunBuildException {
      i.interrupt();
      return super.waitFor();
    }
  });
  i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));

  assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);
  assertLog("start-1", "interrupt-1", "waitFor-1");
}
 
Example #16
Source File: CompositeBuildProcessTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Test
public void test_interruptCalledForFirst() {
  final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();
  final List<String> log = new ArrayList<String>();
  i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {
    @Override
    public void start() throws RunBuildException {
      super.start();
      i.interrupt();
    }
  });
  i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));

  assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);
  assertLog("start-1", "interrupt-1", "waitFor-1");
}
 
Example #17
Source File: DockerTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,
                                       @NotNull Collection<String> argz,
                                       @NotNull File workingDir,
                                       @NotNull Map<String, String> additionalEnvironment) throws RunBuildException {
  final List<String> processed = new ArrayList<String>();
  for (String arg : argz) {
    processed.add(
            arg
                    .replace(home.getPath(), "!HOME!")
                    .replace(work.getPath(), "!WORK!")
                    .replace(FileUtil.getRelativePath(home, work), "!REL_WORK!")
    );
  }

  System.out.println("cmd>> " + processed);
  return cmd.executeCommandLine(hostContext, processed, workingDir, additionalEnvironment);
}
 
Example #18
Source File: AllureBuildServiceAdapter.java    From allure-teamcity with Apache License 2.0 6 votes vote down vote up
private String getProgramPath() throws RunBuildException {

        BuildProgressLogger buildLogger = getLogger();
        String path = clientDirectory.toAbsolutePath().toString();
        String executableName = getExecutableName();

        String executableFile = path + File.separatorChar + "bin" + File.separatorChar + executableName;
        File file = new File(executableFile);

        if (!file.exists()) {
            throw new RunBuildException("Cannot find executable \'" + executableFile + "\'");
        }
        if (!file.setExecutable(true)) {
            buildLogger.message("Cannot set file: " + executableFile + " executable.");
        }
        return file.getAbsolutePath();

    }
 
Example #19
Source File: DockerTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
private DoDockerTest expectCommand(@NotNull final BaseMatcher<Collection<String>> argz) throws RunBuildException {
  m.checking(new Expectations() {{
    //noinspection unchecked
    oneOf(cmd).executeCommandLine(
            with(any(BuildRunnerContext.class)),
            with(argz),
            with(equal(home)),
            with(any(Map.class))
    );
    will(returnValue(new BuildProcessBase() {
      @NotNull
      @Override
      protected BuildFinishedStatus waitForImpl() throws RunBuildException {
        return BuildFinishedStatus.FINISHED_SUCCESS;
      }
    }));
  }});

  return this;
}
 
Example #20
Source File: TryFinallyBuildProcessImpl.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public BuildProcess asBuildProcess() {
  return new DelegatingBuildProcess(new DelegatingBuildProcess.Action() {
    @NotNull
    @Override
    public BuildProcess startImpl() throws RunBuildException {
      return myTryProcess;
    }

    @Override
    public void finishedImpl() {
      catchIt("Failed to execute finally steps", new Action() {
        @Override
        public void execute() throws RunBuildException {
          myFinallyProcess.start();
        }
      });
      catchIt("Failed to execute finally steps", new Action() {
        @Override
        public void execute() throws RunBuildException {
          myFinallyProcess.waitFor();
        }
      });
    }
  });
}
 
Example #21
Source File: CommandlineBuildProcessFactoryImpl.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,
                                       @NotNull Collection<String> argz,
                                       @NotNull File workingDir,
                                       @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {
  BuildRunnerContext context = myFacade.createBuildRunnerContext(
          hostContext.getBuild(),
          SimpleRunnerConstants.TYPE,
          workingDir.getPath(),
          hostContext
  );

  for (Map.Entry<String, String> entry : additionalEnvironment.entrySet()) {
    context.addEnvironmentVariable(entry.getKey(), entry.getValue());
  }

  final List<String> newArgz = new ArrayList<String>(argz);
  final String commandLine = joinCommandLineArguments(newArgz);

  hostContext.getBuild().getBuildLogger().message("Executing command: " + commandLine);

  context.addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
  context.addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, commandLine);

  return myFacade.createExecutable(hostContext.getBuild(), context);
}
 
Example #22
Source File: DockerTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public DoDockerTest expectStartsWith(@NotNull final String... argz) throws RunBuildException {
  return expectCommand(new BaseMatcher<Collection<String>>() {
    @Override
    public boolean matches(Object item) {
      //noinspection unchecked
      final List<String> processed = (List<String>) item;

      for (int i = 0; i < argz.length; i++) {
        String s = argz[i];
        if (!processed.get(i).equals(s)) return false;
      }

      return true;
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("CommandlineStartsWith: " + Arrays.toString(argz));
    }
  });
}
 
Example #23
Source File: DockerTest.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public DoDockerTest expectExactCall(@NotNull final String... argz) throws RunBuildException {
  return expectCommand(new BaseMatcher<Collection<String>>() {
    @Override
    public boolean matches(Object item) {
      //noinspection unchecked
      final List<String> processed = (List<String>) item;

      if (processed.equals(new ArrayList<String>(Arrays.asList(argz)))) {
        return true;
      }

      System.out.println("Was: " + processed);
      return false;
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("Commandline: " + Arrays.toString(argz));
    }
  });
}
 
Example #24
Source File: CompositeBuildProcessImpl.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
protected BuildFinishedStatus waitForImpl() throws RunBuildException {
  if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;
  for (BuildProcess proc = myProcessList.poll(); proc != null; proc = myProcessList.poll()) {
    myCurrentProcess.set(proc);
    try {
      proc.start();
      final BuildFinishedStatus status = proc.waitFor();
      if (status != BuildFinishedStatus.INTERRUPTED && status != BuildFinishedStatus.FINISHED_SUCCESS) return status;
    } finally {
      myCurrentProcess.set(null);
    }
    if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;
  }
  if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;
  return BuildFinishedStatus.FINISHED_SUCCESS;
}
 
Example #25
Source File: AllureBuildServiceAdapter.java    From allure-teamcity with Apache License 2.0 5 votes vote down vote up
private static Path getClientDirectory(Path client) throws RunBuildException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(client, Files::isDirectory)) {
        for (Path path : stream) {
            if (path.getFileName().toString().startsWith("allure")) {
                return path;
            }
        }
    } catch (IOException e) {
        throw new RunBuildException("Cannot find allure tool folder.", e);
    }
    return client;
}
 
Example #26
Source File: CommandlineBuildProcessFactoryTest.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupportEnv() throws RunBuildException {
  m.checking(new Expectations(){{
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, "program");
    oneOf(mySubContext).addEnvironmentVariable("a", "b");
  }});

  myFactory.executeCommandLine(myRootContext, Arrays.asList("program"), myWorkDir, Collections.singletonMap("a", "b"));

  m.assertIsSatisfied();
}
 
Example #27
Source File: CommandlineBuildProcessFactoryTest.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuoteArguments() throws RunBuildException {
  m.checking(new Expectations(){{
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, "program \" \"f o o\" \"z e\" \"");
  }});

  myFactory.executeCommandLine(myRootContext, Arrays.asList("program", "\"", "f o o", "z e", "\""), myWorkDir, Collections.<String, String>emptyMap());

  m.assertIsSatisfied();
}
 
Example #28
Source File: VMRunnerContext.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@NotNull
public String getScript() throws RunBuildException {
  final String script = myContext.getRunnerParameters().get(VMConstants.PARAMETER_SCRIPT);
  if (StringUtil.isEmptyOrSpaces(script)) {
    throw new RunBuildException("Script should not be empty");
  }
  return script;
}
 
Example #29
Source File: CommandlineBuildProcessFactoryTest.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupportQuotes() throws RunBuildException {
  m.checking(new Expectations(){{
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, "program \" foo \"");
  }});

  myFactory.executeCommandLine(myRootContext, Arrays.asList("program", "\"", "foo", "\""), myWorkDir, Collections.<String, String>emptyMap());

  m.assertIsSatisfied();
}
 
Example #30
Source File: CommandlineBuildProcessFactoryTest.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuoteCommandArgs() throws RunBuildException {
  m.checking(new Expectations(){{
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
    oneOf(mySubContext).addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, "\"p r o g r a m\" a \"b c d e\" f");
    oneOf(mySubContext).addEnvironmentVariable("a", "b");
  }});

  myFactory.executeCommandLine(myRootContext, Arrays.asList("p r o g r a m", "a", "b c d e", "f"), myWorkDir, Collections.singletonMap("a", "b"));

  m.assertIsSatisfied();
}