From 0fddc5fa4ea33882b60e072eee51f0e1ea585b4c Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 6 Jan 2016 10:52:46 +0100 Subject: [PATCH] Fix quality flaws --- server/sonar-process-monitor/pom.xml | 2 +- server/sonar-process/pom.xml | 2 +- server/sonar-search/pom.xml | 2 +- .../src/main/java/org/sonar/server/db/BaseDao.java | 6 +++--- .../org/sonar/server/usergroups/ws/UserGroupUpdater.java | 4 ++-- .../src/main/java/org/sonar/server/ws/ServletResponse.java | 2 +- .../org/sonar/batch/protocol/viewer/TextLineNumber.java | 2 +- .../sonar/batch/report/AnalysisContextReportPublisher.java | 6 +++--- .../batch/cache/GlobalPersistentCacheProviderTest.java | 2 +- .../repository/DefaultProjectRepositoriesLoaderTest.java | 2 +- .../batch/repository/DefaultQualityProfileLoaderTest.java | 4 ++-- .../batch/repository/DefaultServerIssuesLoaderTest.java | 2 +- .../sonar/batch/repository/QualityProfileProviderTest.java | 2 +- .../org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java | 4 ++-- .../java/org/sonar/batch/source/CodeColorizersTest.java | 2 +- .../org/sonar/api/security/ExternalGroupsProviderTest.java | 4 ++-- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/server/sonar-process-monitor/pom.xml b/server/sonar-process-monitor/pom.xml index fa609738aa6..79af2d8e42d 100644 --- a/server/sonar-process-monitor/pom.xml +++ b/server/sonar-process-monitor/pom.xml @@ -1,12 +1,12 @@ + 4.0.0 org.sonarsource.sonarqube server 5.4-SNAPSHOT ../ - 4.0.0 sonar-process-monitor SonarQube :: Process Monitor diff --git a/server/sonar-process/pom.xml b/server/sonar-process/pom.xml index 43b835463f4..5b58a3dc90f 100644 --- a/server/sonar-process/pom.xml +++ b/server/sonar-process/pom.xml @@ -1,12 +1,12 @@ + 4.0.0 org.sonarsource.sonarqube server 5.4-SNAPSHOT ../ - 4.0.0 sonar-process SonarQube :: Process diff --git a/server/sonar-search/pom.xml b/server/sonar-search/pom.xml index 495bda9ba93..902f40917c5 100644 --- a/server/sonar-search/pom.xml +++ b/server/sonar-search/pom.xml @@ -1,12 +1,12 @@ + 4.0.0 org.sonarsource.sonarqube server 5.4-SNAPSHOT ../ - 4.0.0 sonar-search jar diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index edac9e409df..9b424776a87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -184,7 +184,7 @@ public abstract class BaseDao, KEY extends Serializ item.setUpdatedAt(now); doUpdate(session, item); if (hasIndex()) { - session.enqueue(new UpsertDto(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, KEY extends Serializ @Override public DTO insert(DbSession session, DTO item, DTO... others) { - insert(session, Lists.asList(item, others)); + insert(session, Lists.asList(item, others)); return item; } @@ -234,7 +234,7 @@ public abstract class BaseDao, KEY extends Serializ @Override public void delete(DbSession session, DTO item, DTO... others) { - delete(session, Lists.asList(item, others)); + delete(session, Lists.asList(item, others)); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java index f6f231126a1..a32fe0cadc5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java index e36f37e7ab6..02ad1e0e6a5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java @@ -34,7 +34,7 @@ import org.sonarqube.ws.MediaTypes; public class ServletResponse implements Response { - private Map headers = new HashMap(); + private Map headers = new HashMap<>(); public static class ServletStream implements Stream { private String mediaType; diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/TextLineNumber.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/TextLineNumber.java index 25817ab5a4d..a7012413a1d 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/TextLineNumber.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/TextLineNumber.java @@ -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(); + fonts = new HashMap<>(); Element root = component.getDocument().getDefaultRootElement(); int index = root.getElementIndex(rowStartOffset); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java index eb7f05b3b06..9f5f77e6fa8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java @@ -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(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 envVariables = system.envVariables(); - for (String env : new TreeSet(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 moduleSettings = settings.getProperties(); - for (String prop : new TreeSet(moduleSettings.keySet())) { + for (String prop : new TreeSet<>(moduleSettings.keySet())) { if (isSystemProp(prop) || isEnvVariable(prop) || !isSqProp(prop)) { continue; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java index 829be758632..64d58899e8d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java @@ -42,7 +42,7 @@ public class GlobalPersistentCacheProviderTest { @Before public void setUp() { - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put("sonar.userHome", temp.getRoot().getAbsolutePath()); globalProperties = new GlobalProperties(map); provider = new GlobalPersistentCacheProvider(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java index a577ca5113f..958ad48f4a7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java @@ -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(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", diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java index 0d6179efa3e..cdce8a352e0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java @@ -76,7 +76,7 @@ public class DefaultQualityProfileLoaderTest { @Test public void testNoProfile() throws IOException { InputStream is = createEncodedQP(); - when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult(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(is, false)); + when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false)); List loaded = qpLoader.loadDefault(null, null); verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java index 28efed6c877..0f9c435d22b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java @@ -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(is, true)); + when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true)); loader.load("foo", mock(Function.class)); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java index 45a1ddb1579..e2acf2276f4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java @@ -73,7 +73,7 @@ public class QualityProfileProviderTest { when(key.get()).thenReturn("project"); when(projectRepo.exists()).thenReturn(true); - response = new ArrayList(1); + response = new ArrayList<>(1); response.add(QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build()); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java index ac84b8ea2fa..eb8f6971046 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java @@ -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(response1, false)); - when(ws.loadStream(req2)).thenReturn(new WSLoaderResult(response2, false)); + when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<>(response1, false)); + when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<>(response2, false)); Collection activeRules = loader.load("c+-test_c+-values-17445", null); assertThat(activeRules).hasSize(226); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java index 3aa635172b0..b62eee31622 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java @@ -195,7 +195,7 @@ public class CodeColorizersTest { public class WebCodeColorizerFormat extends CodeColorizerFormat { - private final List tokenizers = new ArrayList(); + private final List tokenizers = new ArrayList<>(); public WebCodeColorizerFormat() { super("web"); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java index 700db028afe..d142ddd52d0 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/security/ExternalGroupsProviderTest.java @@ -86,7 +86,7 @@ public class ExternalGroupsProviderTest { } private static Map> getTestUserGroupMapping() { - Map> userGroupsMap = new HashMap>(); + Map> 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> userGroupsMap, String user, @Nullable String[] groups) { Collection groupsCollection = null; if (groups != null) { - groupsCollection = new ArrayList(); + groupsCollection = new ArrayList<>(); groupsCollection.addAll(Arrays.asList(groups)); } -- 2.39.5