]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 cleanup
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 13 May 2014 20:56:46 +0000 (22:56 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 13 May 2014 21:20:35 +0000 (23:20 +0200)
51 files changed:
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleDocument.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfileRuleQuery.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesManager.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRuleLookup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRuleParam.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/package-info.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/package-info.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java
sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
sonar-server/src/main/java/org/sonar/server/rule/Rule.java
sonar-server/src/main/java/org/sonar/server/rule/RuleDocument.java
sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java
sonar-server/src/main/java/org/sonar/server/rule/RuleNote.java
sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
sonar-server/src/main/java/org/sonar/server/rule/RuleParam.java
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java
sonar-server/src/main/java/org/sonar/server/rule/Rules.java
sonar-server/src/main/java/org/sonar/server/rule2/ActiveRule.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleDoc.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndex.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleNormalizer.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleResult.java
sonar-server/src/main/java/org/sonar/server/rule2/index/package-info.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/persistence/RuleDao.java
sonar-server/src/main/java/org/sonar/server/rule2/persistence/package-info.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
sonar-server/src/main/java/org/sonar/server/search/Index.java
sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java [deleted file]
sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java
sonar-server/src/main/java/org/sonar/server/search/NestedIndex.java
sonar-server/src/main/java/org/sonar/server/search/Result.java
sonar-server/src/main/java/org/sonar/server/search/action/package-info.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java

index 9c64c53031720716b933495043b3bd38efd0be59..7c2d6cad3e1f96a82ed65f2c428c7f565d5bd55a 100644 (file)
@@ -85,6 +85,7 @@ import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
 import org.sonar.server.authentication.ws.AuthenticationWs;
 import org.sonar.server.charts.ChartFactory;
 import org.sonar.server.cluster.LocalNonBlockingWorkQueue;
+import org.sonar.server.cluster.LocalQueueWorker;
 import org.sonar.server.component.DefaultComponentFinder;
 import org.sonar.server.component.DefaultRubyComponentService;
 import org.sonar.server.component.ws.ComponentsWs;
@@ -180,6 +181,8 @@ import org.sonar.server.qualityprofile.QProfileRuleLookup;
 import org.sonar.server.qualityprofile.QProfiles;
 import org.sonar.server.qualityprofile.RegisterQualityProfiles;
 import org.sonar.server.qualityprofile.RuleActivationContextFactory;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
 import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
 import org.sonar.server.qualityprofile.ws.ProfilesWs;
 import org.sonar.server.qualityprofile.ws.QProfileRecreateBuiltInAction;
@@ -204,6 +207,8 @@ import org.sonar.server.rule.ws.RuleTagsWs;
 import org.sonar.server.rule.ws.RulesWs;
 import org.sonar.server.rule2.RegisterRules;
 import org.sonar.server.rule2.RuleService;
+import org.sonar.server.rule2.index.RuleIndex;
+import org.sonar.server.rule2.index.RuleNormalizer;
 import org.sonar.server.rule2.persistence.RuleDao;
 import org.sonar.server.rule2.ws.RulesWebService;
 import org.sonar.server.rule2.ws.SearchAction;
@@ -348,12 +353,18 @@ class ServerComponents {
       ThreadLocalDatabaseSessionFactory.class,
       new DatabaseSessionProvider(),
       ServerMetadataPersister.class,
-      ESNode.class,
       HttpDownloader.class,
       UriReader.class,
-      ServerIdGenerator.class
+      ServerIdGenerator.class,
+
+      // Elasticsearch
+      ESNode.class,
+      RuleNormalizer.class,
+      ActiveRuleNormalizer.class,
+      RuleIndex.class,
+      ActiveRuleIndex.class,
+      LocalQueueWorker.class
     );
-    components.addAll(IndexUtils.getIndexClasses());
     return components;
   }
 
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java
new file mode 100644 (file)
index 0000000..7d56304
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile;
+
+import org.sonar.core.qualityprofile.db.ActiveRuleKey;
+
+import java.util.Map;
+
+public interface ActiveRule {
+
+  ActiveRuleKey key();
+
+  String severity();
+
+  Boolean override();
+
+  String inherit();
+
+  Map<String, String> params();
+}
index a7aef2a98139f931329d4ca6322d42e95c238e03..a659c755b71477ab5a05680f3fa53974b7c76b74 100644 (file)
  */
 package org.sonar.server.qualityprofile;
 
-
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class ActiveRuleDocument {
 
   public static final String FIELD_ID = "id";
index 49664923678bfa4c7ac111dbc44412bb1cd6641b..47be3d63855a428ce2c49165d2d0087f5b3c5e7c 100644 (file)
@@ -39,7 +39,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
 import org.sonar.server.es.ESIndex;
 import org.sonar.server.es.SearchQuery;
-import org.sonar.server.rule.RuleDocument;
 import org.sonar.server.rule.RuleRegistry;
 
 import java.io.IOException;
@@ -48,6 +47,10 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class ESActiveRule {
 
   public static final String TYPE_ACTIVE_RULE = "active_rule";
index 4080b760b33b9e1e3243dbfa92ecfbfa1ee53852..ec4e3de3f8a41b0fde2f728ca5ae347da0a75415 100644 (file)
@@ -33,8 +33,9 @@ import java.util.*;
 import static com.google.common.collect.Lists.newArrayList;
 
 /**
- * @since 4.2
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class ProfileRuleQuery {
 
   public static final String SORT_BY_CREATION_DATE = "SORT_BY_CREATION_DATE";
index 8cc8c1922ddee5a1d70ed34fd61cfec5b4aeb102..2268a4b963089ef772bf498288bc8dfb9c6e5ea9 100644 (file)
@@ -31,9 +31,14 @@ import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.*;
 import org.sonar.core.preview.PreviewCache;
 import org.sonar.jpa.dao.RulesDao;
+import org.sonar.api.rules.ActiveRule;
 
 import java.util.*;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class ProfilesBackup {
 
   private static final String KEY = "key";
index 27f32a4f516d1dea56f88ecfb219099448a29217..80c3c507799f48e157651b3966d290f759607d0a 100644 (file)
@@ -33,7 +33,12 @@ import org.sonar.jpa.dao.RulesDao;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import java.util.List;
+import org.sonar.api.rules.ActiveRule;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class ProfilesManager extends BaseDao {
 
   private RulesDao rulesDao;
index f4123b4d4460f943400a7b08c01b979eff3ad9e5..2791d17da9f0e562591b3d8d3f543ce8568ca7bf 100644 (file)
@@ -57,6 +57,10 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileActiveRuleOperations implements ServerComponent {
 
   private final MyBatis myBatis;
index ac8ba2f6cff7bed413d0984332cb0c8e99d125d6..bfb5e5173579f1e075278cd6ba0c7fce1e2b7995 100644 (file)
@@ -56,8 +56,9 @@ import java.util.Map;
 import static com.google.common.collect.Lists.newArrayList;
 
 /**
- * Used through ruby code <pre>Internal.profile_backup</pre>
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class QProfileBackup implements ServerComponent {
 
   private final DatabaseSessionFactory sessionFactory;
index b6c15ae3df6606a141a8fec7f9374287c84aa556..2edcbc171eb775a4f615a3a1c75327afa11782fc 100644 (file)
@@ -34,6 +34,10 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileLookup implements ServerComponent {
 
   private final MyBatis myBatis;
index 90a70aa45ee4456b8189f135d8ba879bf503a327..be0597a2fae3ba21c0854f0e86a261cc49eb97cd 100644 (file)
@@ -40,6 +40,10 @@ import javax.annotation.Nullable;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileOperations implements ServerComponent {
 
   public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
index a9ecd599970d7e9e98c4395ac1550391b004fde5..095ba6924d0d466142c503ef16489f1391b64b4c 100644 (file)
@@ -35,6 +35,10 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileRule {
 
   public static final String INHERITED = "INHERITED";
index 84f700dbb5a21f6e3fffea29a1697cba54a7a24d..3c53aacb3cda5fc84769adb5c4bb363c2b261431 100644 (file)
@@ -52,6 +52,10 @@ import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
 import static org.sonar.server.rule.RuleRegistry.INDEX_RULES;
 import static org.sonar.server.rule.RuleRegistry.TYPE_RULE;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileRuleLookup implements ServerExtension {
 
   private static final int PAGE_SIZE = 100;
index b10dd5bf9d95566f3c294515f04492b5f2026b7c..b075778361030c2529ada8eaaf9138c81d237389 100644 (file)
@@ -26,6 +26,10 @@ import org.sonar.server.rule.RuleParam;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class QProfileRuleParam {
 
   private RuleParam param;
index 89f3bd3aa96fb16aa7821095b6b0c6da0d4183e2..4336713a5966adeaf334423794285edd9054187d 100644 (file)
@@ -36,8 +36,9 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * Used through ruby code <pre>Internal.quality_profiles</pre>
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class QProfiles implements ServerComponent {
 
   private static final String LANGUAGE_PARAM = "language";
index c752306ebe829534f7b8b2aa936a13c7e461d14a..7c25e121a7b5782a550864adf5b508153deab7f0 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.qualityprofile.index;
 
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
 
 import java.util.HashMap;
 import java.util.Map;
index f5f844e53c52564f7feb331e78e71311c0d4e04a..5a82f7ff49dc3ea9528fe4ec92f04226f6f7182c 100644 (file)
@@ -42,7 +42,6 @@ import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.sonar.api.rules.ActiveRule;
 import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.profiling.Profiling;
 import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
 import org.sonar.server.rule2.index.RuleNormalizer;
@@ -53,9 +52,8 @@ import java.io.IOException;
 
 public class ActiveRuleIndex extends NestedIndex<ActiveRule, ActiveRuleDto, ActiveRuleKey> {
 
-
-  public ActiveRuleIndex(ActiveRuleNormalizer normalizer, WorkQueue workQueue, Profiling profiling, BaseIndex<?,?,?> index) {
-    super(new ActiveRuleIndexDefinition(), normalizer, workQueue, profiling, index);
+  public ActiveRuleIndex(ActiveRuleNormalizer normalizer, WorkQueue workQueue, BaseIndex<?, ?, ?> index) {
+    super(new ActiveRuleIndexDefinition(), normalizer, workQueue, index);
   }
 
   @Override
@@ -88,4 +86,4 @@ public class ActiveRuleIndex extends NestedIndex<ActiveRule, ActiveRuleDto, Acti
     return null;
   }
 
-}
\ No newline at end of file
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/package-info.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/package-info.java
new file mode 100644 (file)
index 0000000..fb3c18e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.qualityprofile.index;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/package-info.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/package-info.java
new file mode 100644 (file)
index 0000000..c2b7fdc
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.qualityprofile.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 2669eefe9a0ac877eded98983040eb98f7ebe80e..2c08117aea87b273b2f2e46f0eec46fbf95d9abe 100644 (file)
@@ -31,6 +31,10 @@ import org.sonar.server.es.ESIndex;
 import java.io.IOException;
 import java.util.Collection;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class ESRuleTags {
 
   public static final String TYPE_TAG = "tag";
index 26d509c3e8033c17db25398109f14a0d94fc817d..84c9c48ce8314fe7eefdb292259664e0b3facde1 100644 (file)
@@ -67,10 +67,9 @@ import java.util.Set;
 import static com.google.common.collect.Lists.newArrayList;
 
 /**
- * Register rules at server startup
- *
- * @since 4.2
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class RegisterRules implements Startable {
 
   private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
index ba5c933524c602c907074e249dd55150c97d92ef..9c217737a5c6589020ca18e9b76026fc29b657b8 100644 (file)
@@ -30,6 +30,10 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class Rule {
 
   public static final String MANUAL_REPOSITORY_KEY = "manual";
index 1941eb9e1aa7d1eaf4cd971e6826c68be1b7139b..a6a72c05ed027b6259a7ea9f793933f9a0906f75 100644 (file)
 
 package org.sonar.server.rule;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public final class RuleDocument {
 
   public static final String FIELD_ID = "id";
index ac6c87e3c956b0e9d3f986958ae7496094d5ff90..6c8cff5eb202ffc1ca35853a6ccf12a58e60f5b9 100644 (file)
@@ -33,6 +33,10 @@ import java.util.Map;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleDocumentParser {
 
   private RuleDocumentParser() {
index a381eaf5dab2dd6941d1aee8fbbb97601e4487e7..41cdec029b3ca9e8363632aee8d816f05987beed 100644 (file)
@@ -21,6 +21,10 @@ package org.sonar.server.rule;
 
 import java.util.Date;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleNote {
 
   private final String data;
index 951b89dbfb6366f1ef69eb52a68e9b30c8a9aa85..83a4804e68afe96bb973c0d9c64cd1fef5c3c1b7 100644 (file)
@@ -64,6 +64,10 @@ import java.util.Set;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleOperations implements ServerComponent {
 
   private final MyBatis myBatis;
index 55036546ce912e1314fae6a929c6fe8fd6f12571..04d92f0ccd947c60aeb288a9fcd3c59dfca7f965 100644 (file)
@@ -25,6 +25,10 @@ import org.sonar.api.server.rule.RuleParamType;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleParam {
 
   private final String key;
index 99f7c9aa7891f4cbb6dab81c4c6837ea1531d1b7..24ee11f0614b3870ac1dbe3fe252753dc5feeed9 100644 (file)
@@ -71,11 +71,11 @@ import static org.elasticsearch.index.query.FilterBuilders.*;
 import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
 import static org.sonar.api.rules.Rule.STATUS_REMOVED;
 
+
 /**
- * Fill search index with rules
- *
- * @since 4.1
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class RuleRegistry {
 
   private static final Logger LOG = LoggerFactory.getLogger(RuleRegistry.class);
index 5a1da730925ab90da81e4aca9b32a78fd40dfa0f..2c35de519eb33eeced864eba53bd85480a64a651 100644 (file)
  */
 package org.sonar.server.rule;
 
-
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleTagDocument {
 
   public static final String FIELD_VALUE = "value";
index 5b5815ed3ae3fea35cad05cb70e2b184ce864833..475407b56d741907a3a3d00e97ce641d91b4c526 100644 (file)
@@ -23,6 +23,10 @@ import org.sonar.api.ServerComponent;
 
 import java.util.Collection;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleTagLookup implements ServerComponent  {
 
   private final ESRuleTags esRuleTags;
index 39c0c80b7b4f7b237064bb5f53259a8c26d43237..8b50e6bb7e13b395ac63e991caeb768d2fe55d5a 100644 (file)
@@ -31,6 +31,10 @@ import org.sonar.server.user.UserSession;
 
 import java.util.Set;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class RuleTagOperations implements ServerExtension {
 
   private final RuleTagDao ruleTagDao;
index 051e8f9111633ba7a867075ffc4daf8fb2b9040e..d87df4c6073c726b73ffb838dcac321979b441b3 100644 (file)
@@ -26,8 +26,9 @@ import org.sonar.server.user.UserSession;
 import java.util.Collection;
 
 /**
- * Used through ruby code <pre>Internal.rule_tags</pre>
+ * @deprecated to be dropped in 4.4
  */
+@Deprecated
 public class RuleTags implements ServerExtension {
 
   private final RuleTagLookup ruleTagLookup;
index dbdacbd35a00ec9a6d6259848c36ea84c50de1b1..625a62870a22bc5e21b439ef95b4fc67366e915e 100644 (file)
@@ -42,6 +42,10 @@ import java.util.Map;
 
 import static com.google.common.collect.Lists.newArrayList;
 
+/**
+ * @deprecated to be dropped in 4.4
+ */
+@Deprecated
 public class Rules implements ServerExtension {
 
   private final RuleDao ruleDao;
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRule.java b/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRule.java
deleted file mode 100644 (file)
index 67f89df..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.rule2;
-
-import org.sonar.core.qualityprofile.db.ActiveRuleKey;
-
-import java.util.Map;
-
-public interface ActiveRule {
-
-  public ActiveRuleKey key();
-
-  public Boolean override();
-
-  public String severity();
-
-  public String inherit();
-
-  public Map<String, String> params();
-}
index 9a7107833ee2876f6db14ebf3758fee9db15f43e..577ec2b67dbe4b73270970d0ebb0e1969a516427 100644 (file)
@@ -35,15 +35,13 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.utils.TimeProfiler;
 import org.sonar.check.Cardinality;
 import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
+import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.ProfilesManager;
-import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
 import org.sonar.server.rule.RuleDefinitionsLoader;
-import org.sonar.server.rule2.persistence.RuleDao;
 
 import javax.annotation.Nullable;
 import java.util.ArrayList;
@@ -67,38 +65,33 @@ public class RegisterRules implements Startable {
 
   private final RuleDefinitionsLoader defLoader;
   private final ProfilesManager profilesManager;
-  private final MyBatis myBatis;
-  private final RuleDao ruleDao;
-  private final ActiveRuleDao activeRuleDao;
+  private final DbClient dbClient;
   private final CharacteristicDao characteristicDao;
 
 
   public RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
-                       MyBatis myBatis, RuleDao ruleDao, ActiveRuleDao activeRuleDao,
+                       DbClient dbClient,
                        CharacteristicDao characteristicDao) {
-    this(defLoader, profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao, System2.INSTANCE);
+    this(defLoader, profilesManager, dbClient, characteristicDao, System2.INSTANCE);
   }
 
 
   @VisibleForTesting
   RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
-                MyBatis myBatis, RuleDao ruleDao, ActiveRuleDao activeRuleDao,
+                DbClient dbClient,
                 CharacteristicDao characteristicDao, System2 system) {
     this.defLoader = defLoader;
     this.profilesManager = profilesManager;
-    this.myBatis = myBatis;
-    this.ruleDao = ruleDao;
-    this.activeRuleDao = activeRuleDao;
+    this.dbClient = dbClient;
     this.characteristicDao = characteristicDao;
   }
 
   @Override
   public void start() {
     TimeProfiler profiler = new TimeProfiler().start("Register rules");
-    DbSession session = myBatis.openSession(false);
+    DbSession session = dbClient.openSession(false);
     try {
-
-      Map<RuleKey, RuleDto> allRules = getRulesByKey(session);
+      Map<RuleKey, RuleDto> allRules = loadRules(session);
 
       RulesDefinition.Context context = defLoader.load();
       for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
@@ -106,16 +99,14 @@ public class RegisterRules implements Startable {
 
           RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
 
-          RuleDto rule = allRules.containsKey(ruleKey) ?
-            allRules.remove(ruleKey) :
-            this.createRuleDto(ruleDef, session);
+          RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
 
           boolean executeUpdate = false;
           if (mergeRule(ruleDef, rule)) {
             executeUpdate = true;
           }
 
-          if(rule.getSubCharacteristicId() != null) {
+          if (rule.getSubCharacteristicId() != null) {
             CharacteristicDto characteristicDto = characteristicDao.selectById(rule.getSubCharacteristicId(), session);
             if (characteristicDto != null && mergeDebtDefinitions(ruleDef, rule, characteristicDto)) {
               executeUpdate = true;
@@ -127,16 +118,15 @@ public class RegisterRules implements Startable {
           }
 
           if (executeUpdate) {
-            ruleDao.update(rule, session);
+            dbClient.ruleDao().update(rule, session);
           }
 
           mergeParams(ruleDef, rule, session);
-
         }
+        session.commit();
       }
       List<RuleDto> activeRules = processRemainingDbRules(allRules.values(), session);
       removeActiveRulesOnStillExistingRepositories(activeRules, context);
-
       session.commit();
 
     } finally {
@@ -151,9 +141,9 @@ public class RegisterRules implements Startable {
     // nothing
   }
 
-  private Map<RuleKey, RuleDto> getRulesByKey(DbSession session) {
+  private Map<RuleKey, RuleDto> loadRules(DbSession session) {
     Map<RuleKey, RuleDto> rules = new HashMap<RuleKey, RuleDto>();
-    for (RuleDto rule : ruleDao.findByNonManual(session)) {
+    for (RuleDto rule : dbClient.ruleDao().findByNonManual(session)) {
       rules.put(rule.getKey(), rule);
     }
     return rules;
@@ -185,7 +175,7 @@ public class RegisterRules implements Startable {
       .setStatus(ruleDef.status().name())
       .setSystemTags(ruleDef.tags());
 
-    return ruleDao.insert(ruleDto, session);
+    return dbClient.ruleDao().insert(ruleDto, session);
   }
 
   private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) {
@@ -268,7 +258,7 @@ public class RegisterRules implements Startable {
   }
 
   private void mergeParams(RulesDefinition.Rule ruleDef, RuleDto rule, DbSession session) {
-    List<RuleParamDto> paramDtos = ruleDao.findRuleParamsByRuleKey(rule.getKey(), session);
+    List<RuleParamDto> paramDtos = dbClient.ruleDao().findRuleParamsByRuleKey(rule.getKey(), session);
     List<String> existingParamDtoNames = new ArrayList<String>();
 
     for (RuleParamDto paramDto : paramDtos) {
@@ -276,12 +266,12 @@ public class RegisterRules implements Startable {
       if (paramDef == null) {
         //TODO cascade on the activeRule upon RuleDeletion
         //activeRuleDao.removeRuleParam(paramDto, sqlSession);
-        ruleDao.removeRuleParam(rule, paramDto, session);
+        dbClient.ruleDao().removeRuleParam(rule, paramDto, session);
       } else {
         // TODO validate that existing active rules still match constraints
         // TODO store param name
         if (mergeParam(paramDto, paramDef)) {
-          ruleDao.updateRuleParam(rule, paramDto, session);
+          dbClient.ruleDao().updateRuleParam(rule, paramDto, session);
         }
         existingParamDtoNames.add(paramDto.getName());
       }
@@ -293,7 +283,7 @@ public class RegisterRules implements Startable {
           .setDescription(param.description())
           .setDefaultValue(param.defaultValue())
           .setType(param.type().toString());
-        ruleDao.addRuleParam(rule, paramDto, session);
+        dbClient.ruleDao().addRuleParam(rule, paramDto, session);
       }
     }
   }
@@ -338,7 +328,7 @@ public class RegisterRules implements Startable {
       boolean toBeRemoved = true;
       // Update custom rules from template
       if (ruleDto.getParentId() != null) {
-        RuleDto parent = ruleDao.getParent(ruleDto, session);
+        RuleDto parent = dbClient.ruleDao().getParent(ruleDto, session);
         if (parent != null && !Rule.STATUS_REMOVED.equals(parent.getStatus())) {
           ruleDto.setLanguage(parent.getLanguage());
           ruleDto.setStatus(parent.getStatus());
@@ -347,7 +337,7 @@ public class RegisterRules implements Startable {
           ruleDto.setDefaultRemediationCoefficient(parent.getDefaultRemediationCoefficient());
           ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset());
           ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription());
-          ruleDao.update(ruleDto, session);
+          dbClient.ruleDao().update(ruleDto, session);
           toBeRemoved = false;
         }
       }
@@ -358,7 +348,7 @@ public class RegisterRules implements Startable {
         ruleDto.setTags(Collections.EMPTY_SET);
       }
 
-      ruleDao.update(ruleDto, session);
+      dbClient.ruleDao().update(ruleDto, session);
       removedRules.add(ruleDto);
       if (removedRules.size() % 100 == 0) {
         session.commit();
@@ -392,6 +382,7 @@ public class RegisterRules implements Startable {
     for (RuleDto rule : removedRules) {
       // SONAR-4642 Remove active rules only when repository still exists
       if (repositoryKeys.contains(rule.getRepositoryKey())) {
+        // TODO
         profilesManager.removeActivatedRules(rule.getId());
       }
     }
index c8f629274e374368729b601d13083d3dac2f78a4..41b5b32d9b7ebac5a29440264e4f4b312753d235 100644 (file)
@@ -26,12 +26,10 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.server.rule2.Rule;
 import org.sonar.server.rule2.RuleParam;
-import org.sonar.server.rule2.index.RuleNormalizer;
 import org.sonar.server.rule2.index.RuleNormalizer.RuleField;
+import org.sonar.server.search.IndexUtils;
 
 import javax.annotation.CheckForNull;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -175,23 +173,13 @@ class RuleDoc implements Rule {
   @Override
   @CheckForNull
   public Date createdAt() {
-    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
-    try {
-      return sdf.parse((String) fields.get(RuleField.CREATED_AT.key()));
-    } catch (ParseException e) {
-      throw new IllegalStateException("Cannot parse date", e);
-    }
+    return IndexUtils.parseDateTime((String) fields.get(RuleField.CREATED_AT.key()));
   }
 
   @Override
   @CheckForNull
   public Date updatedAt() {
-    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
-    try {
-      return sdf.parse((String) fields.get(RuleField.UPDATED_AT.key()));
-    } catch (ParseException e) {
-      throw new IllegalStateException("Cannot parse date", e);
-    }
+    return IndexUtils.parseDateTime((String) fields.get(RuleField.UPDATED_AT.key()));
   }
 
   @Override
index 01031a006dc2f526e6fc81f9e2be7a9257b52f13..52c742ae386ad7392c7f284b0de94503e13f662b 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.rule2.index;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.search.SearchRequestBuilder;
@@ -37,7 +38,6 @@ import org.elasticsearch.search.sort.SortOrder;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.profiling.Profiling;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.server.es.ESNode;
 import org.sonar.server.rule2.Rule;
@@ -71,9 +71,8 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
     RuleNormalizer.RuleField.INTERNAL_KEY.key(),
     RuleNormalizer.RuleField.UPDATED_AT.key());
 
-  public RuleIndex(RuleNormalizer normalizer, WorkQueue workQueue,
-                   Profiling profiling, ESNode node) {
-    super(new RuleIndexDefinition(), normalizer, workQueue, profiling, node);
+  public RuleIndex(RuleNormalizer normalizer, WorkQueue workQueue, ESNode node) {
+    super(new RuleIndexDefinition(), normalizer, workQueue, node);
   }
 
   protected String getKeyValue(RuleKey key) {
@@ -292,7 +291,6 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
   }
 
   public RuleResult search(RuleQuery query, QueryOptions options) {
-
     SearchRequestBuilder esSearch = this.buildRequest(query, options);
     FilterBuilder fb = this.getFilter(query, options);
     QueryBuilder qb = this.getQuery(query, options);
@@ -306,14 +304,12 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
 
 
   public Rule toDoc(GetResponse response) {
-    if (response == null) {
-      throw new IllegalStateException("Cannot construct Rule with null response!!!");
-    }
+    Preconditions.checkArgument(response != null, "Cannot construct Rule with null response!!!");
     return new RuleDoc(response.getSource());
   }
 
   public Set<String> terms(String... fields) {
-    Set<String> tags  = new HashSet<String>();
+    Set<String> tags = new HashSet<String>();
 
     SearchRequestBuilder request = this.getClient()
       .prepareSearch(this.getIndexName())
@@ -324,7 +320,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
         .global(true)
         .size(Integer.MAX_VALUE));
 
-    SearchResponse esResponse =  request.get();
+    SearchResponse esResponse = request.get();
 
     TermsFacet termFacet = esResponse
       .getFacets().facet("tags");
index df5ddb8120c8b0fe477a2f4f5c2de9e7fe1db629..a2f73746b3ad3bc8bf38afc40c2a2154d2d127d5 100644 (file)
@@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.check.Cardinality;
 import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
index 0bc3a512f4a317fa8f47abfc714d7afbfc40b364..5f4e39461cbcecc416b49cc2cb4f6a01158dc4a3 100644 (file)
@@ -23,7 +23,7 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.SearchHit;
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
 import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.rule2.Rule;
 import org.sonar.server.search.Result;
 
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/index/package-info.java b/sonar-server/src/main/java/org/sonar/server/rule2/index/package-info.java
new file mode 100644 (file)
index 0000000..06dac82
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.rule2.index;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 1e4ccf013339382a0aa02933d1950414322cdebf..e13b10f7877c62c7f82178a3436d2a490a2607f7 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import org.apache.ibatis.session.ResultContext;
 import org.apache.ibatis.session.ResultHandler;
-import org.sonar.api.ServerComponent;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.DbSession;
@@ -43,7 +42,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> implements ServerComponent {
+public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> {
 
   public RuleDao() {
     super(new RuleIndexDefinition(), RuleMapper.class);
@@ -138,7 +137,6 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> implements Se
     Preconditions.checkNotNull(rule.getId(), "Rule id must be set");
     Preconditions.checkNotNull(paramDto.getId(), "Param is not yet persisted must be set");
     paramDto.setRuleId(rule.getId());
-    System.out.println("paramDto = " + paramDto);
     session.enqueue(new EmbeddedIndexAction<RuleKey>(this.getIndexType(), IndexAction.Method.UPDATE, paramDto, rule.getKey()));
     mapper(session).updateParameter(paramDto);
     return paramDto;
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/persistence/package-info.java b/sonar-server/src/main/java/org/sonar/server/rule2/persistence/package-info.java
new file mode 100644 (file)
index 0000000..bbe1f0d
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.rule2.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index c8e58a256cec522ee8af8354bc2788a441ed6eb2..12d109ccb4175f5b0614c59991ba5a297c11027a 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.rule2.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.rule2.Rule;
 import org.sonar.server.rule2.RuleParam;
 import org.sonar.server.rule2.RuleService;
index 9a902c4c47ab492c2de7b1e0f2f839f1a70975fd..6546a6d59c6baebf17fa528aee26f400dd805c83 100644 (file)
@@ -35,7 +35,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.db.Dto;
-import org.sonar.core.profiling.Profiling;
 import org.sonar.server.es.ESNode;
 
 import java.io.IOException;
@@ -49,15 +48,13 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
 
   private static final Logger LOG = LoggerFactory.getLogger(BaseIndex.class);
 
-  private final Profiling profiling;
   private final ESNode node;
   protected BaseNormalizer<E, K> normalizer;
   protected final IndexDefinition indexDefinition;
 
-  public BaseIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer, WorkQueue workQueue,
-                   Profiling profiling, ESNode node) {
+  public BaseIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer,
+                   WorkQueue workQueue, ESNode node) {
     this.normalizer = normalizer;
-    this.profiling = profiling;
     this.node = node;
     this.indexDefinition = indexDefinition;
   }
@@ -86,7 +83,7 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
   public void start() {
 
     /* Setup the index if necessary */
-    this.initializeIndex();
+    initializeIndex();
   }
 
   @Override
@@ -97,7 +94,6 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
   /* Cluster And ES Stats/Client methods */
 
   protected void initializeIndex() {
-
     String index = this.getIndexName();
 
     IndicesExistsResponse indexExistsResponse = getClient().admin().indices()
@@ -315,13 +311,12 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
   }
 
 
-
   protected BoolFilterBuilder addMultiFieldTermFilter(Collection<String> values, BoolFilterBuilder filter, String... fields) {
     if (values != null && !values.isEmpty()) {
       BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter();
       for (String value : values) {
         Collection<FilterBuilder> filterBuilders = new ArrayList<FilterBuilder>();
-        for(String field:fields) {
+        for (String field : fields) {
           filterBuilders.add(FilterBuilders.termFilter(field, value));
         }
         valuesFilter.should(FilterBuilders.orFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()])));
@@ -332,7 +327,6 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
   }
 
 
-
   protected BoolFilterBuilder addTermFilter(String field, Collection<String> values, BoolFilterBuilder filter) {
     if (values != null && !values.isEmpty()) {
       BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter();
index 77371d616560377a6636ae308fee99af859a8b7d..972339c295d6b5f6898426d20d45f22905312c6e 100644 (file)
@@ -24,18 +24,19 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.index.query.FilterBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.picocontainer.Startable;
+import org.sonar.api.ServerComponent;
 import org.sonar.core.db.Dto;
 
 import javax.annotation.CheckForNull;
 import java.io.Serializable;
 
-public interface Index<D, E extends Dto<K>, K extends Serializable> extends Startable {
+public interface Index<D, E extends Dto<K>, K extends Serializable> extends Startable, ServerComponent {
 
   @CheckForNull
   D getByKey(K item);
 
   SearchResponse search(SearchRequestBuilder request,
-                               FilterBuilder filter, QueryBuilder query);
+                        FilterBuilder filter, QueryBuilder query);
 
   String getIndexType();
 
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java
deleted file mode 100644 (file)
index 0cdda8e..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.search;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.db.Dao;
-
-import java.io.Serializable;
-
-public class IndexSynchronizer<K extends Serializable> {
-
-  private static final Logger LOG = LoggerFactory.getLogger(IndexSynchronizer.class);
-
-  private final Index index;
-  private final Dao<?,K> dao;
-  private final WorkQueue workQueue;
-
-  public IndexSynchronizer(Index index, Dao<?,K> dao,  WorkQueue workQueue) {
-    this.index = index;
-    this.dao = dao;
-    this.workQueue = workQueue;
-  }
-
-  public IndexSynchronizer<K> start() {
-
-//    LOG.info("Starting synchronization thread for ", index.getClass().getSimpleName());
-//
-//    Long since = index.getLastSynchronization();
-//    index.setLastSynchronization(System.currentTimeMillis());
-//
-//    for (K key : dao.keysOfRowsUpdatedAfter(since)) {
-//      if (LOG.isTraceEnabled()) {
-//        LOG.trace("Adding {} to workQueue for {}", key, index.getClass().getSimpleName());
-//      }
-//      workQueue.enqueue(new KeyIndexAction<K>(index.getIndexName(), IndexAction.Method.INSERT, key));
-//    }
-
-    return this;
-  }
-}
index 9ee63e345f5909c9a4f43e66ca63a894cd2bef81..99d6254c9c946080733ce2d7b39af5fee8f8fc0b 100644 (file)
  */
 package org.sonar.server.search;
 
-import com.google.common.collect.ImmutableList;
-import org.sonar.server.cluster.LocalQueueWorker;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
-import org.sonar.server.rule2.index.RuleIndex;
-import org.sonar.server.rule2.index.RuleNormalizer;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
-import java.util.List;
-
-public final class IndexUtils {
+public class IndexUtils {
 
+  private IndexUtils() {
+    // only static stuff
+  }
 
-  @SuppressWarnings("unchecked")
-  public static List<Class> getIndexClasses() {
-    return ImmutableList.<Class>of(
-      RuleNormalizer.class,
-      ActiveRuleNormalizer.class,
-      RuleIndex.class,
-      ActiveRuleIndex.class,
-      LocalQueueWorker.class
-    );
+  public static Date parseDateTime(String s) {
+    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+    try {
+      return sdf.parse(s);
+    } catch (ParseException e) {
+      throw new IllegalArgumentException("Cannot parse ES date: " + s, e);
+    }
   }
 }
index 07af4c7f8136917b4ab4a33e3e75ef77e105385d..af3d7d8fd870fab14e234e2d426e2693f014ea4b 100644 (file)
@@ -25,7 +25,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.db.Dto;
-import org.sonar.core.profiling.Profiling;
 
 import java.io.Serializable;
 
@@ -34,11 +33,11 @@ public abstract class NestedIndex<D, E extends Dto<K>, K extends Serializable>
 
   private static final Logger LOG = LoggerFactory.getLogger(NestedIndex.class);
 
-  protected BaseIndex<?,?,?> parentIndex;
+  protected BaseIndex<?, ?, ?> parentIndex;
 
   public NestedIndex(IndexDefinition indexDefinition, BaseNormalizer<E, K> normalizer, WorkQueue workQueue,
-                     Profiling profiling, BaseIndex<?,?,?> index) {
-    super(indexDefinition, normalizer, workQueue, profiling, index.getNode());
+                     BaseIndex<?, ?, ?> index) {
+    super(indexDefinition, normalizer, workQueue, index.getNode());
     this.parentIndex = index;
   }
 
@@ -54,17 +53,16 @@ public abstract class NestedIndex<D, E extends Dto<K>, K extends Serializable>
 
   protected abstract String getIndexField();
 
-  protected String getKeyValue(K key){
+  protected String getKeyValue(K key) {
     return this.getParentKeyValue(key);
   }
 
   protected void initializeIndex() {
-    ;
   }
 
   @Override
   public D getByKey(K key) {
-    return toDoc( getClient().prepareGet(this.getIndexName(), this.indexDefinition.getIndexType(), this.getKeyValue(key))
+    return toDoc(getClient().prepareGet(this.getIndexName(), this.indexDefinition.getIndexType(), this.getKeyValue(key))
       .get());
   }
 
index eeef6d8a1b9a2aa4846576af30f371200e0c116a..1ab0cfd120803a4ae65462e9b1a6377c9024da4a 100644 (file)
@@ -36,41 +36,34 @@ import java.util.Map;
 
 public abstract class Result<K> {
 
-  private Collection<K> hits;
-  private Map<String, Collection<FacetValue>> facets;
-  private int total;
-  private int offset;
-  private long time;
+  private final Collection<K> hits;
+  private final Map<String, Collection<FacetValue>> facets;
+  private final long total;
+  private final long timeInMillis;
 
   public Result(SearchResponse response) {
+    this.hits = new ArrayList<K>();
+    this.total = (int) response.getHits().totalHits();
+    this.timeInMillis = response.getTookInMillis();
 
-    hits = new ArrayList<K>();
-
-    if (response != null) {
-      this.total = (int) response.getHits().totalHits();
-      this.time = response.getTookInMillis();
-
-
-      for (SearchHit hit : response.getHits()) {
-        this.hits.add(getSearchResult(hit));
-      }
-
+    for (SearchHit hit : response.getHits()) {
+      this.hits.add(getSearchResult(hit));
+    }
 
-      if (response.getFacets() != null &&
-        !response.getFacets().facets().isEmpty()) {
-        this.facets = new HashMap<String, Collection<FacetValue>>();
-        for (Facet facet : response.getFacets().facets()) {
-          TermsFacet termFacet = (TermsFacet) facet;
-          List<FacetValue> facetValues = new ArrayList<FacetValue>();
-          for (TermsFacet.Entry facetValue : termFacet.getEntries()) {
-            facetValues.add(new FacetValue<Integer>(facetValue.getTerm().string(),
-              facetValue.getCount()));
-          }
-          this.facets.put(facet.getName(), facetValues);
+    if (response.getFacets() != null &&
+      !response.getFacets().facets().isEmpty()) {
+      this.facets = new HashMap<String, Collection<FacetValue>>();
+      for (Facet facet : response.getFacets().facets()) {
+        TermsFacet termFacet = (TermsFacet) facet;
+        List<FacetValue> facetValues = new ArrayList<FacetValue>();
+        for (TermsFacet.Entry facetValue : termFacet.getEntries()) {
+          facetValues.add(new FacetValue<Integer>(facetValue.getTerm().string(),
+            facetValue.getCount()));
         }
-      } else {
-        this.facets = Collections.emptyMap();
+        this.facets.put(facet.getName(), facetValues);
       }
+    } else {
+      this.facets = Collections.emptyMap();
     }
   }
 
@@ -90,16 +83,12 @@ public abstract class Result<K> {
     return hits;
   }
 
-  public int getTotal() {
+  public long getTotal() {
     return total;
   }
 
-  public int getOffset() {
-    return offset;
-  }
-
-  public long getTime() {
-    return time;
+  public long getTimeInMillis() {
+    return timeInMillis;
   }
 
   public Map<String, Collection<FacetValue>> getFacets() {
diff --git a/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java b/sonar-server/src/main/java/org/sonar/server/search/action/package-info.java
new file mode 100644 (file)
index 0000000..15d2248
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.search.action;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 960c739ad104867ba46158860ca83976643a0fdd..48346239f8e22e876ada223ab46aafc3695ccf8a 100644 (file)
@@ -24,9 +24,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
@@ -34,24 +31,18 @@ import org.sonar.api.server.rule.RulesDefinition;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
-import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.qualityprofile.db.QualityProfileDao;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
+import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.ProfilesManager;
 import org.sonar.server.qualityprofile.persistence.ActiveRuleDao;
-import org.sonar.server.rule.ESRuleTags;
 import org.sonar.server.rule.RuleDefinitionsLoader;
-import org.sonar.server.rule.RuleRegistry;
 import org.sonar.server.rule.RuleRepositories;
 import org.sonar.server.rule2.persistence.RuleDao;
 
-import java.util.Collection;
 import java.util.Date;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -68,32 +59,15 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     "effort_to_fix_description"};
 
   RegisterRules task;
-
-  @Mock
-  ProfilesManager profilesManager;
-
-  @Mock
-  RuleRegistry ruleRegistry;
-
-  @Mock
-  ESRuleTags esRuleTags;
-
-  @Captor
-  ArgumentCaptor<Collection<RuleDto>> rulesCaptor;
-
-  @Captor
-  ArgumentCaptor<Collection<RuleTagDto>> ruleTagsCaptor;
-
+  ProfilesManager profilesManager = mock(ProfilesManager.class);
   MyBatis myBatis;
   RuleDao ruleDao;
-  RuleTagDao ruleTagDao;
   ActiveRuleDao activeRuleDao;
   CharacteristicDao characteristicDao;
   System2 system;
-  WorkQueue queue;
   Date date = DateUtils.parseDateTime("2014-03-17T19:10:03+0100");
-
-  private DbSession session;
+  DbSession session;
+  DbClient dbClient;
 
   @Before
   public void before() {
@@ -101,11 +75,13 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     when(system.now()).thenReturn(date.getTime());
     myBatis = getMyBatis();
     ruleDao = new RuleDao();
-    ruleTagDao = new RuleTagDao(myBatis);
     activeRuleDao = new ActiveRuleDao(new QualityProfileDao(myBatis), ruleDao);
+    dbClient = new DbClient(getDatabase(), getMyBatis(), ruleDao, activeRuleDao, new QualityProfileDao(getMyBatis()));
     characteristicDao = new CharacteristicDao(myBatis);
-    task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{new FakeRepository()}),
-      profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao, system);
+    task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class),
+      new RulesDefinition[]{new FakeRepository()}),
+      profilesManager, dbClient, characteristicDao, system
+    );
     session = myBatis.openSession(false);
   }
 
@@ -289,7 +265,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
   @Test
   public void test_high_number_of_rules() {
     task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{new BigRepository()}),
-      profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao);
+      profilesManager, dbClient, characteristicDao);
 
     setupData("shared");
     task.start();
@@ -305,7 +281,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
   public void insert_extended_repositories() {
     task = new RegisterRules(new RuleDefinitionsLoader(mock(RuleRepositories.class), new RulesDefinition[]{
       new FindbugsRepository(), new FbContribRepository()}),
-      profilesManager, myBatis, ruleDao, activeRuleDao, characteristicDao
+      profilesManager, dbClient, characteristicDao
     );