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

org.zeroturnaround.javarebel.integration.util.AgentUtil Maven / Gradle / Ivy

The newest version!
package org.zeroturnaround.javarebel.integration.util;

import java.io.File;
import java.net.URL;
import java.net.URLDecoder;

/**
 * Helper methods for JavaRebel agent.
 * 
 * @author Rein Raudjärv
 */
public class AgentUtil {

  /**
   * Returns the location of javarebel.jar.
   */
  public static File getRebelJarPath() {
    return getJarFileForClass(AgentUtil.class);
  }

  private static File getJarFileForClass(Class clazz) {
    ClassLoader cl = clazz.getClassLoader();
    if (cl == null)
      cl = ClassLoader.getSystemClassLoader();
    String name = clazz.getName().replace('.', '/') + ".class";

    if (cl == null)
      return getJarFileForURL(ClassLoader.getSystemResource(name));
    else
      return getJarFileForURL(cl.getResource(name));
  }

  private static File getJarFileForURL(URL jarUrl) {
    String jarPath = URLDecoder.decode(jarUrl.getPath());

    int i = jarPath.indexOf("!/");

    if (i == -1)
      return null;

    return new File(jarPath.substring(jarPath.indexOf(":") + 1, i));    
  }  

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy