Skip to content

Commit

Permalink
#759: refactored updateProperties and custom-tools.json
Browse files Browse the repository at this point in the history
replaced regex parsing with indexOf
added JsonIgnores and JsonProperties to CustomTool
converted version from versionIdentifier to String
added Tool record to CustomToolsJson
  • Loading branch information
hohwille committed Jan 8, 2025
1 parent dac39d9 commit d607fa6
Show file tree
Hide file tree
Showing 22 changed files with 528 additions and 642 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.devonfw.tools.ide.git.GitUrl;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.StringProperty;
import com.devonfw.tools.ide.repo.CustomTool;
import com.devonfw.tools.ide.repo.CustomToolMetadata;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.tool.CustomToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
Expand Down Expand Up @@ -164,7 +164,7 @@ private void updateSoftware() {
}

// custom tools in ide-custom-tools.json
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
for (CustomToolMetadata customTool : this.context.getCustomToolRepository().getTools()) {
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
toolCommandlets.add(customToolCommandlet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
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.variable.IdeVariables;

/**
Expand All @@ -36,47 +38,31 @@ public String getName() {

@Override
public void run() {
updateLegacyFolders();
updateProperties();
replaceLegacyVariablesAndBracketsInWorkspace();
checkIfLegacyFolderExists();
}

private void checkIfLegacyFolderExists() {
private void updateLegacyFolders() {
this.context.info("Scanning for legacy folders...");

Path settingsPath = context.getSettingsPath();
updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_TEMPLATES, IdeContext.FOLDER_TEMPLATES);
updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_REPOSITORIES, IdeContext.FOLDER_REPOSITORIES);
}

Path devonFolder = settingsPath.resolve("devon");

Path templatesFolder = settingsPath.resolve("templates");

Path projectsFolder = settingsPath.resolve("projects");

Path repositoriesFolder = settingsPath.resolve("repositories");
private void updateLegacyFolder(Path folder, String legacyName, String newName) {

if (Files.exists(devonFolder) && Files.isDirectory(devonFolder)) {
Path legacyFolder = folder.resolve(legacyName);
Path newFolder = folder.resolve(newName);
if (Files.isDirectory(legacyFolder)) {
try {
if (!Files.exists(templatesFolder)) {
Files.move(devonFolder, templatesFolder, StandardCopyOption.REPLACE_EXISTING);
this.context.success("Successfully updated folder name from 'settings/devon' to 'settings/templates'.");
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("Error updating 'settings/devon' folder to 'settings/templates': " + e.getMessage());
this.context.error("Error renaming folder " + legacyName + " to " + newName + " in " + folder, e);
}
} else {
this.context.warning("The 'templates' folder already exists, skipping renaming.");
}
if (Files.exists(projectsFolder) && Files.isDirectory(projectsFolder)) {
try {
if (!Files.exists(repositoriesFolder)) {
Files.move(projectsFolder, repositoriesFolder, StandardCopyOption.REPLACE_EXISTING);
this.context.success("Successfully updated folder name from 'settings/projects' to 'settings/repositories'.");
}
} catch (IOException e) {
this.context.error("Error updating 'settings/projects' folder to 'settings/repositories': " + e.getMessage());
}
} else {
this.context.warning("The 'repositories' folder already exists, skipping renaming.");
}
}

Expand All @@ -99,44 +85,46 @@ private void replaceLegacyVariablesAndBracketsInWorkspace() {
}

private void updateProperties() {
EnvironmentVariables environmentVariables = context.getVariables();
CustomToolsJson customToolsJson = null;

// updates DEVON_IDE_CUSTOM_TOOLS to new ide-custom-tools.json
String devonCustomToolsName = IdeVariables.DEVON_IDE_CUSTOM_TOOLS.getName();
String devonCustomTools = environmentVariables.getParent().get(devonCustomToolsName);
String devonCustomTools = IdeVariables.DEVON_IDE_CUSTOM_TOOLS.get(this.context);
if (devonCustomTools != null) {
String customToolsContent = environmentVariables.getParent().get(devonCustomToolsName);
if (!customToolsContent.isEmpty()) {
customToolsJson = CustomToolsJson.retrieveCustomToolsFromLegacyConfig(customToolsContent, context);
}
CustomToolsJson customToolsJson = CustomToolsJsonMapper.parseCustomToolsFromLegacyConfig(devonCustomTools, context);
if (customToolsJson != null) {
customToolsJson.doSave(context.getSettingsPath().resolve(IdeContext.FILE_CUSTOM_TOOLS));
CustomToolsJsonMapper.saveJson(customToolsJson, this.context.getSettingsPath().resolve(IdeContext.FILE_CUSTOM_TOOLS));
}
}

EnvironmentVariables environmentVariables = context.getVariables();
while (environmentVariables != null) {
if (environmentVariables instanceof EnvironmentVariablesPropertiesFile environmentVariablesProperties) {
updateProperties(environmentVariablesProperties);
}
environmentVariables = environmentVariables.getParent();
}
Path templateProperties = this.context.getSettingsTemplatePath().resolve(EnvironmentVariables.LEGACY_PROPERTIES);
if (Files.exists(templateProperties)) {
EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.USER,
templateProperties, this.context);
updateProperties(environmentVariablesProperties);
}

if (environmentVariables instanceof EnvironmentVariablesPropertiesFile) {
if (environmentVariables.getLegacyPropertiesFilePath() == null && environmentVariables.getPropertiesFilePath() == null) {
continue;
}
Path propertiesFilePath = environmentVariables.getPropertiesFilePath();
}

private static void updateProperties(EnvironmentVariablesPropertiesFile environmentVariables) {
Path propertiesFilePath = environmentVariables.getPropertiesFilePath();
if (propertiesFilePath != null || environmentVariables.getLegacyPropertiesFilePath() != null) {
if (environmentVariables.getType() == EnvironmentVariablesType.SETTINGS) {
// adds disabled legacySupportEnabled variable if missing in ide.properties
String legacySupportEnabledName = IdeVariables.IDE_VARIABLE_SYNTAX_LEGACY_SUPPORT_ENABLED.getName();
String legacySupportEnabled = environmentVariables.get(legacySupportEnabledName);
if (legacySupportEnabled == null && propertiesFilePath != null && propertiesFilePath.endsWith(EnvironmentVariables.LEGACY_PROPERTIES)) {
String legacySupportEnabledValue = environmentVariables.get(legacySupportEnabledName);
if (!"false".equals(legacySupportEnabledValue)) {
environmentVariables.set(legacySupportEnabledName, "false", false);
}

if (propertiesFilePath != null && propertiesFilePath.endsWith(EnvironmentVariables.LEGACY_PROPERTIES)) {
environmentVariables.remove(devonCustomToolsName);
environmentVariables.save();
}

}
environmentVariables = environmentVariables.getParent();
if ((propertiesFilePath != null) && propertiesFilePath.endsWith(EnvironmentVariables.LEGACY_PROPERTIES)) {
environmentVariables.remove(IdeVariables.DEVON_IDE_CUSTOM_TOOLS.getName());
}
environmentVariables.save();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public DirectoryMerger(IdeContext context) {
TextMerger textMerger = new TextMerger(context);
this.extension2mergerMap.put("name", textMerger); // intellij specific
this.extension2mergerMap.put("editorconfig", textMerger);
this.extension2mergerMap.put("txt", textMerger);
this.fallbackMerger = new FallbackMerger(context);
}

Expand Down Expand Up @@ -154,7 +155,7 @@ public void upgrade(Path folder) {
String filename = child.getFileName().toString();
if ("replacement-patterns.properties".equals(filename)) {
this.context.warning("Found obsolete file {}", child);
// Files.delete(child);
Files.delete(child);
}
FileMerger merger = getMerger(child);
merger.upgrade(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected boolean doUpgradeTextContent(Path workspaceFile) throws IOException {
String migratedContent = upgradeWorkspaceContent(content);
boolean modified = !migratedContent.equals(content);
if (modified) {
Files.writeString(workspaceFile, content);
Files.writeString(workspaceFile, migratedContent);
}
return modified;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void checkForXmlNamespace(Document document, Path workspaceFile) {
}
}
this.context.warning(
"The XML file {} does not contain the XML merge namespace as seems outdated. For details see:\n"
"The XML file {} does not contain the XML merge namespace and seems outdated. For details see:\n"
+ "https://github.com/devonfw/IDEasy/blob/main/documentation/configurator.adoc#xml-merger", workspaceFile);
}

Expand Down
195 changes: 0 additions & 195 deletions cli/src/main/java/com/devonfw/tools/ide/repo/CustomTool.java

This file was deleted.

Loading

0 comments on commit d607fa6

Please sign in to comment.