Defer loading site libraries until database opens

By deferring the library loading a new MySQL database driver can
be downloaded and the old one removed from the lib/ directory before
it is added to the current URLClassLoader. This avoids seeing the
library twice in the classpath.

Bug: issue 1870
Change-Id: I5600d6cc998aad1c702058512b3f7371d547a95e
This commit is contained in:
Shawn Pearce
2013-04-25 13:58:51 -07:00
parent 8d414da1d9
commit 39f16cbea0
8 changed files with 153 additions and 123 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.pgm.init;
import com.google.common.base.Strings;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.pgm.util.Die;
import com.google.gerrit.pgm.util.IoUtil;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
@@ -42,7 +43,6 @@ import java.security.NoSuchAlgorithmException;
class LibraryDownloader {
private final ConsoleUI ui;
private final File lib_dir;
private final ReloadSiteLibrary reload;
private boolean required;
private String name;
@@ -52,11 +52,9 @@ class LibraryDownloader {
private File dst;
@Inject
LibraryDownloader(final ReloadSiteLibrary reload, final ConsoleUI ui,
final SitePaths site) {
LibraryDownloader(ConsoleUI ui, SitePaths site) {
this.ui = ui;
this.lib_dir = site.lib_dir;
this.reload = reload;
}
void setName(final String name) {
@@ -163,7 +161,9 @@ class LibraryDownloader {
}
}
reload.reload();
if (dst.exists()) {
IoUtil.loadJARs(dst);
}
}
private void removeStaleVersions() {

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2009 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.google.gerrit.pgm.init;
/** Requests the site's {@code lib/} directory be scanned again. */
public interface ReloadSiteLibrary {
public void reload();
}