Skip to content

Commit 09fde2b

Browse files
committed
Split Maven and Java ITs
1 parent 47f5224 commit 09fde2b

File tree

3 files changed

+136
-127
lines changed

3 files changed

+136
-127
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* SonarSource :: IT :: SonarQube Maven
3+
* Copyright (C) 2009-2019 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package com.sonar.maven.it.suite;
21+
22+
import com.sonar.maven.it.ItUtils;
23+
import com.sonar.orchestrator.build.MavenBuild;
24+
import java.io.File;
25+
import java.io.FileInputStream;
26+
import java.io.FileNotFoundException;
27+
import java.io.IOException;
28+
import java.util.Properties;
29+
import org.junit.After;
30+
import org.junit.Rule;
31+
import org.junit.Test;
32+
import org.junit.rules.TemporaryFolder;
33+
import org.sonarqube.ws.client.settings.SetRequest;
34+
35+
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.assertj.core.data.MapEntry.entry;
37+
38+
public class JavaTest extends AbstractMavenTest {
39+
40+
@Rule
41+
public TemporaryFolder temp = new TemporaryFolder();
42+
43+
@After
44+
public void cleanup() {
45+
wsClient.settings().set(new SetRequest().setKey("sonar.forceAuthentication").setValue("false"));
46+
}
47+
48+
// MSONAR-83
49+
@Test
50+
public void shouldPopulateLibraries() throws IOException {
51+
File outputProps = temp.newFile();
52+
File projectPom = ItUtils.locateProjectPom("shared/struts-1.3.9-diet");
53+
MavenBuild build = MavenBuild.create(projectPom)
54+
.setGoals(cleanPackageSonarGoal())
55+
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
56+
orchestrator.executeBuild(build);
57+
58+
Properties generatedProps = getProps(outputProps);
59+
String[] moduleIds = generatedProps.getProperty("sonar.modules").split(",");
60+
String strutsCoreModuleId = null;
61+
for (String moduleId : moduleIds) {
62+
if (generatedProps.getProperty(moduleId + ".sonar.moduleKey").equals("org.apache.struts:struts-core")) {
63+
strutsCoreModuleId = moduleId;
64+
break;
65+
}
66+
}
67+
assertThat(strutsCoreModuleId).isNotNull();
68+
assertThat(generatedProps.getProperty(strutsCoreModuleId + ".sonar.java.libraries")).contains("antlr-2.7.2.jar");
69+
assertThat(generatedProps.getProperty(strutsCoreModuleId + ".sonar.libraries")).contains("antlr-2.7.2.jar");
70+
}
71+
72+
@Test
73+
public void read_default_from_plugins_config() throws Exception {
74+
File outputProps = temp.newFile();
75+
// Need package to have test execution
76+
// Surefire reports are not in standard directory
77+
File pom = ItUtils.locateProjectPom("project-default-config");
78+
MavenBuild build = MavenBuild.create(pom)
79+
.setGoals(cleanPackageSonarGoal())
80+
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
81+
orchestrator.executeBuild(build);
82+
83+
Properties props = getProps(outputProps);
84+
assertThat(props).contains(
85+
entry("sonar.findbugs.excludeFilters", new File(pom.getParentFile(), "findbugs-filter.xml").toString()),
86+
entry("sonar.junit.reportsPath", new File(pom.getParentFile(), "target/surefire-output").toString()),
87+
entry("sonar.junit.reportPaths", new File(pom.getParentFile(), "target/surefire-output").toString()),
88+
entry("sonar.java.source", "1.7"));
89+
}
90+
91+
@Test
92+
public void setJavaVersionCompilerConfiguration() throws FileNotFoundException, IOException {
93+
File outputProps = temp.newFile();
94+
95+
File pom = ItUtils.locateProjectPom("version/compilerPluginConfig");
96+
MavenBuild build = MavenBuild.create(pom)
97+
.setGoals(cleanPackageSonarGoal())
98+
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
99+
orchestrator.executeBuild(build);
100+
101+
Properties props = getProps(outputProps);
102+
assertThat(props).contains(
103+
entry("sonar.java.source", "1.7"),
104+
entry("sonar.java.target", "1.8"));
105+
}
106+
107+
Integer mavenVersion = null;
108+
109+
@Test
110+
public void setJavaVersionProperties() throws IOException {
111+
File outputProps = temp.newFile();
112+
113+
File pom = ItUtils.locateProjectPom("version/properties");
114+
MavenBuild build = MavenBuild.create(pom)
115+
.setGoals(cleanPackageSonarGoal())
116+
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
117+
orchestrator.executeBuild(build);
118+
119+
Properties props = getProps(outputProps);
120+
assertThat(props).contains(
121+
entry("sonar.java.source", "1.7"),
122+
entry("sonar.java.target", "1.8"));
123+
}
124+
125+
private Properties getProps(File outputProps)
126+
throws FileNotFoundException, IOException {
127+
Properties props = new Properties();
128+
try (FileInputStream fis = new FileInputStream(outputProps)) {
129+
props.load(fis);
130+
}
131+
return props;
132+
}
133+
134+
}

its/src/test/java/com/sonar/maven/it/suite/MavenTest.java

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@
2424
import com.sonar.orchestrator.build.BuildRunner;
2525
import com.sonar.orchestrator.build.MavenBuild;
2626
import java.io.File;
27-
import java.io.FileInputStream;
28-
import java.io.FileNotFoundException;
29-
import java.io.IOException;
3027
import java.util.List;
3128
import java.util.Map;
32-
import java.util.Properties;
33-
import java.util.regex.Matcher;
34-
import java.util.regex.Pattern;
3529
import org.apache.commons.io.FileUtils;
36-
import org.apache.commons.io.IOUtils;
3730
import org.junit.After;
38-
import org.junit.Assume;
3931
import org.junit.Rule;
4032
import org.junit.Test;
4133
import org.junit.rules.TemporaryFolder;
@@ -44,7 +36,6 @@
4436
import org.sonarqube.ws.client.users.CreateRequest;
4537

4638
import static org.assertj.core.api.Assertions.assertThat;
47-
import static org.assertj.core.data.MapEntry.entry;
4839

4940
public class MavenTest extends AbstractMavenTest {
5041

@@ -88,7 +79,7 @@ public void useUserPropertiesGlobalConfig() throws Exception {
8879
public void supportSonarHostURLParam() {
8980
BuildRunner runner = new BuildRunner(orchestrator.getConfiguration());
9081
MavenBuild build = MavenBuild.create(ItUtils.locateProjectPom("maven/maven-global-properties"))
91-
//global property should take precedence
82+
// global property should take precedence
9283
.setEnvironmentVariable("SONAR_HOST_URL", "http://from-env.org:9000")
9384
.setGoals(cleanSonarGoal());
9485

@@ -419,30 +410,6 @@ public void fail_if_bad_value_of_sonar_tests_property() {
419410
"java2' does not exist for Maven module com.sonarsource.it.samples:maven-bad-tests-property:jar:1.0-SNAPSHOT. Please check the property sonar.tests");
420411
}
421412

422-
// MSONAR-83
423-
@Test
424-
public void shouldPopulateLibraries() throws IOException {
425-
File outputProps = temp.newFile();
426-
File projectPom = ItUtils.locateProjectPom("shared/struts-1.3.9-diet");
427-
MavenBuild build = MavenBuild.create(projectPom)
428-
.setGoals(cleanPackageSonarGoal())
429-
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
430-
orchestrator.executeBuild(build);
431-
432-
Properties generatedProps = getProps(outputProps);
433-
String[] moduleIds = generatedProps.getProperty("sonar.modules").split(",");
434-
String strutsCoreModuleId = null;
435-
for (String moduleId : moduleIds) {
436-
if (generatedProps.getProperty(moduleId + ".sonar.moduleKey").equals("org.apache.struts:struts-core")) {
437-
strutsCoreModuleId = moduleId;
438-
break;
439-
}
440-
}
441-
assertThat(strutsCoreModuleId).isNotNull();
442-
assertThat(generatedProps.getProperty(strutsCoreModuleId + ".sonar.java.libraries")).contains("antlr-2.7.2.jar");
443-
assertThat(generatedProps.getProperty(strutsCoreModuleId + ".sonar.libraries")).contains("antlr-2.7.2.jar");
444-
}
445-
446413
// MSONAR-91
447414
@Test
448415
public void shouldSkipModules() {
@@ -472,25 +439,6 @@ public void shouldSkipWithEnvVar() {
472439
assertThat(result.getLogs()).contains("SonarQube Scanner analysis skipped");
473440
}
474441

475-
@Test
476-
public void read_default_from_plugins_config() throws Exception {
477-
File outputProps = temp.newFile();
478-
// Need package to have test execution
479-
// Surefire reports are not in standard directory
480-
File pom = ItUtils.locateProjectPom("project-default-config");
481-
MavenBuild build = MavenBuild.create(pom)
482-
.setGoals(cleanPackageSonarGoal())
483-
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
484-
orchestrator.executeBuild(build);
485-
486-
Properties props = getProps(outputProps);
487-
assertThat(props).contains(
488-
entry("sonar.findbugs.excludeFilters", new File(pom.getParentFile(), "findbugs-filter.xml").toString()),
489-
entry("sonar.junit.reportsPath", new File(pom.getParentFile(), "target/surefire-output").toString()),
490-
entry("sonar.junit.reportPaths", new File(pom.getParentFile(), "target/surefire-output").toString()),
491-
entry("sonar.java.source", "1.7"));
492-
}
493-
494442
/**
495443
* MSONAR-141
496444
*/
@@ -513,79 +461,6 @@ public void supportMavenEncryption() throws Exception {
513461
orchestrator.executeBuild(build);
514462
}
515463

516-
@Test
517-
public void setJavaVersionCompilerConfiguration() throws FileNotFoundException, IOException {
518-
Assume.assumeTrue(3 == getMavenMajorVersion());
519-
520-
File outputProps = temp.newFile();
521-
522-
File pom = ItUtils.locateProjectPom("version/compilerPluginConfig");
523-
MavenBuild build = MavenBuild.create(pom)
524-
.setGoals(cleanPackageSonarGoal())
525-
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
526-
orchestrator.executeBuild(build);
527-
528-
Properties props = getProps(outputProps);
529-
assertThat(props).contains(
530-
entry("sonar.java.source", "1.7"),
531-
entry("sonar.java.target", "1.8"));
532-
}
533-
534-
Integer mavenVersion = null;
535-
536-
private int getMavenMajorVersion() {
537-
String versionRegex = "Apache Maven\\s(\\d+)\\.\\d+(?:\\.\\d+)?\\s";
538-
539-
if (mavenVersion != null) {
540-
return mavenVersion;
541-
}
542-
543-
MavenBuild build = MavenBuild.create()
544-
.setGoals("-version");
545-
BuildResult result = orchestrator.executeBuild(build);
546-
547-
String logs = result.getLogs();
548-
Pattern p = Pattern.compile(versionRegex);
549-
Matcher matcher = p.matcher(logs);
550-
551-
if (matcher.find()) {
552-
mavenVersion = Integer.parseInt(matcher.group(1));
553-
return mavenVersion;
554-
}
555-
throw new IllegalStateException("Could not find maven version: " + logs);
556-
}
557-
558-
@Test
559-
public void setJavaVersionProperties() throws IOException {
560-
Assume.assumeTrue(3 == getMavenMajorVersion());
561-
562-
File outputProps = temp.newFile();
563-
564-
File pom = ItUtils.locateProjectPom("version/properties");
565-
MavenBuild build = MavenBuild.create(pom)
566-
.setGoals(cleanPackageSonarGoal())
567-
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
568-
orchestrator.executeBuild(build);
569-
570-
Properties props = getProps(outputProps);
571-
assertThat(props).contains(
572-
entry("sonar.java.source", "1.7"),
573-
entry("sonar.java.target", "1.8"));
574-
}
575-
576-
private Properties getProps(File outputProps)
577-
throws FileNotFoundException, IOException {
578-
FileInputStream fis = null;
579-
try {
580-
Properties props = new Properties();
581-
fis = new FileInputStream(outputProps);
582-
props.load(fis);
583-
return props;
584-
} finally {
585-
IOUtils.closeQuietly(fis);
586-
}
587-
}
588-
589464
private boolean hasModules() {
590465
return !orchestrator.getServer().version().isGreaterThanOrEquals(7, 6);
591466
}

its/src/test/java/com/sonar/maven/it/suite/MavenTestSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
@RunWith(Suite.class)
2929
@Suite.SuiteClasses({
30-
LinksTest.class, MavenTest.class, ProxyTest.class
30+
LinksTest.class, MavenTest.class, ProxyTest.class, JavaTest.class
3131
})
3232
public class MavenTestSuite {
3333

0 commit comments

Comments
 (0)