|
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; |
5 | 6 | import java.nio.file.StandardCopyOption; |
| 7 | +import java.nio.file.StandardOpenOption; |
| 8 | +import java.util.List; |
6 | 9 | import java.util.function.Function; |
7 | 10 |
|
8 | 11 | import com.devonfw.tools.ide.context.IdeContext; |
@@ -139,6 +142,7 @@ private void updateProperties(EnvironmentVariablesPropertiesFile environmentVari |
139 | 142 | } |
140 | 143 | updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition); |
141 | 144 | updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition); |
| 145 | + cleanupLegacyProperties(); |
142 | 146 | environmentVariables.save(); |
143 | 147 | this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath()); |
144 | 148 | } |
@@ -181,4 +185,53 @@ private static void updatePropertiesLegacyEdition(EnvironmentVariablesProperties |
181 | 185 | environmentVariables.remove(legacyEditionVariable); |
182 | 186 | } |
183 | 187 | } |
| 188 | + |
| 189 | + private void cleanupLegacyProperties() { |
| 190 | + this.context.info("Cleaning up legacy properties..."); |
| 191 | + |
| 192 | + Path settingsPath = context.getSettingsPath(); |
| 193 | + Path repositoriesPath = settingsPath.resolve(IdeContext.FOLDER_REPOSITORIES); |
| 194 | + |
| 195 | + FileAccess fileAccess = this.context.getFileAccess(); |
| 196 | + if (fileAccess.isExpectedFolder(repositoriesPath)) { |
| 197 | + fileAccess.listChildrenMapped(repositoriesPath, child -> { |
| 198 | + try { |
| 199 | + if (Files.isRegularFile(child) && child.getFileName().toString().endsWith(".properties")) { |
| 200 | + updateRepositoryPropertiesFile(child); |
| 201 | + } |
| 202 | + } catch (IOException e) { |
| 203 | + throw new RuntimeException(e); |
| 204 | + } |
| 205 | + return null; |
| 206 | + }); |
| 207 | + } |
| 208 | + } |
| 209 | + |
| 210 | + private void updateRepositoryPropertiesFile(Path filePath) throws IOException { |
| 211 | + List<String> lines = Files.readAllLines(filePath); |
| 212 | + boolean updated = false; |
| 213 | + |
| 214 | + for (int i = 0; i < lines.size(); i++) { |
| 215 | + String line = lines.get(i).trim(); |
| 216 | + if (line.startsWith("git.url=") || line.startsWith("git-url")) { |
| 217 | + String gitUrl = line.substring(line.indexOf("=") + 1).trim(); |
| 218 | + lines.set(i, "git_url=" + gitUrl); |
| 219 | + updated = true; |
| 220 | + continue; |
| 221 | + } |
| 222 | + if (line.startsWith("eclipse=import")) { |
| 223 | + lines.set(i, "import=eclipse"); |
| 224 | + updated = true; |
| 225 | + } |
| 226 | + } |
| 227 | + if (updated) { |
| 228 | + try { |
| 229 | + Files.write(filePath, lines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); |
| 230 | + this.context.success("Successfully updated repository configuration file {}", filePath); |
| 231 | + } catch (IOException e) { |
| 232 | + this.context.error("Failed to write updated repository configuration file {}", filePath); |
| 233 | + throw e; |
| 234 | + } |
| 235 | + } |
| 236 | + } |
184 | 237 | } |
0 commit comments