|
1 | 1 | package net.neoforged.moddevgradle.internal; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | | -import java.io.IOException; |
5 | | -import java.nio.charset.StandardCharsets; |
6 | | -import java.util.ArrayList; |
7 | | -import java.util.Collections; |
8 | | -import java.util.List; |
9 | | -import java.util.stream.Collectors; |
10 | | -import javax.inject.Inject; |
11 | 3 | import net.neoforged.moddevgradle.dsl.RunModel; |
12 | 4 | import net.neoforged.moddevgradle.internal.utils.ExtensionUtils; |
13 | 5 | import net.neoforged.moddevgradle.internal.utils.FileUtils; |
|
27 | 19 | import org.gradle.api.tasks.TaskAction; |
28 | 20 | import org.gradle.jvm.toolchain.JavaToolchainService; |
29 | 21 |
|
| 22 | +import javax.inject.Inject; |
| 23 | +import java.io.File; |
| 24 | +import java.io.IOException; |
| 25 | +import java.nio.charset.StandardCharsets; |
| 26 | +import java.nio.file.Files; |
| 27 | +import java.nio.file.Path; |
| 28 | +import java.nio.file.attribute.PosixFileAttributeView; |
| 29 | +import java.nio.file.attribute.PosixFilePermission; |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.Collections; |
| 32 | +import java.util.HashSet; |
| 33 | +import java.util.List; |
| 34 | +import java.util.stream.Collectors; |
| 35 | + |
30 | 36 | /** |
31 | 37 | * Writes standalone start scripts to launch the game. |
32 | 38 | * These scripts are useful for launching the game outside Gradle or the IDE, for example, from tools |
@@ -190,10 +196,26 @@ private void writeLaunchScriptForUnix(List<String> javaCommand) throws IOExcepti |
190 | 196 | "(cd " + escapeShellArg(getWorkingDirectory().get()) + "; exec " |
191 | 197 | + javaCommand.stream().map(this::escapeShellArg).collect(Collectors.joining(" ")) + ")"); |
192 | 198 |
|
| 199 | + Path destination = getLaunchScript().get().getAsFile().toPath(); |
193 | 200 | FileUtils.writeStringSafe( |
194 | | - getLaunchScript().get().getAsFile().toPath(), |
| 201 | + destination, |
195 | 202 | String.join("\n", lines), |
196 | 203 | StandardCharsets.UTF_8); |
| 204 | + |
| 205 | + var permissionView = Files.getFileAttributeView(destination, PosixFileAttributeView.class); |
| 206 | + if (permissionView != null) { |
| 207 | + var perm = new HashSet<>(permissionView.readAttributes().permissions()); |
| 208 | + if (perm.contains(PosixFilePermission.OWNER_READ)) { |
| 209 | + perm.add(PosixFilePermission.OWNER_EXECUTE); |
| 210 | + } |
| 211 | + if (perm.contains(PosixFilePermission.GROUP_READ)) { |
| 212 | + perm.add(PosixFilePermission.GROUP_EXECUTE); |
| 213 | + } |
| 214 | + if (perm.contains(PosixFilePermission.OTHERS_READ)) { |
| 215 | + perm.add(PosixFilePermission.OTHERS_EXECUTE); |
| 216 | + } |
| 217 | + permissionView.setPermissions(perm); |
| 218 | + } |
197 | 219 | } |
198 | 220 |
|
199 | 221 | private String escapeShellArg(String text) { |
|
0 commit comments