aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-01 14:59:58 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-08-30 17:38:19 +0200
commitecc4bd7d1f79eaf255a91cc29d825193cfded8e0 (patch)
treea170f48be977bfa52a4557db83667ad9d5542206
parentef892610fe2888078e33b5fd95d9220bd62e3c03 (diff)
downloadsonarqube-ecc4bd7d1f79eaf255a91cc29d825193cfded8e0.tar.gz
sonarqube-ecc4bd7d1f79eaf255a91cc29d825193cfded8e0.zip
SONAR-7722 The project name should not be mandatory
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties1
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo16
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo.measures2
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties1
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo20
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo.measures2
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties4
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo12
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo.measures2
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties1
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo12
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo.measures2
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties3
-rw-r--r--it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties11
-rw-r--r--it/it-tests/src/test/java/it/analysis/BatchTest.java92
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java30
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java7
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-projectName/sonar-project.properties5
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib1.txt1
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib2.txt1
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sonar-project.properties6
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sources/Fake.java1
28 files changed, 236 insertions, 27 deletions
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties
new file mode 100644
index 00000000000..a081a0e6342
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties
@@ -0,0 +1 @@
+sonar.projectName=Sub-module A1
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo
new file mode 100644
index 00000000000..74d29a4fa08
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo
@@ -0,0 +1,16 @@
+package com.sonar.it.samples.modules.a1;
+
+public class HelloA1 {
+ private int i;
+ private HelloA1() {
+
+ }
+
+ public void hello() {
+ System.out.println("hello" + " xoo");
+ }
+
+ protected String getHello() {
+ return "hello";
+ }
+} \ No newline at end of file
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo.measures b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo.measures
new file mode 100644
index 00000000000..7812e4167fb
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:12
+classes:1
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties
new file mode 100644
index 00000000000..fcedab83843
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties
@@ -0,0 +1 @@
+sonar.projectName=Sub-module A2
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo
new file mode 100644
index 00000000000..796d90cfad5
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo
@@ -0,0 +1,20 @@
+package com.sonar.it.samples.modules.a2;
+
+public class HelloA2 {
+
+ public HelloA2(int i) {
+ int j = i++;
+ }
+
+ public void hello() {
+ System.out.println("hello" + " xoo");
+ }
+
+ private String myMethod() {
+ if (foo == bar) {
+ return "hello";
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo.measures b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo.measures
new file mode 100644
index 00000000000..63df5add6d4
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:15
+classes:1
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties
new file mode 100644
index 00000000000..7e6ca9074a4
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties
@@ -0,0 +1,4 @@
+sonar.projectKey=module_a
+sonar.projectName=Module A
+
+sonar.modules=module_a1,module_a2
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo
new file mode 100644
index 00000000000..b83c3af128c
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo
@@ -0,0 +1,12 @@
+package com.sonar.it.samples.modules.b1;
+
+public class HelloB1 {
+ private int i;
+ private HelloB1() {
+
+ }
+
+ public void hello() {
+ System.out.println("hello" + " world");
+ }
+} \ No newline at end of file
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo.measures b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo.measures
new file mode 100644
index 00000000000..3947d3bdbff
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:12
+classes:1 \ No newline at end of file
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties
new file mode 100644
index 00000000000..e597dab4f33
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties
@@ -0,0 +1 @@
+sonar.projectName=Sub-module B2
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo
new file mode 100644
index 00000000000..20b8bb3876a
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo
@@ -0,0 +1,12 @@
+package com.sonar.it.samples.modules.b2;
+
+public class HelloB2 {
+ private int i;
+ private HelloB2() {
+
+ }
+
+ public void hello() {
+ System.out.println("hello" + " world");
+ }
+} \ No newline at end of file
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo.measures b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo.measures
new file mode 100644
index 00000000000..3947d3bdbff
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:12
+classes:1 \ No newline at end of file
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties
new file mode 100644
index 00000000000..7bc39b44133
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties
@@ -0,0 +1,3 @@
+sonar.projectKey=module_b
+
+sonar.modules=module_b1,module_b2
diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties
new file mode 100644
index 00000000000..9c22998b8da
--- /dev/null
+++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties
@@ -0,0 +1,11 @@
+# Root project information
+sonar.projectKey=com.sonarsource.it.samples:multi-modules-sample
+sonar.projectVersion=1.0-SNAPSHOT
+
+sonar.language=xoo
+
+# Some properties that will be inherited by the modules
+sonar.sources=src/main/xoo
+
+# List of the module identifiers
+sonar.modules=module_a,module_b
diff --git a/it/it-tests/src/test/java/it/analysis/BatchTest.java b/it/it-tests/src/test/java/it/analysis/BatchTest.java
index 06ce6e9c155..62c5a4b6ab8 100644
--- a/it/it-tests/src/test/java/it/analysis/BatchTest.java
+++ b/it/it-tests/src/test/java/it/analysis/BatchTest.java
@@ -41,6 +41,10 @@ import org.sonar.wsclient.services.PropertyDeleteQuery;
import org.sonar.wsclient.services.PropertyUpdateQuery;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
+import org.sonarqube.ws.WsComponents.ShowWsResponse;
+import org.sonarqube.ws.client.component.ShowWsRequest;
+import org.sonarqube.ws.client.measure.ComponentWsRequest;
+
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -171,7 +175,7 @@ public class BatchTest {
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.language", "foo",
"sonar.profile", "");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"You must install a plugin that supports the language 'foo'");
}
@@ -183,23 +187,65 @@ public class BatchTest {
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.profile", "unknow");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"sonar.profile was set to 'unknow' but didn't match any profile for any language. Please check your configuration.");
}
@Test
+ public void should_create_project_without_name() {
+ //some of the sub-modules have a name defined, others don't
+ BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name");
+ assertThat(buildResult.isSuccess()).isTrue();
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample");
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b", "module_b");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b1", "module_b1");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b2", "Sub-module B2");
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a", "Module A");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1", "Sub-module A1");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a2", "Sub-module A2");
+
+ }
+
+ @Test
+ public void should_analyze_project_without_name() {
+ orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "My project name");
+ BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name");
+ assertThat(buildResult.isSuccess()).isTrue();
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample", "My project name");
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b", "module_b");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b1", "module_b1");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b2", "Sub-module B2");
+
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a", "Module A");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1", "Sub-module A1");
+ assertProjectName("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a2", "Sub-module A2");
+ }
+
+ private void assertProjectName(String projectKey, String expectedProjectName) {
+ ShowWsRequest req = new ShowWsRequest();
+ req.setKey(projectKey);
+ ShowWsResponse response = ItUtils.newWsClient(orchestrator).components().show(req);
+ assertThat(response.getComponent().getName()).isEqualTo(expectedProjectName);
+ }
+
+ @Test
public void should_honor_sonarUserHome() {
File userHome = temp.getRoot();
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- SonarScanner runner = configureScanner("shared/xoo-sample",
+ SonarScanner scanner = configureScanner("shared/xoo-sample",
"sonar.verbose", "true");
- runner.setEnvironmentVariable("SONAR_USER_HOME", "/dev/null");
- BuildResult buildResult = orchestrator.executeBuildQuietly(runner);
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ scanner.setEnvironmentVariable("SONAR_USER_HOME", "/dev/null");
+ BuildResult buildResult = orchestrator.executeBuildQuietly(scanner);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
buildResult = scan("shared/xoo-sample",
"sonar.verbose", "true",
@@ -218,7 +264,7 @@ public class BatchTest {
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.login", "",
"sonar.password", "");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.");
@@ -226,14 +272,14 @@ public class BatchTest {
buildResult = scanQuietly("shared/xoo-sample",
"sonar.login", "wrong_login",
"sonar.password", "wrong_password");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"Not authorized. Please check the properties sonar.login and sonar.password.");
buildResult = scan("shared/xoo-sample",
"sonar.login", "admin",
"sonar.password", "admin");
- assertThat(buildResult.getStatus()).isEqualTo(0);
+ assertThat(buildResult.getLastStatus()).isEqualTo(0);
} finally {
orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "false"));
@@ -244,7 +290,7 @@ public class BatchTest {
* SONAR-4211 Test Sonar Runner when server requires authentication
*/
@Test
- public void sonar_runner_with_secured_server() {
+ public void sonar_scanner_with_secured_server() {
try {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
@@ -252,21 +298,21 @@ public class BatchTest {
orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true"));
BuildResult buildResult = scanQuietly("shared/xoo-sample");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.");
buildResult = scanQuietly("shared/xoo-sample",
"sonar.login", "wrong_login",
"sonar.password", "wrong_password");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains(
"Not authorized. Please check the properties sonar.login and sonar.password.");
buildResult = scan("shared/xoo-sample",
"sonar.login", "admin",
"sonar.password", "admin");
- assertThat(buildResult.getStatus()).isEqualTo(0);
+ assertThat(buildResult.getLastStatus()).isEqualTo(0);
} finally {
orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "false"));
@@ -345,20 +391,20 @@ public class BatchTest {
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.projectKey", "ar g$l:");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains("\"ar g$l:\" is not a valid project or module key")
.contains("Allowed characters");
// SONAR-4629
buildResult = scanQuietly("shared/xoo-sample",
"sonar.projectKey", "12345");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains("\"12345\" is not a valid project or module key")
.contains("Allowed characters");
buildResult = scanQuietly("shared/xoo-sample",
"sonar.branch", "ar g$l:");
- assertThat(buildResult.getStatus()).isEqualTo(1);
+ assertThat(buildResult.getLastStatus()).isEqualTo(1);
assertThat(buildResult.getLogs()).contains("\"ar g$l:\" is not a valid branch")
.contains("Allowed characters");
}
@@ -371,7 +417,7 @@ public class BatchTest {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
BuildResult result = scanQuietly("shared/xoo-sample", "raiseMessageException", "true");
- assertThat(result.getStatus()).isNotEqualTo(0);
+ assertThat(result.getLastStatus()).isNotEqualTo(0);
assertThat(result.getLogs())
// message
.contains("Error message from plugin")
@@ -422,7 +468,7 @@ public class BatchTest {
orchestrator.getServer().associateProjectToQualityProfile("projectAC", "xoo", "one-issue-per-line");
BuildResult result = scanQuietly("analysis/prevent-common-module/projectAC");
- assertThat(result.getStatus()).isNotEqualTo(0);
+ assertThat(result.getLastStatus()).isNotEqualTo(0);
assertThat(result.getLogs()).contains("Module \"com.sonarsource.it.samples:moduleA\" is already part of project \"projectAB\"");
}
@@ -455,7 +501,7 @@ public class BatchTest {
analysis.setProperty("sonar.projectDate", "2000-10-19");
BuildResult result = orchestrator.executeBuildQuietly(analysis);
- assertThat(result.getStatus()).isNotEqualTo(0);
+ assertThat(result.getLastStatus()).isNotEqualTo(0);
assertThat(result.getLogs()).contains("'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '2000-10-19'. " +
"Latest quality snapshot: ");
assertThat(result.getLogs()).contains("This property may only be used to rebuild the past in a chronological order.");
@@ -466,13 +512,13 @@ public class BatchTest {
}
private BuildResult scan(String projectPath, String... props) {
- SonarScanner runner = configureScanner(projectPath, props);
- return orchestrator.executeBuild(runner);
+ SonarScanner scanner = configureScanner(projectPath, props);
+ return orchestrator.executeBuild(scanner);
}
private BuildResult scanQuietly(String projectPath, String... props) {
- SonarScanner runner = configureScanner(projectPath, props);
- return orchestrator.executeBuildQuietly(runner);
+ SonarScanner scanner = configureScanner(projectPath, props);
+ return orchestrator.executeBuildQuietly(scanner);
}
private SonarScanner configureScanner(String projectPath, String... props) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
index 4c08735f062..33c23cd3f7e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
@@ -190,6 +190,11 @@ public class ProjectDefinition {
public String getVersion() {
return properties.get(CoreProperties.PROJECT_VERSION_PROPERTY);
}
+
+ @CheckForNull
+ public String getOriginalName() {
+ return properties.get(CoreProperties.PROJECT_NAME_PROPERTY);
+ }
public String getName() {
String name = properties.get(CoreProperties.PROJECT_NAME_PROPERTY);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
index a4d68e49f84..31b7bcdf639 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
@@ -59,6 +59,7 @@ public class Project extends Resource implements Component {
private Date analysisDate;
private String analysisVersion;
private Settings settings;
+ private String originalName;
// For internal use
private java.io.File baseDir;
@@ -76,9 +77,11 @@ public class Project extends Resource implements Component {
if (StringUtils.isNotBlank(branch)) {
setKey(String.format(BRANCH_KEY_FORMAT, key, branch));
this.name = String.format("%s %s", name, branch);
+ this.originalName = String.format("%s %s", name, branch);
} else {
setKey(key);
this.name = name;
+ this.originalName = name;
}
setEffectiveKey(getKey());
this.branch = branch;
@@ -95,6 +98,15 @@ public class Project extends Resource implements Component {
this.branch = branch;
return this;
}
+
+ @CheckForNull
+ public String getOriginalName() {
+ return originalName;
+ }
+
+ public void setOriginalName(String originalName) {
+ this.originalName = originalName;
+ }
@Override
public String getName() {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java
index 64e9e242963..16ef6131a23 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java
@@ -47,6 +47,7 @@ public class ProjectConfigurator {
public Project create(ProjectDefinition definition) {
Project project = new Project(definition.getKey(), definition.getBranch(), definition.getName());
project.setDescription(StringUtils.defaultString(definition.getDescription()));
+ project.setOriginalName(definition.getOriginalName());
return project;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
index 2631c37d452..77f36cc7bd7 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
@@ -25,6 +25,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.scanner.index.BatchComponent;
@@ -149,6 +150,10 @@ public class ComponentsPublisher implements ReportPublisherStep {
@CheckForNull
private static String getName(Resource r) {
+ if (ResourceUtils.isProject(r)) {
+ Project project = (Project) r;
+ return project.getOriginalName();
+ }
// Don't return name for directories and files since it can be guessed from the path
return (ResourceUtils.isFile(r) || ResourceUtils.isDirectory(r)) ? null : r.getName();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
index e184fd36292..5c291d30dd2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
@@ -167,7 +167,7 @@ public class ReportPublisher implements Startable {
PostRequest post = new PostRequest("api/ce/submit")
.setMediaType(MediaTypes.PROTOBUF)
.setParam("projectKey", projectDefinition.getKey())
- .setParam("projectName", projectDefinition.getName())
+ .setParam("projectName", projectDefinition.getOriginalName())
.setParam("projectBranch", projectDefinition.getBranch())
.setPart("report", filePart);
WsResponse response = wsClient.call(post).failIfNotSuccessful();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
index 053e735ad01..19bd48ad076 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
@@ -89,7 +89,7 @@ public class ProjectReactorBuilder {
* Array of all mandatory properties required for a project without child.
*/
private static final String[] MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT = {
- PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY,
+ PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY,
CoreProperties.PROJECT_VERSION_PROPERTY, PROPERTY_SOURCES
};
@@ -97,12 +97,12 @@ public class ProjectReactorBuilder {
* Array of all mandatory properties required for a project with children.
*/
private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY,
- CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY};
+ CoreProperties.PROJECT_VERSION_PROPERTY};
/**
* Array of all mandatory properties required for a child project before its properties get merged with its parent ones.
*/
- private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {MODULE_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY};
+ private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {MODULE_KEY_PROPERTY};
/**
* Properties that must not be passed from the parent project to its children.
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
index ae9795a9538..29052149ea8 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
@@ -78,6 +78,36 @@ public class FileSystemMediumTest {
}
@Test
+ public void scanProjectWithoutProjectName() throws IOException {
+ builder = ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project");
+
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ FileUtils.write(xooFile, "Sample xoo\ncontent");
+
+ TaskResult result = tester.newTask()
+ .properties(builder
+ .put("sonar.sources", "src")
+ .build())
+ .start();
+
+ int ref = result.getReportReader().readMetadata().getRootComponentRef();
+ assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
+ assertThat(result.inputFiles()).hasSize(1);
+ assertThat(result.inputDirs()).hasSize(1);
+ assertThat(result.inputFile("src/sample.xoo").type()).isEqualTo(InputFile.Type.MAIN);
+ assertThat(result.inputFile("src/sample.xoo").relativePath()).isEqualTo("src/sample.xoo");
+ assertThat(result.inputDir("src").relativePath()).isEqualTo("src");
+ }
+
+ @Test
public void scanProjectWithSourceDir() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
index f87dc5db8db..84ad528f2df 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
@@ -461,6 +461,13 @@ public class ProjectReactorBuilderTest {
}
@Test
+ public void shouldAcceptNoProjectName() {
+ ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-missing-project-name");
+ assertThat(rootProject.getOriginalName()).isNull();
+ assertThat(rootProject.getName()).isEqualTo("Unnamed - com.foo.project");
+ }
+
+ @Test
public void shouldSetModuleKeyIfNotPresent() {
Map<String, String> props = new HashMap<>();
props.put("sonar.projectVersion", "1.0");
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-projectName/sonar-project.properties b/sonar-scanner-engine/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-projectName/sonar-project.properties
new file mode 100644
index 00000000000..fdfffa678aa
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-projectName/sonar-project.properties
@@ -0,0 +1,5 @@
+sonar.projectKey=com.foo.project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+sonar.sources=.
+
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib1.txt b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib1.txt
new file mode 100644
index 00000000000..81d4e95a0b6
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib1.txt
@@ -0,0 +1 @@
+lib1 \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib2.txt b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib2.txt
new file mode 100644
index 00000000000..7dacac0fd9a
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib2.txt
@@ -0,0 +1 @@
+lib2 \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sonar-project.properties b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sonar-project.properties
new file mode 100644
index 00000000000..656f16bf275
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sonar-project.properties
@@ -0,0 +1,6 @@
+sonar.projectKey=com.foo.project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.libraries=libs/*.txt
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sources/Fake.java b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sources/Fake.java
new file mode 100644
index 00000000000..e67004defc5
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sources/Fake.java
@@ -0,0 +1 @@
+class Fake {}