Skip to content

Commit af5a7ba

Browse files
authored
#1208: #1231: write version file on installation (#1265)
1 parent 30b98e9 commit af5a7ba

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,4 +1317,13 @@ public void reload() {
13171317
this.variables = null;
13181318
this.customToolRepository = null;
13191319
}
1320+
1321+
@Override
1322+
public void writeVersionFile(VersionIdentifier version, Path installationPath) {
1323+
1324+
assert (Files.isDirectory(installationPath));
1325+
Path versionFile = installationPath.resolve(FILE_SOFTWARE_VERSION);
1326+
getFileAccess().writeFileContent(version.toString(), versionFile);
1327+
}
1328+
13201329
}

cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,10 @@ default String findBashRequired() {
719719
*/
720720
void logIdeHomeAndRootStatus();
721721

722+
/**
723+
* @param version the {@link VersionIdentifier} to write.
724+
* @param installationPath the {@link Path directory} where to write the version to a {@link #FILE_SOFTWARE_VERSION version file}.
725+
*/
726+
void writeVersionFile(VersionIdentifier version, Path installationPath);
727+
722728
}

cli/src/main/java/com/devonfw/tools/ide/tool/IdeasyCommandlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public void installIdeasy(Path cwd) {
173173
for (Path installationArtifact : installationArtifacts) {
174174
fileAccess.copy(installationArtifact, ideasyVersionPath);
175175
}
176+
this.context.writeVersionFile(IdeVersion.getVersionIdentifier(), ideasyVersionPath);
176177
fileAccess.symlink(ideasyVersionPath, installationPath);
177178
addToShellRc(BASHRC, ideRoot, null);
178179
addToShellRc(ZSHRC, ideRoot, "autoload -U +X bashcompinit && bashcompinit");

cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.devonfw.tools.ide.tool;
22

3-
import java.io.IOException;
43
import java.nio.file.Files;
54
import java.nio.file.LinkOption;
65
import java.nio.file.Path;
7-
import java.nio.file.StandardOpenOption;
86
import java.util.Collection;
97
import java.util.Set;
108

@@ -223,11 +221,7 @@ public ToolInstallation installTool(GenericVersionRange version, ProcessContext
223221
}
224222
fileAccess.mkdirs(installationPath.getParent());
225223
fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
226-
try {
227-
Files.writeString(toolVersionFile, resolvedVersion.toString(), StandardOpenOption.CREATE_NEW);
228-
} catch (IOException e) {
229-
throw new IllegalStateException("Failed to write version file " + toolVersionFile, e);
230-
}
224+
this.context.writeVersionFile(resolvedVersion, installationPath);
231225
this.context.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
232226
return createToolInstallation(installationPath, resolvedVersion, toolVersionFile, true, processContext, extraInstallation);
233227
}

cli/src/test/java/com/devonfw/tools/ide/tool/IdeasyCommandletTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.junit.jupiter.params.provider.ValueSource;
88

99
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
10+
import com.devonfw.tools.ide.context.IdeContext;
1011
import com.devonfw.tools.ide.context.IdeTestContext;
1112
import com.devonfw.tools.ide.os.SystemInfo;
1213
import com.devonfw.tools.ide.os.SystemInfoMock;
@@ -89,6 +90,7 @@ private void verifyInstallation(Path installationPath) {
8990
assertThat(installationPath.resolve("IDEasy.pdf")).hasContent("IDEasy.pdf mock");
9091
assertThat(installationPath.resolve("setup")).hasContent("setup mock");
9192
assertThat(installationPath.resolve("setup.bat")).hasContent("setup.bat mock");
93+
assertThat(installationPath.resolve(IdeContext.FILE_SOFTWARE_VERSION)).hasContent("SNAPSHOT");
9294
}
9395

9496
}

0 commit comments

Comments
 (0)