From 53ff0ea1de1ef68f7040dac0dba24e52377e8bf5 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 28 Aug 2014 15:09:22 +0200 Subject: [PATCH] Replace bad imports of org.elasticsearch.common by guava --- server/sonar-search/pom.xml | 5 ++++ .../search/script/UpdateListScriptTest.java | 28 +++++++++---------- .../component/ws/ComponentAppAction.java | 4 +-- .../server/permission/PermissionFinder.java | 4 +-- .../qualityprofile/QProfileProjectLookup.java | 2 +- .../qualityprofile/index/ActiveRuleIndex.java | 2 +- .../org/sonar/server/rule/ws/AppAction.java | 2 +- .../activity/ActivityBackendMediumTest.java | 7 +---- .../activity/ActivityServiceMediumTest.java | 23 ++++++--------- .../server/qualitygate/ws/QGatesWsTest.java | 21 +++++++------- .../ActiveRuleChangeMediumTest.java | 2 +- sonar-application/pom.xml | 2 +- .../SyntaxHighlightingDataBuilder.java | 4 +-- 13 files changed, 50 insertions(+), 56 deletions(-) diff --git a/server/sonar-search/pom.xml b/server/sonar-search/pom.xml index 4d471e4251f..bcb4765c738 100644 --- a/server/sonar-search/pom.xml +++ b/server/sonar-search/pom.xml @@ -43,6 +43,11 @@ + + com.google.guava + guava + test + junit junit diff --git a/server/sonar-search/src/test/java/org/sonar/search/script/UpdateListScriptTest.java b/server/sonar-search/src/test/java/org/sonar/search/script/UpdateListScriptTest.java index 5b60a9d5eb7..f32f8f2e057 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/script/UpdateListScriptTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/script/UpdateListScriptTest.java @@ -19,7 +19,7 @@ */ package org.sonar.search.script; -import org.elasticsearch.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.script.ExecutableScript; import org.junit.Before; import org.junit.Test; @@ -35,7 +35,6 @@ public class UpdateListScriptTest { ListUpdate.UpdateListScriptFactory factory; - @Before public void setUp() throws Exception { factory = new ListUpdate.UpdateListScriptFactory(); @@ -100,7 +99,6 @@ public class UpdateListScriptTest { } } - @Test public void update_list() throws Exception { @@ -117,10 +115,10 @@ public class UpdateListScriptTest { params.put(ListUpdate.VALUE, mapOf("key", "1", "value", "A")); ExecutableScript script = factory.newScript(params); - script.setNextVar("ctx", ImmutableMap.of("_source",source)); + script.setNextVar("ctx", ImmutableMap.of("_source", source)); script.run(); - mapFields = (Collection)source.get(listField); + mapFields = (Collection) source.get(listField); System.out.println("source = " + source); assertThat(mapFields).hasSize(1); @@ -131,9 +129,9 @@ public class UpdateListScriptTest { params.put(ListUpdate.ID_VALUE, "2"); params.put(ListUpdate.VALUE, mapOf("key", "2", "value", "B")); script = factory.newScript(params); - script.setNextVar("ctx", ImmutableMap.of("_source",source)); + script.setNextVar("ctx", ImmutableMap.of("_source", source)); script.run(); - mapFields = (Collection)source.get(listField); + mapFields = (Collection) source.get(listField); assertThat(mapFields).hasSize(2); // updated first item in list @@ -143,9 +141,9 @@ public class UpdateListScriptTest { params.put(ListUpdate.ID_VALUE, "1"); params.put(ListUpdate.VALUE, mapOf("key", "1", "value", "a")); script = factory.newScript(params); - script.setNextVar("ctx", ImmutableMap.of("_source",source)); + script.setNextVar("ctx", ImmutableMap.of("_source", source)); script.run(); - mapFields = (Collection)source.get(listField); + mapFields = (Collection) source.get(listField); assertThat(mapFields).hasSize(2); // updated second item in list @@ -153,11 +151,11 @@ public class UpdateListScriptTest { params.put(ListUpdate.FIELD, listField); params.put(ListUpdate.ID_FIELD, "key"); params.put(ListUpdate.ID_VALUE, "2"); - params.put(ListUpdate.VALUE, mapOf("key", "2", "value","b")); + params.put(ListUpdate.VALUE, mapOf("key", "2", "value", "b")); script = factory.newScript(params); - script.setNextVar("ctx", ImmutableMap.of("_source",source)); + script.setNextVar("ctx", ImmutableMap.of("_source", source)); script.run(); - mapFields = (Collection)source.get(listField); + mapFields = (Collection) source.get(listField); assertThat(mapFields).hasSize(2); // delete first item @@ -167,9 +165,9 @@ public class UpdateListScriptTest { params.put(ListUpdate.ID_VALUE, "1"); params.put(ListUpdate.VALUE, null); script = factory.newScript(params); - script.setNextVar("ctx", ImmutableMap.of("_source",source)); + script.setNextVar("ctx", ImmutableMap.of("_source", source)); script.run(); - mapFields = (Collection)source.get(listField); + mapFields = (Collection) source.get(listField); assertThat(mapFields).hasSize(1); } @@ -179,4 +177,4 @@ public class UpdateListScriptTest { map.put(k1, v1); return map; } -} \ No newline at end of file +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java index 6f10598e69c..4cd7bfe2daf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java @@ -24,7 +24,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Multiset; import com.google.common.io.Resources; -import org.elasticsearch.common.inject.internal.Strings; +import org.apache.commons.lang.StringUtils; import org.sonar.api.component.Component; import org.sonar.api.i18n.I18n; import org.sonar.api.measures.CoreMetrics; @@ -227,7 +227,7 @@ public class ComponentAppAction implements RequestHandler { json.prop("fIssues", i18n.formatInteger(UserSession.get().locale(), severitiesAggregation.size())); for (String severity : severitiesAggregation.elementSet()) { - json.prop("f" + Strings.capitalize(severity.toLowerCase()) + "Issues", i18n.formatInteger(UserSession.get().locale(), severitiesAggregation.count(severity))); + json.prop("f" + StringUtils.capitalize(severity.toLowerCase()) + "Issues", i18n.formatInteger(UserSession.get().locale(), severitiesAggregation.count(severity))); } json.endObject(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java index b8a310f6591..765e49e91d5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java @@ -19,9 +19,9 @@ */ package org.sonar.server.permission; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import org.apache.commons.lang.StringUtils; -import org.elasticsearch.common.base.Predicate; -import org.elasticsearch.common.collect.Iterables; import org.sonar.api.ServerComponent; import org.sonar.api.security.DefaultGroups; import org.sonar.api.utils.Paging; diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java index b61a4d9224c..088bd5af9f7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java @@ -21,7 +21,7 @@ package org.sonar.server.qualityprofile; import com.google.common.collect.Lists; -import org.elasticsearch.common.collect.Maps; +import com.google.common.collect.Maps; import org.sonar.api.ServerComponent; import org.sonar.api.component.Component; import org.sonar.api.web.UserRole; diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java index fd7b4034fc0..e96cafcecba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java @@ -19,10 +19,10 @@ */ package org.sonar.server.qualityprofile.index; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.FilterBuilders; diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java index 5a85557efce..1e5dd3561ef 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java @@ -19,7 +19,7 @@ */ package org.sonar.server.rule.ws; -import org.elasticsearch.common.collect.Maps; +import com.google.common.collect.Maps; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java index eb20b732a04..2ab0d3e88ba 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java @@ -19,10 +19,9 @@ */ package org.sonar.server.activity; - import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.collect.Iterables; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -104,7 +103,6 @@ public class ActivityBackendMediumTest { assertThat(activity.details().get(testKey)).isEqualTo(testValue); } - @Test public void current_time_zone() { service.write(dbSession, Activity.Type.QPROFILE, "now"); @@ -141,7 +139,6 @@ public class ActivityBackendMediumTest { } assertThat(count).isEqualTo(max); - // 3 assert synchronize above IndexQueue threshold tester.clearIndexes(); tester.get(Platform.class).executeStartupTasks(); @@ -183,7 +180,6 @@ public class ActivityBackendMediumTest { } assertThat(count).isEqualTo(max); - // 3 assert synchronize above IndexQueue threshold tester.clearIndexes(); tester.get(Platform.class).executeStartupTasks(); @@ -198,7 +194,6 @@ public class ActivityBackendMediumTest { } - class TestActivityLog implements ActivityLog { private final String name; diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceMediumTest.java index 0e48a154e3f..cdd596d5ca6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceMediumTest.java @@ -21,8 +21,8 @@ package org.sonar.server.activity; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.collect.Iterables; import org.joda.time.DateTime; import org.junit.After; import org.junit.Before; @@ -70,7 +70,6 @@ public class ActivityServiceMediumTest { @Test public void find_all() throws InterruptedException { - service.write(dbSession, Activity.Type.QPROFILE, testValue); dbSession.commit(); assertThat(index.findAll().getTotal()).isEqualTo(1); @@ -92,7 +91,6 @@ public class ActivityServiceMediumTest { assertThat(activityResult.getHits().get(0).message()).isEqualTo(testValue); } - @Test public void search_activity_log() throws InterruptedException { @@ -106,7 +104,6 @@ public class ActivityServiceMediumTest { assertThat(activityResult.getHits().get(0).details().get(test_key)).isEqualTo(test_value); } - @Test public void filter_by_type() { service.write(dbSession, Activity.Type.NONE, getActivity()); @@ -119,11 +116,11 @@ public class ActivityServiceMediumTest { new QueryOptions()).getHits()).hasSize(4); assertThat(service.search(new ActivityQuery() - .setTypes(ImmutableSet.of(Activity.Type.SERVER)), + .setTypes(ImmutableSet.of(Activity.Type.SERVER)), new QueryOptions()).getHits()).hasSize(2); assertThat(service.search(new ActivityQuery() - .setTypes(ImmutableSet.of(Activity.Type.QPROFILE)), + .setTypes(ImmutableSet.of(Activity.Type.QPROFILE)), new QueryOptions()).getHits()).hasSize(1); } @@ -145,29 +142,28 @@ public class ActivityServiceMediumTest { dbSession.commit(); DateTime t2 = new DateTime().plusHours(1); - assertThat(service.search(new ActivityQuery(), new QueryOptions()).getHits()).hasSize(3); assertThat(service.search(new ActivityQuery() - .setSince(t0.minusSeconds(5).toDate()), + .setSince(t0.minusSeconds(5).toDate()), new QueryOptions()).getHits()).hasSize(3); assertThat(service.search(new ActivityQuery() - .setSince(t1.minusSeconds(5).toDate()), + .setSince(t1.minusSeconds(5).toDate()), new QueryOptions()).getHits()).hasSize(1); assertThat(service.search(new ActivityQuery() - .setSince(t2.minusSeconds(5).toDate()), + .setSince(t2.minusSeconds(5).toDate()), new QueryOptions()).getHits()).hasSize(0); assertThat(service.search(new ActivityQuery() - .setTo(t1.minusSeconds(5).toDate()), + .setTo(t1.minusSeconds(5).toDate()), new QueryOptions()).getHits()).hasSize(2); assertThat(service.search(new ActivityQuery() - .setSince(t1.minusSeconds(5).toDate()) - .setTo(t2.plusSeconds(5).toDate()), + .setSince(t1.minusSeconds(5).toDate()) + .setTo(t2.plusSeconds(5).toDate()), new QueryOptions()).getHits()).hasSize(1); } @@ -203,7 +199,6 @@ public class ActivityServiceMediumTest { assertThat(count).isEqualTo(max); } - final String test_key = "hello"; final String test_value = "world"; final String testValue = "hello world"; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java index ad089547b51..f710b51a7b9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java @@ -20,7 +20,7 @@ package org.sonar.server.qualitygate.ws; import com.google.common.collect.ImmutableList; -import org.elasticsearch.common.collect.Lists; +import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -218,7 +218,8 @@ public class QGatesWsTest { String name = "New QG"; when(qGates.rename(id, name)).thenReturn(new QualityGateDto().setId(id).setName(name)); tester.newPostRequest("api/qualitygates", "rename").setParam("id", id.toString()).setParam("name", name).execute() - .assertJson("{'id':42,'name':'New QG'}");; + .assertJson("{'id':42,'name':'New QG'}"); + ; } @Test @@ -259,7 +260,7 @@ public class QGatesWsTest { new QualityGateDto().setId(42L).setName("Golden"), new QualityGateDto().setId(43L).setName("Star"), new QualityGateDto().setId(666L).setName("Ninth") - )); + )); when(qGates.currentUserHasWritePermission()).thenReturn(false); tester.newGetRequest("api/qualitygates", "list").execute().assertJson( "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}]}"); @@ -272,7 +273,7 @@ public class QGatesWsTest { defaultQgate, new QualityGateDto().setId(43L).setName("Star"), new QualityGateDto().setId(666L).setName("Ninth") - )); + )); when(qGates.getDefault()).thenReturn(defaultQgate); tester.newGetRequest("api/qualitygates", "list").execute().assertJson( "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}],'default':42}"); @@ -293,13 +294,13 @@ public class QGatesWsTest { when(qGates.listConditions(gateId)).thenReturn(ImmutableList.of( new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"), new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3) - )); + )); tester.newGetRequest("api/qualitygates", "show").setParam("id", Long.toString(gateId)).execute().assertJson( "{'id':12345,'name':'Golden','conditions':[" + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'}," + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}" + "]}" - ); + ); } @Test @@ -310,13 +311,13 @@ public class QGatesWsTest { when(qGates.listConditions(qGateId)).thenReturn(ImmutableList.of( new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"), new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3) - )); + )); tester.newGetRequest("api/qualitygates", "show").setParam("name", gateName).execute().assertJson( "{'id':12345,'name':'Golden','conditions':[" + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'}," + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}" + "]}" - ); + ); } @Test(expected = BadRequestException.class) @@ -386,7 +387,7 @@ public class QGatesWsTest { List projects = ImmutableList.of( new ProjectQgateAssociation().setId(42L).setName("Project One").setMember(false), new ProjectQgateAssociation().setId(24L).setName("Project Two").setMember(true) - ); + ); when(assoc.projects()).thenReturn(projects); when(projectFinder.find(any(ProjectQgateAssociationQuery.class))).thenReturn(assoc); @@ -411,7 +412,7 @@ public class QGatesWsTest { when(assoc.hasMoreResults()).thenReturn(true); List projects = ImmutableList.of( new ProjectQgateAssociation().setId(24L).setName("Project Two").setMember(true) - ); + ); when(assoc.projects()).thenReturn(projects); when(projectFinder.find(any(ProjectQgateAssociationQuery.class))).thenReturn(assoc); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java index 68cf8394c24..58625f7657f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeMediumTest.java @@ -19,7 +19,7 @@ */ package org.sonar.server.qualityprofile; -import org.elasticsearch.common.collect.Iterables; +import com.google.common.collect.Iterables; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 242e6dd7c21..a7e45403831 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -261,7 +261,7 @@ 84000000 - 120000000 + 880000000 ${project.build.directory}/sonarqube-${project.version}.zip diff --git a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java index 80e784d4211..121a6683bca 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/highlighting/SyntaxHighlightingDataBuilder.java @@ -19,11 +19,11 @@ */ package org.sonar.batch.highlighting; +import com.google.common.collect.Sets; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Ordering; -import org.elasticsearch.common.collect.Sets; import javax.annotation.Nullable; @@ -38,7 +38,7 @@ public class SyntaxHighlightingDataBuilder { syntaxHighlightingRuleSet = Sets.newTreeSet(new Ordering() { @Override public int compare(@Nullable SyntaxHighlightingRule left, - @Nullable SyntaxHighlightingRule right) { + @Nullable SyntaxHighlightingRule right) { int result = left.getStartPosition() - right.getStartPosition(); if (result == 0) { result = left.getEndPosition() - right.getEndPosition(); -- 2.39.5