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();
}
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);
}
}
Aggregations