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 | |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 15 | public final class Main { |
| 16 | // We don't do any real work here because we need to import |
| 17 | // the archive lookup code and we cannot import a class in |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 18 | // the default package. So this is just a tiny springboard |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 19 | // to jump into the real main code. |
| 20 | // |
| 21 | |
David Pursehouse | d70fc02 | 2015-03-16 17:35:21 +0900 | [diff] [blame] | 22 | public static void main(final String[] argv) throws Exception { |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 23 | if (onSupportedJavaVersion()) { |
| 24 | com.google.gerrit.launcher.GerritLauncher.main(argv); |
| 25 | |
| 26 | } else { |
| 27 | System.exit(1); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | private static boolean onSupportedJavaVersion() { |
| 32 | final String version = System.getProperty("java.specification.version"); |
David Ostrovsky | 3931c16 | 2014-06-15 00:33:40 +0200 | [diff] [blame] | 33 | if (1.8 <= parse(version)) { |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 34 | return true; |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 35 | } |
David Ostrovsky | 3931c16 | 2014-06-15 00:33:40 +0200 | [diff] [blame] | 36 | System.err.println("fatal: Gerrit Code Review requires Java 8 or later"); |
David Pursehouse | 3232472 | 2016-06-01 21:20:02 +0900 | [diff] [blame] | 37 | System.err.println(" (trying to run on Java " + version + ")"); |
| 38 | return false; |
Shawn O. Pearce | 6ee0554 | 2009-12-18 15:33:35 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | private static double parse(String version) { |
| 42 | if (version == null || version.length() == 0) { |
| 43 | return 0.0; |
| 44 | } |
| 45 | |
| 46 | try { |
| 47 | final int fd = version.indexOf('.'); |
| 48 | final int sd = version.indexOf('.', fd + 1); |
| 49 | if (0 < sd) { |
| 50 | version = version.substring(0, sd); |
| 51 | } |
| 52 | return Double.parseDouble(version); |
| 53 | } catch (NumberFormatException e) { |
| 54 | return 0.0; |
| 55 | } |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Dave Borowitz | 292fa15 | 2016-11-13 09:56:32 -0800 | [diff] [blame] | 58 | private Main() {} |
Shawn O. Pearce | 44671f5 | 2009-11-07 12:55:26 -0800 | [diff] [blame] | 59 | } |