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

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

Introduction

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

Prototype

float JAVA_VERSION_FLOAT

To view the source code for org.apache.commons.lang SystemUtils JAVA_VERSION_FLOAT.

Click Source Link

Document

Gets the Java version as a float.

Example return values:

  • 1.2f for JDK 1.2
  • 1.31f for JDK 1.3.1

The field will return zero if #JAVA_VERSION is null.

Usage

From source file:eu.itool.glassfishmavenplugin.AbstractGlassfishMojo.java

private void checkConfig() throws MojoExecutionException, MojoFailureException {
    if (glassfishHome == null || glassfishHome.equals("ENV")) {
        if (SystemUtils.JAVA_VERSION_FLOAT < 1.5) {
            throw new MojoExecutionException(
                    "Neither GLASSFISH_HOME nor the glassfishHome configuration parameter is set! Also, to save you the trouble, JBOSS_HOME cannot be read running a VM < 1.5, so set the GlassFish Home configuration parameter or use -D.");
        }/*from   www.j a v a 2s .co m*/
        glassfishHome = System.getenv("GLASSFISH_HOME");
    }

    if (glassfishHome == null) {
        throw new MojoExecutionException(
                "Neither GLASSFISH_HOME nor the glassfishHome configuration parameter is set!");
    }

    glassfishHomeDir = new File(glassfishHome);

    if (!glassfishHomeDir.exists()) {
        throw new MojoFailureException("The glassfishHome specifed does not exist.");
    }
}

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

/**
 * Calling a {@code InterfaceMethodref} constant pool entry with {@code invokestatic}
 * is not allowed in Java 7 bytecode. It'll fail at class loading time with
 * "VerifyError: Illegal type at constant pool entry"
 *//*w w w  .  j  a  v a  2 s  . c  o m*/
@Test
public void calling_static_methods_of_library_interfaces__new_interface() {
    assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));

    thrown.expect(NoClassDefFoundError.class);
    thrown.expectMessage("java/util/stream/Stream");
    // We don't want this call to prevent loading this whole test class,
    // it should only fail when this line is executed
    Stream.of(1, 2, 3);
}

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();/*from   ww w . j av  a 2 s  . co  m*/
}

From source file:net.sf.jasperreports.soutils.EnvironmentUtils.java

/**
 * @return the Java version number as <code>float</code>. For example <code>1.5</code> for JDK
 *         1.5./*from  ww w .ja v  a 2  s. c o  m*/
 */
public static float getJavaVersion() {
    if (m_forcedJavaVersion != null) {
        return m_forcedJavaVersion;
    }
    return SystemUtils.JAVA_VERSION_FLOAT;
}

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

@Test
public void bytecode_constant_pool_will_not_contain_dangling_references_to_MethodHandles() throws IOException {
    assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.7f)));

    ClassReader cr = new ClassReader(getClass().getName().replace('.', '/'));
    char[] buf = new char[cr.getMaxStringLength()];

    for (int item = 0; item < cr.getItemCount(); item++) {
        Object constant = readConstant(item, buf, cr);
        if (constant instanceof Type) {
            Type type = (Type) constant;
            assertThat("constant #" + item, type.getDescriptor(), not(containsString("java/lang/invoke")));
        }/*from  w  w  w. j  av  a  2s  .  c  om*/
    }
}

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

/**
 * Lambdas which capture this in default methods will generate the lambda implementation
 * method as a private <em>instance</em> method. We must avoid copying those methods to
 * the interface implementers as if they were default methods.
 *///from  ww  w .j a v  a2  s .  co  m
@Test
public void default_methods_with_lambdas_in_another_package() throws Exception {
    assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));

    UsesLambdasInAnotherPackage obj = new UsesLambdasInAnotherPackage() {
    };
    assertThat(obj.stateless().call(), is("foo"));
    assertThat(obj.captureThis().call(), is("foo"));
    assertThat("should contain only delegates to the two default methods", obj.getClass().getDeclaredMethods(),
            arrayWithSize(2));
}

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

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

    class C implements Iterable<String> {
        @Override// www  .j av a 2 s. c o m
        public Iterator<String> iterator() {
            return Collections.emptyIterator();
        }
    }

    thrown.expect(NoSuchMethodError.class);
    thrown.expectMessage("spliterator");
    // Called directly on the class (invokevirtual) instead of the interface (invokeinterface),
    // to make sure that no method was inserted to the class (in which case this call would not fail)
    new C().spliterator();
}

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

/**
 * A naive method for removing method bodies would easily also remove their annotations,
 * because in ASM method annotations are expressed as calls on the MethodVisitor.
 *//*from w w w . java2  s .c om*/
@Test
@SuppressWarnings("unchecked")
public void keeps_annotations_on_interface_methods() throws Exception {
    assertThat("interface", AnnotatedInterface.class.getAnnotations(), arrayContaining(someAnnotation(1)));

    assertThat("abstract method",
            AnnotatedInterface.class.getMethod("annotatedAbstractMethod").getAnnotations(),
            arrayContaining(someAnnotation(2)));

    assertThat("default method", AnnotatedInterface.class.getMethod("annotatedDefaultMethod").getAnnotations(),
            arrayContaining(someAnnotation(3)));

    assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));
    assertThat("static method",
            companionOf(AnnotatedInterface.class).getMethod("annotatedStaticMethod").getAnnotations(),
            arrayContaining(someAnnotation(4)));
}

From source file:org.apache.maven.plugin.javadoc.AbstractJavadocMojo.java

/**
 * Set a new value for <code>fJavadocVersion</code>
 *
 * @param jExecutable not null/*  w w  w.  j  a va  2 s .c o m*/
 * @throws MavenReportException if not found
 * @see JavadocUtil#getJavadocVersion(File)
 */
private void setFJavadocVersion(File jExecutable) throws MavenReportException {
    float jVersion;
    try {
        jVersion = JavadocUtil.getJavadocVersion(jExecutable);
    } catch (IOException e) {
        if (getLog().isWarnEnabled()) {
            getLog().warn("Unable to find the javadoc version: " + e.getMessage());
            getLog().warn("Using the Java version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT);
        }
        jVersion = SystemUtils.JAVA_VERSION_FLOAT;
    } catch (CommandLineException e) {
        if (getLog().isWarnEnabled()) {
            getLog().warn("Unable to find the javadoc version: " + e.getMessage());
            getLog().warn("Using the Java the version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT);
        }
        jVersion = SystemUtils.JAVA_VERSION_FLOAT;
    } catch (IllegalArgumentException e) {
        if (getLog().isWarnEnabled()) {
            getLog().warn("Unable to find the javadoc version: " + e.getMessage());
            getLog().warn("Using the Java the version instead of, i.e. " + SystemUtils.JAVA_VERSION_FLOAT);
        }
        jVersion = SystemUtils.JAVA_VERSION_FLOAT;
    }

    if (StringUtils.isNotEmpty(javadocVersion)) {
        try {
            fJavadocVersion = Float.parseFloat(javadocVersion);
        } catch (NumberFormatException e) {
            throw new MavenReportException("Unable to parse javadoc version: " + e.getMessage(), e);
        }

        if (fJavadocVersion != jVersion && getLog().isWarnEnabled()) {
            getLog().warn("Are you sure about the <javadocVersion/> parameter? It seems to be " + jVersion);
        }
    } else {
        fJavadocVersion = jVersion;
    }
}

From source file:org.apache.maven.plugin.jdeps.AbstractJDepsMojo.java

private String getJDepsExecutable() throws IOException {
    Toolchain tc = getToolchain();//from  w  w  w  .  j a  v  a  2s.  com

    String jdepsExecutable = null;
    if (tc != null) {
        jdepsExecutable = tc.findTool("jdeps");
    }

    String jdepsCommand = "jdeps" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");

    File jdepsExe;

    if (StringUtils.isNotEmpty(jdepsExecutable)) {
        jdepsExe = new File(jdepsExecutable);

        if (jdepsExe.isDirectory()) {
            jdepsExe = new File(jdepsExe, jdepsCommand);
        }

        if (SystemUtils.IS_OS_WINDOWS && jdepsExe.getName().indexOf('.') < 0) {
            jdepsExe = new File(jdepsExe.getPath() + ".exe");
        }

        if (!jdepsExe.isFile()) {
            throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file.");
        }
        return jdepsExe.getAbsolutePath();
    }

    // ----------------------------------------------------------------------
    // Try to find jdepsExe from System.getProperty( "java.home" )
    // By default, System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME
    // should be in the JDK_HOME
    // ----------------------------------------------------------------------
    // For IBM's JDK 1.2
    if (SystemUtils.IS_OS_AIX) {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh",
                jdepsCommand);
    }
    // For Apple's JDK 1.6.x (and older?) on Mac OSX
    // CHECKSTYLE_OFF: MagicNumber
    else if (SystemUtils.IS_OS_MAC_OSX && SystemUtils.JAVA_VERSION_FLOAT < 1.7f)
    // CHECKSTYLE_ON: MagicNumber
    {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + "bin", jdepsCommand);
    } else {
        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin",
                jdepsCommand);
    }

    // ----------------------------------------------------------------------
    // Try to find jdepsExe from JAVA_HOME environment variable
    // ----------------------------------------------------------------------
    if (!jdepsExe.exists() || !jdepsExe.isFile()) {
        Properties env = CommandLineUtils.getSystemEnvVars();
        String javaHome = env.getProperty("JAVA_HOME");
        if (StringUtils.isEmpty(javaHome)) {
            throw new IOException("The environment variable JAVA_HOME is not correctly set.");
        }
        if ((!new File(javaHome).getCanonicalFile().exists())
                || (new File(javaHome).getCanonicalFile().isFile())) {
            throw new IOException("The environment variable JAVA_HOME=" + javaHome
                    + " doesn't exist or is not a valid directory.");
        }

        jdepsExe = new File(javaHome + File.separator + "bin", jdepsCommand);
    }

    if (!jdepsExe.getCanonicalFile().exists() || !jdepsExe.getCanonicalFile().isFile()) {
        throw new IOException("The jdeps executable '" + jdepsExe
                + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable.");
    }

    return jdepsExe.getAbsolutePath();
}