Search in sources :

Example 1 with PerJobLocalRepositoryLocator

use of hudson.maven.local_repo.PerJobLocalRepositoryLocator 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)

Example 2 with PerJobLocalRepositoryLocator

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

the class SonarMaven method wrapUpArguments.

@Override
protected void wrapUpArguments(ArgumentListBuilder args, String normalizedTarget, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
    args.addTokenized(additionalProperties);
    ExtendedArgumentListBuilder argsBuilder = new ExtendedArgumentListBuilder(args, launcher.isUnix());
    argsBuilder.append("sonar.host.url", getInstallation().getServerUrl());
    argsBuilder.append("sonar.branch", publisher.getBranch());
    if (StringUtils.isNotBlank(getInstallation().getServerAuthenticationToken())) {
        argsBuilder.appendMasked("sonar.login", getInstallation().getServerAuthenticationToken());
    }
    if (build instanceof MavenModuleSetBuild) {
        FilePath localRepo = locaRepository.locate((MavenModuleSetBuild) build);
        if (localRepo != null) {
            args.add("-Dmaven.repo.local=" + localRepo.getRemote());
        }
    } else if (locaRepository instanceof PerJobLocalRepositoryLocator) {
        FilePath workspace = build.getWorkspace();
        if (workspace != null) {
            args.add("-Dmaven.repo.local=" + workspace.child(".repository"));
        }
    }
}
Also used : MavenModuleSetBuild(hudson.maven.MavenModuleSetBuild) FilePath(hudson.FilePath) PerJobLocalRepositoryLocator(hudson.maven.local_repo.PerJobLocalRepositoryLocator)

Example 3 with PerJobLocalRepositoryLocator

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

the class BaseTest method testMavenProject.

/**
 * Maven Project.
 * <ul>
 * <li>SONARPLUGINS-19: Maven "-B" option (batch mode)</li>
 * <li>SONARPLUGINS-73: Root POM</li>
 * <li>SONARPLUGINS-101: Private Repository</li>
 * <li>SONARPLUGINS-253: Maven "-e" option</li>
 * <li>SONARPLUGINS-263: Path to POM with spaces</li>
 * <li>SONARPLUGINS-326: Use alternate settings file</li>
 * </ul>
 *
 * @throws Exception if something is wrong
 */
@Test
public void testMavenProject() throws Exception {
    configureDefaultMaven();
    configureDefaultSonar();
    String pomName = "space test/root-pom.xml";
    MavenModuleSet project = setupSonarMavenProject(pomName);
    project.setAlternateSettings("/settings.xml");
    project.setLocalRepository(new PerJobLocalRepositoryLocator());
    Run<?, ?> build = build(project);
}
Also used : PerJobLocalRepositoryLocator(hudson.maven.local_repo.PerJobLocalRepositoryLocator) MavenModuleSet(hudson.maven.MavenModuleSet) Test(org.junit.Test)

Aggregations

PerJobLocalRepositoryLocator (hudson.maven.local_repo.PerJobLocalRepositoryLocator)3 MavenModuleSet (hudson.maven.MavenModuleSet)2 EnvVars (hudson.EnvVars)1 FilePath (hudson.FilePath)1 MavenModuleSetBuild (hudson.maven.MavenModuleSetBuild)1 DefaultLocalRepositoryLocator (hudson.maven.local_repo.DefaultLocalRepositoryLocator)1 LocalRepositoryLocator (hudson.maven.local_repo.LocalRepositoryLocator)1 GlobalSettingsProvider (jenkins.mvn.GlobalSettingsProvider)1 SettingsProvider (jenkins.mvn.SettingsProvider)1 Test (org.junit.Test)1