|
1 | 1 | package com.devonfw.tools.ide.commandlet;
|
2 | 2 |
|
| 3 | +import java.io.IOException; |
3 | 4 | import java.nio.file.Files;
|
4 | 5 | import java.nio.file.Path;
|
| 6 | +import java.nio.file.Paths; |
5 | 7 | import java.nio.file.StandardCopyOption;
|
| 8 | +import java.nio.file.StandardOpenOption; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
6 | 11 | import java.util.function.Function;
|
7 | 12 |
|
8 | 13 | import com.devonfw.tools.ide.context.IdeContext;
|
@@ -139,6 +144,7 @@ private void updateProperties(EnvironmentVariablesPropertiesFile environmentVari
|
139 | 144 | }
|
140 | 145 | updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition);
|
141 | 146 | updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition);
|
| 147 | + cleanupLegacyProperties(); |
142 | 148 | environmentVariables.save();
|
143 | 149 | this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath());
|
144 | 150 | }
|
@@ -181,4 +187,43 @@ private static void updatePropertiesLegacyEdition(EnvironmentVariablesProperties
|
181 | 187 | environmentVariables.remove(legacyEditionVariable);
|
182 | 188 | }
|
183 | 189 | }
|
| 190 | + |
| 191 | + private void cleanupLegacyProperties() { |
| 192 | + this.context.info("Cleaning up legacy properties..."); |
| 193 | + |
| 194 | + Path rootDirectory = Paths.get(System.getProperty("user.dir")); |
| 195 | + try { |
| 196 | + Files.walk(rootDirectory) |
| 197 | + .filter(path -> path.getFileName().toString().equals("IDEasy.properties")) |
| 198 | + .forEach(filePath -> { |
| 199 | + try { |
| 200 | + updateProperties(filePath); |
| 201 | + } catch (IOException e) { |
| 202 | + this.context.warning("Error processing IDEasy.properties at " + filePath); |
| 203 | + } |
| 204 | + }); |
| 205 | + } catch (IOException e) { |
| 206 | + this.context.warning("Error walking the file tree to find IDEasy.properties."); |
| 207 | + } |
| 208 | + } |
| 209 | + |
| 210 | + private void updateProperties(Path filePath) throws IOException { |
| 211 | + List<String> lines = Files.readAllLines(filePath); |
| 212 | + List<String> updatedLines = new ArrayList<>(); |
| 213 | + |
| 214 | + for (String line : lines) { |
| 215 | + if (line.startsWith("git.url=") || line.startsWith("git-url")) { |
| 216 | + String gitUrl = line.substring("git.url=".length()); |
| 217 | + updatedLines.add("git_url=" + gitUrl); |
| 218 | + continue; |
| 219 | + } |
| 220 | + if (line.startsWith("eclipse=import")) { |
| 221 | + updatedLines.add("import=eclipse"); |
| 222 | + continue; |
| 223 | + } |
| 224 | + updatedLines.add(line); |
| 225 | + } |
| 226 | + Files.write(filePath, updatedLines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); |
| 227 | + this.context.success("Successfully updated IDEasy.properties at " + filePath); |
| 228 | + } |
184 | 229 | }
|
0 commit comments