|
8 | 8 | import org.gradle.api.distribution.DistributionContainer; |
9 | 9 | import org.gradle.api.file.FileCopyDetails; |
10 | 10 | import org.gradle.api.file.RelativePath; |
| 11 | +import org.gradle.api.logging.Logger; |
| 12 | +import org.gradle.api.logging.Logging; |
11 | 13 | import org.gradle.api.tasks.JavaExec; |
12 | 14 | import org.gradle.api.tasks.application.CreateStartScripts; |
13 | 15 | import org.javamodularity.moduleplugin.extensions.RunModuleOptions; |
14 | 16 | import org.javamodularity.moduleplugin.internal.TaskOption; |
15 | 17 |
|
16 | 18 | import java.io.IOException; |
| 19 | +import java.nio.charset.Charset; |
17 | 20 | import java.nio.file.Files; |
18 | 21 | import java.nio.file.Path; |
19 | 22 | import java.util.ArrayList; |
20 | 23 | import java.util.List; |
21 | 24 |
|
22 | 25 | public class StartScriptsMutator extends AbstractExecutionMutator { |
| 26 | + private static final Logger LOGGER = Logging.getLogger(StartScriptsMutator.class); |
23 | 27 |
|
24 | 28 | private static final String LIBS_PLACEHOLDER = "APP_HOME_LIBS_PLACEHOLDER"; |
25 | 29 | private static final String PATCH_LIBS_PLACEHOLDER = "APP_HOME_PATCH_LIBS_PLACEHOLDER"; |
@@ -127,13 +131,27 @@ private void removeClasspathArgs(CreateStartScripts startScriptsTask) { |
127 | 131 |
|
128 | 132 | private static void replaceLibsPlaceHolder(Path path, String libText, String patchLibText) { |
129 | 133 | try { |
130 | | - String updatedScriptContent = Files.readString(path) |
| 134 | + String content = getContent(path); |
| 135 | + String updatedScriptContent = content |
131 | 136 | .replaceAll(LIBS_PLACEHOLDER, libText) |
132 | 137 | .replaceAll(PATCH_LIBS_PLACEHOLDER, patchLibText); |
133 | 138 |
|
134 | 139 | Files.writeString(path, updatedScriptContent); |
135 | 140 | } catch (IOException e) { |
136 | | - throw new GradleException("Couldn't replace placeholder in " + path); |
| 141 | + throw new GradleException("Couldn't replace placeholder in " + path, e); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + private static String getContent(Path path) { |
| 146 | + try { |
| 147 | + return Files.readString(path); |
| 148 | + } catch (IOException e) { |
| 149 | + try { |
| 150 | + Charset cs = Charset.forName(System.getProperty("file.encoding")); |
| 151 | + return Files.readString(path, cs); |
| 152 | + } catch (Exception ex) { |
| 153 | + throw new GradleException("Cannot read the content of " + path, ex); |
| 154 | + } |
137 | 155 | } |
138 | 156 | } |
139 | 157 |
|
|
0 commit comments