Example #1
0
  @Override
  public boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) {
    try {
      for (Entry<String, String> nativeEntry : platformNativeIndex.entrySet()) {
        if (nativeEntry.getKey().contains(libname)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Loading mapped entry: [{}] [{}] [{}]",
                libname,
                nativeEntry.getKey(),
                nativeEntry.getValue());
          }
          File nativeLibCopy =
              extractJarEntry(
                  nativeEntry.getValue(),
                  nativeEntry.getKey(),
                  System.getProperty(JAVA_TMP_DIR),
                  String.format("%s.jni", libname));
          System.load(nativeLibCopy.getAbsolutePath());
          return true;
        }
      }
    } catch (Exception e) {
      log.error("Unable to load native library [{}] - {}", libname, e);
    }

    if (log.isDebugEnabled()) {
      log.debug("No mapped library match for [{}]", libname);
    }
    return false;
  }
 private String version(String jarPath) throws IOException {
   Attributes attributes = getManifestAttributes(jarPath);
   if (attributes == null) {
     log.trace("no main attributes in manifest {}", jarPath);
     return null;
   }
   String version = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
   log.trace("found specification version {}", version);
   return version;
 }
 private Attributes getManifestAttributes(String jarPath) throws IOException {
   String manifestPath = jarPath + MANIFEST_PATH;
   try {
     log.trace("manifest path: {}", manifestPath);
     Manifest manifest = new Manifest(new URL(manifestPath).openStream());
     log.trace("found entries: {}", manifest.getEntries().keySet());
     return manifest.getMainAttributes();
   } catch (FileNotFoundException e) {
     log.trace("No manifest found at {}", manifestPath);
     return null;
   }
 }
 private String readVersionFromManifest(Class<?> api) throws IOException {
   String className = api.getSimpleName() + ".class";
   URL resource = api.getResource(className);
   log.trace("get resource for {} -> {} -> {}", new Object[] {className, pathOf(api), resource});
   if (resource == null) return null;
   String version = null;
   String classPath = resource.toString();
   if (classPath.startsWith("jar:"))
     version = version(classPath.substring(0, classPath.lastIndexOf("!") + 1));
   if (version == null && classPath.endsWith(pathOf(api) + ".class"))
     version = version(classPath.substring(0, classPath.length() - pathOf(api).length() - 7));
   if (version == null && classPath.contains("/WEB-INF/"))
     version = version(classPath.substring(0, classPath.lastIndexOf("/WEB-INF/")));
   log.debug("version {} for {} from {}.", version, api, classPath);
   return version;
 }
 public String getVersion(Class<?> api) {
   log.trace("getVersion for {}", api);
   Package pkg = api.getPackage();
   log.trace("    -> {}/{}", pkg.getImplementationVersion(), pkg.getSpecificationVersion());
   String version = pkg.getSpecificationVersion();
   if (version == null) version = pkg.getImplementationVersion();
   if (version == null) {
     try {
       version = readVersionFromManifest(api);
     } catch (IOException e) {
       log.error("Could not extract version for " + api, e);
       return null;
     }
   }
   return version;
 }
 @Override
 public void addTo(Message message, Class<?> api, Object pojo) throws JMSException {
   log.trace("applyTo api={}, pojo={}", api, pojo);
   String version = getVersion(api);
   if (version != null) {
     message.setStringProperty("VERSION", version);
   }
 }
Example #7
0
  public GLBootstrap() throws Exception {

    System.setProperty("jogamp.gluegen.UseTempJarCache", "false");

    log.info(
        "Initializing native JOGL jar dependencies for platform [{}]. Temp jar cache disabled.",
        PlatformPropsImpl.os_and_arch);

    String nativeJarName = String.format("%s-%s", NATIVES, PlatformPropsImpl.os_and_arch);
    String[] classpathEntries =
        System.getProperty(JAVA_CLASSPATH).split(System.getProperty(JAVA_SEPARATOR));

    for (String jarPath : classpathEntries) {

      if (jarPath.contains(nativeJarName)) {

        if (log.isDebugEnabled()) {
          log.debug("Applicable platform jar: [{}]", jarPath);
        }

        JarFile jf = new JarFile(jarPath);

        try {
          Enumeration<JarEntry> jarEntries = jf.entries();

          while (jarEntries.hasMoreElements()) {

            JarEntry je = jarEntries.nextElement();

            if (!je.isDirectory() && !je.getName().contains(JAVA_META_INF)) {
              if (log.isDebugEnabled()) {
                log.debug("Mapping jar entry [{}] -> [{}]", je.getName(), jarPath);
              }
              if (log.isDebugEnabled() && platformNativeIndex.containsKey(je.getName())) {
                log.debug("Duplicate jar entry: [{}]", je.getName());
                log.debug("Mapped at: [{}]", platformNativeIndex.get(je.getName()));
                log.debug("Also at: [{}]", jarPath);
              }
              platformNativeIndex.put(je.getName(), jarPath);
            }
          }
        } finally {
          closeJar(jf);
        }
      }
    }
  }