diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-13 15:36:49 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-16 17:26:06 +0100 |
commit | 1309845e856c33c5ca18c7295764993564a2a9c2 (patch) | |
tree | 8b25a6710e31343b23b432340f6cfda236fb2717 | |
parent | a7fbd0596d337b2aa2a2540355866efbbc3a17ad (diff) | |
download | sonarqube-1309845e856c33c5ca18c7295764993564a2a9c2.tar.gz sonarqube-1309845e856c33c5ca18c7295764993564a2a9c2.zip |
SONAR-6976 Branch should not allow \n character
5 files changed, 54 insertions, 34 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 4aed42870d6..13e7d8d25e7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -48,15 +48,11 @@ public class ProjectConfigurator { } public Project create(ProjectDefinition definition) { - Project project = new Project(definition.getKey(), loadProjectBranch(), definition.getName()); + Project project = new Project(definition.getKey(), definition.getBranch(), definition.getName()); project.setDescription(StringUtils.defaultString(definition.getDescription())); return project; } - private String loadProjectBranch() { - return settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY); - } - public ProjectConfigurator configure(Project project) { Date analysisDate = loadAnalysisDate(); project diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java index e9fbe316420..6aa753723b8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java @@ -29,7 +29,6 @@ import java.util.List; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; @@ -51,7 +50,7 @@ public class ProjectReactorValidator { } public void validate(ProjectReactor reactor) { - String branch = settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY); + String branch = reactor.getRoot().getBranch(); List<String> validationMessages = new ArrayList<>(); checkDeprecatedProperties(validationMessages); diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java index 119aa973416..ed7a35a4836 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java @@ -20,14 +20,12 @@ package org.sonar.batch.mediumtest.fs; import com.google.common.collect.ImmutableMap; -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.List; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.batch.mediumtest.BatchMediumTester; import org.sonar.batch.mediumtest.TaskResult; @@ -35,12 +33,20 @@ import org.sonar.batch.protocol.output.BatchReport.Issue; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; public class ProjectBuilderMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); + + @Rule + public ExpectedException exception = ExpectedException.none(); public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) @@ -62,17 +68,8 @@ public class ProjectBuilderMediumTest { @Test public void testProjectBuilder() throws IOException { - - File baseDir = temp.getRoot(); - 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"); - + File baseDir = prepareProject(); + TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "scan") @@ -99,19 +96,32 @@ public class ProjectBuilderMediumTest { assertThat(foundIssueAtLine1).isTrue(); } + + @Test + // SONAR-6976 + public void testProjectBuilderWithNewLine() throws IOException { + File baseDir = prepareProject(); + + exception.expect(IllegalStateException.class); + exception.expectMessage("is not a valid branch name"); + 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.branch", "branch\n") + .put("sonar.projectVersion", "1.0-SNAPSHOT") + .put("sonar.projectDescription", "Description of Foo Project") + .put("sonar.sources", ".") + .put("sonar.xoo.enableProjectBuilder", "true") + .build()) + .start(); + } @Test public void testProjectBuilderWithBranch() throws IOException { - - File baseDir = temp.getRoot(); - 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"); + File baseDir = prepareProject(); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -140,5 +150,19 @@ public class ProjectBuilderMediumTest { } assertThat(foundIssueAtLine1).isTrue(); } + + private File prepareProject() throws IOException { + File baseDir = temp.getRoot(); + 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"); + + return baseDir; + } } diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java index ff4dceaef4c..6789d45e61b 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java @@ -59,7 +59,7 @@ public class ComponentContainer implements ContainerPopulator.Container { try { return super.getComponent(componentKeyOrType, annotation); } catch (Throwable t) { - throw new IllegalStateException("Unable to load component " + componentKeyOrType, t); + throw new IllegalStateException("Unable to load component " + componentKeyOrType + ": " + t.getMessage(), t); } } diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java index b2eb18a9d4d..826649e0040 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java @@ -77,6 +77,7 @@ public class ComponentKeysTest { assertThat(ComponentKeys.isValidBranch("ab_12")).isTrue(); assertThat(ComponentKeys.isValidBranch("ab/12")).isTrue(); assertThat(ComponentKeys.isValidBranch("ab\\12")).isFalse(); + assertThat(ComponentKeys.isValidBranch("ab\n")).isFalse(); } } |