Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 1 | // 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 Kempin | 5540ae5 | 2021-11-29 09:34:55 +0100 | [diff] [blame] | 15 | @SuppressWarnings("DefaultPackage") |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 16 | public final class Main { |
Edwin Kempin | 2b81d71 | 2018-05-08 11:41:55 +0200 | [diff] [blame] | 17 | private static final String FLOGGER_BACKEND_PROPERTY = "flogger.backend_factory"; |
Edwin Kempin | d92f6f7 | 2018-08-03 09:00:08 +0200 | [diff] [blame] | 18 | private static final String FLOGGER_LOGGING_CONTEXT = "flogger.logging_context"; |
Luca Milanesio | b8a2304 | 2024-04-29 10:53:32 +0000 | [diff] [blame] | 19 | private static final Runtime.Version MIN_JAVA_VERSION = Runtime.Version.parse("17.0.5"); |
Edwin Kempin | 2b81d71 | 2018-05-08 11:41:55 +0200 | [diff] [blame] | 20 | |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 21 | // 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. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 23 | // the default package. So this is just a tiny springboard |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 24 | // to jump into the real main code. |
| 25 | // |
| 26 | |
Han-Wen Nienhuys | b0fb0a7 | 2017-06-13 18:10:03 +0200 | [diff] [blame] | 27 | public static void main(String[] argv) throws Exception { |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 28 | if (onSupportedJavaVersion()) { |
Edwin Kempin | 2b81d71 | 2018-05-08 11:41:55 +0200 | [diff] [blame] | 29 | configureFloggerBackend(); |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 30 | com.google.gerrit.launcher.GerritLauncher.main(argv); |
| 31 | |
| 32 | } else { |
| 33 | System.exit(1); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | private static boolean onSupportedJavaVersion() { |
David Ostrovsky | 98025a6 | 2023-04-24 22:01:26 +0200 | [diff] [blame] | 38 | Runtime.Version version = Runtime.version(); |
| 39 | if (version.compareTo(MIN_JAVA_VERSION) >= 0) { |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 40 | return true; |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 41 | } |
David Ostrovsky | 98025a6 | 2023-04-24 22:01:26 +0200 | [diff] [blame] | 42 | System.err.println("fatal: Gerrit Code Review requires Java " + MIN_JAVA_VERSION + " or later"); |
David Pursehouse | 3232472 | 2016-06-01 21:20:02 +0900 | [diff] [blame] | 43 | System.err.println(" (trying to run on Java " + version + ")"); |
| 44 | return false; |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Edwin Kempin | 2b81d71 | 2018-05-08 11:41:55 +0200 | [diff] [blame] | 47 | private static void configureFloggerBackend() { |
Edwin Kempin | d92f6f7 | 2018-08-03 09:00:08 +0200 | [diff] [blame] | 48 | System.setProperty( |
| 49 | FLOGGER_LOGGING_CONTEXT, "com.google.gerrit.server.logging.LoggingContext#getInstance"); |
| 50 | |
Edwin Kempin | 2b81d71 | 2018-05-08 11:41:55 +0200 | [diff] [blame] | 51 | 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 Borowitz | 292fa15 | 2016-11-13 09:56:32 -0800 | [diff] [blame] | 62 | private Main() {} |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 63 | } |