blob: e824a959961ce17f38c8d85a140a0831c99bca76 [file] [log] [blame]
Shawn O. Pearce44671f52009-11-07 12:55:26 -08001// Copyright (C) 2009 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
Edwin Kempin5540ae52021-11-29 09:34:55 +010015@SuppressWarnings("DefaultPackage")
Shawn O. Pearce44671f52009-11-07 12:55:26 -080016public final class Main {
Edwin Kempin2b81d712018-05-08 11:41:55 +020017 private static final String FLOGGER_BACKEND_PROPERTY = "flogger.backend_factory";
Edwin Kempind92f6f72018-08-03 09:00:08 +020018 private static final String FLOGGER_LOGGING_CONTEXT = "flogger.logging_context";
Luca Milanesiob8a23042024-04-29 10:53:32 +000019 private static final Runtime.Version MIN_JAVA_VERSION = Runtime.Version.parse("17.0.5");
Edwin Kempin2b81d712018-05-08 11:41:55 +020020
Shawn O. Pearce44671f52009-11-07 12:55:26 -080021 // We don't do any real work here because we need to import
22 // the archive lookup code and we cannot import a class in
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080023 // the default package. So this is just a tiny springboard
Shawn O. Pearce44671f52009-11-07 12:55:26 -080024 // to jump into the real main code.
25 //
26
Han-Wen Nienhuysb0fb0a72017-06-13 18:10:03 +020027 public static void main(String[] argv) throws Exception {
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080028 if (onSupportedJavaVersion()) {
Edwin Kempin2b81d712018-05-08 11:41:55 +020029 configureFloggerBackend();
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080030 com.google.gerrit.launcher.GerritLauncher.main(argv);
31
32 } else {
33 System.exit(1);
34 }
35 }
36
37 private static boolean onSupportedJavaVersion() {
David Ostrovsky98025a62023-04-24 22:01:26 +020038 Runtime.Version version = Runtime.version();
39 if (version.compareTo(MIN_JAVA_VERSION) >= 0) {
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080040 return true;
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080041 }
David Ostrovsky98025a62023-04-24 22:01:26 +020042 System.err.println("fatal: Gerrit Code Review requires Java " + MIN_JAVA_VERSION + " or later");
David Pursehouse32324722016-06-01 21:20:02 +090043 System.err.println(" (trying to run on Java " + version + ")");
44 return false;
Shawn O. Pearce6ee05542009-12-18 15:33:35 -080045 }
46
Edwin Kempin2b81d712018-05-08 11:41:55 +020047 private static void configureFloggerBackend() {
Edwin Kempind92f6f72018-08-03 09:00:08 +020048 System.setProperty(
49 FLOGGER_LOGGING_CONTEXT, "com.google.gerrit.server.logging.LoggingContext#getInstance");
50
Edwin Kempin2b81d712018-05-08 11:41:55 +020051 if (System.getProperty(FLOGGER_BACKEND_PROPERTY) != null) {
52 // Flogger backend is already configured
53 return;
54 }
55
56 // Configure log4j backend
57 System.setProperty(
58 FLOGGER_BACKEND_PROPERTY,
59 "com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance");
60 }
61
Dave Borowitz292fa152016-11-13 09:56:32 -080062 private Main() {}
Shawn O. Pearce44671f52009-11-07 12:55:26 -080063}