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

com.github.endoscope.util.AppIdentificationUtil Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.github.endoscope.util;

import java.net.InetAddress;
import java.net.URL;

public class AppIdentificationUtil {
    public static String calculateHost(){
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch(Exception e){
            return "unknown_host";
        }
    }

    public static String calculateType(){
        try{
            String resource = AppIdentificationUtil.class.getName().replaceAll("\\.", "/") + ".class";
            URL url = ClassLoader.getSystemClassLoader().getResource(resource);
            if( url == null ){
                url = AppIdentificationUtil.class.getClassLoader().getResource(resource);
            }
            String group = url.getFile().replace("\\", "/")
                    .replace("/" + resource, "")
                    //JBoss WAR stuff
                    .replace("/content/", "")
                    .replaceFirst("/WEB-INF/lib/.*", "")
                    //IntelliJ support
                    .replaceFirst(".*/exploded/", "");

            return group;
        } catch(Exception e){
            return "unknown_type";
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy