Example usage for java.lang Package getSpecificationVersion

List of usage examples for java.lang Package getSpecificationVersion

Introduction

In this page you can find the example usage for java.lang Package getSpecificationVersion.

Prototype

public String getSpecificationVersion() 

Source Link

Document

Returns the version number of the specification that this package implements.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Package p = Package.getPackage("javax.swing");
    System.out.print("Swing Version: ");
    System.out.println(p.getSpecificationVersion());

    p = Package.getPackage("java.awt");
    System.out.print("AWT Version: ");
    System.out.println(p.getSpecificationVersion());

}

From source file:Main.java

public static void main(String[] args) {

    // get the java lang package
    Package pack = Package.getPackage("java.lang");

    // print the specification version for this package
    System.out.println(pack.getSpecificationVersion());

}

From source file:PackageInfo.java

public static void main(String[] args) {
    Package p = Package.getPackage("java.lang");

    System.out.println("Name = " + p.getName());

    System.out.println("Implementation title = " + p.getImplementationTitle());

    System.out.println("Implementation vendor = " + p.getImplementationVendor());

    System.out.println("Implementation version = " + p.getImplementationVersion());

    System.out.println("Specification title = " + p.getSpecificationTitle());

    System.out.println("Specification vendor = " + p.getSpecificationVendor());

    System.out.println("Specification version = " + p.getSpecificationVersion());
}

From source file:PackageInfo.java

static void pkgInfo(ClassLoader classLoader, String pkgName, String className) {

    try {//from  ww  w.  j av  a2s .  c o  m
        classLoader.loadClass(pkgName + "." + className);

        Package p = Package.getPackage(pkgName);
        if (p == null) {
            System.out.println("WARNING: Package.getPackage(" + pkgName + ") is null");
        } else {
            System.out.println(p);
            System.out.println("Specification Title = " + p.getSpecificationTitle());
            System.out.println("Specification Vendor = " + p.getSpecificationVendor());
            System.out.println("Specification Version = " + p.getSpecificationVersion());

            System.out.println("Implementation Vendor = " + p.getImplementationVendor());
            System.out.println("Implementation Version = " + p.getImplementationVersion());
        }
    } catch (ClassNotFoundException e) {
        System.out.println("Unable to load " + pkgName);
    }

    System.out.println();
}

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));
    }//from www .j a  v  a2 s . c om

    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.github.wolf480pl.mias4j.core.runtime.BMClassLoader.java

protected Package copyPackage(Package pkg, CodeSource cs) {
    return definePackage(pkg.getName(), pkg.getSpecificationTitle(), pkg.getSpecificationVersion(),
            pkg.getSpecificationVendor(), pkg.getImplementationTitle(), pkg.getImplementationVersion(),
            pkg.getImplementationVendor(), pkg.isSealed() ? cs.getLocation() : null);
}

From source file:com.gs.obevo.db.impl.core.DbDeployer.java

private void validateProperDbUtilsVersion() {
    Package dbutilsPackage = BasicRowProcessor.class.getPackage();
    String dbutilsVersion = dbutilsPackage.getSpecificationVersion();

    if (dbutilsVersion == null) {
        return; // in case the jar is shaded, this information may not be available; hence, we are forced to return
    }/*w  w  w  . j  a  v a 2s  .  c o  m*/
    String[] versionParts = dbutilsVersion.split("\\.");
    if (versionParts.length < 2) {
        throw new IllegalArgumentException(
                "Improper dbutils version; must have at least two parts x.y; " + dbutilsVersion);
    }

    int majorVersion = Integer.valueOf(versionParts[0]).intValue();
    int minorVersion = Integer.valueOf(versionParts[1]).intValue();

    if (!(majorVersion >= 1 && minorVersion >= 6)) {
        throw new IllegalArgumentException(
                "commons-dbutils:commons-dbutils version must be >= 1.6 to avoid bugs w/ JDBC getColumnName() usage in <= 1.5");
    }
}

From source file:com.alfaariss.oa.OAContextListener.java

/**
 * Starts the engine before all servlets are initialized.
 * //from  w w  w .  j a v  a2s.  c  o m
 * Searches for the properties needed for the configuration in:
 * <code>[Servlet context dir]/WEB-INF/[PROPERTIES_FILENAME]</code>
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
@Override
public void contextInitialized(ServletContextEvent oServletContextEvent) {
    Properties pConfig = new Properties();
    try {
        _logger.info("Starting Asimba");

        Package pCurrent = OAContextListener.class.getPackage();

        String sSpecVersion = pCurrent.getSpecificationVersion();
        if (sSpecVersion != null)
            _logger.info("Specification-Version: " + sSpecVersion);

        String sImplVersion = pCurrent.getImplementationVersion();
        if (sImplVersion != null)
            _logger.info("Implementation-Version: " + sImplVersion);

        ServletContext oServletContext = oServletContextEvent.getServletContext();

        Enumeration enumContextAttribs = oServletContext.getInitParameterNames();
        while (enumContextAttribs.hasMoreElements()) {
            String sName = (String) enumContextAttribs.nextElement();
            pConfig.put(sName, oServletContext.getInitParameter(sName));
        }

        if (pConfig.size() > 0) {
            _logger.info("Using configuration items found in servlet context: " + pConfig);
        }

        // Add MountingPoint to PathTranslator
        PathTranslator.getInstance().addKey(MP_WEBAPP_ROOT, oServletContext.getRealPath(""));

        // Try to see whether there is a system property with the location of the properties file:
        String sPropertiesFilename = System.getProperty(PROPERTIES_FILENAME_PROPERTY);
        if (null != sPropertiesFilename && !"".equals(sPropertiesFilename)) {
            File fConfig = new File(sPropertiesFilename);
            if (fConfig.exists()) {
                _logger.info("Reading Asimba properties from " + fConfig.getAbsolutePath());
                pConfig.putAll(getProperties(fConfig));
            }
        }

        String sWebInf = oServletContext.getRealPath("WEB-INF");
        if (sWebInf != null) {
            _logger.info("Cannot find path in ServletContext for WEB-INF");
            StringBuffer sbConfigFile = new StringBuffer(sWebInf);
            if (!sbConfigFile.toString().endsWith(File.separator))
                sbConfigFile.append(File.separator);
            sbConfigFile.append(PROPERTIES_FILENAME);

            File fConfig = new File(sbConfigFile.toString());
            if (fConfig.exists()) {
                _logger.info("Updating configuration items with the items in file: " + fConfig.toString());
                pConfig.putAll(getProperties(fConfig));
            } else {
                _logger.info("No optional configuration properties (" + PROPERTIES_FILENAME
                        + ") file found at: " + fConfig.toString());
            }
        }
        //Search for PROPERTIES_FILENAME file in servlet context classloader classpath 
        //it looks first at this location: ./<context>/web-inf/classes/[PROPERTIES_FILENAME]
        //if previous location didn't contain PROPERTIES_FILENAME then checking: 
        //./tomcat/common/classes/PROPERTIES_FILENAME
        URL urlProperties = oServletContext.getClass().getClassLoader().getResource(PROPERTIES_FILENAME);
        if (urlProperties != null) {
            String sProperties = urlProperties.getFile();
            _logger.debug("Found '" + PROPERTIES_FILENAME + "' file in classpath: " + sProperties);
            File fProperties = new File(sProperties);
            if (fProperties != null && fProperties.exists()) {
                _logger.info("Updating configuration items with the items in file: "
                        + fProperties.getAbsolutePath());
                pConfig.putAll(getProperties(fProperties));
            } else
                _logger.info("Could not resolve: " + fProperties.getAbsolutePath());
        } else
            _logger.info("No optional '" + PROPERTIES_FILENAME
                    + "' configuration file found in servlet context classpath");

        if (!pConfig.containsKey("configuration.handler.filename")) {
            StringBuffer sbOAConfigFile = new StringBuffer(sWebInf);
            if (!sbOAConfigFile.toString().endsWith(File.separator))
                sbOAConfigFile.append(File.separator);
            sbOAConfigFile.append("conf");
            sbOAConfigFile.append(File.separator);
            sbOAConfigFile.append("asimba.xml");
            File fOAConfig = new File(sbOAConfigFile.toString());
            if (fOAConfig.exists()) {
                pConfig.put("configuration.handler.filename", sbOAConfigFile.toString());
                _logger.info(
                        "Setting 'configuration.handler.filename' configuration property with configuration file found at: "
                                + fOAConfig.toString());
            }
        }

        _oEngineLauncher.start(pConfig);

        _logger.info("Started Engine with OAContextListener");
    } catch (Exception e) {
        _logger.error("Can't start Engine with OAContextListener", e);

        _logger.debug("try stopping the server");
        _oEngineLauncher.stop();
    }

}

From source file:net.pandoragames.far.ui.FARConfig.java

private String getCurrentApplicationVersion() {
    Package pkg = getClass().getPackage();
    if (pkg != null) {
        return pkg.getSpecificationVersion();
    } else { // not in a jar
        return null;
    }//from  w  ww .j a v a  2s  . c o m
}

From source file:adalid.util.info.JavaInfo.java

public void printPackageDetails(String name) {
    Package pack = Package.getPackage(name);
    out.println("Package " + name + ": " + pack);
    if (pack != null) {
        out.println("\t" + Attributes.Name.IMPLEMENTATION_TITLE + ":   " + pack.getImplementationTitle());
        out.println("\t" + Attributes.Name.IMPLEMENTATION_VENDOR + ":  " + pack.getImplementationVendor());
        out.println("\t" + Attributes.Name.IMPLEMENTATION_VERSION + ": " + pack.getImplementationVersion());
        out.println("\t" + Attributes.Name.SPECIFICATION_TITLE + ":    " + pack.getSpecificationTitle());
        out.println("\t" + Attributes.Name.SPECIFICATION_VENDOR + ":   " + pack.getSpecificationVendor());
        out.println("\t" + Attributes.Name.SPECIFICATION_VERSION + ":  " + pack.getSpecificationVersion());
        out.println();/*from w w  w . j  av  a2s .  c  om*/
    }
}