Skip to content

Commit

Permalink
Merge branch 'main' into devonfw#734-improve-process-result
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Jan 14, 2025
2 parents a32b83d + c62e383 commit 8b91016
Show file tree
Hide file tree
Showing 62 changed files with 1,871 additions and 549 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE

Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/757[#757]: Support to allow settings in code repository
* https://github.com/devonfw/IDEasy/issues/826[#826]: Fix git settings check when settings folder is empty
* https://github.com/devonfw/IDEasy/issues/894[#894]: Fix ide.bat printing for initialization and error output
* https://github.com/devonfw/IDEasy/issues/759[#759]: Add UpgradeSettingsCommandlet for the upgrade of legacy devonfw-ide settings to IDEasy

The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/18?closed=1[milestone 2025.01.001].

Expand Down
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 @@ -106,7 +106,11 @@ private void setupConf(Path template, Path conf) {
}
}

private void updateSettings() {
/**
* Updates the settings repository in IDE_HOME/settings by either cloning if no such repository exists or pulling
* if the repository exists then saves the latest current commit ID in the file ".commit.id".
*/
protected void updateSettings() {

Path settingsPath = this.context.getSettingsPath();
GitContext gitContext = this.context.getGitContext();
Expand All @@ -132,6 +136,7 @@ private void updateSettings() {
}
gitContext.pullOrClone(GitUrl.of(repository), settingsPath);
}
this.context.getGitContext().saveCurrentCommitId(settingsPath, this.context.getSettingsCommitIdPath());
step.success("Successfully updated settings repository.");
} finally {
if (step != null) {
Expand Down Expand Up @@ -164,7 +169,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 @@ -88,6 +88,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new RepositoryCommandlet(context));
add(new UninstallCommandlet(context));
add(new UpdateCommandlet(context));
add(new UpgradeSettingsCommandlet(context));
add(new CreateCommandlet(context));
add(new BuildCommandlet(context));
add(new InstallPluginCommandlet(context));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.devonfw.tools.ide.commandlet;

import java.nio.file.Files;
import java.nio.file.Path;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.git.GitUrl;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.StringProperty;
Expand All @@ -18,6 +20,9 @@ public class CreateCommandlet extends AbstractUpdateCommandlet {
/** {@link FlagProperty} for skipping the setup of git repositories */
public final FlagProperty skipRepositories;

/** {@link FlagProperty} for creating a project with settings inside a code repository */
public final FlagProperty codeRepositoryFlag;

/**
* The constructor.
*
Expand All @@ -28,6 +33,7 @@ public CreateCommandlet(IdeContext context) {
super(context);
this.newProject = add(new StringProperty("", true, "project"));
this.skipRepositories = add(new FlagProperty("--skip-repositories"));
this.codeRepositoryFlag = add(new FlagProperty("--code"));
add(this.settingsRepo);
}

Expand Down Expand Up @@ -59,12 +65,32 @@ public void run() {
initializeProject(newProjectPath);
this.context.setIdeHome(newProjectPath);
super.run();

if (this.skipRepositories.isTrue()) {
this.context.info("Skipping the cloning of project repositories as specified by the user.");
} else {
updateRepositories();
}
this.context.success("Successfully created new project '{}'.", newProjectName);

}

private void initializeCodeRepository(String repoUrl) {

// clone the given repository into IDE_HOME/workspaces/main
GitUrl gitUrl = GitUrl.of(repoUrl);
Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);

// check for settings folder and create symlink to IDE_HOME/settings
Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
if (Files.exists(settingsFolder)) {
this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
// create a file in IDE_HOME with the current local commit id
this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
} else {
this.context.warning("No settings folder was found inside the code repository.");
}
}

private void initializeProject(Path newInstancePath) {
Expand All @@ -79,4 +105,25 @@ private void updateRepositories() {

this.context.getCommandletManager().getCommandlet(RepositoryCommandlet.class).run();
}

@Override
protected void updateSettings() {

if (codeRepositoryFlag.isTrue()) {
String codeRepository = this.settingsRepo.getValue();
if (codeRepository == null || codeRepository.isBlank()) {
String message = """
No code repository was given after '--code'.
Please give the code repository below that includes your settings folder.
Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
Code repository URL:
""";
codeRepository = this.context.askForInput(message);
}
initializeCodeRepository(codeRepository);
} else {
super.updateSettings();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void run() {
return;
}

List<Path> propertiesFiles = this.context.getFileAccess().listChildren(repositories, path -> path.getFileName().toString().endsWith(".properties"));
List<Path> propertiesFiles = this.context.getFileAccess()
.listChildren(repositories, path -> path.getFileName().toString().endsWith(".properties"));

boolean forceMode = this.context.isForceMode();
for (Path propertiesFile : propertiesFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ private void logSettingsLegacyStatus() {
}

private void logSettingsGitStatus() {
Path settingsPath = this.context.getSettingsPath();
Path settingsPath = this.context.getSettingsGitRepository();
if (settingsPath != null) {
GitContext gitContext = this.context.getGitContext();
if (gitContext.isRepositoryUpdateAvailable(settingsPath)) {
if (gitContext.isRepositoryUpdateAvailable(settingsPath, this.context.getSettingsCommitIdPath())) {
this.context.warning("Your settings are not up-to-date, please run 'ide update'.");
} else {
this.context.success("Your settings are up-to-date.");
Expand Down
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);
}
}
}
Loading

0 comments on commit 8b91016

Please sign in to comment.