Skip to content

Commit

Permalink
Update UpdateCommandlet.java
Browse files Browse the repository at this point in the history
  • Loading branch information
salimbouch committed Jan 18, 2024
1 parent 7c6de4c commit 7047ebd
Showing 1 changed file with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.variable.IdeVariables;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Stream;

/**
* {@link Commandlet} to update settings, software and repositories
Expand Down Expand Up @@ -43,10 +45,45 @@ public String getName() {
public void run() {

updateSettings();
this.context.getFileAccess().mkdirs(this.context.getWorkspacePath());
setupConf(this.context.getSettingsPath().resolve("devon"), this.context.getIdeHome());
updateSoftware();
updateRepositories();
}

private void setupConf(Path template, Path conf) {

try (Stream<Path> childStream = Files.list(template)) {
Iterator<Path> iterator = childStream.iterator();
while (iterator.hasNext()) {
Path child = iterator.next();
String basename = child.getFileName().toString();

if (!basename.equals(".") && !basename.equals("..") && !basename.equals("*")) {
Path confPath = conf.resolve(basename);

if (Files.isDirectory(child)) {
if (!Files.exists(confPath) || !Files.isDirectory(confPath)) {
this.context.getFileAccess().mkdirs(confPath);
}
setupConf(child, confPath);
} else if (Files.isRegularFile(child)) {
if (Files.isRegularFile(confPath)) {
this.context.debug("Configuration {} already exists - skipping to copy from {}", confPath, child);
} else {
if (!basename.equals("settings.xml")) {
this.context.info("Copying template {} to {}.", child, confPath);
this.context.getFileAccess().copy(child, confPath);
}
}
}
}
}
} catch (IOException e) {
throw new IllegalStateException("Could not setup the conf folder.", e);
}

}

private void updateSettings() {

Expand Down Expand Up @@ -77,6 +114,7 @@ private void updateSettings() {
repository = DEFAULT_SETTINGS_REPO_URL;
}
this.context.gitPullOrClone(settingsPath, repository);
this.context.success("Successfully cloned settings repository.");
}
}

Expand All @@ -96,8 +134,10 @@ private void updateSoftware() {

// regular tools in $IDE_TOOLS
List<String> regularTools = IdeVariables.IDE_TOOLS.get(this.context);
for (String regularTool : regularTools) {
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(regularTool));
if (regularTools != null) {
for (String regularTool : regularTools) {
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(regularTool));
}
}

// custom tools
Expand Down

0 comments on commit 7047ebd

Please sign in to comment.