Skip to content

Commit

Permalink
Merge pull request #75 from coehlrich/master
Browse files Browse the repository at this point in the history
Set Environment Properties that are set by argument's earlier
  • Loading branch information
cpw authored Jan 2, 2022
2 parents 2907a0f + c144bc0 commit 766836f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
35 changes: 19 additions & 16 deletions src/main/java/cpw/mods/modlauncher/ArgumentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,28 @@ public class ArgumentHandler {
private OptionSpec<String> launchTarget;
private OptionSpec<String> uuidOption;

Path setArgs(String[] args) {
Path setArgs(String[] args, Environment env) {
this.args = args;
final OptionParser parser = new OptionParser();
final ArgumentAcceptingOptionSpec<Path> gameDir = parser.accepts("gameDir", "Alternative game directory").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.DIRECTORY_EXISTING)).defaultsTo(Path.of("."));
parser.allowsUnrecognizedOptions();
final OptionParser parser = getDefaultParser();

final OptionSet optionSet = parser.parse(args);
return optionSet.valueOf(gameDir);
env.computePropertyIfAbsent(IEnvironment.Keys.VERSION.get(), s -> this.optionSet.valueOf(profileOption));
env.computePropertyIfAbsent(IEnvironment.Keys.GAMEDIR.get(), f -> this.optionSet.valueOf(gameDirOption));
env.computePropertyIfAbsent(IEnvironment.Keys.ASSETSDIR.get(), f -> this.optionSet.valueOf(assetsDirOption));
env.computePropertyIfAbsent(IEnvironment.Keys.LAUNCHTARGET.get(), f -> this.optionSet.valueOf(launchTarget));
env.computePropertyIfAbsent(IEnvironment.Keys.UUID.get(), f -> this.optionSet.valueOf(uuidOption));
return optionSet.valueOf(gameDirOption);
}

void processArguments(Environment env, Consumer<OptionParser> parserConsumer, BiConsumer<OptionSet, BiFunction<String, OptionSet, ITransformationService.OptionResult>> resultConsumer) {
void processArguments(Consumer<OptionParser> parserConsumer, BiConsumer<OptionSet, BiFunction<String, OptionSet, ITransformationService.OptionResult>> resultConsumer) {
final OptionParser parser = getDefaultParser();
parserConsumer.accept(parser);
nonOption = parser.nonOptions();
this.optionSet = parser.parse(this.args);
resultConsumer.accept(this.optionSet, this::optionResults);
}

OptionParser getDefaultParser() {
final OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
profileOption = parser.accepts("version", "The version we launched with").withRequiredArg();
Expand All @@ -56,16 +68,7 @@ void processArguments(Environment env, Consumer<OptionParser> parserConsumer, Bi
minecraftJarOption = parser.accepts("minecraftJar", "Path to minecraft jar").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.READABLE)).withValuesSeparatedBy(',');
uuidOption = parser.accepts("uuid", "The UUID of the logging in player").withRequiredArg();
launchTarget = parser.accepts("launchTarget", "LauncherService target to launch").withRequiredArg();

parserConsumer.accept(parser);
nonOption = parser.nonOptions();
this.optionSet = parser.parse(this.args);
env.computePropertyIfAbsent(IEnvironment.Keys.VERSION.get(), s -> this.optionSet.valueOf(profileOption));
env.computePropertyIfAbsent(IEnvironment.Keys.GAMEDIR.get(), f -> this.optionSet.valueOf(gameDirOption));
env.computePropertyIfAbsent(IEnvironment.Keys.ASSETSDIR.get(), f -> this.optionSet.valueOf(assetsDirOption));
env.computePropertyIfAbsent(IEnvironment.Keys.LAUNCHTARGET.get(), f -> this.optionSet.valueOf(launchTarget));
env.computePropertyIfAbsent(IEnvironment.Keys.UUID.get(), f -> this.optionSet.valueOf(uuidOption));
resultConsumer.accept(this.optionSet, this::optionResults);
return parser;
}

Path[] getSpecialJars() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cpw/mods/modlauncher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final TypesafeMap blackboard() {
}

private void run(String... args) {
final Path gameDir = this.argumentHandler.setArgs(args);
final Path gameDir = this.argumentHandler.setArgs(args, this.environment);
this.transformationServicesHandler.discoverServices(gameDir);
final var scanResults = this.transformationServicesHandler.initializeTransformationServices(this.argumentHandler, this.environment, this.nameMappingServiceHandler);
var bylayer = scanResults.stream().collect(Collectors.groupingBy(ITransformationService.Resource::target));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TransformingClassLoader buildTransformingClassLoader(final LaunchPluginHandler p
private void processArguments(ArgumentHandler argumentHandler, Environment environment) {
LOGGER.debug(MODLAUNCHER,"Configuring option handling for services");

argumentHandler.processArguments(environment, this::computeArgumentsForServices, this::offerArgumentResultsToServices);
argumentHandler.processArguments(this::computeArgumentsForServices, this::offerArgumentResultsToServices);
}

private void computeArgumentsForServices(OptionParser parser) {
Expand Down

0 comments on commit 766836f

Please sign in to comment.