Skip to content

Commit

Permalink
#505: set IDEA_PROPERTIES in runTool instead of postInstall (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
slskiba authored Sep 11, 2024
1 parent bb83b36 commit e73c7ae
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,16 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier
}

/**
* Method to set the environment variable for the dependency of the tool.
* Method to set environment variables for the process context.
*
* @param envContext the {@link EnvironmentContext} of the tool.
* @param dependencyPath the {@link Path} of the dependency.
* @param value the {@link Path value} of the pathVariable.
*/
private void setEnvironment(EnvironmentContext envContext, Path dependencyPath) {
protected void setEnvironment(EnvironmentContext envContext, Path value) {

if (envContext != null) {
String pathVariable = this.tool.toUpperCase(Locale.ROOT) + "_HOME";
envContext.withEnvVar(pathVariable, dependencyPath.toString());
envContext.withEnvVar(pathVariable, value.toString());
}
}

Expand Down
13 changes: 10 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,24 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, bool
ProcessContext pc;

if (existsEnvironmentContext) {
pc = getProcessContext(binaryPath, args);
pc = createProcessContext(binaryPath, args);
install(pc, true);
} else {
install(true);
pc = getProcessContext(binaryPath, args);
pc = createProcessContext(binaryPath, args);
}

pc.run(processMode);
}

private ProcessContext getProcessContext(Path binaryPath, String... args) {
/**
* Creates a new {@link ProcessContext} from the given executable with the provided arguments attached.
*
* @param binaryPath path to the binary executable for this process
* @param args the command-line arguments for this process
* @return {@link ProcessContext}
*/
protected ProcessContext createProcessContext(Path binaryPath, String... args) {

return this.context.newProcess().errorHandling(ProcessErrorHandling.THROW).executable(binaryPath).addArgs(args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.androidstudio;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.cli.CliArgument;
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.ProcessContext;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeaBasedIdeToolCommandlet;
Expand Down Expand Up @@ -51,16 +51,10 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri
args = CliArgument.prepend(args, this.context.getWorkspacePath().toString());

install(true);
super.runTool(processMode, toolVersion, args);
ProcessContext pc = createProcessContext(Path.of(getBinaryName()), args);
pc.withEnvVar("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString());
pc.run(processMode);

}

@Override
protected void postInstall() {

super.postInstall();
EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF);
envVars.set("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString(), true);
envVars.save();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.intellij;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.cli.CliArgument;
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.ProcessContext;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeaBasedIdeToolCommandlet;
Expand Down Expand Up @@ -39,7 +39,10 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri

install(true);
args = CliArgument.prepend(args, this.context.getWorkspacePath().toString());
super.runTool(ProcessMode.BACKGROUND, toolVersion, args);
ProcessContext pc = createProcessContext(Path.of(getBinaryName()), args);
pc.withEnvVar("IDEA_PROPERTIES", this.context.getWorkspacePath().resolve("idea.properties").toString());
pc.run(processMode);

}

@Override
Expand All @@ -61,13 +64,4 @@ public boolean install(boolean silent) {
return super.install(silent);
}

@Override
protected void postInstall() {

super.postInstall();
EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF);
envVars.set("IDEA_PROPERTIES", this.context.getWorkspacePath().resolve("idea.properties").toString(), true);
envVars.save();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void testAndroidStudioRun(String os, WireMockRuntimeInfo wmRuntimeInfo) t
private void checkInstallation(IdeTestContext context) {
// commandlet - android-studio
assertThat(context.getSoftwarePath().resolve("android-studio/.ide.software.version")).exists().hasContent("2024.1.1.1");
assertThat(context.getVariables().get("STUDIO_PROPERTIES")).isEqualTo(context.getWorkspacePath().resolve("studio.properties").toString());
assertThat(context).logAtSuccess().hasMessage("Successfully installed android-studio in version 2024.1.1.1");
assertThat(context).logAtSuccess().hasMessage("Install plugin: mockedPlugin");
assertThat(context.getPluginsPath().resolve("android-studio").resolve("mockedPlugin").resolve("MockedClass.class")).exists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public void testIntellijRun(String os, WireMockRuntimeInfo wmRuntimeInfo) throws
private void checkInstallation(IdeTestContext context) {

assertThat(context.getSoftwarePath().resolve("intellij/.ide.software.version")).exists().hasContent("2023.3.3");
assertThat(context.getVariables().get("IDEA_PROPERTIES")).isEqualTo(context.getWorkspacePath().resolve("idea.properties").toString());
assertThat(context).logAtSuccess().hasEntries("Successfully installed java in version 17.0.10_7",
"Successfully installed intellij in version 2023.3.3",
"Install plugin: mockedPlugin");
Expand Down

0 comments on commit e73c7ae

Please sign in to comment.