use of org.apache.commons.text.StringSubstitutor in project LauncherV3 by TechnicPack.
the class MinecraftLauncher method buildCommands.
private List<String> buildCommands(ModpackModel pack, long memory, MojangVersion version, LaunchOptions options) {
LaunchCommandCollector commands = new LaunchCommandCollector();
// Wrapper command (optirun, etc)
String wrapperCommand = options.getOptions().getWrapperCommand();
if (StringUtils.isNotEmpty(wrapperCommand)) {
commands.addRaw(wrapperCommand);
}
JavaVersion javaVersion = version.getJavaVersion();
if (javaVersion != null && options.getOptions().shouldUseMojangJava()) {
File runtimeRoot = new File(directories.getRuntimesDirectory(), javaVersion.getComponent());
Path javaExecutable;
if (OperatingSystem.getOperatingSystem() == OperatingSystem.WINDOWS) {
javaExecutable = runtimeRoot.toPath().resolve("bin/javaw.exe");
} else if (OperatingSystem.getOperatingSystem() == OperatingSystem.OSX) {
javaExecutable = runtimeRoot.toPath().resolve("jre.bundle/Contents/Home/bin/java");
} else {
javaExecutable = runtimeRoot.toPath().resolve("bin/java");
}
commands.addRaw(javaExecutable.toString());
} else {
commands.addRaw(javaVersions.getSelectedPath());
}
OperatingSystem operatingSystem = OperatingSystem.getOperatingSystem();
String nativesDir = new File(pack.getBinDir(), "natives").getAbsolutePath();
String cpString = buildClassPath(pack, version);
// build arg parameter map
Map<String, String> params = new HashMap<String, String>();
IUserType user = userModel.getCurrentUser();
File gameDirectory = pack.getInstalledDirectory();
ILaunchOptions launchOpts = options.getOptions();
params.put("auth_username", user.getUsername());
params.put("auth_session", user.getSessionId());
params.put("auth_access_token", user.getAccessToken());
params.put("auth_player_name", user.getDisplayName());
params.put("auth_uuid", user.getId());
params.put("profile_name", user.getDisplayName());
params.put("version_name", version.getId());
params.put("version_type", version.getType().getName());
params.put("game_directory", gameDirectory.getAbsolutePath());
params.put("natives_directory", nativesDir);
params.put("classpath", cpString);
params.put("resolution_width", Integer.toString(launchOpts.getCustomWidth()));
params.put("resolution_height", Integer.toString(launchOpts.getCustomHeight()));
StringSubstitutor paramDereferencer = new StringSubstitutor(params);
String targetAssets = directories.getAssetsDirectory().getAbsolutePath();
String assetsKey = version.getAssetsKey();
if (assetsKey == null || assetsKey.isEmpty()) {
assetsKey = "legacy";
}
if (version.getAreAssetsVirtual()) {
targetAssets += File.separator + "virtual" + File.separator + assetsKey;
} else if (version.getAssetsMapToResources()) {
targetAssets = pack.getResourcesDir().getAbsolutePath();
}
params.put("game_assets", targetAssets);
params.put("assets_root", targetAssets);
params.put("assets_index_name", assetsKey);
params.put("user_type", user.getMCUserType());
params.put("user_properties", user.getUserProperties());
params.put("launcher_name", "technic");
params.put("launcher_version", "4." + buildNumber.getBuildNumber());
// Prepend custom JVM arguments
String customJvmArgs = options.getOptions().getJavaArgs();
if (StringUtils.isNotEmpty(customJvmArgs)) {
customJvmArgs = customJvmArgs.replaceAll("[\\r\\n]", " ");
for (String customJvmArg : customJvmArgs.split("[ ]+")) {
commands.addRaw(customJvmArg);
}
}
// build jvm args
String launchJavaVersion = javaVersions.getSelectedVersion().getVersionNumber();
ArgumentList jvmArgs = version.getJavaArguments();
if (jvmArgs != null) {
for (String arg : jvmArgs.resolve(options.getOptions(), paramDereferencer)) {
commands.add(arg);
}
}
int permSize = 128;
if (memory >= (1024 * 6)) {
permSize = 512;
} else if (memory >= 2048) {
permSize = 256;
}
commands.addRaw("-Xms" + memory + "m");
commands.addRaw("-Xmx" + memory + "m");
if (!RunData.isJavaVersionAtLeast(launchJavaVersion, "1.8"))
commands.add("-XX:MaxPermSize=" + permSize + "m");
commands.addUnique("-Djava.library.path=" + nativesDir);
// Tell forge 1.5 to download from our mirror instead
// This can't be HTTPS because Forge 1.5 doesn't load up Let's Encrypt root certs (we use Let's Encrypt on the mirror)
commands.addUnique("-Dfml.core.libraries.mirror=http://mirror.technicpack.net/Technic/lib/fml/%s");
// This is required because we strip META-INF from the minecraft.jar
commands.addUnique("-Dfml.ignoreInvalidMinecraftCertificates=true");
commands.addUnique("-Dfml.ignorePatchDiscrepancies=true");
// This is for ForgeWrapper >= 1.4.2
if (MojangUtils.requiresForgeWrapper(version)) {
commands.addUnique("-Dforgewrapper.librariesDir=" + directories.getCacheDirectory().getAbsolutePath());
// The Forge installer jar is really the modpack.jar
File modpackJar = new File(pack.getBinDir(), "modpack.jar");
commands.addUnique("-Dforgewrapper.installer=" + modpackJar.getAbsolutePath());
// We feed ForgeWrapper the unmodified Minecraft jar here
String mcVersion = MojangUtils.getMinecraftVersion(version);
File minecraftJar = new File(directories.getCacheDirectory(), "minecraft_" + mcVersion + ".jar");
commands.addUnique("-Dforgewrapper.minecraft=" + minecraftJar.getAbsolutePath());
}
commands.addUnique("-Dminecraft.applet.TargetDirectory=" + pack.getInstalledDirectory().getAbsolutePath());
commands.addUnique("-Duser.language=en");
if (!options.getOptions().shouldUseStencilBuffer())
commands.add("-Dforge.forceNoStencil=true");
if (operatingSystem.equals(OperatingSystem.OSX)) {
commands.add("-Xdock:icon=" + options.getIconPath());
commands.add("-Xdock:name=" + pack.getDisplayName());
} else if (operatingSystem.equals(OperatingSystem.WINDOWS)) {
// I have no idea if this helps technic or not.
commands.addUnique("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump");
}
// build game args
commands.addUnique("-cp", cpString);
commands.addRaw(version.getMainClass());
List<String> mcArgs = version.getMinecraftArguments().resolve(launchOpts, paramDereferencer);
// We manually iterate over the arguments so we can add them in "--name value" pairs, and exclude duplicates
// this way. For example: --username Foobar
ListIterator<String> mcArgsIterator = mcArgs.listIterator();
String current, next;
while (mcArgsIterator.hasNext()) {
current = mcArgsIterator.next();
if (mcArgsIterator.hasNext()) {
// We don't consume it so we can later add it to the commands if it turns out to not be a value
// This allows us to keep the pair detection working correctly, and if we do end up using the value,
// we just consume it from the iterator later on
next = mcArgs.get(mcArgsIterator.nextIndex());
} else {
next = null;
}
// ${auth_player_name} ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets}
if (current.startsWith("--")) {
// This is an --argument, now we check if it has a value or not
if (next != null && !next.startsWith("--")) {
// LiteLoader to coexist
if (current.equals("--tweakClass")) {
commands.add(current, next);
} else {
commands.addUnique(current, next);
}
// Consume the next element in the iterator
mcArgsIterator.next();
} else {
// This --argument doesn't have a value, so we just add the argument itself as a unique parameter
commands.addUnique(current);
}
} else {
// Doesn't start with --, so this is not a named argument, and since we have no way of knowing if this
// is a duplicate or not, we just add it as a regular argument (no duplicate detection)
commands.add(current);
}
}
options.appendToCommands(commands);
// TODO: Add all the other less important commands
return commands.collect();
}
use of org.apache.commons.text.StringSubstitutor in project triplea by triplea-game.
the class RemoveUnitsHistoryChange method perform.
@Override
public void perform(final IDelegateBridge bridge) {
transformDamagedUnitsHistoryChange.perform(bridge);
final Collection<Unit> allKilledUnits = new ArrayList<>();
final CompositeChange change = new CompositeChange();
if (!killedUnits.isEmpty()) {
allKilledUnits.addAll(killedUnits);
change.add(ChangeFactory.removeUnits(location, killedUnits));
}
if (!unloadedUnits.isEmpty()) {
unloadedUnits.forEach((territory, units) -> {
allKilledUnits.addAll(units);
change.add(ChangeFactory.removeUnits(territory, units));
});
}
if (change.isEmpty()) {
return;
}
this.change.add(change);
bridge.addChange(this.change);
final String text = new StringSubstitutor(Map.of("units", MyFormatter.unitsToText(allKilledUnits), "territory", location.getName())).replace(messageTemplate);
bridge.getHistoryWriter().addChildToEvent(text, allKilledUnits);
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class PropertiesStringLookupTest method testInterpolatorWithParameterizedKey.
@Test
public void testInterpolatorWithParameterizedKey() {
final Map<String, String> map = new HashMap<>();
map.put("KeyIsHere", KEY);
final StringSubstitutor stringSubstitutor = new StringSubstitutor(StringLookupFactory.INSTANCE.interpolatorStringLookup(map));
final String replaced = stringSubstitutor.replace("$${properties:" + PropertiesStringLookup.toPropertyKey(DOC_PATH, "${KeyIsHere}}"));
assertEquals("${properties:" + PropertiesStringLookup.toPropertyKey(DOC_PATH, "mykey}"), replaced);
assertEquals("Hello World!", stringSubstitutor.replace(replaced));
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorFilterReaderTest method testReadMixedBufferLengthsReplace.
@Test
public void testReadMixedBufferLengthsReplace() throws IOException {
final String template = "${aa}${bb}";
final StringSubstitutor substitutor = new StringSubstitutor(values);
try (Reader reader = createReader(substitutor, template)) {
assertEquals('1', reader.read());
final char[] cbuf = new char[3];
assertEquals(0, reader.read(cbuf, 0, 0));
reader.read(cbuf);
final String result = String.valueOf(cbuf);
assertEquals("122", result, () -> String.format("length %,d", result.length()));
}
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class StringSubstitutorFilterReaderTest method testReadMixedBufferLengths1ToVarLenPlusNoReplace.
@Test
public void testReadMixedBufferLengths1ToVarLenPlusNoReplace() throws IOException {
final StringSubstitutor substitutor = new StringSubstitutor(values);
final String template = "123456";
assertTrue(template.length() > getMinExpressionLength(substitutor) + 1);
try (Reader reader = createReader(substitutor, template)) {
assertEquals('1', reader.read());
final char[] cbuf = new char[template.length() - 1];
reader.read(cbuf);
final String result = String.valueOf(cbuf);
assertEquals(template.substring(1), result);
}
}
Aggregations