@@ -48,7 +48,7 @@ public class RuntimeEnvDependency {
4848 try {
4949 Class .forName ("com.mohistmc.MohistMC" );
5050 isAetherFound = false ;
51- }catch (ClassNotFoundException ignored ){
51+ } catch (ClassNotFoundException ignored ) {
5252 }
5353 }
5454
@@ -226,46 +226,54 @@ void loadDependencyLegacy(
226226 /**
227227 * 从本地文件中加载依赖
228228 */
229- @ SuppressWarnings ("deprecation" )
230229 public void loadFromLocalFile (URL url ) throws Throwable {
231230 if (url == null ) {
232231 return ;
233232 }
234233 try (InputStream inputStream = url .openStream ()) {
235- JsonElement parsed = new JsonParser ().parse (PrimitiveIO .readFully (inputStream , StandardCharsets .UTF_8 ));
236- if (!parsed .isJsonArray ()) return ;
237- JsonArray array = parsed .getAsJsonArray ();
238- for (JsonElement element : array ) {
239- JsonObject object = element .getAsJsonObject ();
240- // 获取检查条件
241- List <String > test = new ArrayList <>();
242- for (JsonElement testElement : array (object , "test" )) {
243- test .add (testElement .getAsString ());
244- }
245- if (!test .isEmpty () && test .stream ().allMatch (this ::test )) {
246- continue ;
247- }
248- // 获取依赖信息
249- String value = object .get ("value" ).getAsString ();
250- String repository = find (object , "repository" , defaultRepositoryCentral );
251- boolean transitive = find (object , "transitive" );
252- boolean ignoreOptional = find (object , "ignoreOptional" );
253- boolean ignoreException = find (object , "ignoreException" );
254- boolean external = find (object , "external" );
255- // 读取依赖范围
256- List <DependencyScope > scopes = new ArrayList <>();
257- for (JsonElement scope : array (object , "scopes" )) {
258- scopes .add (DependencyScope .valueOf (scope .getAsString ().toUpperCase ()));
259- }
260- // 读取重定向规则
261- List <JarRelocation > relocation = new ArrayList <>();
262- JsonArray relocate = array (object , "relocate" );
263- for (int i = 0 ; i + 1 < relocate .size (); i += 2 ) {
264- relocation .add (new JarRelocation (relocate .get (i ).getAsString (), relocate .get (i + 1 ).getAsString ()));
265- }
266- // 加载依赖
267- loadDependency (value , new File (defaultLibrary ), relocation , repository , ignoreOptional , ignoreException , transitive , scopes , external );
234+ String json = PrimitiveIO .readFully (inputStream , StandardCharsets .UTF_8 );
235+ loadFromJson (json );
236+ }
237+ }
238+
239+ /**
240+ * 读取 JSON 字符串并根据格式加载依赖
241+ */
242+ public void loadFromJson (String json ) throws Throwable {
243+ //noinspection deprecation
244+ JsonElement parsed = new JsonParser ().parse (json );
245+ if (!parsed .isJsonArray ()) return ;
246+ JsonArray array = parsed .getAsJsonArray ();
247+ for (JsonElement element : array ) {
248+ JsonObject object = element .getAsJsonObject ();
249+ // 获取检查条件
250+ List <String > test = new ArrayList <>();
251+ for (JsonElement testElement : array (object , "test" )) {
252+ test .add (testElement .getAsString ());
253+ }
254+ if (!test .isEmpty () && test .stream ().allMatch (this ::test )) {
255+ continue ;
256+ }
257+ // 获取依赖信息
258+ String value = object .get ("value" ).getAsString ();
259+ String repository = find (object , "repository" , defaultRepositoryCentral );
260+ boolean transitive = find (object , "transitive" );
261+ boolean ignoreOptional = find (object , "ignoreOptional" );
262+ boolean ignoreException = find (object , "ignoreException" );
263+ boolean external = find (object , "external" );
264+ // 读取依赖范围
265+ List <DependencyScope > scopes = new ArrayList <>();
266+ for (JsonElement scope : array (object , "scopes" )) {
267+ scopes .add (DependencyScope .valueOf (scope .getAsString ().toUpperCase ()));
268+ }
269+ // 读取重定向规则
270+ List <JarRelocation > relocation = new ArrayList <>();
271+ JsonArray relocate = array (object , "relocate" );
272+ for (int i = 0 ; i + 1 < relocate .size (); i += 2 ) {
273+ relocation .add (new JarRelocation (relocate .get (i ).getAsString (), relocate .get (i + 1 ).getAsString ()));
268274 }
275+ // 加载依赖
276+ loadDependency (value , new File (defaultLibrary ), relocation , repository , ignoreOptional , ignoreException , transitive , scopes , external );
269277 }
270278 }
271279
0 commit comments