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);
}
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");
}
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);
}
}
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;
}
}
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);
}
Aggregations