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

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

Introduction

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

Prototype

String JAVA_VERSION

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

Click Source Link

Document

The java.version System Property.

Usage

From source file:io.pcp.parfait.benchmark.ReportHelper.java

static void environmentReportHeader() {
    String hostName = getCurrentHostname();
    System.out.printf("Host: %s\tJava: %s\n", hostName, SystemUtils.JAVA_VERSION);
}

From source file:CommandLineInterpreter.java

/**
 *
 *
 * @param version/*from  w w  w  . j  a va2 s  .c om*/
 */
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:com.cloudera.cdk.morphline.solr.EnvironmentTest.java

@Test
public void testEnvironment() throws UnknownHostException {
    System.out.println("EXPECTED_SOLR_VERSION: " + EXPECTED_SOLR_VERSION);

    System.out.println("Running test suite with java version: " + SystemUtils.JAVA_VERSION + " "
            + SystemUtils.JAVA_VM_NAME + " on " + SystemUtils.OS_NAME + " " + SystemUtils.OS_VERSION + "/"
            + SystemUtils.OS_ARCH + " on host: " + InetAddress.getLocalHost().getHostName());

    Package p = SolrCore.class.getPackage();
    System.out.println("Running test suite with solr-spec-version: " + p.getSpecificationVersion()
            + ", solr-impl-version: " + p.getImplementationVersion());
    if (EXPECTED_SOLR_VERSION != null) {
        assertTrue("unexpected version: " + p.getSpecificationVersion(),
                p.getSpecificationVersion().startsWith(EXPECTED_SOLR_VERSION));
        assertTrue("unexpected version: " + p.getImplementationVersion(),
                p.getImplementationVersion().startsWith(EXPECTED_SOLR_VERSION));
    }// w  w w.j a v a  2  s  . c o m

    p = LucenePackage.class.getPackage();
    System.out.println("Running test suite with lucene-spec-version: " + p.getSpecificationVersion()
            + ", lucene-impl-version: " + p.getImplementationVersion());
    if (EXPECTED_SOLR_VERSION != null) {
        assertTrue("unexpected version: " + p.getSpecificationVersion(),
                p.getSpecificationVersion().startsWith(EXPECTED_SOLR_VERSION));
        assertTrue("unexpected version: " + p.getImplementationVersion(),
                p.getImplementationVersion().startsWith(EXPECTED_SOLR_VERSION));

        Version expectedMinorLuceneVersion = getMinorLuceneVersion(EXPECTED_SOLR_VERSION);
        System.out.println("expectedMinorLuceneVersion: " + expectedMinorLuceneVersion);
        assertTrue(Version.LUCENE_CURRENT.onOrAfter(expectedMinorLuceneVersion));
    }
}

From source file:com.yahoo.flowetl.commons.runner.Main.java

/**
 * Gets some useful runtime info as a map of names -> info.
 */// w w  w. j  a  v a 2s. c o  m
private static Map<String, Object> getRuntimeInfo() {
    Map<String, Object> sysInfo = new TreeMap<String, Object>();
    StringBuilder jvminfo = new StringBuilder();
    jvminfo.append("Vendor: ");
    jvminfo.append(SystemUtils.JAVA_VENDOR);
    jvminfo.append(", Version: ");
    jvminfo.append(SystemUtils.JAVA_VERSION + " - " + SystemUtils.JAVA_VM_INFO);
    jvminfo.append(", OS: ");
    jvminfo.append(SystemUtils.OS_NAME + " (" + SystemUtils.OS_VERSION + " : " + SystemUtils.OS_ARCH + ")");
    sysInfo.put(WordUtils.capitalizeFully("jvm"), jvminfo.toString());
    sysInfo.put(WordUtils.capitalizeFully("default charset encoding"), DEF_CHAR_SET.name());
    String netAdd = NetUtils.getLocalAddress();
    if (StringUtils.isEmpty(netAdd)) {
        netAdd = "????";
    }
    String localName = NetUtils.getLocalHostName();
    if (StringUtils.isEmpty(localName)) {
        localName = "????";
    }
    sysInfo.put(WordUtils.capitalizeFully("network"), localName + " at ip address " + netAdd);
    String cPath = SystemUtils.JAVA_CLASS_PATH;
    String linesep = StringEscapeUtils.escapeJava(SystemUtils.LINE_SEPARATOR);
    sysInfo.put(WordUtils.capitalizeFully("classpath"), cPath);
    sysInfo.put(WordUtils.capitalizeFully("jvm home"), SystemUtils.JAVA_HOME);
    sysInfo.put(WordUtils.capitalizeFully("jvm tmpdir"), SystemUtils.JAVA_IO_TMPDIR);
    sysInfo.put(WordUtils.capitalizeFully("jvm libpath"), SystemUtils.JAVA_LIBRARY_PATH);
    sysInfo.put(WordUtils.capitalizeFully("line separator"), linesep);
    sysInfo.put(WordUtils.capitalizeFully("path separator"),
            StringEscapeUtils.escapeJava(SystemUtils.PATH_SEPARATOR));
    sysInfo.put(WordUtils.capitalizeFully("user timezone"), SystemUtils.USER_TIMEZONE);
    sysInfo.put(WordUtils.capitalizeFully("user home"), SystemUtils.USER_HOME);
    sysInfo.put(WordUtils.capitalizeFully("user language"), SystemUtils.USER_LANGUAGE);
    sysInfo.put(WordUtils.capitalizeFully("user name"), SystemUtils.USER_NAME);
    return sysInfo;
}

From source file:net.java.jpatch.maven.ReleaseMojo.java

/**
 * Creates the release package.//ww  w. ja  va  2  s . c o m
 * 
 * @throws MojoExecutionException if the method fails.
 * @throws MojoFailureException if the method fails.
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    // Search for existing release
    Artifact releaseArtifact = resolveReleaseArtifact();
    File releaseFile = releaseArtifact.getFile();

    // Check existing release
    if (releaseFile != null && releaseFile.exists()) {
        getLog().info(releaseFile.getAbsolutePath());
        getLog().error("Release file already exist! For new release execute first jpatch:release-clean.");
        throw new MojoFailureException("Release package already exist!");
    }

    // Create release directory
    File directory = createTargetDirectory(releaseArtifact.getVersion());

    // Create release properties file.
    Properties releaseProperties = new Properties();

    // Load projects
    List<MavenProject> mavenProjects = loadMavenProjects();

    // Filter the projects
    List<MavenProject> filterProjects = filterMavenProjects(mavenProjects, getPackages());

    // Unpack the libraries in the output directory
    for (MavenProject project : filterProjects) {

        String revision = scmRevision(project);
        releaseProperties.setProperty(project.getId(), revision);

        Artifact artifact = project.getArtifact();
        resolveArtifactFromLocalRepository(artifact);
        unpackArtifactFile(directory, artifact.getFile());
    }

    // Setup the advanced properties to the release property
    SimpleDateFormat sdf = new SimpleDateFormat();
    releaseProperties.put(RELEASE_PROPERTY_DATE, sdf.format(new Date()));
    releaseProperties.put(RELEASE_PROPERTY_USER_NAME, SystemUtils.USER_NAME);
    releaseProperties.put(RELEASE_PROPERTY_JAVA_VERSION, SystemUtils.JAVA_VERSION);
    releaseProperties.put(RELEASE_PROPERTY_OS_NAME, SystemUtils.OS_NAME);

    // Save release properties file
    try {
        File propFile = new File(mavenProject.getBuild().getDirectory(),
                mavenProject.getBuild().getFinalName() + ".properties");
        releaseProperties.store(new FileOutputStream(propFile), null);
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating the release properties file!", e);
    }

    // Create package file
    String fileName = mavenProject.getBuild().getFinalName();
    File packFile = new File(mavenProject.getBuild().getDirectory(), fileName + ".zip");
    packDirectory(directory, packFile);

    // Attached the package to the project
    releaseArtifact.setFile(packFile);
    mavenProject.addAttachedArtifact(releaseArtifact);

    // Create build file (project.jpatch)
    createBuildFile();
}

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

private void genVMStatus() throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    startGroup("VM");

    // BEGIN ClassPath
    String classpath = SystemUtils.JAVA_CLASS_PATH;
    if (classpath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(classpath, SystemUtils.PATH_SEPARATOR);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }/* ww  w  .j  a  va2s. c o  m*/
        addMultilineValue("classpath", paths);
    }
    // END ClassPath

    // BEGIN CONTEXT CLASSPATH
    String contextClassPath = null;
    try {
        contextClassPath = (String) this.context.get(Constants.CONTEXT_CLASSPATH);
    } catch (ContextException e) {
        // we ignore this
    }
    if (contextClassPath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(contextClassPath, File.pathSeparator);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }
        addMultilineValue("context-classpath", paths);
    }
    // END CONTEXT CLASSPATH

    // BEGIN Memory status
    startGroup("Memory");
    final long totalMemory = Runtime.getRuntime().totalMemory();
    final long freeMemory = Runtime.getRuntime().freeMemory();
    addValue("total", String.valueOf(totalMemory));
    addValue("used", String.valueOf(totalMemory - freeMemory));
    addValue("free", String.valueOf(freeMemory));
    endGroup();
    // END Memory status

    // BEGIN JRE
    startGroup("JRE");
    addValue("version", SystemUtils.JAVA_VERSION);
    atts.clear();
    // qName = prefix + ':' + localName
    atts.addAttribute(XLINK_NS, "type", XLINK_PREFIX + ":type", "CDATA", "simple");
    atts.addAttribute(XLINK_NS, "href", XLINK_PREFIX + ":href", "CDATA", SystemUtils.JAVA_VENDOR_URL);
    addValue("java-vendor", SystemUtils.JAVA_VENDOR, atts);
    endGroup();
    // END JRE

    // BEGIN Operating system
    startGroup("Operating System");
    addValue("name", SystemUtils.OS_NAME);
    addValue("architecture", SystemUtils.OS_ARCH);
    addValue("version", SystemUtils.OS_VERSION);
    endGroup();
    // END operating system

    // BEGIN Cache
    if (this.storeJanitor != null) {
        startGroup("Store Janitor");

        // For each element in StoreJanitor
        Iterator i = this.storeJanitor.iterator();
        while (i.hasNext()) {
            Store store = (Store) i.next();
            startGroup(
                    store.getClass().getName() + " (hash = 0x" + Integer.toHexString(store.hashCode()) + ")");
            int size = 0;
            int empty = 0;
            atts.clear();
            atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
            super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

            atts.clear();
            Enumeration e = store.keys();
            while (e.hasMoreElements()) {
                size++;
                Object key = e.nextElement();
                Object val = store.get(key);
                String line;
                if (val == null) {
                    empty++;
                } else {
                    line = key + " (class: " + val.getClass().getName() + ")";
                    super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                    super.contentHandler.characters(line.toCharArray(), 0, line.length());
                    super.contentHandler.endElement(NAMESPACE, "line", "line");
                }
            }
            if (size == 0) {
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                String value = "[empty]";
                super.contentHandler.characters(value.toCharArray(), 0, value.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
            super.contentHandler.endElement(NAMESPACE, "value", "value");

            addValue("size", String.valueOf(size) + " items in cache (" + empty + " are empty)");
            endGroup();
        }
        endGroup();
    }

    if (this.storePersistent != null) {
        startGroup(storePersistent.getClass().getName() + " (hash = 0x"
                + Integer.toHexString(storePersistent.hashCode()) + ")");
        int size = 0;
        int empty = 0;
        atts.clear();
        atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
        super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

        atts.clear();
        Enumeration e = this.storePersistent.keys();
        while (e.hasMoreElements()) {
            size++;
            Object key = e.nextElement();
            Object val = storePersistent.get(key);
            String line;
            if (val == null) {
                empty++;
            } else {
                line = key + " (class: " + val.getClass().getName() + ")";
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                super.contentHandler.characters(line.toCharArray(), 0, line.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
        }
        if (size == 0) {
            super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
            String value = "[empty]";
            super.contentHandler.characters(value.toCharArray(), 0, value.length());
            super.contentHandler.endElement(NAMESPACE, "line", "line");
        }
        super.contentHandler.endElement(NAMESPACE, "value", "value");

        addValue("size", size + " items in cache (" + empty + " are empty)");
        endGroup();
    }
    // END Cache

    endGroup();
}

From source file:org.apache.maven.plugins.enforcer.DisplayInfoMojo.java

/**
 * Entry point to the mojo/*from ww  w.  jav  a  2 s . co m*/
 */
public void execute() throws MojoExecutionException {
    try {
        EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator(session, translator, project);
        DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper(session, evaluator, getLog(),
                container);
        RuntimeInformation rti = (RuntimeInformation) helper.getComponent(RuntimeInformation.class);
        getLog().info("Maven Version: " + rti.getApplicationVersion());
        getLog().info("JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: "
                + RequireJavaVersion.normalizeJDKVersion(SystemUtils.JAVA_VERSION_TRIMMED));
        RequireOS os = new RequireOS();
        os.displayOSInfo(getLog(), true);
    } catch (ComponentLookupException e) {
        getLog().warn("Unable to Lookup component: " + e.getLocalizedMessage());
    }
}

From source file:org.codehaus.mojo.keytool.AbstractKeyToolCommandLineBuilder.java

/**
 * {@inheritDoc}/*from   www  .ja va  2  s.  c om*/
 */
public final void checkSupportedRequest(KeyToolRequest request) throws UnsupportedKeyToolRequestException {
    Class<? extends KeyToolRequest> requestType = request.getClass();
    if (!supportRequestType(requestType)) {
        throw new UnsupportedKeyToolRequestException("Request " + requestType.getName()
                + " is not supported by your version of keytool (java " + SystemUtils.JAVA_VERSION + ")");
    }
}

From source file:org.zaproxy.zap.control.AddOn.java

/**
 * Tells whether or not this add-on can be run in the currently running Java version.
 * <p>/*from  ww w . ja  v  a2  s  .c  o  m*/
 * This is a convenience method that calls {@code canRunInJavaVersion(String)} with the running Java version (as given by
 * {@code SystemUtils.JAVA_VERSION}) as parameter.
 * 
 * @return {@code true} if the add-on can be run in the currently running Java version, {@code false} otherwise
 * @since 2.4.0
 * @see #canRunInJavaVersion(String)
 * @see SystemUtils#JAVA_VERSION
 */
public boolean canRunInCurrentJavaVersion() {
    return canRunInJavaVersion(SystemUtils.JAVA_VERSION);
}

From source file:org.zaproxy.zap.control.AddOnRunIssuesUtils.java

/**
 * Returns the textual representations of the running issues (Java version and dependency), if any.
 * <p>/*w w w .j av a 2s.  com*/
 * The messages are internationalised thus suitable for UI components.
 *
 * @param requirements the run requirements of the add-on
 * @param addOnSearcher the class responsible for searching add-ons with a given id, used to search for add-ons that are
 *            missing for the add-on
 * @return a {@code List} containing all the running issues of the add-on, empty if none
 * @see #getRunningIssues(AddOn.BaseRunRequirements)
 * @see #getUiExtensionsRunningIssues(AddOn.AddOnRunRequirements, AddOnSearcher)
 */
public static List<String> getUiRunningIssues(AddOn.BaseRunRequirements requirements,
        AddOnSearcher addOnSearcher) {
    List<String> issues = new ArrayList<>(2);
    if (requirements.isNewerJavaVersionRequired()) {
        if (requirements.getAddOn() != requirements.getAddOnMinimumJavaVersion()) {
            issues.add(MessageFormat.format(
                    Constant.messages
                            .getString("cfu.warn.addon.with.missing.requirements.javaversion.dependency"),
                    requirements.getMinimumJavaVersion(),
                    (SystemUtils.JAVA_VERSION == null
                            ? Constant.messages.getString("cfu.warn.unknownJavaVersion")
                            : SystemUtils.JAVA_VERSION),
                    requirements.getAddOnMinimumJavaVersion().getName()));
        } else {
            issues.add(MessageFormat.format(
                    Constant.messages.getString("cfu.warn.addon.with.missing.requirements.javaversion"),
                    requirements.getMinimumJavaVersion(),
                    (SystemUtils.JAVA_VERSION == null
                            ? Constant.messages.getString("cfu.warn.unknownJavaVersion")
                            : SystemUtils.JAVA_VERSION)));
        }
    }

    if (requirements.hasDependencyIssue()) {
        List<Object> issueDetails = requirements.getDependencyIssueDetails();
        AddOn addOn;
        String message = null;
        switch (requirements.getDependencyIssue()) {
        case CYCLIC:
            message = Constant.messages.getString("cfu.warn.addon.with.missing.requirements.addon.id");
            break;
        case OLDER_VERSION:
            // Do not set a message, the state is already reported as requiring an update.
            break;
        case MISSING:
            String addOnId = (String) issueDetails.get(0);
            if (addOnSearcher != null) {
                addOn = addOnSearcher.searchAddOn(addOnId);
            } else {
                addOn = null;
            }
            if (addOn == null) {
                message = MessageFormat.format(
                        Constant.messages.getString("cfu.warn.addon.with.missing.requirements.addon.id"),
                        addOnId);

            } else {
                message = MessageFormat.format(
                        Constant.messages.getString("cfu.warn.addon.with.missing.requirements.addon"),
                        addOn.getName());
            }
            break;
        case PACKAGE_VERSION_NOT_BEFORE:
            addOn = (AddOn) issueDetails.get(0);
            message = MessageFormat.format(
                    Constant.messages
                            .getString("cfu.warn.addon.with.missing.requirements.addon.version.notBefore"),
                    addOn.getName(), issueDetails.get(1), Integer.valueOf(addOn.getFileVersion()));
            break;
        case PACKAGE_VERSION_NOT_FROM:
            addOn = (AddOn) issueDetails.get(0);
            message = MessageFormat.format(
                    Constant.messages
                            .getString("cfu.warn.addon.with.missing.requirements.addon.version.notAfter"),
                    addOn.getName(), issueDetails.get(1), Integer.valueOf(addOn.getFileVersion()));
            break;
        case VERSION:
            addOn = (AddOn) issueDetails.get(0);
            if (addOn.getVersion() == null) {
                message = MessageFormat.format(
                        Constant.messages.getString(
                                "cfu.warn.addon.with.missing.requirements.addon.semver.notAvailable"),
                        addOn.getName(), issueDetails.get(1));
            } else {
                message = MessageFormat.format(
                        Constant.messages.getString("cfu.warn.addon.with.missing.requirements.addon.semver"),
                        addOn.getName(), issueDetails.get(1), addOn.getVersion());
            }
            break;
        default:
            message = Constant.messages.getString("cfu.warn.addon.with.missing.requirements.unknown");
            LOGGER.warn("Failed to handle dependency issue with name \""
                    + requirements.getDependencyIssue().name() + "\" and details: " + issueDetails);
            break;
        }

        if (message != null) {
            issues.add(message);
        }
    }
    return issues;
}