Skip to content

Commit

Permalink
#759: completed last things (*.properties in ~)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jan 9, 2025
1 parent cb81b78 commit 1307d33
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.
Expand Down Expand Up @@ -97,39 +98,48 @@ void updateProperties() {
}
}

// 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 templateProperties = this.context.getSettingsTemplatePath().resolve(IdeContext.FOLDER_CONF).resolve(EnvironmentVariables.LEGACY_PROPERTIES);
if (Files.exists(templateProperties)) {
EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.USER,
templateProperties, this.context);
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 (propertiesFilePath != null || environmentVariables.getLegacyPropertiesFilePath() != null) {
if (environmentVariables.getLegacyConfiguration() != 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 legacySupportEnabledValue = environmentVariables.get(legacySupportEnabledName);
if (!"false".equals(legacySupportEnabledValue)) {
environmentVariables.set(legacySupportEnabledName, "false", false);
}
environmentVariables.set(IdeVariables.IDE_VARIABLE_SYNTAX_LEGACY_SUPPORT_ENABLED.getName(), "false", false);
}
if ((propertiesFilePath != null) && propertiesFilePath.endsWith(EnvironmentVariables.LEGACY_PROPERTIES)) {
environmentVariables.remove(IdeVariables.DEVON_IDE_CUSTOM_TOOLS.getName());
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::mapLegacyIntellijEdition);
environmentVariables.save();
this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public abstract class AbstractIdeContext implements IdeContext {

private Path softwareExtraPath;

private Path softwareRepositoryPath;
private final Path softwareRepositoryPath;

protected Path pluginsPath;

Expand All @@ -91,15 +91,15 @@ public abstract class AbstractIdeContext implements IdeContext {

protected Path urlsPath;

private Path tempPath;
private final Path tempPath;

private Path tempDownloadPath;
private final Path tempDownloadPath;

private Path cwd;

private Path downloadPath;

private Path toolRepositoryPath;
private final Path toolRepositoryPath;

protected Path userHome;

Expand Down Expand Up @@ -308,11 +308,10 @@ private boolean isIdeHome(Path dir) {
private EnvironmentVariables createVariables() {

AbstractEnvironmentVariables system = createSystemVariables();
AbstractEnvironmentVariables user = extendVariables(system, this.userHomeIde, EnvironmentVariablesType.USER);
AbstractEnvironmentVariables settings = extendVariables(user, this.settingsPath, EnvironmentVariablesType.SETTINGS);
// TODO should we keep this workspace properties? Was this feature ever used?
AbstractEnvironmentVariables workspace = extendVariables(settings, this.workspacePath, EnvironmentVariablesType.WORKSPACE);
AbstractEnvironmentVariables conf = extendVariables(workspace, this.confPath, EnvironmentVariablesType.CONF);
AbstractEnvironmentVariables user = system.extend(this.userHomeIde, EnvironmentVariablesType.USER);
AbstractEnvironmentVariables settings = user.extend(this.settingsPath, EnvironmentVariablesType.SETTINGS);
AbstractEnvironmentVariables workspace = settings.extend(this.workspacePath, EnvironmentVariablesType.WORKSPACE);
AbstractEnvironmentVariables conf = workspace.extend(this.confPath, EnvironmentVariablesType.CONF);
return conf.resolved();
}

Expand All @@ -321,26 +320,6 @@ protected AbstractEnvironmentVariables createSystemVariables() {
return EnvironmentVariables.ofSystem(this);
}

protected AbstractEnvironmentVariables extendVariables(AbstractEnvironmentVariables envVariables, Path propertiesPath, EnvironmentVariablesType type) {

Path propertiesFile = null;
if (propertiesPath == null) {
trace("Configuration directory for type {} does not exist.", type);
} else if (Files.isDirectory(propertiesPath)) {
propertiesFile = propertiesPath.resolve(EnvironmentVariables.DEFAULT_PROPERTIES);
boolean legacySupport = (type != EnvironmentVariablesType.USER);
if (legacySupport && !Files.exists(propertiesFile)) {
Path legacyFile = propertiesPath.resolve(EnvironmentVariables.LEGACY_PROPERTIES);
if (Files.exists(legacyFile)) {
propertiesFile = legacyFile;
}
}
} else {
debug("Configuration directory {} does not exist.", propertiesPath);
}
return envVariables.extend(propertiesFile, type);
}

@Override
public SystemInfo getSystemInfo() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public VariableSource getSource() {
protected boolean isExported(String name) {

if (this.parent != null) {
if (this.parent.isExported(name)) {
return true;
}
return this.parent.isExported(name);
}
return false;
}
Expand Down Expand Up @@ -144,13 +142,14 @@ protected VariableLine createVariableLine(String name, boolean onlyExported, Abs
}

/**
* @param propertiesFilePath the {@link #getPropertiesFilePath() propertiesFilePath} of the child {@link EnvironmentVariables}.
* @param propertiesFolderPath the {@link Path} to the folder containing the {@link #getPropertiesFilePath() properties file} of the child
* {@link EnvironmentVariables}.
* @param type the {@link #getType() type}.
* @return the new {@link EnvironmentVariables}.
*/
public AbstractEnvironmentVariables extend(Path propertiesFilePath, EnvironmentVariablesType type) {
public AbstractEnvironmentVariables extend(Path propertiesFolderPath, EnvironmentVariablesType type) {

return new EnvironmentVariablesPropertiesFile(this, type, propertiesFilePath, this.context);
return new EnvironmentVariablesPropertiesFile(this, type, propertiesFolderPath, null, this.context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ default EnvironmentVariables getParent() {
return null;
}

/**
* @param name the {@link com.devonfw.tools.ide.variable.VariableDefinition#getName() name} of the variable to set.
* @param value the new {@link #get(String) value} of the variable to set. May be {@code null} to unset the variable.
* @return the old variable value.
*/
default String set(String name, String value) {

throw new UnsupportedOperationException();
}

/**
* @param name the {@link com.devonfw.tools.ide.variable.VariableDefinition#getName() name} of the variable to set.
* @param value the new {@link #get(String) value} of the variable to set. May be {@code null} to unset the variable.
Expand Down
Loading

0 comments on commit 1307d33

Please sign in to comment.