Search in sources :

Example 11 with MavenModuleSet

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

the class SonarPublisherSQServerSlicerTest method availableMavenProjectsWithSonarPublisher.

@Test
public void availableMavenProjectsWithSonarPublisher() throws IOException {
    final MavenModuleSet project = j.jenkins.createProject(MavenModuleSet.class, "random-name");
    assertThat(new SonarPublisherSQServerSlicer().getWorkDomain().size()).isZero();
    project.getPublishersList().add(new SonarPublisher("MySonar", null, null, null, null, null, null, null, null, null, false));
    assertThat(new SonarPublisherSQServerSlicer().getWorkDomain().size()).isEqualTo(1);
}
Also used : SonarPublisher(hudson.plugins.sonar.SonarPublisher) MavenModuleSet(hudson.maven.MavenModuleSet) Test(org.junit.Test)

Example 12 with MavenModuleSet

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

the class SonarPublisherSQServerSlicerTest method changeJobAdditionalProperties.

@Test
public void changeJobAdditionalProperties() throws Exception {
    final MavenModuleSet project = j.jenkins.createProject(MavenModuleSet.class, "random-name");
    final SonarPublisher mySonar = new SonarPublisher("MySonar", null, null, null, null, null, null, null, null, null, false);
    project.getPublishersList().add(mySonar);
    final SonarPublisherSQServerSlicer.SonarPublisherSQInstallSlicerSpec spec = new SonarPublisherSQServerSlicer.SonarPublisherSQInstallSlicerSpec();
    final List<String> values = spec.getValues(project);
    assertThat(values.get(0)).isEqualTo("MySonar");
    final List<String> newValues = new ArrayList<String>();
    newValues.add("MySonar 2");
    spec.setValues(project, newValues);
    assertThat(mySonar.getInstallationName()).isEqualTo("MySonar 2");
}
Also used : SonarPublisher(hudson.plugins.sonar.SonarPublisher) ArrayList(java.util.ArrayList) MavenModuleSet(hudson.maven.MavenModuleSet) Test(org.junit.Test)

Example 13 with MavenModuleSet

use of hudson.maven.MavenModuleSet in project evosuite by EvoSuite.

the class ProjectAction method perform.

public void perform(AbstractMavenProject<?, ?> project, AbstractBuild<?, ?> build, BuildListener listener) throws InterruptedException, IOException {
    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());
    VirtualChannel channel = build.getWorkspace().getChannel();
    MavenModuleSet prj = (MavenModuleSet) this.project;
    for (MavenModule module : prj.getModules()) {
        FilePath fp = new FilePath(channel, build.getWorkspace().getRemote() + File.separator + (module.getRelativePath().isEmpty() ? "" : module.getRelativePath() + File.separator) + Properties.CTG_DIR + File.separator + Properties.CTG_PROJECT_INFO);
        if (!fp.exists()) {
            listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "There is not any " + fp.getRemote() + " file for module " + module.getName());
            continue;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        fp.copyTo(out);
        ByteArrayInputStream projectXML = new ByteArrayInputStream(out.toByteArray());
        listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Analysing " + Properties.CTG_PROJECT_INFO + " file from " + fp.getRemote());
        ModuleAction m = new ModuleAction(build, module.getName());
        if (!m.build(channel, projectXML, listener)) {
            continue;
        }
        this.modules.add(m);
    }
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) VirtualChannel(hudson.remoting.VirtualChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) MavenModule(hudson.maven.MavenModule) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MavenModuleSet(hudson.maven.MavenModuleSet)

Example 14 with MavenModuleSet

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

the class SonarPublisher method executeSonar.

private boolean executeSonar(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, SonarInstallation sonarInstallation) {
    try {
        String pomName = getPomName(build, listener);
        String mavenInstallName = getMavenInstallationName();
        if (isMavenBuilder(build.getProject())) {
            MavenModuleSet mavenModuleSet = getMavenProject(build);
            if (null != mavenModuleSet.getMaven().getName()) {
                mavenInstallName = mavenModuleSet.getMaven().getName();
            }
        }
        // Execute maven
        return SonarMaven.executeMaven(build, launcher, listener, mavenInstallName, pomName, sonarInstallation, this, getJDK(), getSettings(), getGlobalSettings(), usesPrivateRepository());
    } catch (IOException e) {
        Logger.printFailureMessage(listener);
        Util.displayIOException(e, listener);
        Logger.LOG.throwing(this.getClass().getName(), "setValues", e);
        e.printStackTrace(listener.fatalError("command execution failed"));
        return false;
    } catch (InterruptedException e) {
        Logger.LOG.throwing(this.getClass().getName(), "executeSonar", e);
        return false;
    } catch (Exception e) {
        Logger.printFailureMessage(listener);
        e.printStackTrace(listener.fatalError("command execution failed"));
        Logger.LOG.throwing(this.getClass().getName(), "executeSonar", e);
        return false;
    }
}
Also used : IOException(java.io.IOException) MavenModuleSet(hudson.maven.MavenModuleSet) IOException(java.io.IOException)

Example 15 with MavenModuleSet

use of hudson.maven.MavenModuleSet 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

MavenModuleSet (hudson.maven.MavenModuleSet)17 Test (org.junit.Test)10 SonarPublisher (hudson.plugins.sonar.SonarPublisher)8 EnvVars (hudson.EnvVars)4 ArrayList (java.util.ArrayList)4 MavenModule (hudson.maven.MavenModule)3 IOException (java.io.IOException)3 FilePath (hudson.FilePath)2 PerJobLocalRepositoryLocator (hudson.maven.local_repo.PerJobLocalRepositoryLocator)2 ImmutableList (com.google.common.collect.ImmutableList)1 DefaultLocalRepositoryLocator (hudson.maven.local_repo.DefaultLocalRepositoryLocator)1 LocalRepositoryLocator (hudson.maven.local_repo.LocalRepositoryLocator)1 VirtualChannel (hudson.remoting.VirtualChannel)1 ArgumentListBuilder (hudson.util.ArgumentListBuilder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 List (java.util.List)1 GlobalSettingsProvider (jenkins.mvn.GlobalSettingsProvider)1 SettingsProvider (jenkins.mvn.SettingsProvider)1