Search in sources :

Example 1 with ExtendedArgumentListBuilder

use of hudson.plugins.sonar.utils.ExtendedArgumentListBuilder in project sonar-scanner-jenkins by SonarSource.

the class SonarRunnerBuilderTest method prepareMockWorkspace.

@Before
public void prepareMockWorkspace() throws IOException {
    workspace = temp.newFolder();
    moduleDir = new File(workspace, "trunk");
    FileUtils.forceMkdir(moduleDir);
    args = new ArgumentListBuilder();
    argsBuilder = new ExtendedArgumentListBuilder(args, false);
    AbstractProject<?, ?> p = mock(AbstractProject.class);
    SCM scm = mock(SCM.class);
    FilePath workspacePath = new FilePath(workspace);
    when(scm.getModuleRoot(eq(workspacePath), any(AbstractBuild.class))).thenReturn(new FilePath(moduleDir));
    when(p.getScm()).thenReturn(scm);
    build = new MyBuild(p);
    build.setWorkspace(workspacePath);
    listener = mock(BuildListener.class);
    env = new EnvVars();
}
Also used : FilePath(hudson.FilePath) BuildListener(hudson.model.BuildListener) EnvVars(hudson.EnvVars) AbstractBuild(hudson.model.AbstractBuild) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) ArgumentListBuilder(hudson.util.ArgumentListBuilder) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) SCM(hudson.scm.SCM) File(java.io.File) Before(org.junit.Before)

Example 2 with ExtendedArgumentListBuilder

use of hudson.plugins.sonar.utils.ExtendedArgumentListBuilder in project sonar-scanner-jenkins by SonarSource.

the class SonarRunnerBuilder method perform.

private void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    if (!SonarInstallation.isValid(getInstallationName(), listener)) {
        throw new AbortException("Invalid SonarQube server installation");
    }
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarRunnerInstallation sri = getSonarRunnerInstallation();
    if (sri == null) {
        // No idea if the path contains old sonar-runner or new sonar-scanner, so prefer the new one
        args.add(launcher.isUnix() ? "sonar-scanner" : "sonar-scanner.bat");
    } else {
        sri = BuilderUtils.getBuildTool(sri, env, listener, workspace);
        String exe = sri.getExecutable(launcher);
        if (exe == null) {
            Logger.printFailureMessage(listener);
            String msg = Messages.SonarScanner_ExecutableNotFound(sri.getName());
            listener.fatalError(msg);
            throw new AbortException(msg);
        }
        args.add(exe);
    }
    SonarInstallation sonarInst = getSonarInstallation();
    addTaskArgument(args);
    addAdditionalArguments(args, sonarInst);
    ExtendedArgumentListBuilder argsBuilder = new ExtendedArgumentListBuilder(args, launcher.isUnix());
    populateConfiguration(argsBuilder, run, workspace, listener, env, sonarInst);
    // Java
    computeJdkToUse(run, workspace, listener, env);
    // Java options
    env.put("SONAR_SCANNER_OPTS", getJavaOpts());
    // For backward compatibility with old sonar-runner
    env.put("SONAR_RUNNER_OPTS", getJavaOpts());
    long startTime = System.currentTimeMillis();
    int exitCode;
    try {
        exitCode = executeSonarQubeScanner(run, workspace, launcher, listener, args, env);
    } catch (IOException e) {
        handleErrors(listener, sri, startTime, e);
        exitCode = -1;
    }
    // with workflows, we don't have realtime access to build logs, so url might be null
    // if the analyis doesn't succeed, it will also be null
    SonarUtils.addBuildInfoTo(run, listener, workspace, getSonarInstallation().getName());
    if (exitCode != 0) {
        throw new AbortException("SonarQube scanner exited with non-zero code: " + exitCode);
    }
}
Also used : EnvVars(hudson.EnvVars) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) ArgumentListBuilder(hudson.util.ArgumentListBuilder) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) IOException(java.io.IOException) AbortException(hudson.AbortException)

Aggregations

EnvVars (hudson.EnvVars)2 ExtendedArgumentListBuilder (hudson.plugins.sonar.utils.ExtendedArgumentListBuilder)2 ArgumentListBuilder (hudson.util.ArgumentListBuilder)2 AbortException (hudson.AbortException)1 FilePath (hudson.FilePath)1 AbstractBuild (hudson.model.AbstractBuild)1 BuildListener (hudson.model.BuildListener)1 SCM (hudson.scm.SCM)1 File (java.io.File)1 IOException (java.io.IOException)1 Before (org.junit.Before)1