Example usage for org.apache.commons.lang SystemUtils isJavaVersionAtLeast

List of usage examples for org.apache.commons.lang SystemUtils isJavaVersionAtLeast

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils isJavaVersionAtLeast.

Prototype

public static boolean isJavaVersionAtLeast(int requiredVersion) 

Source Link

Document

Is the Java version at least the requested version.

Example input:

  • 120 to test for JDK 1.2 or greater
  • 131 to test for JDK 1.3.1 or greater

Usage

From source file:SystemUtilsTrial.java

public static void main(String[] args) {
    System.out.println("1) FILE_SEPARATOR =" + SystemUtils.FILE_SEPARATOR);
    System.out.println("2) JAVA_EXT_DIRS =" + SystemUtils.JAVA_EXT_DIRS);
    System.out.println("3) JAVA_HOME =" + SystemUtils.JAVA_HOME);
    System.out.println("4) Is 1.3 + =" + SystemUtils.isJavaVersionAtLeast(1.3f));
    System.out.println("5) JAVA_EXT_DIRS =" + SystemUtils.JAVA_EXT_DIRS);
    System.out.println("6) JAVA_VENDOR =" + SystemUtils.JAVA_VENDOR);
    System.out.println("7) OS_NAME =" + SystemUtils.OS_NAME);
}

From source file:net.sf.housekeeper.Housekeeper.java

/**
 * Starts the Housekeeper application with a Swing GUI.
 * //  w  w  w  .j  av a 2s.  c  om
 * @param args "--debug" enables debugging messages.
 */
public static void main(final String[] args) {
    if (!SystemUtils.isJavaVersionAtLeast(140)) {
        LogFactory.getLog(Housekeeper.class).fatal("You need at least JRE 1.4 to run Housekeeper!");
        System.exit(1);
    }
    new Housekeeper(args);
}

From source file:net.orfjackal.retrolambda.test.Java5BytecodeTest.java

@Test
public void does_not_generate_stack_map_tables_for_Java_5() throws IOException {
    String javapOutput = javap(Dummy.class);

    if (SystemUtils.isJavaVersionAtLeast(1.6f)) {
        assertThat(javapOutput, containsString("StackMap"));
    } else {//from w  w  w.  ja  v a  2s .  c o m
        assertThat(javapOutput, not(containsString("StackMap")));
    }
}

From source file:CommandLineInterpreter.java

/**
 *
 *
 * @param version/*from w w  w .j a  v a  2s. co  m*/
 */
private static boolean checkJREVersion(final float minVersion, final boolean guiAlert) {
    if (!SystemUtils.isJavaVersionAtLeast(minVersion)) {
        String message = "You need at least Java " + minVersion + " to run the application.\n"
                + "\tYour Java version is " + SystemUtils.JAVA_VERSION + ".";
        alert(message, guiAlert);
        return false;
    }
    return true;
}

From source file:net.orfjackal.retrolambda.test.TryWithResourcesTest.java

@Test
public void suppressed_exceptions() {
    Exception thrown;//w w w  . j a v a  2  s. c om
    try {
        try (ThrowSecondaryExceptionOnClose c = new ThrowSecondaryExceptionOnClose()) {
            throw new PrimaryException();
        }
    } catch (Exception e) {
        thrown = e;
    }

    assertThat("thrown", thrown, is(instanceOf(PrimaryException.class)));
    assertThat("cause", thrown.getCause(), is(nullValue()));

    // On Java 6 and lower we will swallow the suppressed exception, because the API does not exist,
    // but on Java 7 we want to keep the original behavior.
    if (SystemUtils.isJavaVersionAtLeast(1.7f)) {
        assertThat("suppressed", thrown.getSuppressed(), arrayContaining(instanceOf(SecondaryException.class)));
    }
}

From source file:net.orfjackal.retrolambda.test.InterfaceStaticMethodsTest.java

@Test
public void calling_static_methods_of_library_interfaces__new_method_on_old_interface() {
    assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));

    thrown.expect(IncompatibleClassChangeError.class);
    thrown.expectMessage(SystemUtils.isJavaVersionAtLeast(1.6f)
            ? equalTo("Found interface java.util.Comparator, but class was expected")
            : nullValue(String.class)); // on Java 5 there is no message

    // We don't want this call to prevent loading this whole test class,
    // it should only fail when this line is executed
    Comparator.naturalOrder();/*  w  w  w.  java  2 s . co  m*/
}

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathProviderImpl.java

/**
 * WORKAROUND for tomcat 5.0/jdk 1.5 problem tomcat\common\endorsed contains an xml-apis.jar needed by tomcat and
 * loaded before all xmsl stuff present in the jdk (1.4 naming problem). In the xml-apis.jar file the
 * TransformerFactoryImpl is set to "org.apache.xalan.processor.TransformerFactoryImpl" instead of
 * "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl". solution: remove the file xml-apis.jar
 * from the directory OR manually change the javax.xml.transform.TransformerFactory system property
 *//*from   www  .  j a va2 s .c  o  m*/
protected void checkXmlSettings() {
    if (SystemUtils.isJavaVersionAtLeast(1.5f) && "org.apache.xalan.processor.TransformerFactoryImpl"
            .equals(System.getProperty("javax.xml.transform.TransformerFactory"))) {

        String transformerClass = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";

        try {
            Class.forName(transformerClass);

            System.setProperty("javax.xml.transform.TransformerFactory", transformerClass);

            log.info(
                    "Java 1.5 detected, setting system property \"javax.xml.transform.TransformerFactory\" to \"{}\"",
                    transformerClass);
        } catch (Throwable e) {
            // not in the classpath. We can't assume which one to use, so just go on
        }
    }
}

From source file:be.fedict.eid.tsl.TrustServiceList.java

private boolean isJava6u18OrAbove() {
    String javaVersion = System.getProperty("java.version");
    String javaVmVersion = System.getProperty("java.vm.version");
    LOG.debug("java version: " + javaVersion);
    LOG.debug("java vm version: " + javaVmVersion);
    if (false == SystemUtils.isJavaVersionAtLeast(160)) {
        // 1.5- here
        return false;
    }// ww  w  . j  a va 2s .  c  o  m
    // 1.6+ here
    if (false == javaVersion.startsWith("1.6.0")) {
        // 1.7+ here
        return true;
    }
    // 1.6 here
    String updateVersion = javaVersion.substring("1.6.0_".length());
    LOG.debug("update version: " + updateVersion);
    if (-1 != updateVersion.indexOf("-")) {
        updateVersion = updateVersion.substring(0, updateVersion.indexOf("-"));
    }
    try {
        Integer updateVersionNumber = Integer.parseInt(updateVersion);
        LOG.debug("update version number: " + updateVersionNumber);
        if (updateVersionNumber < 18) {
            /*
             * Only from Java 6u18 we have the RSA-SHA256 XML signature algo
             * available.
             */
            return false;
        }
        return true;
    } catch (NumberFormatException e) {
        // let's give it a try in this case
        return true;
    }
}

From source file:org.apache.cocoon.components.notification.DefaultNotifyingBuilder.java

/**
 * Print stacktrace of the Throwable and stacktraces of its all nested causes into a Writer.
 *///from ww  w  .  j  av  a 2  s  .c om
private static void appendTraceChain(Writer out, Throwable t) {
    PrintWriter pw = new PrintWriter(out);
    if (SystemUtils.isJavaVersionAtLeast(140)) {
        t.printStackTrace(pw);
    } else {
        for (Throwable cause = t; cause != null; cause = ExceptionUtils.getCause(cause)) {
            if (cause != t) {
                pw.println();
            }
            cause.printStackTrace(pw);
        }
    }
}

From source file:org.apache.cocoon.generation.ExceptionGenerator.java

public static void toSAX(Throwable thr, ContentHandler handler) throws SAXException {
    Throwable root = ExceptionUtils.getRootCause(thr);
    if (root == null)
        root = thr;/*from   ww w .  j  ava  2 s. c o m*/

    AttributesImpl attr = new AttributesImpl();
    handler.startPrefixMapping("ex", EXCEPTION_NS);
    attr.addCDATAAttribute("class", root.getClass().getName());
    handler.startElement(EXCEPTION_NS, "exception-report", "ex:exception-report", attr);

    // Root exception location
    Location loc = LocationUtils.getLocation(root);
    if (LocationUtils.isKnown(loc)) {
        attr.clear();
        dumpLocation(loc, attr, handler);
    }

    // Root exception message
    attr.clear();
    String message = root instanceof LocatableException ? ((LocatableException) root).getRawMessage()
            : root.getMessage();
    simpleElement("message", attr, message, handler);

    // Cocoon stacktrace: dump all located exceptions in the exception stack
    handler.startElement(EXCEPTION_NS, "cocoon-stacktrace", "ex:cocoon-stacktrace", attr);
    Throwable current = thr;
    while (current != null) {
        loc = LocationUtils.getLocation(current);
        if (LocationUtils.isKnown(loc)) {
            // One or more locations: dump it
            handler.startElement(EXCEPTION_NS, "exception", "ex:exception", attr);

            message = current instanceof LocatableException ? ((LocatableException) current).getRawMessage()
                    : current.getMessage();
            simpleElement("message", attr, message, handler);

            attr.clear();
            handler.startElement(EXCEPTION_NS, "locations", "ex:locations", attr);
            dumpLocation(loc, attr, handler);

            if (current instanceof MultiLocatable) {
                List locations = ((MultiLocatable) current).getLocations();
                for (int i = 1; i < locations.size(); i++) { // start at 1 because we already dumped the first one
                    attr.clear();
                    dumpLocation((Location) locations.get(i), attr, handler);
                }
            }
            handler.endElement(EXCEPTION_NS, "locations", "ex:locations");
            handler.endElement(EXCEPTION_NS, "exception", "ex:exception");
        }

        // Dump parent location
        current = ExceptionUtils.getCause(current);
    }

    handler.endElement(EXCEPTION_NS, "cocoon-stacktrace", "ex:cocoon-stacktrace");

    // Root exception stacktrace
    attr.clear();
    simpleElement("stacktrace", attr, ExceptionUtils.getStackTrace(root), handler);

    // Full stack trace (if exception is chained)
    if (thr != root) {
        String trace = SystemUtils.isJavaVersionAtLeast(140) ? ExceptionUtils.getStackTrace(thr)
                : ExceptionUtils.getFullStackTrace(thr);

        simpleElement("full-stacktrace", attr, trace, handler);
    }

    handler.endElement(EXCEPTION_NS, "exception-report", "ex:exception-report");
    handler.endPrefixMapping("ex");
}