List of usage examples for org.apache.commons.lang3 SystemUtils isJavaVersionAtLeast
public static boolean isJavaVersionAtLeast(final JavaVersion requiredVersion)
Is the Java version at least the requested version.
From source file:de.undercouch.citeproc.script.JREScriptRunnerTestSuite.java
/** * Sets the runner to use//from ww w . j av a 2 s. com */ @BeforeClass public static void setUp() { if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_7)) { //don't use the JRE runner with Java 1.6. It would fail anyway. prev = ScriptRunnerFactory.setRunnerType(RunnerType.AUTO); } else { prev = ScriptRunnerFactory.setRunnerType(RunnerType.JRE); } }
From source file:com.github.shredder121.testannotations.timezone.TimeZoneRule.java
private static TimeZone parseToTimeZone(TimeZoneTest timeZone) { String id = timeZone.value(); if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) { return getTimeZoneJavaTime(id); } else {/*from ww w. j ava 2 s . c om*/ return getTimeZoneLegacy(id); } }
From source file:de.undercouch.citeproc.script.ScriptRunnerFactory.java
/** * @return a {@link ScriptRunner} that uses the Rhino embedded into the JRE */// ww w. j a va 2 s .c om private static ScriptRunner createJreRunner() { //Rhino is not available. Check if we have the right JRE version if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_7)) { throw new RuntimeException("You're using a JRE 6 or lower and " + "Mozilla Rhino was not found in the classpath. The " + "bundled Rhino in JRE 6 does not support E4X " + "(ECMAScript for XML) which is needed for " + "citeproc-java. Either include Rhino in your " + "classpath or upgrade to a newer JRE."); } return new JREScriptRunner(); }
From source file:bear.core.BearMain.java
public static boolean hasFx() { return SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_7); }
From source file:com.fireball1725.firelib.FireMod.java
@Mod.EventHandler public final void preInit(FMLPreInitializationEvent event) { final Stopwatch stopwatch = Stopwatch.createStarted(); this.getLogger().info("Pre Initialization (Started)"); // Check java version to make sure we are on Java 1.8 if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) { //throw new OutdatedJavaException(String.format("%s requires Java 8 or newer, Please update your java", ModInfo.MOD_NAME)); }/*from ww w. j a v a2s . c o m*/ this.proxy().registerEventHandler(this); proxy().initConfiguration(event); proxy().preInitStart(event); proxy().registerEventHandler(new RegistrationHelper(this)); proxy().preInitEnd(event); this.getLogger() .info("Pre Initialization (Ended after " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms)"); }
From source file:com.google.code.jconfig.ConfigurationManager.java
private ConfigurationManager(Map<String, IConfigurationChangeListener> listeners, String filepath) { logger.debug("Running on machine with Java version: " + SystemUtils.JAVA_RUNTIME_VERSION); if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)) { logger.fatal("Current Java version: " + SystemUtils.JAVA_RUNTIME_VERSION + " - NEEDED " + JavaVersion.JAVA_1_5 + " or above."); throw new RuntimeException("You must have at leat Java 1.5 using this library."); }//from w ww.ja v a 2 s.c o m logger.info("******* ConfigurationManager initialization *******"); logger.info(" -> configuration: " + filepath); logger.info(" -> registered listeners: " + listeners); logger.info("***************************************************"); this.filepath = filepath; activeListeners = listeners; currentConfigurationInfo = new ConfigurationInfo(); }
From source file:de.undercouch.citeproc.script.ScriptRunnerBenchmark.java
/** * Tests the JRE script runner/*from ww w.j av a 2s .c o m*/ * @throws Exception if something goes wrong */ @BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 1) @Test public void jre() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_7)) { //skip test for Java 1.6. It would fail anyway return; } RunnerType prev = ScriptRunnerFactory.setRunnerType(RunnerType.JRE); try { runTest(); } finally { ScriptRunnerFactory.setRunnerType(prev); } }
From source file:objenome.util.ClassUtils.java
/** * <p>Checks if an array of Classes can be assigned to another array of Classes.</p> * * <p>This method calls {@link #isAssignable(Class, Class) isAssignable} for each * Class pair in the input arrays. It can be used to check if a set of arguments * (the first parameter) are suitably compatible with a set of method parameter types * (the second parameter).</p>//from w ww. j a v a 2 s. c om * * <p>Unlike the {@link Class#isAssignableFrom(Class)} method, this * method takes into account widenings of primitive classes and * {@code null}s.</p> * * <p>Primitive widenings allow an int to be assigned to a {@code long}, * {@code float} or {@code double}. This method returns the correct * result for these cases.</p> * * <p>{@code Null} may be assigned to any reference type. This method will * return {@code true} if {@code null} is passed in and the toClass is * non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>, * sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * <p><strong>Since Lang 3.0,</strong> this method will default behavior for * calculating assignability between primitive and wrapper types <em>corresponding * to the running Java version</em>; i.e. autoboxing will be the default * behavior in VMs running Java versions > 1.5.</p> * * @param classArray the array of Classes to check, may be {@code null} * @param toClassArray the array of Classes to try to assign into, may be {@code null} * @return {@code true} if assignment possible */ public static boolean isAssignable(Class<?>[] classArray, Class<?>... toClassArray) { return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); }
From source file:objenome.util.ClassUtils.java
/** * <p>Checks if one {@code Class} can be assigned to a variable of * another {@code Class}.</p>//from w w w.j av a2 s. c o m * * <p>Unlike the {@link Class#isAssignableFrom(Class)} method, * this method takes into account widenings of primitive classes and * {@code null}s.</p> * * <p>Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases.</p> * * <p>{@code Null} may be assigned to any reference type. This method * will return {@code true} if {@code null} is passed in and the * toClass is non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>, * sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * <p><strong>Since Lang 3.0,</strong> this method will default behavior for * calculating assignability between primitive and wrapper types <em>corresponding * to the running Java version</em>; i.e. autoboxing will be the default * behavior in VMs running Java versions > 1.5.</p> * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @return {@code true} if assignment possible */ public static boolean isAssignable(Class<?> cls, Class<?> toClass) { return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); }
From source file:org.apache.maven.cli.transfer.FileSizeFormatTest.java
@Test public void testSizeWithSelectedScaleUnit() { FileSizeFormat format = new FileSizeFormat(Locale.ENGLISH); long _0_bytes = 0L; assertEquals("0 B", format.format(_0_bytes)); assertEquals("0 B", format.format(_0_bytes, ScaleUnit.BYTE)); assertEquals("0 kB", format.format(_0_bytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_0_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_0_bytes, ScaleUnit.GIGABYTE)); long _5_bytes = 5L; assertEquals("5 B", format.format(_5_bytes)); assertEquals("5 B", format.format(_5_bytes, ScaleUnit.BYTE)); assertEquals("0 kB", format.format(_5_bytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_5_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_5_bytes, ScaleUnit.GIGABYTE)); long _49_bytes = 49L; assertEquals("49 B", format.format(_49_bytes)); assertEquals("49 B", format.format(_49_bytes, ScaleUnit.BYTE)); assertEquals("0 kB", format.format(_49_bytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_49_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_49_bytes, ScaleUnit.GIGABYTE)); long _50_bytes = 50L; assertEquals("50 B", format.format(_50_bytes)); assertEquals("50 B", format.format(_50_bytes, ScaleUnit.BYTE)); if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) { assertEquals("0.1 kB", format.format(_50_bytes, ScaleUnit.KILOBYTE)); }/*from w w w . j av a2 s . co m*/ assertEquals("0 MB", format.format(_50_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_50_bytes, ScaleUnit.GIGABYTE)); long _999_bytes = 999L; assertEquals("999 B", format.format(_999_bytes)); assertEquals("999 B", format.format(_999_bytes, ScaleUnit.BYTE)); assertEquals("1.0 kB", format.format(_999_bytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_999_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_999_bytes, ScaleUnit.GIGABYTE)); long _1000_bytes = 1000L; assertEquals("1.0 kB", format.format(_1000_bytes)); assertEquals("1000 B", format.format(_1000_bytes, ScaleUnit.BYTE)); assertEquals("1.0 kB", format.format(_1000_bytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_1000_bytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_1000_bytes, ScaleUnit.GIGABYTE)); long _49_kilobytes = 49L * 1000L; assertEquals("49 kB", format.format(_49_kilobytes)); assertEquals("49000 B", format.format(_49_kilobytes, ScaleUnit.BYTE)); assertEquals("49 kB", format.format(_49_kilobytes, ScaleUnit.KILOBYTE)); assertEquals("0 MB", format.format(_49_kilobytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_49_kilobytes, ScaleUnit.GIGABYTE)); long _50_kilobytes = 50L * 1000L; assertEquals("50 kB", format.format(_50_kilobytes)); assertEquals("50000 B", format.format(_50_kilobytes, ScaleUnit.BYTE)); assertEquals("50 kB", format.format(_50_kilobytes, ScaleUnit.KILOBYTE)); if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) { assertEquals("0.1 MB", format.format(_50_kilobytes, ScaleUnit.MEGABYTE)); } assertEquals("0 GB", format.format(_50_kilobytes, ScaleUnit.GIGABYTE)); long _999_kilobytes = 999L * 1000L; assertEquals("999 kB", format.format(_999_kilobytes)); assertEquals("999000 B", format.format(_999_kilobytes, ScaleUnit.BYTE)); assertEquals("999 kB", format.format(_999_kilobytes, ScaleUnit.KILOBYTE)); assertEquals("1.0 MB", format.format(_999_kilobytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_999_kilobytes, ScaleUnit.GIGABYTE)); long _1000_kilobytes = 1000L * 1000L; assertEquals("1.0 MB", format.format(_1000_kilobytes)); assertEquals("1000000 B", format.format(_1000_kilobytes, ScaleUnit.BYTE)); assertEquals("1000 kB", format.format(_1000_kilobytes, ScaleUnit.KILOBYTE)); assertEquals("1.0 MB", format.format(_1000_kilobytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_1000_kilobytes, ScaleUnit.GIGABYTE)); long _49_megabytes = 49L * 1000L * 1000L; assertEquals("49 MB", format.format(_49_megabytes)); assertEquals("49000000 B", format.format(_49_megabytes, ScaleUnit.BYTE)); assertEquals("49000 kB", format.format(_49_megabytes, ScaleUnit.KILOBYTE)); assertEquals("49 MB", format.format(_49_megabytes, ScaleUnit.MEGABYTE)); assertEquals("0 GB", format.format(_49_megabytes, ScaleUnit.GIGABYTE)); long _50_megabytes = 50L * 1000L * 1000L; assertEquals("50 MB", format.format(_50_megabytes)); assertEquals("50000000 B", format.format(_50_megabytes, ScaleUnit.BYTE)); assertEquals("50000 kB", format.format(_50_megabytes, ScaleUnit.KILOBYTE)); assertEquals("50 MB", format.format(_50_megabytes, ScaleUnit.MEGABYTE)); if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) { assertEquals("0.1 GB", format.format(_50_megabytes, ScaleUnit.GIGABYTE)); } long _999_megabytes = 999L * 1000L * 1000L; assertEquals("999 MB", format.format(_999_megabytes)); assertEquals("999000000 B", format.format(_999_megabytes, ScaleUnit.BYTE)); assertEquals("999000 kB", format.format(_999_megabytes, ScaleUnit.KILOBYTE)); assertEquals("999 MB", format.format(_999_megabytes, ScaleUnit.MEGABYTE)); assertEquals("1.0 GB", format.format(_999_megabytes, ScaleUnit.GIGABYTE)); long _1000_megabytes = 1000L * 1000L * 1000L; assertEquals("1.0 GB", format.format(_1000_megabytes)); assertEquals("1000000000 B", format.format(_1000_megabytes, ScaleUnit.BYTE)); assertEquals("1000000 kB", format.format(_1000_megabytes, ScaleUnit.KILOBYTE)); assertEquals("1000 MB", format.format(_1000_megabytes, ScaleUnit.MEGABYTE)); assertEquals("1.0 GB", format.format(_1000_megabytes, ScaleUnit.GIGABYTE)); }