-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --fabric.addMods / -Dfabric.addMods for adding extra path separator separated mods, list file if prefixed with @ #470
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
602cee2
Add --fabric.addMods / -Dfabric.addMods for adding extra path separat…
sfPlayer1 b30fc64
There is no line
sfPlayer1 b2014c8
Reuse SystemProperties value for Arguments
sfPlayer1 7c8ed22
Support dirs containing JARs as well
sfPlayer1 3f48a94
Merge branch 'master' into addModsArg
sfPlayer1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/net/fabricmc/loader/impl/discovery/ArgumentModCandidateFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2016 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.loader.impl.discovery; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import net.fabricmc.loader.impl.FabricLoaderImpl; | ||
import net.fabricmc.loader.impl.util.Arguments; | ||
import net.fabricmc.loader.impl.util.SystemProperties; | ||
import net.fabricmc.loader.impl.util.log.Log; | ||
import net.fabricmc.loader.impl.util.log.LogCategory; | ||
|
||
public class ArgumentModCandidateFinder implements ModCandidateFinder { | ||
private final boolean requiresRemap; | ||
|
||
public ArgumentModCandidateFinder(boolean requiresRemap) { | ||
this.requiresRemap = requiresRemap; | ||
} | ||
|
||
@Override | ||
public void findCandidates(ModCandidateConsumer out) { | ||
String list = System.getProperty(SystemProperties.ADD_MODS); | ||
if (list != null) addMods(list, "system property", out); | ||
|
||
list = FabricLoaderImpl.INSTANCE.getGameProvider().getArguments().remove(Arguments.ADD_MODS); | ||
if (list != null) addMods(list, "argument", out); | ||
} | ||
|
||
private void addMods(String list, String source, ModCandidateConsumer out) { | ||
for (String pathStr : list.split(File.pathSeparator)) { | ||
if (pathStr.isEmpty()) continue; | ||
|
||
if (pathStr.startsWith("@")) { | ||
Path path = Paths.get(pathStr.substring(1)); | ||
|
||
if (!Files.isRegularFile(path)) { | ||
Log.warn(LogCategory.DISCOVERY, "Missing/invalid %s provided mod list file %s", source, path); | ||
continue; | ||
} | ||
|
||
try (BufferedReader reader = Files.newBufferedReader(path)) { | ||
String fileSource = String.format("%s file %s", source, path); | ||
String line; | ||
|
||
while ((line = reader.readLine()) != null) { | ||
line = line.trim(); | ||
if (line.isEmpty()) continue; | ||
|
||
addMod(line, fileSource, out); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Error reading %s provided mod list file %s", source, path), e); | ||
} | ||
} else { | ||
addMod(pathStr, source, out); | ||
} | ||
} | ||
} | ||
|
||
private void addMod(String pathStr, String source, ModCandidateConsumer out) { | ||
Path path = Paths.get(pathStr); | ||
boolean isDir; | ||
|
||
if (!Files.exists(path)) { | ||
Log.warn(LogCategory.DISCOVERY, "Missing %s provided mod path %s", source, path); | ||
} else if ((isDir = Files.isDirectory(path)) && !Files.isRegularFile(path.resolve("fabric.mod.json")) | ||
|| !isDir && !DirectoryModCandidateFinder.isValidFile(path)) { | ||
Log.warn(LogCategory.DISCOVERY, "Incompatible path in %s provided mod path %s (must be a directory with a fabric.mod.json or a non-hidden jar file", source, path); | ||
} else { | ||
out.accept(path, requiresRemap); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why null out the arguments? Just because they're not needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe to allow garbage collection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to trap any accidental reuse