From: Duarte Meneses Date: Tue, 30 Aug 2016 12:42:49 +0000 (+0200) Subject: SONAR-7258 The project version should be optional X-Git-Tag: 6.1-RC1~253 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1195%2Fhead;p=sonarqube.git SONAR-7258 The project version should be optional --- diff --git a/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/module_a/module_a1/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/module_a/module_a2/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/module_a/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/module_b/module_b2/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/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-version/module_b/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/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-version/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-version/sonar-project.properties b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/sonar-project.properties new file mode 100644 index 00000000000..074304998f5 --- /dev/null +++ b/it/it-projects/shared/xoo-multi-module-sample-without-project-name-version/sonar-project.properties @@ -0,0 +1,10 @@ +# Root project information +sonar.projectKey=com.sonarsource.it.samples:multi-modules-sample + +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-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 deleted file mode 100644 index a081a0e6342..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a1/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 74d29a4fa08..00000000000 --- 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 +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 7812e4167fb..00000000000 --- 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 +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index fcedab83843..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/module_a2/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 796d90cfad5..00000000000 --- 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 +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 63df5add6d4..00000000000 --- 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 +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 7e6ca9074a4..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_a/sonar-project.properties +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index b83c3af128c..00000000000 --- 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 +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 3947d3bdbff..00000000000 --- 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 +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index e597dab4f33..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/module_b2/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 20b8bb3876a..00000000000 --- 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 +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 3947d3bdbff..00000000000 --- 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 +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 7bc39b44133..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/module_b/sonar-project.properties +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 9c22998b8da..00000000000 --- a/it/it-projects/shared/xoo-multi-module-sample-without-project-name/sonar-project.properties +++ /dev/null @@ -1,11 +0,0 @@ -# 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 62c5a4b6ab8..194c2b74f07 100644 --- a/it/it-tests/src/test/java/it/analysis/BatchTest.java +++ b/it/it-tests/src/test/java/it/analysis/BatchTest.java @@ -193,45 +193,50 @@ public class BatchTest { } @Test - public void should_create_project_without_name() { + public void should_create_project_without_name_version() { //some of the sub-modules have a name defined, others don't - BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name"); + BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name-version"); assertThat(buildResult.isSuccess()).isTrue(); - assertProjectName("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample", "not provided"); - 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"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b", "module_b", "not provided"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b1", "module_b1", "not provided"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b2", "Sub-module B2", "not provided"); - 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"); - + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a", "Module A", "not provided"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1", "Sub-module A1", "not provided"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a2", "Sub-module A2", "not provided"); } @Test - public void should_analyze_project_without_name() { + public void should_analyze_project_without_name_version() { orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "My project name"); - BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name"); + BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name-version", + "sonar.projectName", "My project name", + "sonar.projectVersion", "1.0"); + assertThat(buildResult.isSuccess()).isTrue(); + + buildResult = scan("shared/xoo-multi-module-sample-without-project-name-version"); assertThat(buildResult.isSuccess()).isTrue(); - assertProjectName("com.sonarsource.it.samples:multi-modules-sample", "My project name"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample", "My project name", "1.0"); - 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"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b", "module_b", "1.0"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b1", "module_b1", "1.0"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b2", "Sub-module B2", "1.0"); - 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"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a", "Module A", "1.0"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1", "Sub-module A1", "1.0"); + assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a2", "Sub-module A2", "1.0"); } - 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); + private void assertNameAndVersion(String projectKey, String expectedProjectName, String expectedProjectVersion) { + // new WS Client with api/components doesn't return the project version, so use the old one + Resource resource = orchestrator.getServer().getAdminWsClient().find(new ResourceQuery(projectKey)); + assertThat(resource.getName()).isEqualTo(expectedProjectName); + assertThat(resource.getVersion()).isEqualTo(expectedProjectVersion); + } @Test 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 33c23cd3f7e..95953da2422 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 @@ -186,9 +186,18 @@ public class ProjectDefinition { } return null; } + + @CheckForNull + public String getOriginalVersion() { + return properties.get(CoreProperties.PROJECT_VERSION_PROPERTY); + } public String getVersion() { - return properties.get(CoreProperties.PROJECT_VERSION_PROPERTY); + String version = properties.get(CoreProperties.PROJECT_VERSION_PROPERTY); + if (StringUtils.isBlank(version)) { + version = "not provided"; + } + return version; } @CheckForNull diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java index c3f2efde151..6fbf0bdfdc7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java @@ -68,7 +68,7 @@ public class ProjectBuilderTest { subProject.setBaseDir(baseDir); subProject.setWorkDir(new File(baseDir, "target/.sonar")); subProject.setKey("groupId:parentProjectId"); - subProject.setVersion(root.getVersion()); + subProject.setVersion(root.getOriginalVersion()); subProject.setName("Sub Project"); subProject.setSources("src"); root.addSubProject(subProject); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java index 2db3cef3a86..9cee607615c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java @@ -41,6 +41,14 @@ public class ProjectDefinitionTest { assertThat(def.getVersion()).isEqualTo("2.0-SNAPSHOT"); } + @Test + public void shouldSupportNoVersion() { + ProjectDefinition def = ProjectDefinition.create(); + def.setVersion(null); + assertThat(def.getVersion()).isEqualTo("not provided"); + assertThat(def.getOriginalVersion()).isEqualTo(""); + } + @Test public void shouldSetOptionalFields() { ProjectDefinition def = ProjectDefinition.create(); 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 77f36cc7bd7..1f5238b8a8d 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 @@ -109,13 +109,19 @@ public class ComponentsPublisher implements ReportPublisherStep { if (c.isProjectOrModule()) { ProjectDefinition def = reactor.getProjectDefinition(c.key()); String version = getVersion(def); - builder.setVersion(version); + if(version != null) { + builder.setVersion(version); + } } } private static String getVersion(ProjectDefinition def) { - String version = def.getVersion(); - return StringUtils.isNotBlank(version) ? version : getVersion(def.getParent()); + String version = def.getOriginalVersion(); + if(StringUtils.isNotBlank(version)) { + return version; + } + + return def.getParent() != null ? getVersion(def.getParent()) : null; } private void writeLinks(BatchComponent c, ScannerReport.Component.Builder builder) { 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 19bd48ad076..f3da9c37976 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,15 +89,13 @@ 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_VERSION_PROPERTY, PROPERTY_SOURCES + PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, PROPERTY_SOURCES }; /** * 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_VERSION_PROPERTY}; + private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY}; /** * Array of all mandatory properties required for a child project before its properties get merged with its parent ones. diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 7929b0ebe4f..0f6eb6dbdcc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -20,6 +20,8 @@ package org.sonar.scanner.report; import java.io.File; +import java.io.IOException; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -116,6 +118,73 @@ public class ComponentsPublisherTest { assertThat(module1Protobuf.getDescription()).isEqualTo("Module description"); assertThat(module1Protobuf.getVersion()).isEqualTo("1.0"); } + + @Test + public void add_components_without_version_and_name() throws IOException { + ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo"); + Project root = new Project("foo").setDescription("Root description") + .setAnalysisDate(DateUtils.parseDate(("2012-12-12"))); + root.setId(1).setUuid("PROJECT_UUID"); + resourceCache.add(root, null).setInputComponent(new DefaultInputModule("foo")); + + Project module1 = new Project("module1").setDescription("Module description"); + module1.setParent(root); + module1.setId(2).setUuid("MODULE_UUID"); + resourceCache.add(module1, root).setInputComponent(new DefaultInputModule("module1")); + rootDef.addSubProject(ProjectDefinition.create().setKey("module1")); + + Directory dir = Directory.create("src"); + dir.setEffectiveKey("module1:src"); + dir.setId(3).setUuid("DIR_UUID"); + resourceCache.add(dir, module1).setInputComponent(new DefaultInputDir("foo", "src")); + + org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", FakeJava.INSTANCE, false); + file.setEffectiveKey("module1:src/Foo.java"); + file.setId(4).setUuid("FILE_UUID"); + resourceCache.add(file, dir).setInputComponent(new DefaultInputFile("module1", "src/Foo.java").setLines(2)); + + org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false); + fileWithoutLang.setEffectiveKey("module1:src/make"); + fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID"); + resourceCache.add(fileWithoutLang, dir).setInputComponent(new DefaultInputFile("module1", "src/make").setLines(10)); + + org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", FakeJava.INSTANCE, true); + testFile.setEffectiveKey("module1:test/FooTest.java"); + testFile.setId(6).setUuid("TEST_FILE_UUID"); + resourceCache.add(testFile, dir).setInputComponent(new DefaultInputFile("module1", "test/FooTest.java").setLines(4)); + + ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef); + + ComponentsPublisher publisher = new ComponentsPublisher(reactor, resourceCache); + + File outputDir = temp.newFolder(); + ScannerReportWriter writer = new ScannerReportWriter(outputDir); + publisher.publish(writer); + + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue(); + + // no such reference + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse(); + + ScannerReportReader reader = new ScannerReportReader(outputDir); + Component rootProtobuf = reader.readComponent(1); + assertThat(rootProtobuf.getKey()).isEqualTo("foo"); + assertThat(rootProtobuf.getName()).isEqualTo(""); + assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); + assertThat(rootProtobuf.getVersion()).isEqualTo(""); + assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); + + Component module1Protobuf = reader.readComponent(2); + assertThat(module1Protobuf.getKey()).isEqualTo("module1"); + assertThat(module1Protobuf.getName()).isEqualTo(""); + assertThat(module1Protobuf.getDescription()).isEqualTo("Module description"); + assertThat(module1Protobuf.getVersion()).isEqualTo(""); + } @Test public void add_components_with_links_and_branch() throws Exception {