Line data Source code
1 : // Copyright (C) 2019 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.acceptance; 16 : 17 : import com.google.gerrit.extensions.events.LifecycleListener; 18 : import com.google.gerrit.index.project.ProjectIndexer; 19 : import com.google.gerrit.lifecycle.LifecycleModule; 20 : import com.google.gerrit.server.git.GitRepositoryManager; 21 : import com.google.inject.Inject; 22 : import com.google.inject.Scopes; 23 : 24 : /** Reindex all projects at Gerrit daemon startup. */ 25 : public class ReindexProjectsAtStartup implements LifecycleListener { 26 : private final ProjectIndexer projectIndexer; 27 : private final GitRepositoryManager repoMgr; 28 : 29 138 : public static class ReindexProjectsAtStartupModule extends LifecycleModule { 30 : @Override 31 : protected void configure() { 32 138 : listener().to(ReindexProjectsAtStartup.class).in(Scopes.SINGLETON); 33 138 : } 34 : } 35 : 36 : @Inject 37 138 : public ReindexProjectsAtStartup(ProjectIndexer projectIndexer, GitRepositoryManager repoMgr) { 38 138 : this.projectIndexer = projectIndexer; 39 138 : this.repoMgr = repoMgr; 40 138 : } 41 : 42 : @Override 43 : public void start() { 44 138 : repoMgr.list().stream().forEach(projectIndexer::index); 45 138 : } 46 : 47 : @Override 48 138 : public void stop() {} 49 : }