Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#13: implement tool commandlet for aws cli #122

Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4d07265
#13: implement aws toolcommandlet
MattesMrzik Oct 27, 2023
01f9484
#13: added linux specific procedure to install aws
MattesMrzik Oct 27, 2023
bd4b999
Merge branch 'devonfw:main' into feature/#13-implement-ToolCommandlet…
MattesMrzik Nov 7, 2023
a710192
aws toolcommandlet now for linux
MattesMrzik Nov 7, 2023
e94cc15
aws extends localtoolcommandlet
MattesMrzik Nov 8, 2023
c970265
#139: relative symlink feature
MattesMrzik Nov 13, 2023
a360f9f
#139: clean up
MattesMrzik Nov 13, 2023
15d2525
#13: before i merge branch 139: relative symlink into this branch
MattesMrzik Nov 13, 2023
d9f33a8
Merge remote-tracking branch 'origin/feature/#139-feature-for-making-…
MattesMrzik Nov 13, 2023
42a008b
#13: fix merge error and bug in Aws.moveAndProcessExtraction
MattesMrzik Nov 13, 2023
e295e9d
#139: added check for windows when rewriting junction
MattesMrzik Nov 16, 2023
4e1ba6f
#13: implemented suggested improvements
MattesMrzik Nov 28, 2023
66f09cf
#139: rewrote test, one still missing
MattesMrzik Nov 28, 2023
75eb709
#139: improved test, removed makeSymlinkRelative
MattesMrzik Nov 29, 2023
0719c4f
Merge remote-tracking branch 'upstream/main' into feature/#139-featur…
MattesMrzik Nov 29, 2023
cf287fe
#139: small bugfix in test
MattesMrzik Nov 29, 2023
24f3307
#139: fixed linux bug
MattesMrzik Nov 29, 2023
5252a35
Merge remote-tracking branch 'upstream/main' into feature/#13-impleme…
MattesMrzik Nov 29, 2023
70aef25
Merge remote-tracking branch 'origin/feature/#139-feature-for-making-…
MattesMrzik Nov 29, 2023
eaa85fc
Merge remote-tracking branch 'origin/main' into feature/#13-implement…
MattesMrzik Jan 8, 2024
9f4e0ea
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MattesMrzik Jan 8, 2024
2138357
#13: small change
MattesMrzik Jan 8, 2024
0b23360
#13: reformatted comment
MattesMrzik Jan 8, 2024
b5a2d4b
#13: readded @SuppressWarnings("javadoc")
MattesMrzik Jan 8, 2024
208b39d
Merge branch 'main' into feature/#13-implement-ToolCommandlet-for-AWS…
MattesMrzik Jan 11, 2024
fa619a9
Merge branch 'main' into feature/#13-implement-ToolCommandlet-for-AWS…
hohwille Jan 23, 2024
af01a32
Update cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java
MattesMrzik Jan 26, 2024
88b0e48
#13: removed paths.add(path) in SystemPath.setPath
MattesMrzik Jan 26, 2024
e521c6b
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MattesMrzik Jan 26, 2024
0c241ff
Merge branch 'feature/#13-implement-ToolCommandlet-for-AWS-CLI' of ht…
MattesMrzik Jan 26, 2024
05f1576
#13: added url to TODO issue
MattesMrzik Jan 26, 2024
f255f75
#13: added missing import
MattesMrzik Jan 26, 2024
ce21ca6
Merge branch 'main' into feature/#13-implement-ToolCommandlet-for-AWS…
MattesMrzik Jan 26, 2024
c358890
Merge branch 'main' into feature/#13-implement-ToolCommandlet-for-AWS…
hohwille Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.aws.Aws;
import com.devonfw.tools.ide.tool.az.Azure;
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
import com.devonfw.tools.ide.tool.gh.Gh;
Expand Down Expand Up @@ -72,6 +73,7 @@ private CommandletManagerImpl(IdeContext context) {
add(new KotlincNative(context));
add(new Vscode(context));
add(new Azure(context));
add(new Aws(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public Path getPath(String tool) {
*/
public void setPath(String tool, Path path) {

this.paths.add(path);
MattesMrzik marked this conversation as resolved.
Show resolved Hide resolved
this.tool2pathMap.put(tool, path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ private void deleteLinkIfExists(Path path) throws IOException {
return;
}
}
exists = exists || Files.exists(path); // "||" since broken junctions are not detected by
// Files.exists(brokenJunction)
// "||" since broken junctions are not detected by Files.exists(brokenJunction)
exists = exists || Files.exists(path);
boolean isSymlink = exists && Files.isSymbolicLink(path);

assert !(isSymlink && isJunction);
Expand Down Expand Up @@ -378,7 +378,7 @@ private Path adaptPath(Path source, Path targetLink, boolean relative) throws IO

/**
* Creates a Windows junction at {@code targetLink} pointing to {@code source}.
*
*
* @param source must be another Windows junction or a directory.
* @param targetLink the location of the Windows junction.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void run() {
* Ensures the tool is installed and then runs this tool with the given arguments.
*
* @param toolVersion the explicit version (pattern) to run. Typically {@code null} to ensure the configured version
* is installed and use that one. Otherwise the specified version will be installed in the software repository
* is installed and use that one. Otherwise, the specified version will be installed in the software repository
* without touching and IDE installation and used to run.
* @param args the commandline arguments to run the tool.
*/
Expand Down Expand Up @@ -266,14 +266,19 @@ protected void extract(Path file, Path targetDir) {
} else {
throw new IllegalStateException("Unknown archive format " + extension + ". Can not extract " + file);
}
fileAccess.move(getProperInstallationSubDirOf(tmpDir), targetDir);
moveAndProcessExtraction(getProperInstallationSubDirOf(tmpDir), targetDir);
fileAccess.delete(tmpDir);
} else {
this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", getName(), file);
fileAccess.move(file, targetDir);
}
}

protected void moveAndProcessExtraction(Path from, Path to) {

this.context.getFileAccess().move(from, to);
}

/**
* @return {@code true} to extract (unpack) the downloaded binary file, {@code false} otherwise.
*/
Expand Down
99 changes: 99 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.devonfw.tools.ide.tool.aws;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

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.tool.LocalToolCommandlet;

/**
* {@link LocalToolCommandlet} for AWS CLI (aws).
*
* @see <a href="https://docs.aws.amazon.com/cli/">AWS CLI homepage</a>
*/

public class Aws extends LocalToolCommandlet {

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public Aws(IdeContext context) {

super(context, "aws", Set.of(TAG_CLOUD));
MattesMrzik marked this conversation as resolved.
Show resolved Hide resolved
}

private void makeExecutable(Path file) {

// TODO this can be removed if issue #132 is fixed
Set<PosixFilePermission> permissions = null;
try {
permissions = Files.getPosixFilePermissions(file);
permissions.add(PosixFilePermission.GROUP_EXECUTE);
permissions.add(PosixFilePermission.OWNER_EXECUTE);
permissions.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(file, permissions);
} catch (IOException e) {
throw new RuntimeException("Adding execution permission for Group, Owner and Others did not work for " + file, e);
}
}

@Override
protected void moveAndProcessExtraction(Path from, Path to) {
MattesMrzik marked this conversation as resolved.
Show resolved Hide resolved

if (this.context.getSystemInfo().isLinux()) {
// make binary executable using java nio because unpacking didn't preserve the file permissions
// TODO this can be removed if issue #132 is fixed
Path awsInDistPath = from.resolve("dist").resolve("aws");
Path awsCompleterInDistPath = from.resolve("dist").resolve("aws_completer");
makeExecutable(awsInDistPath);
makeExecutable(awsCompleterInDistPath);

// running the install-script that aws shipped
ProcessContext pc = this.context.newProcess();
Path linuxInstallScript = from.resolve("install");
pc.executable(linuxInstallScript);
pc.addArgs("-i", from.toString(), "-b", from.toString());
pc.run();
hohwille marked this conversation as resolved.
Show resolved Hide resolved

// 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() }) {
Path link = from.resolve(file);
try {
this.context.getFileAccess().symlink(link.toRealPath(), link, true);
} catch (IOException e) {
throw new RuntimeException(
"Failed to replace absolute link (" + link + ") provided by AWS install script with relative link.", e);
}
}
this.context.getFileAccess().delete(linuxInstallScript);
this.context.getFileAccess().delete(from.resolve("dist"));
}
super.moveAndProcessExtraction(from, to);
}

@Override
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();
}
}
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ usage=Usage:
values=Values:
commandlets=Available commandlets:
options=Options:
cmd-aws=Tool commandlet for AWS CLI.
cmd-az=Tool commandlet for Azure CLI.
cmd-env=Print the environment variables to set and export.
cmd-get-version=Get the version of the selected tool.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ usage=Verwendung:
values=Werte:
commandlets=Verfügbare Kommandos:
options=Optionen:
cmd-aws=Werkzeug Kommando fuer AWS Kommandoschnittstelle.
cmd-az=Werkzeug Kommando fuer Azure Kommandoschnittstelle.
cmd-env=Gibt die zu setztenden und exportierenden Umgebungsvariablen aus.
cmd-get-version=Zeigt die Version des selektierten Werkzeugs an.
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 All @@ -76,7 +77,7 @@ void testSave() throws Exception {
variables.set("var5", "5", true);
variables.set("var1", "1.0", false);
variables.set("var10", "10", false);
variables.set("var11", "11", true); // var11 must be set after var 10, the other lines can be shuffled
variables.set("var11", "11", true);
variables.set("var3", "3", false);
variables.set("var7", "7", true);
variables.set("var6", "6.0", true);
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 @@ -325,7 +325,7 @@ private void createSymlinks(FileAccess fa, Path dir, boolean relative) {

/**
* Checks if the symlinks exist. This is used by the tests of {@link FileAccessImpl#symlink(Path, Path, boolean)}.
*
*
* @param dir the {@link Path} to the directory where the symlinks are expected.
*/
private void assertSymlinksExist(Path dir) {
Expand Down
Loading