Search in sources :

Example 1 with DefaultLocalRepositoryLocator

use of hudson.maven.local_repo.DefaultLocalRepositoryLocator 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 2 with DefaultLocalRepositoryLocator

use of hudson.maven.local_repo.DefaultLocalRepositoryLocator in project sonar-scanner-jenkins by SonarSource.

the class SonarMaven method executeMaven.

public static boolean executeMaven(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String mavenName, String pom, SonarInstallation sonarInstallation, SonarPublisher sonarPublisher, JDK jdk, SettingsProvider settings, GlobalSettingsProvider globalSettings, boolean usesLocalRepository) throws IOException, InterruptedException {
    MavenModuleSet mavenModuleProject = sonarPublisher.getMavenProject(build);
    EnvVars envVars = build.getEnvironment(listener);
    /**
     * MAVEN_OPTS
     */
    String mvnOptions = sonarPublisher.getMavenOpts();
    if (StringUtils.isEmpty(mvnOptions) && mavenModuleProject != null && StringUtils.isNotEmpty(mavenModuleProject.getMavenOpts())) {
        mvnOptions = mavenModuleProject.getMavenOpts();
    }
    // Private Repository and Alternate Settings
    LocalRepositoryLocator locaRepositoryToUse = usesLocalRepository ? new PerJobLocalRepositoryLocator() : new DefaultLocalRepositoryLocator();
    SettingsProvider settingsToUse = settings;
    GlobalSettingsProvider globalSettingsToUse = globalSettings;
    if (mavenModuleProject != null) {
        // If we are on a Maven job then take values from the job itself
        locaRepositoryToUse = mavenModuleProject.getLocalRepository();
        settingsToUse = mavenModuleProject.getSettings();
        globalSettingsToUse = mavenModuleProject.getGlobalSettings();
    }
    // Other properties
    String additionalArguments = sonarInstallation.getAdditionalProperties();
    String analysisProperties = StringUtils.join(sonarInstallation.getAdditionalAnalysisPropertiesUnix(), ' ');
    String jobProperties = envVars.expand(sonarPublisher.getJobAdditionalProperties());
    String additionalProperties = "" + (StringUtils.isNotBlank(additionalArguments) ? additionalArguments : "") + " " + (StringUtils.isNotBlank(analysisProperties) ? analysisProperties : "") + " " + (StringUtils.isNotBlank(jobProperties) ? jobProperties : "");
    // Execute Maven
    // SONARPLUGINS-487
    String pomPath = build.getModuleRoot().child(pom).getRemote();
    return new SonarMaven(additionalProperties, mavenName, pomPath, mvnOptions, locaRepositoryToUse, sonarPublisher, listener, jdk, settingsToUse, globalSettingsToUse).perform(build, launcher, listener);
}
Also used : SettingsProvider(jenkins.mvn.SettingsProvider) GlobalSettingsProvider(jenkins.mvn.GlobalSettingsProvider) EnvVars(hudson.EnvVars) PerJobLocalRepositoryLocator(hudson.maven.local_repo.PerJobLocalRepositoryLocator) DefaultLocalRepositoryLocator(hudson.maven.local_repo.DefaultLocalRepositoryLocator) LocalRepositoryLocator(hudson.maven.local_repo.LocalRepositoryLocator) PerJobLocalRepositoryLocator(hudson.maven.local_repo.PerJobLocalRepositoryLocator) MavenModuleSet(hudson.maven.MavenModuleSet) DefaultLocalRepositoryLocator(hudson.maven.local_repo.DefaultLocalRepositoryLocator) GlobalSettingsProvider(jenkins.mvn.GlobalSettingsProvider)

Aggregations

DefaultLocalRepositoryLocator (hudson.maven.local_repo.DefaultLocalRepositoryLocator)2 EnvVars (hudson.EnvVars)1 Launcher (hudson.Launcher)1 MavenModuleSet (hudson.maven.MavenModuleSet)1 LocalRepositoryLocator (hudson.maven.local_repo.LocalRepositoryLocator)1 PerJobLocalRepositoryLocator (hudson.maven.local_repo.PerJobLocalRepositoryLocator)1 AbstractBuild (hudson.model.AbstractBuild)1 BuildListener (hudson.model.BuildListener)1 SonarInstallation (hudson.plugins.sonar.SonarInstallation)1 SonarPublisher (hudson.plugins.sonar.SonarPublisher)1 ArgumentListBuilder (hudson.util.ArgumentListBuilder)1 GlobalSettingsProvider (jenkins.mvn.GlobalSettingsProvider)1 SettingsProvider (jenkins.mvn.SettingsProvider)1 Test (org.junit.Test)1