Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6250 Fix use of sonar.branch on dotnet projects
- Loading branch information
Showing
5 changed files
with
226 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/extensions/XooProjectBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.xoo.extensions; | ||
|
||
import org.sonar.api.batch.bootstrap.ProjectBuilder; | ||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | ||
import org.sonar.api.config.Settings; | ||
|
||
import java.io.File; | ||
|
||
public class XooProjectBuilder extends ProjectBuilder { | ||
|
||
private Settings settings; | ||
|
||
public XooProjectBuilder(Settings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
public void build(Context context) { | ||
if (!settings.getBoolean("sonar.xoo.enableProjectBuilder")) { | ||
return; | ||
} | ||
ProjectDefinition root = context.projectReactor().getRoot(); | ||
|
||
ProjectDefinition module = ProjectDefinition.create() | ||
.setKey(root.getKey() + ":module1") | ||
.setName("Module 1"); | ||
|
||
module.setBaseDir(new File(root.getBaseDir(), "module1")); | ||
module.setWorkDir(new File(root.getWorkDir(), "module1")); | ||
|
||
module.setSources("src"); | ||
|
||
root.addSubProject(module); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.batch.mediumtest.fs; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.sonar.api.CoreProperties; | ||
import org.sonar.batch.mediumtest.BatchMediumTester; | ||
import org.sonar.batch.mediumtest.TaskResult; | ||
import org.sonar.batch.protocol.input.ActiveRule; | ||
import org.sonar.xoo.XooPlugin; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Date; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ProjectBuilderMediumTest { | ||
|
||
@org.junit.Rule | ||
public TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
public BatchMediumTester tester = BatchMediumTester.builder() | ||
.registerPlugin("xoo", new XooPlugin()) | ||
.addDefaultQProfile("xoo", "Sonar Way") | ||
.bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW)) | ||
.setPreviousAnalysisDate(new Date()) | ||
.activateRule(new ActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")) | ||
.build(); | ||
|
||
@Before | ||
public void prepare() { | ||
tester.start(); | ||
} | ||
|
||
@After | ||
public void stop() { | ||
tester.stop(); | ||
} | ||
|
||
@Test | ||
public void testProjectBuilder() throws IOException { | ||
|
||
File baseDir = temp.newFolder(); | ||
File module1Dir = new File(baseDir, "module1"); | ||
module1Dir.mkdir(); | ||
|
||
File srcDir = new File(module1Dir, "src"); | ||
srcDir.mkdir(); | ||
|
||
File xooFile = new File(srcDir, "sample.xoo"); | ||
FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); | ||
|
||
TaskResult result = tester.newTask() | ||
.properties(ImmutableMap.<String, String>builder() | ||
.put("sonar.task", "scan") | ||
.put("sonar.projectBaseDir", baseDir.getAbsolutePath()) | ||
.put("sonar.projectKey", "com.foo.project") | ||
.put("sonar.projectName", "Foo Project") | ||
.put("sonar.projectVersion", "1.0-SNAPSHOT") | ||
.put("sonar.projectDescription", "Description of Foo Project") | ||
.put("sonar.sources", ".") | ||
.put("sonar.xoo.enableProjectBuilder", "true") | ||
.build()) | ||
.start(); | ||
|
||
assertThat(result.issues()).hasSize(10); | ||
|
||
boolean foundIssueAtLine1 = false; | ||
for (org.sonar.api.issue.Issue issue : result.issues()) { | ||
if (issue.line() == 1) { | ||
foundIssueAtLine1 = true; | ||
assertThat(issue.componentKey()).isEqualTo("com.foo.project:module1:src/sample.xoo"); | ||
assertThat(issue.message()).isEqualTo("This issue is generated on each line"); | ||
assertThat(issue.effortToFix()).isNull(); | ||
} | ||
} | ||
assertThat(foundIssueAtLine1).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testProjectBuilderWithBranch() throws IOException { | ||
|
||
File baseDir = temp.newFolder(); | ||
File module1Dir = new File(baseDir, "module1"); | ||
module1Dir.mkdir(); | ||
|
||
File srcDir = new File(module1Dir, "src"); | ||
srcDir.mkdir(); | ||
|
||
File xooFile = new File(srcDir, "sample.xoo"); | ||
FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); | ||
|
||
TaskResult result = tester.newTask() | ||
.properties(ImmutableMap.<String, String>builder() | ||
.put("sonar.task", "scan") | ||
.put("sonar.projectBaseDir", baseDir.getAbsolutePath()) | ||
.put("sonar.projectKey", "com.foo.project") | ||
.put("sonar.projectName", "Foo Project") | ||
.put("sonar.projectVersion", "1.0-SNAPSHOT") | ||
.put("sonar.projectDescription", "Description of Foo Project") | ||
.put("sonar.branch", "my-branch") | ||
.put("sonar.sources", ".") | ||
.put("sonar.xoo.enableProjectBuilder", "true") | ||
.build()) | ||
.start(); | ||
|
||
assertThat(result.issues()).hasSize(10); | ||
|
||
boolean foundIssueAtLine1 = false; | ||
for (org.sonar.api.issue.Issue issue : result.issues()) { | ||
if (issue.line() == 1) { | ||
foundIssueAtLine1 = true; | ||
assertThat(issue.componentKey()).isEqualTo("com.foo.project:module1:my-branch:src/sample.xoo"); | ||
assertThat(issue.message()).isEqualTo("This issue is generated on each line"); | ||
assertThat(issue.effortToFix()).isNull(); | ||
} | ||
} | ||
assertThat(foundIssueAtLine1).isTrue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters