From 15d252513f6e5d83a7b9b2e1034bf79b6aff894b Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Mon, 13 Nov 2023 16:15:09 +0100 Subject: [PATCH] #13: before i merge branch 139: relative symlink into this branch --- .../com/devonfw/tools/ide/tool/aws/Aws.java | 26 +++++++------------ ...nvironmentVariablesPropertiesFileTest.java | 7 +++-- .../ide/version/VersionIdentifierTest.java | 2 +- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java b/cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java index b6b567bcc..85149a624 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java @@ -12,7 +12,6 @@ import com.devonfw.tools.ide.process.ProcessContext; import com.devonfw.tools.ide.tool.LocalToolCommandlet; - /** * {@link LocalToolCommandlet} for AWS CLI (aws). * @@ -30,7 +29,9 @@ public Aws(IdeContext context) { super(context, "aws", Set.of(TAG_CLOUD)); } + private void makeExecutable(Path file) { + // TODO this can be removed if issue #132 is fixed Set permissions = null; try { @@ -45,19 +46,18 @@ private void makeExecutable(Path file) { } @Override - protected void moveAndProcessExtraction(Path from, Path to) { + protected void moveAndProcessExtraction(Path to, Path from) { + if (!this.context.getSystemInfo().isLinux()) { this.context.getFileAccess().move(from, to); } else { - // make binary executable using java nio - // because unpacking didn't preserve the file permissions + // make binary executable using java nio because unpacking didn't preserve the file permissions Path awsInDistPath = from.resolve("dist").resolve("aws"); Path awsCompleterInDistPath = from.resolve("dist").resolve("aws_completer"); // TODO this can be removed if issue #132 is fixed makeExecutable(awsInDistPath); makeExecutable(awsCompleterInDistPath); - // running the install-script that aws shipped ProcessContext pc = this.context.newProcess(); Path linuxInstallScript = from.resolve("install"); @@ -66,17 +66,11 @@ protected void moveAndProcessExtraction(Path from, Path to) { pc.run(); // the install-script that aws ships creates symbolic links to binaries but using absolute paths - // since the current process happens in a temporary dir these links wouldn't be valid after moving the installation - // files to the target dir. So the absolute paths are replaced by relative ones. - for (String file : new String[]{"aws", "aws_completer", Path.of("v2").resolve("current").toString()}) { - try { - Path link = from.resolve(file); - Path linkTarget = link.toRealPath(); - this.context.getFileAccess().delete(link); // delete old absolute link - this.context.getFileAccess().relativeSymlink(link, linkTarget); // and replace it by the new relative link - } catch (IOException e) { - throw new RuntimeException(e); - } + // since the current process happens in a temporary dir these links wouldn't be valid after moving the + // installation files to the target dir. So the absolute paths are replaced by relative ones. + for (String file : new String[] { "aws", "aws_completer", Path.of("v2").resolve("current").toString() }) { + Path link = from.resolve(file); + this.context.getFileAccess().makeSymlinkRelative(link, true); } this.context.getFileAccess().delete(linuxInstallScript); this.context.getFileAccess().delete(from.resolve("dist")); diff --git a/cli/src/test/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFileTest.java b/cli/src/test/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFileTest.java index c7e0bbddb..bf26fa2b2 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFileTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFileTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import com.devonfw.tools.ide.context.IdeTestContextMock; +import org.junit.jupiter.api.io.TempDir; /** * Test of {@link EnvironmentVariablesPropertiesFile}. @@ -40,7 +41,7 @@ public void testLoad() { } @Test - void testSave() throws Exception { + void testSave(@TempDir Path tempDir) throws Exception { // arrange List linesToWrite = new ArrayList<>(); @@ -60,7 +61,7 @@ void testSave() throws Exception { linesToWrite.add("# 5th comment"); linesToWrite.add("var9=9"); - Path propertiesFilePath = Path.of("target/tmp-EnvironmentVariablesPropertiesFileTest-ide.properties"); + Path propertiesFilePath = tempDir.resolve("test.properties"); Files.write(propertiesFilePath, linesToWrite, StandardOpenOption.CREATE_NEW); // check if this writing was correct List lines = Files.readAllLines(propertiesFilePath); @@ -107,7 +108,5 @@ void testSave() throws Exception { lines = Files.readAllLines(propertiesFilePath); assertThat(lines).containsExactlyElementsOf(linesAfterSave); - // clean up - Files.delete(propertiesFilePath); } } \ No newline at end of file diff --git a/cli/src/test/java/com/devonfw/tools/ide/version/VersionIdentifierTest.java b/cli/src/test/java/com/devonfw/tools/ide/version/VersionIdentifierTest.java index 9256e6e7d..20fa0ed8d 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/version/VersionIdentifierTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/version/VersionIdentifierTest.java @@ -93,7 +93,7 @@ public void testIllegal() { for (String version : illegalVersions) { try { VersionIdentifier.of(version); - fail("Illegal verion '" + version + "' did not cause an exception!"); + fail("Illegal version '" + version + "' did not cause an exception!"); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalArgumentException.class); assertThat(e).hasMessageContaining(version);