]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7722 The project name should not be mandatory
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 1 Jul 2016 12:59:58 +0000 (14:59 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 30 Aug 2016 15:38:19 +0000 (17:38 +0200)
28 files changed:
it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties [new file with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties [new file with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties [new file with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties [new file with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties [new file with mode: 0644]
it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties [new file with mode: 0644]
it/it-tests/src/test/java/it/analysis/BatchTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectConfigurator.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
sonar-scanner-engine/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-projectName/sonar-project.properties [new file with mode: 0644]
sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib1.txt [new file with mode: 0644]
sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/libs/lib2.txt [new file with mode: 0644]
sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sonar-project.properties [new file with mode: 0644]
sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/simple-project-with-missing-project-name/sources/Fake.java [new file with mode: 0644]

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 (file)
index 0000000..a081a0e
--- /dev/null
@@ -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 (file)
index 0000000..74d29a4
--- /dev/null
@@ -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 (file)
index 0000000..7812e41
--- /dev/null
@@ -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 (file)
index 0000000..fcedab8
--- /dev/null
@@ -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 (file)
index 0000000..796d90c
--- /dev/null
@@ -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 (file)
index 0000000..63df5ad
--- /dev/null
@@ -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 (file)
index 0000000..7e6ca90
--- /dev/null
@@ -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 (file)
index 0000000..b83c3af
--- /dev/null
@@ -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 (file)
index 0000000..3947d3b
--- /dev/null
@@ -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 (file)
index 0000000..e597dab
--- /dev/null
@@ -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 (file)
index 0000000..20b8bb3
--- /dev/null
@@ -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 (file)
index 0000000..3947d3b
--- /dev/null
@@ -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 (file)
index 0000000..7bc39b4
--- /dev/null
@@ -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 (file)
index 0000000..9c22998
--- /dev/null
@@ -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
index 06ce6e9c15576a7166bba30f4b48f03fd3850e2f..62c5a4b6ab88c94becd505a49fbda4572e9ba2ef 100644 (file)
@@ -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,11 +187,53 @@ 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();
@@ -195,11 +241,11 @@ public class BatchTest {
     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) {
index 4c08735f06278f4a60502af239fa81ee6ab34461..33c23cd3f7e5019436bf9e56c9a9381119eb4c3b 100644 (file)
@@ -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);
index a4d68e49f848c08c843633d0d9efe3f3a4ed82af..31b7bcdf639dd3eaf12e7abf1efa0c24ba21ce86 100644 (file)
@@ -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() {
index 64e9e24296337b4ab4958a78ebc81a8dccca4b4c..16ef6131a231c4adfe0e194bdfb11f021e823730 100644 (file)
@@ -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;
   }
 
index 2631c37d452d67815d9dcf67c0fc1672644f799f..77f36cc7bd79ff70e4ef44a9dd0a6d1c893bfe0d 100644 (file)
@@ -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();
   }
index e184fd3629279709e92c98471330de9340618170..5c291d30dd2efbddd2e77bbf82c46899265c2018 100644 (file)
@@ -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();
index 053e735ad0121f74d7df3659f5a6233760eeb5f9..19bd48ad076b7337dcdd87b71290bca43ba3708f 100644 (file)
@@ -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.
index ae9795a95384fb7e3f1573d5c4efda7d01548d99..29052149ea86c065c08faaa3839255e61645c11d 100644 (file)
@@ -77,6 +77,36 @@ public class FileSystemMediumTest {
     tester.stop();
   }
 
+  @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");
index f87dc5db8db0164113a6522c072e79918ac30e32..84ad528f2df21b0943fb64b39696ac529c098091 100644 (file)
@@ -460,6 +460,13 @@ public class ProjectReactorBuilderTest {
     ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);
   }
 
+  @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<>();
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 (file)
index 0000000..fdfffa6
--- /dev/null
@@ -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 (file)
index 0000000..81d4e95
--- /dev/null
@@ -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 (file)
index 0000000..7dacac0
--- /dev/null
@@ -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 (file)
index 0000000..656f16b
--- /dev/null
@@ -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 (file)
index 0000000..e67004d
--- /dev/null
@@ -0,0 +1 @@
+class Fake {}