Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.httpd.plugins; 16 : 17 : import com.google.gerrit.extensions.api.lfs.LfsDefinitions; 18 : import com.google.gerrit.httpd.resources.Resource; 19 : import com.google.gerrit.httpd.resources.ResourceKey; 20 : import com.google.gerrit.httpd.resources.ResourceWeigher; 21 : import com.google.gerrit.server.cache.CacheModule; 22 : import com.google.gerrit.server.plugins.ModuleGenerator; 23 : import com.google.gerrit.server.plugins.ReloadPluginListener; 24 : import com.google.gerrit.server.plugins.StartPluginListener; 25 : import com.google.inject.internal.UniqueAnnotations; 26 : import com.google.inject.servlet.ServletModule; 27 : 28 99 : public class HttpPluginModule extends ServletModule { 29 : static final String PLUGIN_RESOURCES = "plugin_resources"; 30 : 31 : @Override 32 : protected void configureServlets() { 33 99 : bind(HttpPluginServlet.class); 34 99 : serveRegex("^/(?:a/)?plugins/(.*)?$").with(HttpPluginServlet.class); 35 : 36 99 : bind(LfsPluginServlet.class); 37 99 : serveRegex(LfsDefinitions.LFS_URL_REGEX).with(LfsPluginServlet.class); 38 : 39 99 : bind(StartPluginListener.class) 40 99 : .annotatedWith(UniqueAnnotations.create()) 41 99 : .to(HttpPluginServlet.class); 42 : 43 99 : bind(ReloadPluginListener.class) 44 99 : .annotatedWith(UniqueAnnotations.create()) 45 99 : .to(HttpPluginServlet.class); 46 : 47 99 : bind(StartPluginListener.class) 48 99 : .annotatedWith(UniqueAnnotations.create()) 49 99 : .to(LfsPluginServlet.class); 50 : 51 99 : bind(ReloadPluginListener.class) 52 99 : .annotatedWith(UniqueAnnotations.create()) 53 99 : .to(LfsPluginServlet.class); 54 : 55 99 : bind(ModuleGenerator.class).to(HttpAutoRegisterModuleGenerator.class); 56 : 57 99 : install( 58 99 : new CacheModule() { 59 : @Override 60 : protected void configure() { 61 99 : cache(PLUGIN_RESOURCES, ResourceKey.class, Resource.class) 62 99 : .maximumWeight(2 << 20) 63 99 : .weigher(ResourceWeigher.class); 64 99 : } 65 : }); 66 99 : } 67 : }