Skip to content

Commit

Permalink
Merge branch 'devonfw:main' into devonfw#734-improve-process-result
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeilex authored Jan 14, 2025
2 parents 6100259 + 875fbff commit e9e6dd4
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 34 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
16 changes: 8 additions & 8 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
<properties>
<mainClass>com.devonfw.tools.ide.cli.Ideasy</mainClass>
<imageName>ideasy</imageName>
<native.maven.plugin.version>0.10.2</native.maven.plugin.version>
<native.maven.plugin.version>0.10.4</native.maven.plugin.version>
<assembly.maven.plugin.version>3.7.1</assembly.maven.plugin.version>
<jline.version>3.24.1</jline.version>
<jansi.version>2.4.0</jansi.version>
<jackson.version>2.18.0</jackson.version>
<jline.version>3.28.0</jline.version>
<jansi.version>2.4.1</jansi.version>
<jackson.version>2.18.2</jackson.version>
</properties>

<dependencies>
<!-- unpack tar, gzip, bzip2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<version>1.27.1</version>
</dependency>
<!-- JSON and XML support -->
<dependency>
Expand Down Expand Up @@ -88,14 +88,14 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<version>5.15.2</version>
<scope>test</scope>
</dependency>
<!-- Needed for WireMock test support -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.1</version>
<version>2.35.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -115,7 +115,7 @@
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj3</artifactId>
<version>2.9.1</version>
<version>2.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
21 changes: 16 additions & 5 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,29 @@ default void extract(Path archiveFile, Path targetDir, Consumer<Path> postExtrac
boolean isEmptyDir(Path dir);

/**
* Makes a file executable. Equivalent of using 'chmod a+x'. Adds execute permissions to current file permissions.
* Makes a file executable (analog to 'chmod a+x').
*
* @param filePath {@link Path} to the file.
* @param file {@link Path} to the file.
*/
void makeExecutable(Path filePath);
default void makeExecutable(Path file) {

makeExecutable(file, false);
}

/**
* Makes a file executable (analog to 'chmod a+x').
*
* @param file {@link Path} to the file.
* @param confirm - {@code true} to get user confirmation before adding missing executable flags, {@code false} otherwise (always set missing flags).
*/
void makeExecutable(Path file, boolean confirm);

/**
* Like the linux touch command this method will update the modification time of the given {@link Path} to the current
* {@link System#currentTimeMillis() system time}. In case the file does not exist, it will be created as empty file. If already the
* {@link Path#getParent() parent folder} does not exist, the operation will fail.
*
* @param filePath the {@link Path} to the file or folder.
* @param file the {@link Path} to the file or folder.
*/
void touch(Path filePath);
void touch(Path file);
}
50 changes: 33 additions & 17 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -903,52 +904,67 @@ public Path findExistingFile(String fileName, List<Path> searchDirs) {
}

@Override
public void makeExecutable(Path filePath) {
public void makeExecutable(Path file, boolean confirm) {

if (Files.exists(filePath)) {
if (Files.exists(file)) {
if (SystemInfoImpl.INSTANCE.isWindows()) {
this.context.trace("Windows does not have executable flags hence omitting for file {}", filePath);
this.context.trace("Windows does not have executable flags hence omitting for file {}", file);
return;
}
try {
// Read the current file permissions
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(filePath);
Set<PosixFilePermission> existingPermissions = Files.getPosixFilePermissions(file);

// Add execute permission for all users
Set<PosixFilePermission> executablePermissions = new HashSet<>(existingPermissions);
boolean update = false;
update |= perms.add(PosixFilePermission.OWNER_EXECUTE);
update |= perms.add(PosixFilePermission.GROUP_EXECUTE);
update |= perms.add(PosixFilePermission.OTHERS_EXECUTE);
update |= executablePermissions.add(PosixFilePermission.OWNER_EXECUTE);
update |= executablePermissions.add(PosixFilePermission.GROUP_EXECUTE);
update |= executablePermissions.add(PosixFilePermission.OTHERS_EXECUTE);

if (update) {
this.context.debug("Setting executable flags for file {}", filePath);
if (confirm) {
boolean yesContinue = this.context.question(
"We want to execute " + file.getFileName() + " but this command seems to lack executable permissions!\n"
+ "Most probably the tool vendor did forgot to add x-flags in the binary release package.\n"
+ "Before running the command, we suggest to set executable permissions to the file:\n"
+ file + "\n"
+ "For security reasons we ask for your confirmation so please check this request.\n"
+ "Changing permissions from " + PosixFilePermissions.toString(existingPermissions) + " to " + PosixFilePermissions.toString(
executablePermissions) + ".\n"
+ "Do you confirm to make the command executable before running it?");
if (!yesContinue) {
return;
}
}
this.context.debug("Setting executable flags for file {}", file);
// Set the new permissions
Files.setPosixFilePermissions(filePath, perms);
Files.setPosixFilePermissions(file, executablePermissions);
} else {
this.context.trace("Executable flags already present so no need to set them for file {}", filePath);
this.context.trace("Executable flags already present so no need to set them for file {}", file);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
this.context.warning("Cannot set executable flag on file that does not exist: {}", filePath);
this.context.warning("Cannot set executable flag on file that does not exist: {}", file);
}
}

@Override
public void touch(Path filePath) {
public void touch(Path file) {

if (Files.exists(filePath)) {
if (Files.exists(file)) {
try {
Files.setLastModifiedTime(filePath, FileTime.fromMillis(System.currentTimeMillis()));
Files.setLastModifiedTime(file, FileTime.fromMillis(System.currentTimeMillis()));
} catch (IOException e) {
throw new IllegalStateException("Could not update modification-time of " + filePath, e);
throw new IllegalStateException("Could not update modification-time of " + file, e);
}
} else {
try {
Files.createFile(filePath);
Files.createFile(file);
} catch (IOException e) {
throw new IllegalStateException("Could not create empty file " + filePath, e);
throw new IllegalStateException("Could not create empty file " + file, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ProcessResult run(ProcessMode processMode) {
this.executable = systemPath.findBinary(this.executable);
this.processBuilder.environment().put(IdeVariables.PATH.getName(), path);
List<String> args = new ArrayList<>(this.arguments.size() + 4);
String interpreter = addExecutable(this.executable.toString(), args);
String interpreter = addExecutable(args);
args.addAll(this.arguments);
String command = createCommand();
if (this.context.debug().isEnabled()) {
Expand Down Expand Up @@ -306,11 +306,12 @@ private String getSheBang(Path file) {
return null;
}

private String addExecutable(String exec, List<String> args) {
private String addExecutable(List<String> args) {

String interpreter = null;
String fileExtension = FilenameUtil.getExtension(exec);
String fileExtension = FilenameUtil.getExtension(this.executable.getFileName().toString());
boolean isBashScript = "sh".equals(fileExtension);
this.context.getFileAccess().makeExecutable(this.executable, true);
if (!isBashScript) {
String sheBang = getSheBang(this.executable);
if (sheBang != null) {
Expand All @@ -334,7 +335,7 @@ private String addExecutable(String exec, List<String> args) {
args.add(0, "/i");
args.add(0, "msiexec");
}
args.add(exec);
args.add(this.executable.toString());
return interpreter;
}

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit e9e6dd4

Please sign in to comment.