use of hudson.plugins.sonar.SonarInstallation in project sonar-scanner-jenkins by SonarSource.
the class SonarMavenTest method shouldReturnTarget.
@Test
public void shouldReturnTarget() {
SonarInstallation installation = mock(SonarInstallation.class);
when(installation.getMojoVersion()).thenReturn("").thenReturn("1.0-beta-2");
assertThat(SonarMaven.getTarget(installation)).isEqualTo("-e -B sonar:sonar");
assertThat(SonarMaven.getTarget(installation)).isEqualTo("-e -B org.codehaus.mojo:sonar-maven-plugin:1.0-beta-2:sonar");
}
use of hudson.plugins.sonar.SonarInstallation in project sonar-scanner-jenkins by SonarSource.
the class SQProjectResolverTest method mockSQServer56.
private void mockSQServer56() throws Exception {
super.configureSonar(new SonarInstallation(SONAR_INSTALLATION_NAME, SERVER_URL, TOKEN, null, null, null, null));
when(client.getHttp(SERVER_URL + WsClient.API_VERSION, null)).thenReturn("5.6");
when(client.getHttp(startsWith(SERVER_URL + WsClient.API_PROJECT_STATUS_WITH_ANALYSISID), eq(TOKEN))).thenReturn(getFile("projectStatus.json"));
when(client.getHttp(startsWith(SERVER_URL + WsClient.API_CE_TASK), eq(TOKEN))).thenReturn(getFile("ce_task.json"));
}
use of hudson.plugins.sonar.SonarInstallation in project sonar-scanner-jenkins by SonarSource.
the class SonarMavenTest method shouldWrapUpArguments.
@Test
public void shouldWrapUpArguments() throws Exception {
SonarPublisher publisher = mock(SonarPublisher.class);
SonarInstallation installation = mock(SonarInstallation.class);
when(installation.getServerUrl()).thenReturn("hostUrl");
when(installation.getServerAuthenticationToken()).thenReturn("xyz");
when(publisher.getInstallation()).thenReturn(installation);
when(publisher.getBranch()).thenReturn("branch");
ArgumentListBuilder args = new ArgumentListBuilder();
SonarMaven sonarMaven = new SonarMaven("-Dprop=value", "Default Maven", "pom.xml", "", new DefaultLocalRepositoryLocator(), publisher, mock(BuildListener.class), null, null, null);
sonarMaven.wrapUpArguments(args, "sonar:sonar", mock(AbstractBuild.class), mock(Launcher.class), mock(BuildListener.class));
List<String> result = args.toList();
assertThat(result).contains("-Dprop=value");
assertThat(result).contains("-Dsonar.host.url=hostUrl");
assertThat(result).contains("-Dsonar.branch=branch");
assertThat(result).contains("-Dsonar.login=xyz");
}
use of hudson.plugins.sonar.SonarInstallation in project sonar-scanner-jenkins by SonarSource.
the class WaitForQualityGateStepTest method submitPipeline.
private QueueTaskFuture<WorkflowRun> submitPipeline(boolean specifyServer) throws IOException, InterruptedException, ExecutionException {
SonarQubeWebHook.get().listeners.clear();
String serverUrl = "http://localhost:" + port + "/sonarqube";
story.j.jenkins.getDescriptorByType(SonarGlobalConfiguration.class).setInstallations(new SonarInstallation(SONAR_INSTALLATION_NAME, serverUrl, null, null, null, null, null));
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, JOB_NAME);
String reportTaskContent = "dashboardUrl=" + serverUrl + "/dashboard\\n" + "ceTaskId=" + FAKE_TASK_ID + "\\nserverUrl=" + serverUrl + "\\nprojectKey=foo";
p.setDefinition(new CpsFlowDefinition(script(reportTaskContent, specifyServer), true));
return p.scheduleBuild2(0);
}
use of hudson.plugins.sonar.SonarInstallation in project sonar-scanner-jenkins by SonarSource.
the class SQProjectResolver method resolve.
/**
* Resolve information concerning the quality gate.
* Might return null if it's not possible to fetch it, which should be interpreted as 'nothing to display'.
* Errors that should be displayed are included in {@link ProjectInformation#getErrors()}.
*/
@CheckForNull
public ProjectInformation resolve(@Nullable String serverUrl, @Nullable String projectDashboardUrl, String ceTaskId, String installationName) {
SonarInstallation inst = SonarInstallation.get(installationName);
if (inst == null) {
Logger.LOG.info(() -> "Invalid installation name: " + installationName);
return null;
}
if (serverUrl == null) {
Logger.LOG.info("No server url.");
return null;
}
try {
WsClient wsClient = new WsClient(client, serverUrl, inst.getServerAuthenticationToken());
Version version = new Version(wsClient.getServerVersion());
if (version.compareTo(new Version("5.6")) < 0) {
Logger.LOG.info(() -> "SQ < 5.6 is not supported");
return null;
}
ProjectInformation projectInfo = new ProjectInformation();
projectInfo.setUrl(projectDashboardUrl);
String analysisId = requestCETaskDetails(wsClient, projectInfo, ceTaskId);
if (analysisId != null) {
projectInfo.setStatus(wsClient.requestQualityGateStatus(analysisId));
}
return projectInfo;
} catch (Exception e) {
Logger.LOG.log(Level.WARNING, "Error fetching project information", e);
return null;
}
}
Aggregations