Skip to content

Commit 1439588

Browse files
HannesWellakurtakov
authored andcommitted
Simplify SymLink creation in eclipse.core.tests
1 parent 80fd47a commit 1439588

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/FileSystemHelper.java

+1-44
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import static org.eclipse.core.tests.harness.TestHarnessPlugin.PI_HARNESS;
1818
import static org.eclipse.core.tests.harness.TestHarnessPlugin.log;
1919

20-
import java.io.BufferedReader;
2120
import java.io.File;
2221
import java.io.IOException;
23-
import java.io.InputStreamReader;
2422
import java.nio.file.Files;
2523
import java.nio.file.Path;
2624
import org.eclipse.core.runtime.ILog;
@@ -121,48 +119,7 @@ public static void clear(java.io.File file) {
121119
*/
122120
public static void createSymLink(File basedir, String linkName, String linkTarget, boolean isDir)
123121
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));
166123
}
167124

168125
/**

0 commit comments

Comments
 (0)