EnumeratorModuleClassPath.java
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.mumfrey.liteloader.core;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.launchwrapper.LaunchClassLoader;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
/**
* Enumerator module which searches for mods on the classpath
*
* @author Adam Mummery-Smith
*/
public class EnumeratorModuleClassPath implements EnumeratorModule<File>
{
/**
* Array of class path entries specified to the JVM instance
*/
private final String[] classPathEntries;
/**
* URLs to add once init is completed
*/
private final List<LoadableMod<File>> loadableMods = new ArrayList<LoadableMod<File>>();
private boolean loadTweaks;
/**
* @param parent
* @param searchProtectionDomain
* @param searchClassPath
* @param loadTweaks
*/
public EnumeratorModuleClassPath(boolean loadTweaks)
{
// Read the JVM class path into the local array
this.classPathEntries = this.readClassPath();
this.loadTweaks = loadTweaks;
}
@Override
public String toString()
{
return "<Java Class Path>";
}
@Override
public void init(PluggableEnumerator enumerator)
{
}
@Override
public void writeSettings(PluggableEnumerator enumerator)
{
}
/**
* Reads the class path entries that were supplied to the JVM and returns them as an array
*/
private String[] readClassPath()
{
LiteLoaderLogger.info("Enumerating class path...");
String classPath = System.getProperty("java.class.path");
String classPathSeparator = System.getProperty("path.separator");
String[] classPathEntries = classPath.split(classPathSeparator);
LiteLoaderLogger.info("Class path separator=\"%s\"", classPathSeparator);
LiteLoaderLogger.info("Class path entries=(\n classpathEntry=%s\n)", classPath.replace(classPathSeparator, "\n classpathEntry="));
return classPathEntries;
}
@Override
public void enumerate(PluggableEnumerator enumerator, EnabledModsList enabledModsList, String profile)
{
if (this.loadTweaks)
{
LiteLoaderLogger.info("Discovering tweaks on class path...");
for (String classPathPart : this.classPathEntries)
{
File packagePath = new File(classPathPart);
if (packagePath.exists())
{
LoadableModClassPath classPathMod = new LoadableModClassPath(packagePath);
if (enumerator.isContainerEnabled(classPathMod))
{
this.loadableMods.add(classPathMod);
if (classPathMod.hasTweakClass() || classPathMod.hasClassTransformers())
{
enumerator.registerTweakContainer(classPathMod);
}
}
else
{
LiteLoaderLogger.info("Mod %s is disabled or missing a required dependency, not injecting tranformers", classPathMod.getIdentifier());
}
}
}
}
}
@Override
public void injectIntoClassLoader(PluggableEnumerator enumerator, LaunchClassLoader classLoader, EnabledModsList enabledModsList, String profile)
{
}
/**
* @param classLoader
*/
@Override
public void registerMods(PluggableEnumerator enumerator, LaunchClassLoader classLoader)
{
LiteLoaderLogger.info("Discovering mods on class path...");
for (LoadableMod<File> classPathMod : this.loadableMods)
{
LiteLoaderLogger.info("Searching %s...", classPathMod);
enumerator.registerModsFrom(classPathMod, true);
}
}
}