Skip to content

Commit

Permalink
devonfw#13: before i merge branch 139: relative symlink into this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Nov 13, 2023
1 parent e94cc15 commit 15d2525
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
26 changes: 10 additions & 16 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 @@ -12,7 +12,6 @@
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;


/**
* {@link LocalToolCommandlet} for AWS CLI (aws).
*
Expand All @@ -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<PosixFilePermission> permissions = null;
try {
Expand All @@ -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");
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -40,7 +41,7 @@ public void testLoad() {
}

@Test
void testSave() throws Exception {
void testSave(@TempDir Path tempDir) throws Exception {

// arrange
List<String> linesToWrite = new ArrayList<>();
Expand All @@ -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<String> lines = Files.readAllLines(propertiesFilePath);
Expand Down Expand Up @@ -107,7 +108,5 @@ void testSave() throws Exception {

lines = Files.readAllLines(propertiesFilePath);
assertThat(lines).containsExactlyElementsOf(linesAfterSave);
// clean up
Files.delete(propertiesFilePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 15d2525

Please sign in to comment.