Search in sources :

Example 1 with SonarInstallation

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");
}
Also used : SonarInstallation(hudson.plugins.sonar.SonarInstallation) Test(org.junit.Test)

Example 2 with SonarInstallation

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"));
}
Also used : SonarInstallation(hudson.plugins.sonar.SonarInstallation)

Example 3 with SonarInstallation

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");
}
Also used : BuildListener(hudson.model.BuildListener) AbstractBuild(hudson.model.AbstractBuild) SonarPublisher(hudson.plugins.sonar.SonarPublisher) SonarInstallation(hudson.plugins.sonar.SonarInstallation) Launcher(hudson.Launcher) ArgumentListBuilder(hudson.util.ArgumentListBuilder) DefaultLocalRepositoryLocator(hudson.maven.local_repo.DefaultLocalRepositoryLocator) Test(org.junit.Test)

Example 4 with SonarInstallation

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);
}
Also used : SonarGlobalConfiguration(hudson.plugins.sonar.SonarGlobalConfiguration) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) SonarInstallation(hudson.plugins.sonar.SonarInstallation) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob)

Example 5 with SonarInstallation

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;
    }
}
Also used : Version(hudson.plugins.sonar.utils.Version) SonarInstallation(hudson.plugins.sonar.SonarInstallation) CheckForNull(javax.annotation.CheckForNull)

Aggregations

SonarInstallation (hudson.plugins.sonar.SonarInstallation)5 Test (org.junit.Test)2 Launcher (hudson.Launcher)1 DefaultLocalRepositoryLocator (hudson.maven.local_repo.DefaultLocalRepositoryLocator)1 AbstractBuild (hudson.model.AbstractBuild)1 BuildListener (hudson.model.BuildListener)1 SonarGlobalConfiguration (hudson.plugins.sonar.SonarGlobalConfiguration)1 SonarPublisher (hudson.plugins.sonar.SonarPublisher)1 Version (hudson.plugins.sonar.utils.Version)1 ArgumentListBuilder (hudson.util.ArgumentListBuilder)1 CheckForNull (javax.annotation.CheckForNull)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1