Revert "Javamelody: Enable monitoring of SQL activity"

This reverts commit 8c5d68b266cf6cea0388bc503fb82098bd2f3599.

Change-Id: I7a5b0eb31c6c54b27916c28ae0174f4420592216
diff --git a/BUCK b/BUCK
index d636c32..cd52cd5 100644
--- a/BUCK
+++ b/BUCK
@@ -1,45 +1,15 @@
-INTERCEPTOR = ['src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java']
-SRCS = glob(['src/main/java/**/*.java'], excludes = INTERCEPTOR)
-RSRC = glob(['src/main/resources/**/*'])
-DEPS = [
-  '//plugins/javamelody/lib:javamelody',
-  '//plugins/javamelody/lib:jrobin',
-]
-
-manifest_entries = [
-  'Gerrit-PluginName: javamelody',
-  'Gerrit-Module: com.googlesource.gerrit.plugins.javamelody.Module',
-  'Gerrit-HttpModule: com.googlesource.gerrit.plugins.javamelody.HttpModule',
-]
-
 gerrit_plugin(
   name = 'javamelody',
-  srcs = SRCS,
-  resources = RSRC,
-  manifest_entries = manifest_entries,
-  deps = DEPS,
+  srcs = glob(['src/main/java/**/*.java']),
+  resources = glob(['src/main/resources/**/*']),
+  manifest_entries = [
+    'Gerrit-PluginName: javamelody',
+    'Gerrit-Module: com.googlesource.gerrit.plugins.javamelody.Module',
+    'Gerrit-HttpModule: com.googlesource.gerrit.plugins.javamelody.HttpModule',
+  ],
+  deps = [
+    '//plugins/javamelody/lib:javamelody',
+    '//plugins/javamelody/lib:jrobin',
+  ],
 )
 
-gerrit_plugin(
-  name = 'javamelody-nodep',
-  srcs = SRCS,
-  resources = RSRC,
-  manifest_entries = manifest_entries,
-  compile_deps = DEPS,
-)
-
-java_binary(
-  name = 'javamelody-deps',
-  deps = DEPS,
-)
-
-java_binary(
-  name = 'javamelody-datasource-interceptor',
-  deps = [':javamelody-datasource-interceptor-lib'],
-)
-
-java_library2(
-  name = 'javamelody-datasource-interceptor-lib',
-  srcs = INTERCEPTOR,
-  compile_deps = DEPS + ['//gerrit-extension-api:lib'],
-)
\ No newline at end of file
diff --git a/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java b/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java
deleted file mode 100644
index 3ea3a98..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.javamelody;
-
-import javax.sql.DataSource;
-
-import net.bull.javamelody.JdbcWrapper;
-
-import com.google.gerrit.extensions.persistence.DataSourceInterceptor;
-
-public class MonitoringDataSourceInterceptor implements DataSourceInterceptor {
-
-  @Override
-  public DataSource intercept(String name, DataSource dataSource) {
-    return JdbcWrapper.SINGLETON.createDataSourceProxy(name, dataSource);
-  }
-}
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index b4a8dd6..9e3e4f3 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -9,29 +9,12 @@
   buck build plugins/javamelody:javamelody
 ```
 
-If [database interception](database-monitoring.html) should be activated,
-then the following targets must be used instead:
-
-```
-  buck build plugins/javamelody:javamelody-nodep
-  buck build plugins/javamelody:javamelody-deps
-  buck build plugins/javamelody:javamelody-datasource-interceptor
-```
-
-The output from the former target is:
+The output is created in
 
 ```
   buck-out/gen/plugins/javamelody/javamelody.jar
 ```
 
-The output from the later targets are:
-
-```
-  buck-out/gen/plugins/javamelody/javamelody-nodep.jar
-  buck-out/gen/plugins/javamelody/javamelody-deps.jar
-  buck-out/gen/plugins/javamelody/javamelody-datasource-interceptor.jar
-```
-
 This project can be imported into the Eclipse IDE:
 
 ```
diff --git a/src/main/resources/Documentation/database-monitoring.md b/src/main/resources/Documentation/database-monitoring.md
index 943d791..09ec050 100644
--- a/src/main/resources/Documentation/database-monitoring.md
+++ b/src/main/resources/Documentation/database-monitoring.md
@@ -1,60 +1,68 @@
 Database-Monitoring
 ===================
 
-JavaMelody supports out of the box JNDI DataSource in Web container (Tomcat).
+This feature is experimental and is not supported out of the box for Gerrit
+monitoring on Jetty.
+
+Background: JavaMelody only supports JNDI DataSource in Web container (Tomcat).
 Because Gerrit instantiates its data source on its own, JavaMelody can not
 intercept it and therefore no SQL statistic reports can be gathered.
 
-To overcome that problem a data source proxy must be installed.
+To overcome that problem a data source proxy must be installed. Because the
+instantiation of the data source takes place in Gerrit core, it must be patched.
 
-Datasource interceptor JAR (that creates the data source proxy) must be
-available in the bootstrap classpath for Gerrit core to load it. Moreover,
-because the interceptor depends on javamelody core library, it must be
-provided in the bootstrap classpath too. In this case the plugin must
-not contain the javamelody core library (shaded jar).
+Next problem: JavaMelody JARs (that creates the data source proxies) must be
+available in the bootstrap classpath for Gerrit core to load it.
 
-Thus the javamelody dependencies must not be packaged in the plugin itself.
+Last problem: we shouldn't package the plugin dependencies inside the
+plugin itself (shaded jar in Maven jargon) and in $gerrit_site/lib. We would
+need to strip it from the plugin.
 
-Add the following line to `$gerrit_site/etc/gerrit.config` under `database` section:
+Cherry-pick this change and compile Gerrit:
+
+https://gerrit-review.googlesource.com/#/c/52747
+
+Add the following target to BUCK in javamelody plugin:
 
 ```
-dataSourceInterceptorClass = com.googlesource.gerrit.plugins.javamelody.MonitoringDataSourceInterceptor
+gerrit_plugin(
+  name = 'javamelody-no-deps',
+  srcs = glob(['src/main/java/**/*.java']),
+  resources = glob(['src/main/resources/**/*']),
+  manifest_entries = [
+    'Gerrit-PluginName: javamelody',
+    'Gerrit-Module: com.googlesource.gerrit.plugins.javamelody.Module',
+    'Gerrit-HttpModule: com.googlesource.gerrit.plugins.javamelody.HttpModule',
+  ],
+  compile_deps = [
+    '//plugins/javamelody/lib:javamelody',
+    '//plugins/javamelody/lib:jrobin',
+  ],
+)
 ```
 
 Compile the plugin without dependencies:
 
 ```
-buck build plugins/javamelody:javamelody-nodep
+buck build plugins/javamelody:javamelody-no-deps
 ```
 
-Compile the plugin dependencies:
+Copy the dependencies manually to $gerrit_site/libs:
 
 ```
-buck build plugins/javamelody:javamelody-deps
-```
-
-Compile datasource interceptor:
+cp
+~/.gerritcodereview/buck-cache/jrobin-1.5.9.jar-bd9a84484c67de930fa841f23cd6a93108b05cd0
+$gerrit_site/lib/jrobin.jar
+cp
+~/.gerritcodereview/buck-cache/javamelody-core-1.48.0.jar-4c573306061019430a735d9d58f93639f4a0ff0b
+$gerrit_site/lib/javamelody.jar
 
 ```
-buck build plugins/javamelody:javamelody-datasource-interceptor
-```
 
-Deploy the datasource-interceptor to `$gerrit_site/libs`:
+Deploy plugin without dependencies:
 
 ```
-cp buck-out/gen/plugins/javamelody/javamelody-datasource-interceptor.jar `$gerrit_site/libs`
-```
-
-Deploy the javamelody dependencies to `$gerrit_site/libs`:
-
-```
-cp buck-out/gen/plugins/javamelody/javamelody-deps.jar `$gerrit_site/libs`
-```
-
-Deploy the plugin without dependencies:
-
-```
-cp buck-out/gen/plugins/javamelody/javamelody-nodep.jar `$gerrit_site/plugins`
+cp buck-out/gen/plugins/javamelody/javamelody-no-deps.jar $gerrit_site/plugins
 ```
 
 Run Gerrit@Jetty and enjoy SQL statistics, a lá: