|
17 | 17 | import static org.eclipse.core.tests.harness.TestHarnessPlugin.PI_HARNESS;
|
18 | 18 | import static org.eclipse.core.tests.harness.TestHarnessPlugin.log;
|
19 | 19 |
|
20 |
| -import java.io.BufferedReader; |
21 | 20 | import java.io.File;
|
22 | 21 | import java.io.IOException;
|
23 |
| -import java.io.InputStreamReader; |
24 | 22 | import java.nio.file.Files;
|
25 | 23 | import java.nio.file.Path;
|
26 | 24 | import org.eclipse.core.runtime.ILog;
|
@@ -121,48 +119,7 @@ public static void clear(java.io.File file) {
|
121 | 119 | */
|
122 | 120 | public static void createSymLink(File basedir, String linkName, String linkTarget, boolean isDir)
|
123 | 121 | throws IOException {
|
124 |
| - // The following code creates even a link if |
125 |
| - // Files.createSymbolicLink(new File(basedir, linkName).toPath(), new |
126 |
| - // File(basedir, linkTarget).toPath()); |
127 |
| - // would throw java.nio.file.FileSystemException "missing rights" |
128 |
| - // |
129 |
| - Process process = startSymlinkCreation(basedir, linkName, linkTarget, isDir); |
130 |
| - try { |
131 |
| - int exitcode = process.waitFor(); |
132 |
| - if (exitcode != 0) { |
133 |
| - // xxx wrong charset. from jdk17+ we could use Console.charset() |
134 |
| - try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) { |
135 |
| - String result = reader.readLine(); |
136 |
| - throw new IllegalStateException("Creating symlink is unsupported: " + result); |
137 |
| - } |
138 |
| - } |
139 |
| - } catch (InterruptedException e) { |
140 |
| - throw new IOException("Creating symlink failed due to interrupted exception", e); |
141 |
| - } |
142 |
| - } |
143 |
| - |
144 |
| - private static Process startSymlinkCreation(File basedir, String linkName, String linkTarget, boolean isDir) |
145 |
| - throws IOException { |
146 |
| - // Deliberately use an empty environment to make the test reproducible. |
147 |
| - String[] environmentParameters = {}; |
148 |
| - if (Platform.getOS().equals(Platform.OS_WIN32)) { |
149 |
| - return startSymlinkCreationOnWindows(basedir, linkName, linkTarget, isDir, environmentParameters); |
150 |
| - } |
151 |
| - String[] cmd = { "ln", "-s", linkTarget, linkName }; |
152 |
| - return Runtime.getRuntime().exec(cmd, environmentParameters, basedir); |
153 |
| - } |
154 |
| - |
155 |
| - private static Process startSymlinkCreationOnWindows(File basedir, String linkName, String linkTarget, |
156 |
| - boolean isDir, String[] environmentParameters) throws IOException { |
157 |
| - // use File.getPath to avoid 'Illegal argument - ".."' for using "../" |
158 |
| - // instead of "..\" |
159 |
| - if (isDir) { |
160 |
| - String[] cmd = { "cmd", "/c", "mklink", "/d", new File(linkName).getPath(), |
161 |
| - new File(linkTarget).getPath() }; |
162 |
| - return Runtime.getRuntime().exec(cmd, environmentParameters, basedir); |
163 |
| - } |
164 |
| - String[] cmd = { "cmd", "/c", "mklink", new File(linkName).getPath(), new File(linkTarget).getPath() }; |
165 |
| - return Runtime.getRuntime().exec(cmd, environmentParameters, basedir); |
| 122 | + Files.createSymbolicLink(basedir.toPath().resolve(linkName), basedir.toPath().resolve(linkTarget)); |
166 | 123 | }
|
167 | 124 |
|
168 | 125 | /**
|
|
0 commit comments