jetbrains.buildServer.agent.runner.ProgramCommandLine Java Examples

The following examples show how to use jetbrains.buildServer.agent.runner.ProgramCommandLine. 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: 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 #2
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 #3
Source File: AnsibleRunService.java    From tc-ansible-runner with MIT License 5 votes vote down vote up
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
    AnsibleRunConfig config = new AnsibleRunConfig(getRunnerParameters());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Going to run ansible with parameters: " + config.toString());
    }
    if (AnsibleCommand.CUSTOM_SCRIPT.equals(config.getCommandType())) {
        return makeCustomScriptCommand(config);
    }
    return makeExecutableCommand(config);
}
 
Example #4
Source File: AnsibleRunService.java    From tc-ansible-runner with MIT License 5 votes vote down vote up
private ProgramCommandLine makeCustomScriptCommand(AnsibleRunConfig config) throws RunBuildException {
    String workingDir = getWorkingDirectory().getPath();
    List<String> args = Collections.emptyList();
    String customScript = getCustomScriptExecutable(config);
    return new SimpleProgramCommandLine(getProvidedEnvironmetVariables(),
            workingDir,
            customScript, args);
}
 
Example #5
Source File: SQRBuildService.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
    final String jdkHome = getRunnerContext().getRunnerParameters().get(JavaRunnerConstants.TARGET_JDK_HOME);
    if (jdkHome != null) {
        getRunnerContext().addEnvironmentVariable("JAVA_HOME", jdkHome);
    }

    final String sonarScannerRoot = getSonarScannerRoot();
    if (sonarScannerRoot == null) {
        throw new RunBuildException("No SonarQube Scanner selected");
    }
    final List<String> programArgs = composeSQRArgs(getRunnerContext().getRunnerParameters(), getBuild().getSharedConfigParameters(), sonarScannerRoot);

    final boolean useScanner = isUseScannerMain(sonarScannerRoot);
    final JavaCommandLineBuilder builder = new JavaCommandLineBuilder();

    final ProgramCommandLine build = builder.withClassPath(getClasspath())
            .withMainClass(getMainClass(useScanner))
            .withJavaHome(jdkHome)
            .withBaseDir(getBuild().getCheckoutDirectory().getAbsolutePath())
            .withEnvVariables(getRunnerContext().getBuildParameters().getEnvironmentVariables())
            .withJvmArgs(JavaRunnerUtil.extractJvmArgs(getRunnerContext().getRunnerParameters()))
            .withClassPath(getClasspath())
            .withProgramArgs(programArgs)
            .withWorkingDir(getRunnerContext().getWorkingDirectory().getAbsolutePath()).build();

    getLogger().message("Starting SQS from " + sonarScannerRoot);
    for (String str : build.getArguments()) {
        getLogger().message(str);
    }

    return build;
}
 
Example #6
Source File: SQMSBuildFinishServiceFactory.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public CommandLineBuildService createService() {
    final SonarQubeMSBuildScannerLocator msBuildScannerLocator = myMSBuildScannerLocator;
    final File workingDirectory = myWorkingDirectory;
    final SQRParametersAccessor sqrParametersAccessor = mySqrParametersAccessor;
    if (msBuildScannerLocator == null || workingDirectory == null || sqrParametersAccessor == null) {
        return new CommandLineBuildService() {
            @NotNull
            @Override
            public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
                throw new RunBuildException("SonarScanner for MSBuild: begin analysis runner was not triggered yet");
            }
        };
    }

    return new SimpleExecute(
            new ExecutionChain(Arrays.asList(
                    new SonarQubeArgumentsWrapper(new SQScannerArgsComposer(myOSType), new SQRParametersAccessorFactory() {
                        public SQRParametersAccessor createAccessor(@NotNull final BuildRunnerContext runnerContext) {
                            return sqrParametersAccessor;
                        }
                    }),
                    new MonoWrapper(myOSType, myMonoLocator),
                    new EndExecution())),
            new SQMSBuildExecutableFactory(msBuildScannerLocator), workingDirectory.getAbsolutePath());
}
 
Example #7
Source File: SimpleExecute.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
    final Executable executable = myChain.modify(myExecutableFactory.create(getRunnerContext()), getRunnerContext());

    return new SimpleProgramCommandLine(
            getRunnerContext().getBuildParameters().getEnvironmentVariables(),
            myAbsolutePath != null ? myAbsolutePath : getRunnerContext().getWorkingDirectory().getAbsolutePath(),
            executable.myExecutable,
            executable.myArguments);
}