Skip to content

Commit

Permalink
#298: refactoring setting environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
paz-capgemini committed Feb 28, 2025
1 parent 71f59be commit 211a00e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
20 changes: 11 additions & 9 deletions cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolInstallation;

/**
* {@link LocalToolCommandlet} for <a href="https://docs.aws.amazon.com/cli/">AWS CLI</a> (Amazon Web Services Command Line Interface).
Expand All @@ -32,15 +32,8 @@ public Aws(IdeContext context) {
public void postInstall() {

super.postInstall();
EnvironmentVariables variables = this.context.getVariables();
EnvironmentVariables typeVariables = variables.getByType(EnvironmentVariablesType.CONF);
Path awsConfigDir = this.context.getConfPath().resolve("aws");
this.context.getFileAccess().mkdirs(awsConfigDir);
Path awsConfigFile = awsConfigDir.resolve("config");
Path awsCredentialsFile = awsConfigDir.resolve("credentials");
typeVariables.set("AWS_CONFIG_FILE", awsConfigFile.toString(), true);
typeVariables.set("AWS_SHARED_CREDENTIALS_FILE", awsCredentialsFile.toString(), true);
typeVariables.save();
}

@Override
Expand Down Expand Up @@ -78,4 +71,13 @@ public void printHelp(NlsBundle bundle) {
this.context.info("To get detailed help about the usage of the AWS CLI, use \"aws help\"");
}

@Override
public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {

super.setEnvironment(environmentContext, toolInstallation, extraInstallation);
Path awsConfigDir = this.context.getConfPath().resolve("aws");
environmentContext.withEnvVar("AWS_CONFIG_FILE", awsConfigDir.resolve("config").toString());
environmentContext.withEnvVar("AWS_SHARED_CREDENTIALS_FILE", awsConfigDir.resolve("credentials").toString());
}

}
16 changes: 9 additions & 7 deletions cli/src/main/java/com/devonfw/tools/ide/tool/az/Azure.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.ToolInstallation;

/**
* {@link ToolCommandlet} for azure CLI (azure).
Expand All @@ -30,11 +30,6 @@ public Azure(IdeContext context) {
public void postInstall() {

super.postInstall();

EnvironmentVariables variables = this.context.getVariables();
EnvironmentVariables typeVariables = variables.getByType(EnvironmentVariablesType.CONF);
typeVariables.set("AZURE_CONFIG_DIR", this.context.getConfPath().resolve(".azure").toString(), true);
typeVariables.save();
this.context.getFileAccess().symlink(Path.of("wbin"), getToolPath().resolve("bin"));
}

Expand All @@ -43,4 +38,11 @@ public String getToolHelpArguments() {

return "-h";
}

@Override
public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {

super.setEnvironment(environmentContext, toolInstallation, extraInstallation);
environmentContext.withEnvVar("AZURE_CONFIG_DIR", this.context.getConfPath().resolve(".azure").toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
import com.devonfw.tools.ide.tool.ToolInstallation;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
Expand Down Expand Up @@ -48,10 +46,14 @@ protected String getBinaryName() {
@Override
public void postInstall() {

EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF);
envVars.set("GRAALVM_HOME", getToolPath().toString(), true);
envVars.save();
super.postInstall();
}

@Override
public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {

super.setEnvironment(environmentContext, toolInstallation, extraInstallation);
environmentContext.withEnvVar("GRAALVM_HOME", getToolPath().toString());
}

}

0 comments on commit 211a00e

Please sign in to comment.