2424import com .sonar .orchestrator .build .BuildRunner ;
2525import com .sonar .orchestrator .build .MavenBuild ;
2626import java .io .File ;
27- import java .io .FileInputStream ;
28- import java .io .FileNotFoundException ;
29- import java .io .IOException ;
3027import java .util .List ;
3128import java .util .Map ;
32- import java .util .Properties ;
33- import java .util .regex .Matcher ;
34- import java .util .regex .Pattern ;
3529import org .apache .commons .io .FileUtils ;
36- import org .apache .commons .io .IOUtils ;
3730import org .junit .After ;
38- import org .junit .Assume ;
3931import org .junit .Rule ;
4032import org .junit .Test ;
4133import org .junit .rules .TemporaryFolder ;
4436import org .sonarqube .ws .client .users .CreateRequest ;
4537
4638import static org .assertj .core .api .Assertions .assertThat ;
47- import static org .assertj .core .data .MapEntry .entry ;
4839
4940public 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 }
0 commit comments