Skip to content

Commit

Permalink
Merge branch 'devonfw#420-create-win-installer' of https://github.com…
Browse files Browse the repository at this point in the history
…/alfeilex/IDEasy into devonfw#420-create-win-installer
  • Loading branch information
alfeilex committed Feb 26, 2025
2 parents 7ab9bc7 + edeba9d commit 509ef3e
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.ToolProperty;
import com.devonfw.tools.ide.tool.IdeasyCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

/**
Expand All @@ -21,7 +22,7 @@ public UninstallCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
this.tools = add(new ToolProperty("", true, true, "tool"));
this.tools = add(new ToolProperty("", false, true, "tool"));
}

@Override
Expand All @@ -30,10 +31,27 @@ public String getName() {
return "uninstall";
}

@Override
public boolean isIdeRootRequired() {

return this.tools.getValueCount() > 0;
}

@Override
public void run() {

for (int i = 0; i < this.tools.getValueCount(); i++) {
int valueCount = this.tools.getValueCount();
if (valueCount == 0) {
if (!this.context.isForceMode()) {
this.context.askToContinue("Sub-command uninstall without any further arguments will perform the entire uninstallation of IDEasy.\n"
+ "Since this is typically not to be called manually, you may have forgotten to specify the tool to install as extra argument.\n"
+ "The current command will uninstall IDEasy from your computer. Are you sure?");
}
IdeasyCommandlet ideasy = new IdeasyCommandlet(this.context);
ideasy.uninstallIdeasy();
return;
}
for (int i = 0; i < valueCount; i++) {
ToolCommandlet toolCommandlet = this.tools.getValue(i);
if (toolCommandlet.getInstalledVersion() != null) {
toolCommandlet.uninstall();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.devonfw.tools.ide.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;

/**
* Represents the PATH variable in a structured way. Similar to {@link SystemPath} but much simper: It just tokenizes the PATH into a {@link java.util.List} of
* {@link String}s.
*/
public class SimpleSystemPath {

private final char separator;

private final List<String> entries;

private SimpleSystemPath(char separator, List<String> entries) {

super();
this.separator = separator;
this.entries = entries;
}

/**
* @return the entries of this PATH as a mutable {@link List}.
*/
public List<String> getEntries() {

return this.entries;
}

/**
* Remove all entries from this PATH that match the given {@link Predicate}.
*
* @param filter the {@link Predicate} {@link Predicate#test(Object) deciding} what to filter and remove.
*/
public void removeEntries(Predicate<String> filter) {

Iterator<String> iterator = this.entries.iterator();
while (iterator.hasNext()) {
String entry = iterator.next();
if (filter.test(entry)) {
iterator.remove();
}
}
}

@Override
public String toString() {

StringBuilder sb = new StringBuilder();
boolean first = true;
for (String entry : this.entries) {
if (first) {
first = false;
} else {
sb.append(this.separator);
}
sb.append(entry);
}
return sb.toString();
}

/**
* @param path the entire PATH as {@link String},
* @param separator the separator character.
* @return the {@link SimpleSystemPath}.
*/
public static SimpleSystemPath of(String path, char separator) {

List<String> entries = new ArrayList<>();
int start = 0;
int len = path.length();
while (start < len) {
int end = path.indexOf(separator, start);
if (end < 0) {
end = len;
}
entries.add(path.substring(start, end));
start = end + 1;
}
return new SimpleSystemPath(separator, entries);
}
}
5 changes: 5 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public interface WindowsHelper {
*/
void setUserEnvironmentValue(String key, String value);

/**
* @param key the name of the environment variable to remove.
*/
void removeUserEnvironmentValue(String key);

/**
* @param key the name of the environment variable.
* @return the value of the environment variable in the users context.
Expand Down
11 changes: 11 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.process.ProcessResult;

Expand Down Expand Up @@ -33,6 +34,16 @@ public void setUserEnvironmentValue(String key, String value) {
assert (result.isSuccessful());
}

@Override
public void removeUserEnvironmentValue(String key) {
ProcessResult result = this.context.newProcess().executable("reg").addArgs("delete", HKCU_ENVIRONMENT, "/v", key, "/f").run(ProcessMode.DEFAULT_CAPTURE);
if (result.isSuccessful()) {
this.context.debug("Removed environment variable {}", key);
} else {
result.log(IdeLogLevel.WARNING, this.context);
}
}

@Override
public String getUserEnvironmentValue(String key) {

Expand Down
Loading

0 comments on commit 509ef3e

Please sign in to comment.