]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws 5.4-M3
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 6 Jan 2016 09:52:46 +0000 (10:52 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 6 Jan 2016 09:52:57 +0000 (10:52 +0100)
16 files changed:
server/sonar-process-monitor/pom.xml
server/sonar-process/pom.xml
server/sonar-search/pom.xml
server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java
server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/TextLineNumber.java
sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java
sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java
sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java
sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java
sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java

index fa609738aa636d16d078aa6d18ca48c122ef16e2..79af2d8e42dab165c26a8f0cda60d4636b935baa 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.sonarsource.sonarqube</groupId>
     <artifactId>server</artifactId>
     <version>5.4-SNAPSHOT</version>
     <relativePath>../</relativePath>
   </parent>
-  <modelVersion>4.0.0</modelVersion>
 
   <artifactId>sonar-process-monitor</artifactId>
   <name>SonarQube :: Process Monitor</name>
index 43b835463f49efcd253f728166f4ad55533140b7..5b58a3dc90f3de31b33f6e07df09b98f817ee168 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.sonarsource.sonarqube</groupId>
     <artifactId>server</artifactId>
     <version>5.4-SNAPSHOT</version>
     <relativePath>../</relativePath>
   </parent>
-  <modelVersion>4.0.0</modelVersion>
 
   <artifactId>sonar-process</artifactId>
   <name>SonarQube :: Process</name>
index 495bda9ba93fe7221dc0289eb4226dd1c2d3a327..902f40917c51f11dc5c13c23d477b221e51bc6dd 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.sonarsource.sonarqube</groupId>
     <artifactId>server</artifactId>
     <version>5.4-SNAPSHOT</version>
     <relativePath>../</relativePath>
   </parent>
-  <modelVersion>4.0.0</modelVersion>
 
   <artifactId>sonar-search</artifactId>
   <packaging>jar</packaging>
index edac9e409df0a8a82546683594e64a2c98872d0e..9b424776a87c96a90aefaeaee39881dcb5c197e7 100644 (file)
@@ -184,7 +184,7 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
       item.setUpdatedAt(now);
       doUpdate(session, item);
       if (hasIndex()) {
-        session.enqueue(new UpsertDto<DTO>(getIndexType(), item));
+        session.enqueue(new UpsertDto<>(getIndexType(), item));
       }
     } catch (Exception e) {
       throw new IllegalStateException("Fail to update item in db: " + item, e);
@@ -208,7 +208,7 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
 
   @Override
   public DTO insert(DbSession session, DTO item, DTO... others) {
-    insert(session, Lists.<DTO>asList(item, others));
+    insert(session, Lists.asList(item, others));
     return item;
   }
 
@@ -234,7 +234,7 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
 
   @Override
   public void delete(DbSession session, DTO item, DTO... others) {
-    delete(session, Lists.<DTO>asList(item, others));
+    delete(session, Lists.asList(item, others));
   }
 
   @Override
index f6f231126a1ad32e6c3b8b6798fe6b80b19c7790..a32fe0cadc53a338b57f3d76c8b22281aeeae03c 100644 (file)
@@ -52,12 +52,12 @@ public class UserGroupUpdater {
     checkNameNotAnyone(name);
   }
 
-  private void checkNameLength(String name) {
+  private static void checkNameLength(String name) {
     Preconditions.checkArgument(!name.isEmpty(), "Name cannot be empty");
     Preconditions.checkArgument(name.length() <= NAME_MAX_LENGTH, String.format("Name cannot be longer than %d characters", NAME_MAX_LENGTH));
   }
 
-  private void checkNameNotAnyone(String name) {
+  private static void checkNameNotAnyone(String name) {
     Preconditions.checkArgument(!DefaultGroups.isAnyone(name), String.format("Name '%s' is reserved (regardless of case)", DefaultGroups.ANYONE));
   }
 
index e36f37e7ab6022a45c69327a3f1e228f66d96ec6..02ad1e0e6a5228947880eda06d36f6aa8c0f50bf 100644 (file)
@@ -34,7 +34,7 @@ import org.sonarqube.ws.MediaTypes;
 
 public class ServletResponse implements Response {
 
-  private Map<String, String> headers = new HashMap<String, String>();
+  private Map<String, String> headers = new HashMap<>();
 
   public static class ServletStream implements Stream {
     private String mediaType;
index 25817ab5a4de13305f4d6dedf599ffa25327f1e0..a7012413a1dc8cf6df036ab68987995d2aecbf2f 100644 (file)
@@ -346,7 +346,7 @@ public class TextLineNumber extends JPanel implements CaretListener, DocumentLis
     } else // We need to check all the attributes for font changes
     {
       if (fonts == null)
-        fonts = new HashMap<String, FontMetrics>();
+        fonts = new HashMap<>();
 
       Element root = component.getDocument().getDefaultRootElement();
       int index = root.getElementIndex(rowStartOffset);
index eb7f05b3b063cdec8ccf9a078a41720683b14b75..9f5f77e6fa8c2538e6b78d1b3ed6da0a52eb0b84 100644 (file)
@@ -85,7 +85,7 @@ public class AnalysisContextReportPublisher {
   private void writeSystemProps(BufferedWriter fileWriter) throws IOException {
     fileWriter.write("System properties:\n");
     Properties sysProps = system.properties();
-    for (String prop : new TreeSet<String>(sysProps.stringPropertyNames())) {
+    for (String prop : new TreeSet<>(sysProps.stringPropertyNames())) {
       if (prop.startsWith(SONAR_PROP_PREFIX)) {
         continue;
       }
@@ -96,7 +96,7 @@ public class AnalysisContextReportPublisher {
   private void writeEnvVariables(BufferedWriter fileWriter) throws IOException {
     fileWriter.append("Environment variables:\n");
     Map<String, String> envVariables = system.envVariables();
-    for (String env : new TreeSet<String>(envVariables.keySet())) {
+    for (String env : new TreeSet<>(envVariables.keySet())) {
       fileWriter.append(String.format("  - %s=%s", env, envVariables.get(env))).append('\n');
     }
   }
@@ -109,7 +109,7 @@ public class AnalysisContextReportPublisher {
     try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) {
       fileWriter.append(String.format("Settings for module: %s", moduleDefinition.getKey())).append('\n');
       Map<String, String> moduleSettings = settings.getProperties();
-      for (String prop : new TreeSet<String>(moduleSettings.keySet())) {
+      for (String prop : new TreeSet<>(moduleSettings.keySet())) {
         if (isSystemProp(prop) || isEnvVariable(prop) || !isSqProp(prop)) {
           continue;
         }
index 829be758632cb8720605a2dafa3be2327f31aa4f..64d58899e8d6b550bd6fd601e59bb65abcef8476 100644 (file)
@@ -42,7 +42,7 @@ public class GlobalPersistentCacheProviderTest {
 
   @Before
   public void setUp() {
-    HashMap<String, String> map = new HashMap<String, String>();
+    HashMap<String, String> map = new HashMap<>();
     map.put("sonar.userHome", temp.getRoot().getAbsolutePath());
     globalProperties = new GlobalProperties(map);
     provider = new GlobalPersistentCacheProvider();
index a577ca5113f916f24a553718791b6e36b8f4aca0..958ad48f4a7a7e57407e75ae5eed5e3bc3ff40fe 100644 (file)
@@ -126,7 +126,7 @@ public class DefaultProjectRepositoriesLoaderTest {
   @Test
   public void readRealResponse() throws IOException {
     InputStream is = getTestResource("project.protobuf");
-    when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, true));
+    when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
 
     ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true, null);
     FileData fd = proj.fileData("org.sonarsource.github:sonar-github-plugin",
index 0d6179efa3e32ad6b09b0934c05fb74564376e31..cdce8a352e0a6b7485ac9e34214a090d00633d22 100644 (file)
@@ -76,7 +76,7 @@ public class DefaultQualityProfileLoaderTest {
   @Test
   public void testNoProfile() throws IOException {
     InputStream is = createEncodedQP();
-    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, false));
+    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
 
     exception.expect(MessageException.class);
     exception.expectMessage("No quality profiles");
@@ -88,7 +88,7 @@ public class DefaultQualityProfileLoaderTest {
   @Test
   public void use_real_response() throws IOException {
     InputStream is = getTestResource("quality_profile_search_default");
-    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, false));
+    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
 
     List<QualityProfile> loaded = qpLoader.loadDefault(null, null);
     verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true");
index 28efed6c877e9c509a981f279d6af889ba492b31..0f9c435d22b246dce8354db96890c36277c32cc4 100644 (file)
@@ -77,7 +77,7 @@ public class DefaultServerIssuesLoaderTest {
   public void testError() throws IOException {
     InputStream is = mock(InputStream.class);
     when(is.read()).thenThrow(IOException.class);
-    when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<InputStream>(is, true));
+    when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true));
     loader.load("foo", mock(Function.class));
   }
 }
index 45a1ddb1579b7efb3561386739a25661382ed4a5..e2acf2276f43414643449ab1ce99aaae3c656c92 100644 (file)
@@ -73,7 +73,7 @@ public class QualityProfileProviderTest {
     when(key.get()).thenReturn("project");
     when(projectRepo.exists()).thenReturn(true);
 
-    response = new ArrayList<QualityProfile>(1);
+    response = new ArrayList<>(1);
     response.add(QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build());
   }
 
index ac84b8ea2fa4c6008f5164817a9d5ee37f59eae5..eb8f6971046e0e0841dd507fe2fb4c9b0557ae42 100644 (file)
@@ -53,8 +53,8 @@ public class DefaultActiveRulesLoaderTest {
 
     String req1 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=1&ps=500";
     String req2 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=2&ps=500";
-    when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<InputStream>(response1, false));
-    when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<InputStream>(response2, false));
+    when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<>(response1, false));
+    when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<>(response2, false));
 
     Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445", null);
     assertThat(activeRules).hasSize(226);
index 3aa635172b0b7f71b028dc3a94423500b68413b8..b62eee316226e1c6f870f059ce1919a39ec86d5d 100644 (file)
@@ -195,7 +195,7 @@ public class CodeColorizersTest {
 
   public class WebCodeColorizerFormat extends CodeColorizerFormat {
 
-    private final List<Tokenizer> tokenizers = new ArrayList<Tokenizer>();
+    private final List<Tokenizer> tokenizers = new ArrayList<>();
 
     public WebCodeColorizerFormat() {
       super("web");
index 700db028afe74d2f53fefd2b8206e58b825f812f..d142ddd52d0e40aabe34465898c32d7700ad8cd5 100644 (file)
@@ -86,7 +86,7 @@ public class ExternalGroupsProviderTest {
   }
 
   private static Map<String, Collection<String>> getTestUserGroupMapping() {
-    Map<String, Collection<String>> userGroupsMap = new HashMap<String, Collection<String>>();
+    Map<String, Collection<String>> userGroupsMap = new HashMap<>();
     addUserGroupMapping(userGroupsMap, "userWithOneGroups", new String[] {"group1"});
     addUserGroupMapping(userGroupsMap, "userWithTwoGroups", new String[] {"group1", "group2"});
     addUserGroupMapping(userGroupsMap, "userWithNoGroup", new String[] {});
@@ -98,7 +98,7 @@ public class ExternalGroupsProviderTest {
   private static void addUserGroupMapping(Map<String, Collection<String>> userGroupsMap, String user, @Nullable String[] groups) {
     Collection<String> groupsCollection = null;
     if (groups != null) {
-      groupsCollection = new ArrayList<String>();
+      groupsCollection = new ArrayList<>();
       groupsCollection.addAll(Arrays.asList(groups));
     }