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

improve logging, step debugging, various fixes #282

Merged
merged 28 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cbe4711
added advanced step logging/tracing infrastructure
hohwille Apr 9, 2024
7a2c52d
fixes and improvements to GitContext, added missing JavaDoc
hohwille Apr 9, 2024
f8d4f1d
improved logging
hohwille Apr 9, 2024
4601632
fixed and improved variables
hohwille Apr 9, 2024
cc2fa6d
improved exception handling and return codes
hohwille Apr 9, 2024
431a6d2
use new step debugging, remove StepContainer
hohwille Apr 9, 2024
5fd7cd3
Merge branch 'main' into feature/improve-step-logging
hohwille Apr 9, 2024
cda8d9a
further improvements to step and logging
hohwille Apr 9, 2024
0dc0366
added missing JavaDoc
hohwille Apr 9, 2024
88f4655
avoid undesired log message
hohwille Apr 9, 2024
f050774
removed asterisks falsely added by IDE formatter bug
hohwille Apr 9, 2024
3fed048
#260: additional fixes to also handle error of env command and log va…
hohwille Apr 9, 2024
cb696c2
#260: avoid requirement for ideasy[.exe] to be on PATH
hohwille Apr 9, 2024
e153acf
fixed test logging
hohwille Apr 9, 2024
00a16bc
fixed tests and assertions
hohwille Apr 9, 2024
b162534
Update cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl…
hohwille Apr 12, 2024
32115c8
Update cli/src/main/java/com/devonfw/tools/ide/step/StepSummary.java
hohwille Apr 12, 2024
0dfbfd3
Update cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
hohwille Apr 12, 2024
7fa7f80
CliOfflineException.java: complete JavaDoc
hohwille Apr 12, 2024
de16143
Update cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
hohwille Apr 12, 2024
04062a6
Update cli/src/main/java/com/devonfw/tools/ide/step/Step.java
hohwille Apr 12, 2024
3fc41d5
Update cli/src/main/java/com/devonfw/tools/ide/step/Step.java
hohwille Apr 12, 2024
cb31366
GitContext.java: imroved JavaDoc
hohwille Apr 12, 2024
cee0726
Update cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
hohwille Apr 12, 2024
26005ba
Update cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
hohwille Apr 12, 2024
b106714
Update cli/src/main/java/com/devonfw/tools/ide/step/StepSummary.java
hohwille Apr 12, 2024
7887aa9
Update cli/src/main/java/com/devonfw/tools/ide/step/Step.java
hohwille Apr 12, 2024
0c1806a
Update cli/src/main/java/com/devonfw/tools/ide/step/Step.java
hohwille Apr 12, 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
34 changes: 18 additions & 16 deletions cli/src/main/java/com/devonfw/tools/ide/cli/CliAbortException.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.devonfw.tools.ide.cli;

/**
* {@link CliException} that is thrown if the user aborted further processing due
*/
public final class CliAbortException extends CliException {

/**
* The constructor.
*/
public CliAbortException() {

super("Aborted by end-user.", 22);
}

}
package com.devonfw.tools.ide.cli;

import com.devonfw.tools.ide.process.ProcessResult;

/**
* {@link CliException} that is thrown if the user aborted further processing due
*/
public final class CliAbortException extends CliException {

/**
* The constructor.
*/
public CliAbortException() {

super("Aborted by end-user.", ProcessResult.ABORT);
}

}
16 changes: 16 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/cli/CliArgument.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.devonfw.tools.ide.cli;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -256,6 +258,20 @@ private CliArgument createStart() {
return new CliArgument(NAME_START, this);
}

/**
* @return a {@link String} array with all arguments starting from this one.
*/
public String[] asArray() {

List<String> args = new ArrayList<>();
CliArgument current = this;
while (!current.isEnd()) {
args.add(current.arg);
current = current.next;
}
return args.toArray(size -> new String[size]);
}

@Override
public String toString() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.devonfw.tools.ide.cli;

import com.devonfw.tools.ide.process.ProcessResult;

/**
* {@link CliException} that is thrown if the user aborted further processing due
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved
*/
public final class CliOfflineException extends CliException {

/**
* The constructor.
*/
public CliOfflineException() {

super("You are offline but network connection is required to perform the operation.", ProcessResult.OFFLINE);
}

/**
* The constructor.
*
* @param message the {@link #getMessage() message}.
*/
public CliOfflineException(String message) {

super(message, ProcessResult.OFFLINE);
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.common.StepContainer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.devonfw.tools.ide.context.GitContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.StringProperty;
import com.devonfw.tools.ide.repo.CustomTool;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.tool.CustomToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.variable.IdeVariables;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Abstract {@link Commandlet} base-class for both {@link UpdateCommandlet} and {@link CreateCommandlet}.
*/
public abstract class AbstractUpdateCommandlet extends Commandlet {

/** {@link StringProperty} for the settings repository URL. */
protected final StringProperty settingsRepo;

/**
Expand All @@ -26,7 +31,7 @@ public abstract class AbstractUpdateCommandlet extends Commandlet {
public AbstractUpdateCommandlet(IdeContext context) {

super(context);
settingsRepo = new StringProperty("", false, "settingsRepository");
this.settingsRepo = new StringProperty("", false, "settingsRepository");
}

@Override
Expand All @@ -45,7 +50,13 @@ public void run() {
}
}

setupConf(templatesFolder, this.context.getIdeHome());
Step step = this.context.newStep("Copy configuration templates", templatesFolder);
try {
setupConf(templatesFolder, this.context.getIdeHome());
step.success();
} finally {
step.end();
}
updateSoftware();
}

Expand Down Expand Up @@ -77,72 +88,77 @@ private void setupConf(Path template, Path conf) {

private void updateSettings() {

this.context.info("Updating settings repository ...");
Path settingsPath = this.context.getSettingsPath();
if (Files.isDirectory(settingsPath) && !this.context.getFileAccess().isEmptyDir(settingsPath)) {
// perform git pull on the settings repo
this.context.getGitContext().pull(settingsPath);
this.context.success("Successfully updated settings repository.");
} else {
// check if a settings repository is given then clone, otherwise prompt user for a repository.
String repository = settingsRepo.getValue();
if (repository == null) {
String message = "Missing your settings at " + settingsPath + " and no SETTINGS_URL is defined.\n" +
"Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.asciidoc\n" +
"Please contact the technical lead of your project to get the SETTINGS_URL for your project.\n" +
"In case you just want to test IDEasy you may simply hit return to install the default settings.\n" +
"Settings URL [" + IdeContext.DEFAULT_SETTINGS_REPO_URL + "]:";
GitContext gitContext = this.context.getGitContext();
Step step = null;
try {
// here we do not use pullOrClone to prevent asking a pointless question for repository URL...
if (Files.isDirectory(settingsPath) && !this.context.getFileAccess().isEmptyDir(settingsPath)) {
step = this.context.newStep("Pull settings repository");
gitContext.pull(settingsPath);
} else {
step = this.context.newStep("Clone settings repository");
// check if a settings repository is given, otherwise prompt user for a repository.
String repository = this.settingsRepo.getValue();
if (repository == null) {
String message = "Missing your settings at " + settingsPath + " and no SETTINGS_URL is defined.\n"
+ "Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.asciidoc\n"
+ "Please contact the technical lead of your project to get the SETTINGS_URL for your project.\n"
+ "In case you just want to test IDEasy you may simply hit return to install the default settings.\n"
+ "Settings URL [" + IdeContext.DEFAULT_SETTINGS_REPO_URL + "]:";
repository = this.context.askForInput(message, IdeContext.DEFAULT_SETTINGS_REPO_URL);
} else if ("-".equals(repository)) {
repository = IdeContext.DEFAULT_SETTINGS_REPO_URL;
}
gitContext.pullOrClone(repository, settingsPath);
}
step.success("Successfully updated settings repository.");
} finally {
if (step != null) {
step.end();
}
this.context.getGitContext().pullOrClone(repository, settingsPath);
this.context.success("Successfully cloned settings repository.");
}
}

private void updateSoftware() {

Set<ToolCommandlet> toolCommandlets = new HashSet<>();

// installed tools in IDE_HOME/software
List<Path> softwares = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(), Files::isDirectory);
for (Path software : softwares) {
String toolName = software.getFileName().toString();
ToolCommandlet toolCommandlet = this.context.getCommandletManager().getToolCommandletOrNull(toolName);
if (toolCommandlet != null) {
toolCommandlets.add(toolCommandlet);
Step step = this.context.newStep("Install or update software");
try {
Set<ToolCommandlet> toolCommandlets = new HashSet<>();

// installed tools in IDE_HOME/software
List<Path> softwares = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(),
Files::isDirectory);
for (Path software : softwares) {
String toolName = software.getFileName().toString();
ToolCommandlet toolCommandlet = this.context.getCommandletManager().getToolCommandletOrNull(toolName);
if (toolCommandlet != null) {
toolCommandlets.add(toolCommandlet);
}
}
}

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

// custom tools in ide-custom-tools.json
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
toolCommandlets.add(customToolCommandlet);
}
// custom tools in ide-custom-tools.json
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
toolCommandlets.add(customToolCommandlet);
}

// update/install the toolCommandlets
StepContainer container = new StepContainer(this.context);
for (ToolCommandlet toolCommandlet : toolCommandlets) {
try {
container.startStep(toolCommandlet.getName());
// update/install the toolCommandlets
for (ToolCommandlet toolCommandlet : toolCommandlets) {
toolCommandlet.install(false);
container.endStep(toolCommandlet.getName(), true, null);
} catch (Exception e) {
container.endStep(toolCommandlet.getName(), false, e);
}
}
// summary
if (!toolCommandlets.isEmpty()) {
container.complete();
step.success();
} finally {
step.end();
}
}

}

Loading
Loading