-
Couldn't load subscription status.
- Fork 45
#759: upgrade settings commandlet #820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hohwille
merged 121 commits into
devonfw:main
from
leonrohne27:implement/759-UpgradeSettingsCommandlet
Jan 14, 2025
Merged
Changes from all commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
7af9fc5
#765: Fix typos in DoD asciidoc
aeae1dd
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf e520d16
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 29403d3
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 5bff5eb
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 890c107
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf c55af62
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 3be67d0
#737: Added cd command to shell commandlet
leonrohne27 60f2e8a
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
leonrohne27 5224bf9
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 02cdeb0
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini d925977
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 2d41161
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini 4a8f60b
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 1a6cdb8
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf bad672f
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini f79c030
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 3d2b190
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf e1854bb
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf b85ca18
Merge branch 'main' into implement/737-add-cd-command-to-shell-comman…
jan-vcapgemini 51dd0c2
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellComman…
leonrohne27 0bd754c
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellComman…
leonrohne27 0302acf
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 1af2948
#737: optimized cd command
leonrohne27 ec4d5f6
#737: optimized cd command
leonrohne27 06e9b8a
#737: Added Changelog entry
leonrohne27 4602866
#759:
leonrohne27 7bb5674
kian ist der best
KianRolf 50b9fb2
#759: listchildrenrecursive
KianRolf 07ae66e
#759: rename
leonrohne27 709cb34
#759: check
KianRolf ad841a9
#759: delete devon.properties
leonrohne27 1410aaa
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 09ecb53
#759
leonrohne27 9a6d662
#759
leonrohne27 0ab3f49
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf bb75cf9
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf 72a720c
#759: Added CheckIfLegacyFolderExists() method
leonrohne27 47b8ead
#759: combine
KianRolf a2e3ca9
#759
KianRolf 374a059
#759:
leonrohne27 af2842e
#759: Added recursive variable replacement
leonrohne27 78c2fad
#759: Added method that deletes file
leonrohne27 c51ef83
#759: merge
KianRolf c5c4324
#759:small fix
KianRolf bb0c401
#759
leonrohne27 d8d2a81
#759: Added checkForXMLNameSpace()-method
leonrohne27 1a55e15
#759
leonrohne27 8fad8d0
#759: custom-json-file
KianRolf 3668654
Merge branch 'main' of https://github.com/KianRolf/IDEasy
KianRolf b41dcc7
#759: small changes
leonrohne27 79c2ff3
#759: Added documentation
leonrohne27 23b24b5
#759:
leonrohne27 44bfb40
#759: clean up
leonrohne27 ba49f5f
#759:clean up and reformat
KianRolf 3c5a53e
#759
leonrohne27 a6d4e94
#759: performance improvement
KianRolf 0f34d7d
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
KianRolf 27f317c
#759: remove
KianRolf 5159b15
#759: remove
KianRolf 2733362
#759
leonrohne27 a5817db
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
leonrohne27 195f190
#759: Add help properties
KianRolf 1126b60
Merge branch 'implement/759-UpgradeSettingsCommandlet' of https://git…
KianRolf f6277b4
Update ShellCommandlet.java
KianRolf a6fdcca
Update ShellCommandlet.java
KianRolf fa91325
Rename ide.properties to devon.properties
KianRolf c980055
#759: Test beginning
KianRolf 587ebb9
Update CHANGELOG.adoc
leonrohne27 b919d35
#759: fixed documention link
leonrohne27 cd751e1
Merge branch 'implement/759-UpgradeSettingsCommandlet' of https://git…
leonrohne27 db2a4a7
#759: use getSettingsPath() for resolving settings directories
leonrohne27 d7f60da
#759: file_path to filePath
leonrohne27 6f3229e
#759: Changed method name
leonrohne27 afaa4f7
#759: changed checkForXmlNamespace() method
leonrohne27 3322aa2
Merge branch 'implement/759-UpgradeSettingsCommandlet' of https://git…
KianRolf 589eb25
#759: Test for commandlet
KianRolf 97cae94
#759: Javadoc
KianRolf 1801808
#759: clean up
KianRolf 694a7b8
#759: changed structure for XmlNamespace() method
leonrohne27 84ed5a4
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
jan-vcapgemini 1383b7b
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
jan-vcapgemini b614c6d
#759: optimized parsing of custom tools
jan-vcapgemini 6408d55
#759: added missing changes
jan-vcapgemini 1902729
#759: fixed test
jan-vcapgemini 3c85ec1
#759: rewritten implementation to upgrade variable expressions in wor…
hohwille 7f2d622
#759: implemented requested changes
jan-vcapgemini c4f3aa5
#759: push changes of DirectoryMergerTest
hohwille 9960940
#759: implemented requested changes
jan-vcapgemini 517892b
#759: implemented requested changes
jan-vcapgemini dac39d9
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
jan-vcapgemini d607fa6
#759: refactored updateProperties and custom-tools.json
hohwille a4d685b
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
hohwille 6e087c3
#759: fix NPE
hohwille 8545343
#759: cleanup to resolve review feedback
hohwille a3154b9
Update CHANGELOG.adoc
hohwille d37a005
#759: final fixes and test improvements
hohwille 730d826
#759: fixed test
jan-vcapgemini b4f9e4a
#820: trying to debug test problem
hohwille e1f6071
#759: also update legacy editions
hohwille 52e98b8
#759: fixed test by adding missing conf due to .gitignore
hohwille cb81b78
#759: optimized tests
jan-vcapgemini 1307d33
#759: completed last things (*.properties in ~)
hohwille 323bcc4
#759: replacement-patterns.properties was deleted and then tried to m…
hohwille 1ee9951
#759: fix log message
hohwille db02a0c
#759: completed (.m2 to mvn)
hohwille d78dbc2
#759: added more tests
jan-vcapgemini 87eac3e
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
jan-vcapgemini 60e0901
#759: adjusted changelog
jan-vcapgemini 7126cf9
#759: optimized tests
jan-vcapgemini 5c9c80b
#759: fixed typo
jan-vcapgemini 0056345
#759: implemented requested changes
jan-vcapgemini 2632801
#759: cleanup
jan-vcapgemini 488d5b9
#759: cleanup
jan-vcapgemini b4660a6
#759: implemented requested changes
jan-vcapgemini b7b0d10
#759: implemented requested changes
jan-vcapgemini 3db4692
#759: review rework (JavaDoc)
hohwille 0eac439
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
hohwille e2ff421
Merge branch 'main' into implement/759-UpgradeSettingsCommandlet
jan-vcapgemini 0ebdb62
#759: implemented requested changes
jan-vcapgemini 115768c
#759: implemented requested changes
jan-vcapgemini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| package com.devonfw.tools.ide.commandlet; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.function.Function; | ||
|
|
||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.environment.EnvironmentVariables; | ||
| import com.devonfw.tools.ide.environment.EnvironmentVariablesPropertiesFile; | ||
| import com.devonfw.tools.ide.environment.EnvironmentVariablesType; | ||
| import com.devonfw.tools.ide.merge.DirectoryMerger; | ||
| import com.devonfw.tools.ide.repo.CustomToolsJson; | ||
| import com.devonfw.tools.ide.repo.CustomToolsJsonMapper; | ||
| import com.devonfw.tools.ide.tool.mvn.Mvn; | ||
| import com.devonfw.tools.ide.variable.IdeVariables; | ||
| import com.devonfw.tools.ide.variable.VariableDefinition; | ||
|
|
||
| /** | ||
| * {@link Commandlet} to upgrade settings after a migration from devonfw-ide to IDEasy. | ||
| */ | ||
| public class UpgradeSettingsCommandlet extends Commandlet { | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the {@link IdeContext}. | ||
| */ | ||
| public UpgradeSettingsCommandlet(IdeContext context) { | ||
|
|
||
| super(context); | ||
| addKeyword(getName()); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
|
|
||
| return "upgrade-settings"; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| updateLegacyFolders(); | ||
| updateProperties(); | ||
| updateWorkspaceTemplates(); | ||
| } | ||
|
|
||
| private void updateLegacyFolders() { | ||
| this.context.info("Updating legacy folders if present..."); | ||
| Path settingsPath = context.getSettingsPath(); | ||
| updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_REPOSITORIES, IdeContext.FOLDER_REPOSITORIES); | ||
| updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_TEMPLATES, IdeContext.FOLDER_TEMPLATES); | ||
| updateLegacyFolder(settingsPath.resolve(IdeContext.FOLDER_TEMPLATES).resolve(IdeContext.FOLDER_CONF), Mvn.MVN_CONFIG_LEGACY_FOLDER, Mvn.MVN_CONFIG_FOLDER); | ||
| } | ||
|
|
||
| private void updateLegacyFolder(Path folder, String legacyName, String newName) { | ||
|
|
||
| Path legacyFolder = folder.resolve(legacyName); | ||
| Path newFolder = folder.resolve(newName); | ||
| if (Files.isDirectory(legacyFolder)) { | ||
| try { | ||
| if (!Files.exists(newFolder)) { | ||
| Files.move(legacyFolder, newFolder, StandardCopyOption.REPLACE_EXISTING); | ||
| this.context.success("Successfully renamed folder '{}' to '{}' in {}.", legacyName, newName, folder); | ||
| } | ||
| } catch (IOException e) { | ||
| this.context.error(e, "Error renaming folder {} to {} in {}", legacyName, newName, folder); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void updateWorkspaceTemplates() { | ||
| this.context.info("Updating workspace templates (replace legacy variables and change variable syntax)..."); | ||
|
|
||
| DirectoryMerger merger = this.context.getWorkspaceMerger(); | ||
| Path settingsDir = this.context.getSettingsPath(); | ||
| Path workspaceDir = settingsDir.resolve(IdeContext.FOLDER_WORKSPACE); | ||
| if (Files.isDirectory(workspaceDir)) { | ||
| merger.upgrade(workspaceDir); | ||
| } | ||
| this.context.getFileAccess().listChildrenMapped(settingsDir, child -> { | ||
| Path childWorkspaceDir = child.resolve(IdeContext.FOLDER_WORKSPACE); | ||
| if (Files.isDirectory(childWorkspaceDir)) { | ||
| merger.upgrade(childWorkspaceDir); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| private void updateProperties() { | ||
| // updates DEVON_IDE_CUSTOM_TOOLS to new ide-custom-tools.json | ||
| String devonCustomTools = IdeVariables.DEVON_IDE_CUSTOM_TOOLS.get(this.context); | ||
| if (devonCustomTools != null) { | ||
| CustomToolsJson customToolsJson = CustomToolsJsonMapper.parseCustomToolsFromLegacyConfig(devonCustomTools, context); | ||
| if (customToolsJson != null) { | ||
| CustomToolsJsonMapper.saveJson(customToolsJson, this.context.getSettingsPath().resolve(IdeContext.FILE_CUSTOM_TOOLS)); | ||
| } | ||
| } | ||
|
|
||
| // update properties (devon.properties -> ide.properties, convert legacy properties) | ||
| EnvironmentVariables environmentVariables = context.getVariables(); | ||
| while (environmentVariables != null) { | ||
| if (environmentVariables instanceof EnvironmentVariablesPropertiesFile environmentVariablesProperties) { | ||
| updateProperties(environmentVariablesProperties); | ||
| } | ||
| environmentVariables = environmentVariables.getParent(); | ||
| } | ||
| Path templatePropertiesDir = this.context.getSettingsTemplatePath().resolve(IdeContext.FOLDER_CONF); | ||
| if (Files.exists(templatePropertiesDir)) { | ||
| EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.CONF, | ||
| templatePropertiesDir, null, this.context); | ||
| updateProperties(environmentVariablesProperties); | ||
| } | ||
| } | ||
|
|
||
| private void updateProperties(EnvironmentVariablesPropertiesFile environmentVariables) { | ||
| Path propertiesFilePath = environmentVariables.getPropertiesFilePath(); | ||
| if (environmentVariables.getLegacyConfiguration() != null) { | ||
| if (environmentVariables.getType() == EnvironmentVariablesType.SETTINGS) { | ||
| // adds disabled legacySupportEnabled variable if missing in ide.properties | ||
| environmentVariables.set(IdeVariables.IDE_VARIABLE_SYNTAX_LEGACY_SUPPORT_ENABLED.getName(), "false", false); | ||
| } | ||
| environmentVariables.remove(IdeVariables.DEVON_IDE_CUSTOM_TOOLS.getName()); | ||
| for (VariableDefinition<?> var : IdeVariables.VARIABLES) { | ||
| String legacyName = var.getLegacyName(); | ||
| if (legacyName != null) { | ||
| String value = environmentVariables.get(legacyName); | ||
| if (value != null) { | ||
| String name = var.getName(); | ||
| String newValue = environmentVariables.get(name); | ||
| if (newValue == null) { | ||
| environmentVariables.set(name, value, environmentVariables.isExported(name)); | ||
| } | ||
| } | ||
| environmentVariables.remove(legacyName); | ||
| } | ||
| } | ||
| updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition); | ||
| updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition); | ||
| environmentVariables.save(); | ||
| this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath()); | ||
| } | ||
| } | ||
|
|
||
| private String mapLegacyIntellijEdition(String legacyEdition) { | ||
|
|
||
| return switch (legacyEdition) { | ||
| case "U" -> "ultimate"; | ||
| case "C" -> "intellij"; | ||
| default -> { | ||
| this.context.warning("Undefined legacy edition {}", legacyEdition); | ||
| yield "intellij"; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private String mapLegacyEclipseEdition(String legacyEdition) { | ||
|
|
||
| return switch (legacyEdition) { | ||
| case "java" -> "eclipse"; | ||
| case "jee" -> "jee"; | ||
| case "cpp" -> "cpp"; | ||
| default -> { | ||
| this.context.warning("Undefined legacy edition {}", legacyEdition); | ||
| yield "eclipse"; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private static void updatePropertiesLegacyEdition(EnvironmentVariablesPropertiesFile environmentVariables, String legacyEditionVariable, | ||
| String newEditionVariable, Function<String, String> editionMapper) { | ||
|
|
||
| String legacyEdition = environmentVariables.get(legacyEditionVariable); | ||
| if (legacyEdition != null) { | ||
| String newEdition = environmentVariables.get(newEditionVariable); | ||
| if (newEdition == null) { | ||
| environmentVariables.set(newEditionVariable, editionMapper.apply(legacyEdition), false); | ||
| } | ||
| environmentVariables.remove(legacyEditionVariable); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.