All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aspectran.core.util.Aspectran Maven / Gradle / Ivy

There is a newer version: 8.1.5
Show newest version
/*
 * Copyright (c) 2008-2024 The Aspectran Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aspectran.core.util;

import com.aspectran.utils.Assert;
import com.aspectran.utils.annotation.jsr305.NonNull;

import java.io.PrintStream;

/**
 * Class that exposes the build information of Aspectran.
 * Fetches the "Implementation-Version" manifest attribute from the jar file.
 */
public abstract class Aspectran {

    public static final String VERSION;

    public static final String POWERED_BY;

    public static final String POWERED_BY_LINK;

    public static final boolean STABLE;

    static {
        Package pkg = Aspectran.class.getPackage();
        if (pkg != null && "The Aspectran Project".equals(pkg.getImplementationVendor()) &&
                pkg.getImplementationVersion() != null) {
            VERSION = pkg.getImplementationVersion();
        } else {
            VERSION = System.getProperty("aspectran.version", "8.1.x");
        }

        POWERED_BY = "Powered by Aspectran " + VERSION;
        POWERED_BY_LINK = "Powered by Aspectran " + VERSION + "";

        // Show warning when RC# or M# is in version string
        STABLE = !VERSION.matches("^.*\\.(RC|M)[0-9]+$");
    }

    public static String getVersion() {
        return VERSION;
    }

    public static String getPoweredBy() {
        return POWERED_BY;
    }

    public static String getPoweredByLink() {
        return POWERED_BY_LINK;
    }

    /**
     * Prints Aspectran information to the specified print stream.
     * @param output a {@link PrintStream} object to print
     */
    public static void printAboutMe(PrintStream output) {
        Assert.notNull(output, "output must not be null");
        output.println("Aspectran: " + VERSION);
        output.println("JVM: " + System.getProperty("java.version") +
                " (\"" + System.getProperty("java.vm.vendor") + "\"" + " " +
                System.getProperty("java.runtime.version") + ")");
        output.println("OS: " + System.getProperty("os.name") + " " +
                System.getProperty("os.version") + " " + System.getProperty("os.arch"));
    }

    /**
     * Prints Aspectran information to the specified print stream.
     * @param output a {@link PrintStream} object to print
     */
    public static void printPrettyAboutMe(@NonNull PrintStream output) {
        Assert.notNull(output, "output must not be null");
        output.println("---------------------------------------------------------------------");
        output.printf(" %1$-9s : %2$s%n", "Aspectran", VERSION);
        output.printf(" %1$-9s : %2$s%n", "JVM", System.getProperty("java.version") +
                " (\"" + System.getProperty("java.vm.vendor") + "\"" + " " +
                System.getProperty("java.runtime.version") + ")");
        output.printf(" %1$-9s : %2$s%n", "OS", System.getProperty("os.name") + " " +
                System.getProperty("os.version") + " " + System.getProperty("os.arch"));
        output.println("---------------------------------------------------------------------");
    }

    /**
     * Prints Aspectran information to {@link System#out}.
     * @param args a string array containing the command line arguments
     */
    public static void main(String[] args) {
        printPrettyAboutMe(System.out);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy