aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-23 12:27:39 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-23 12:28:50 +0100
commitdffb2a58206c68b7ae69cbcdebdfb7c30cdbf579 (patch)
tree5435e6cf451e9c8668d8a63ed4860c0564ffd559 /sonar-core
parent5d6ab3e62e41fc1d9928156557c96c301bc50ce5 (diff)
downloadsonarqube-dffb2a58206c68b7ae69cbcdebdfb7c30cdbf579.tar.gz
sonarqube-dffb2a58206c68b7ae69cbcdebdfb7c30cdbf579.zip
SONAR-983 provide the component org.sonar.core.resource.ResourceIndexer that is a layer over ResourceIndexerDao
+ move derby SQL files to org.sonar.core.persistence
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DdlUtils.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java74
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql (renamed from sonar-core/src/main/resources/org/sonar/persistence/rows-derby.sql)0
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl (renamed from sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl)0
4 files changed, 76 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DdlUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DdlUtils.java
index 95f42e51369..179f7648810 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DdlUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DdlUtils.java
@@ -44,8 +44,8 @@ public final class DdlUtils {
* The connection is commited in this method but not closed.
*/
public static void createSchema(Connection connection, String dialect) {
- executeScript(connection, "org/sonar/persistence/schema-" + dialect + ".ddl");
- executeScript(connection, "org/sonar/persistence/rows-" + dialect + ".sql");
+ executeScript(connection, "org/sonar/core/persistence/schema-" + dialect + ".ddl");
+ executeScript(connection, "org/sonar/core/persistence/rows-" + dialect + ".sql");
}
private static void executeScript(Connection connection, String path) {
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java
new file mode 100644
index 00000000000..32c8df9a261
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java
@@ -0,0 +1,74 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.resource;
+
+import com.google.common.annotations.Beta;
+import org.apache.commons.lang.ArrayUtils;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Scopes;
+
+/**
+ * This component will be automatically called in v3.0 when a resource is created or updated.
+ * It means that it will not be exposed to plugin API.
+ *
+ * @since 2.13
+ */
+@Beta
+public class ResourceIndexer implements BatchComponent, ServerComponent {
+ private ResourceIndexerDao dao;
+
+ /**
+ * Hardcoded list of qualifiers to index. Need to be configurable.
+ * Directories and packages are explicitly excluded.
+ */
+ private String[] INDEXABLE_QUALIFIERS = {
+ Qualifiers.VIEW,
+ Qualifiers.SUBVIEW,
+ Qualifiers.PROJECT,
+ Qualifiers.MODULE,
+ Qualifiers.FILE,
+ Qualifiers.CLASS,
+ Qualifiers.UNIT_TEST_FILE
+ };
+
+ public ResourceIndexer(ResourceIndexerDao dao) {
+ this.dao = dao;
+ }
+
+ public ResourceIndexer index(String resourceName, String qualifier, int resourceId, int rootProjectId) {
+ if (ArrayUtils.contains(INDEXABLE_QUALIFIERS, qualifier)) {
+ dao.index(resourceName, qualifier, resourceId, rootProjectId);
+ }
+ return this;
+ }
+
+ /**
+ * Used only for the migration from a version less than 2.13.
+ */
+ public ResourceIndexer indexAll() {
+ ResourceIndexerFilter filter = ResourceIndexerFilter.create()
+ .setScopes(new String[]{Scopes.PROJECT, Scopes.FILE})
+ .setQualifiers(INDEXABLE_QUALIFIERS);
+ dao.index(filter);
+ return this;
+ }
+}
diff --git a/sonar-core/src/main/resources/org/sonar/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
index 2be852b3d1c..2be852b3d1c 100644
--- a/sonar-core/src/main/resources/org/sonar/persistence/rows-derby.sql
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
diff --git a/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
index b01f46b5494..b01f46b5494 100644
--- a/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl