|
3 | 3 | import static io.sloeber.core.common.Const.*; |
4 | 4 |
|
5 | 5 | import java.io.File; |
| 6 | +import java.io.IOException; |
6 | 7 | import java.net.URI; |
7 | 8 | import java.net.URISyntaxException; |
8 | 9 | import java.net.URL; |
| 10 | +import java.nio.file.Files; |
| 11 | +import java.nio.file.Path; |
9 | 12 | import java.nio.file.Paths; |
| 13 | +import java.util.Comparator; |
10 | 14 |
|
11 | 15 | import org.eclipse.cdt.core.CCorePlugin; |
12 | 16 | import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; |
|
18 | 22 | import org.eclipse.core.resources.ResourcesPlugin; |
19 | 23 | import org.eclipse.core.runtime.IPath; |
20 | 24 | import org.eclipse.core.runtime.IStatus; |
21 | | -import org.eclipse.core.runtime.Path; |
22 | 25 | import org.eclipse.core.runtime.Platform; |
23 | 26 | import org.eclipse.core.runtime.Status; |
24 | 27 | import org.eclipse.ui.statushandlers.StatusManager; |
|
28 | 31 | public class Common { |
29 | 32 |
|
30 | 33 | public final static String sloeberHome = getSloeberHome(); |
31 | | - public final static IPath sloeberHomePath = new Path(sloeberHome); |
| 34 | + public final static IPath sloeberHomePath = new org.eclipse.core.runtime.Path(sloeberHome); |
32 | 35 | public final static String sloeberHomePathToString = sloeberHomePath.toString(); |
33 | 36 |
|
34 | 37 | private static String getSloeberHome() { |
@@ -239,7 +242,7 @@ public static String makePathEnvironmentString(IPath path) { |
239 | 242 | } |
240 | 243 |
|
241 | 244 | public static String makePathVersionString(File file) { |
242 | | - return new Path(file.getPath()).toString().replace(sloeberHomePathToString, SLOEBER_HOME_VAR); |
| 245 | + return file.getPath().replace(sloeberHomePathToString, SLOEBER_HOME_VAR); |
243 | 246 | } |
244 | 247 |
|
245 | 248 | /** |
@@ -278,4 +281,21 @@ static public String getOldWayEnvVar(ICConfigurationDescription confDesc, String |
278 | 281 | getBuildEnvironmentVariable(confDesc, envName.toUpperCase(), EMPTY, false), false); |
279 | 282 | } |
280 | 283 |
|
| 284 | + public static void deleteDirectory(org.eclipse.core.runtime.IPath directory) throws IOException { |
| 285 | + deleteDirectory(Path.of(directory.toOSString())); |
| 286 | + } |
| 287 | + |
| 288 | + public static void deleteDirectory(Path directory) throws IOException { |
| 289 | + Files.walk(directory).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); |
| 290 | + } |
| 291 | + |
| 292 | + /** |
| 293 | + * this is some code to work around issue |
| 294 | + * https://github.com/eclipse-cdt/cdt/issues/539 |
| 295 | + * |
| 296 | + */ |
| 297 | + public static String getFileExtension(String fileName) { |
| 298 | + int dotPosition = fileName.lastIndexOf('.'); |
| 299 | + return (dotPosition == -1 || dotPosition == fileName.length() - 1) ? "" : fileName.substring(dotPosition + 1); //$NON-NLS-1$ |
| 300 | + } |
281 | 301 | } |
0 commit comments