MCPcopy Create free account
hub / github.com/SeanDragon/protools / ToolPosition

Class ToolPosition

common/src/main/java/pro/tools/system/ToolPosition.java:8–61  ·  view source on GitHub ↗

@author SeanDragon

Source from the content-addressed store, hash-verified

6 * @author SeanDragon
7 */
8public final class ToolPosition {
9
10 private static String webRootPath;
11 private static String rootClassPath;
12
13 @SuppressWarnings("rawtypes")
14 public static String getPath(Class clazz) {
15 String path = clazz.getResource("").getPath();
16 return new File(path).getAbsolutePath();
17 }
18
19 public static String getPath(Object object) {
20 String path = object.getClass().getResource("").getPath();
21 return new File(path).getAbsolutePath();
22 }
23
24 public static String getRootClassPath() {
25 if (rootClassPath == null) {
26 try {
27 String path = ToolPosition.class.getClassLoader().getResource("").toURI().getPath();
28 rootClassPath = new File(path).getAbsolutePath();
29 } catch (Exception e) {
30 String path = ToolPosition.class.getClassLoader().getResource("").getPath();
31 rootClassPath = new File(path).getAbsolutePath();
32 }
33 }
34 return rootClassPath;
35 }
36
37 public static String getPackagePath(Object object) {
38 Package p = object.getClass().getPackage();
39 return p != null ? p.getName().replaceAll("\\.", "/") : "";
40 }
41
42 public static File getFileFromJar(String file) {
43 throw new RuntimeException("Not finish. Do not use this method.");
44 }
45
46 public static String getWebRootPath() {
47 if (webRootPath == null) {
48 webRootPath = detectWebRootPath();
49 }
50 return webRootPath;
51 }
52
53 private static String detectWebRootPath() {
54 try {
55 String path = ToolPosition.class.getResource("/").toURI().getPath();
56 return new File(path).getParentFile().getParentFile().getCanonicalPath();
57 } catch (Exception e) {
58 throw new RuntimeException(e);
59 }
60 }
61}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected