Skip to content

Commit 43c1a70

Browse files
authored
improve logging, step debugging, various fixes (#282)
1 parent d8c158e commit 43c1a70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2641
-1664
lines changed
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
package com.devonfw.tools.ide.cli;
2-
3-
/**
4-
* {@link CliException} that is thrown if the user aborted further processing due
5-
*/
6-
public final class CliAbortException extends CliException {
7-
8-
/**
9-
* The constructor.
10-
*/
11-
public CliAbortException() {
12-
13-
super("Aborted by end-user.", 22);
14-
}
15-
16-
}
1+
package com.devonfw.tools.ide.cli;
2+
3+
import com.devonfw.tools.ide.process.ProcessResult;
4+
5+
/**
6+
* {@link CliException} that is thrown if the user aborted further processing due
7+
*/
8+
public final class CliAbortException extends CliException {
9+
10+
/**
11+
* The constructor.
12+
*/
13+
public CliAbortException() {
14+
15+
super("Aborted by end-user.", ProcessResult.ABORT);
16+
}
17+
18+
}

cli/src/main/java/com/devonfw/tools/ide/cli/CliArgument.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.devonfw.tools.ide.cli;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.Objects;
46

57
/**
@@ -256,6 +258,20 @@ private CliArgument createStart() {
256258
return new CliArgument(NAME_START, this);
257259
}
258260

261+
/**
262+
* @return a {@link String} array with all arguments starting from this one.
263+
*/
264+
public String[] asArray() {
265+
266+
List<String> args = new ArrayList<>();
267+
CliArgument current = this;
268+
while (!current.isEnd()) {
269+
args.add(current.arg);
270+
current = current.next;
271+
}
272+
return args.toArray(size -> new String[size]);
273+
}
274+
259275
@Override
260276
public String toString() {
261277

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.devonfw.tools.ide.cli;
2+
3+
import com.devonfw.tools.ide.process.ProcessResult;
4+
5+
/**
6+
* {@link CliException} that is thrown if further processing requires network but the user if offline.
7+
*/
8+
public final class CliOfflineException extends CliException {
9+
10+
/**
11+
* The constructor.
12+
*/
13+
public CliOfflineException() {
14+
15+
super("You are offline but network connection is required to perform the operation.", ProcessResult.OFFLINE);
16+
}
17+
18+
/**
19+
* The constructor.
20+
*
21+
* @param message the {@link #getMessage() message}.
22+
*/
23+
public CliOfflineException(String message) {
24+
25+
super(message, ProcessResult.OFFLINE);
26+
}
27+
28+
}

cli/src/main/java/com/devonfw/tools/ide/commandlet/AbstractUpdateCommandlet.java

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import com.devonfw.tools.ide.common.StepContainer;
3+
import java.nio.file.Files;
4+
import java.nio.file.Path;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
import java.util.Set;
8+
9+
import com.devonfw.tools.ide.context.GitContext;
410
import com.devonfw.tools.ide.context.IdeContext;
511
import com.devonfw.tools.ide.property.StringProperty;
612
import com.devonfw.tools.ide.repo.CustomTool;
13+
import com.devonfw.tools.ide.step.Step;
714
import com.devonfw.tools.ide.tool.CustomToolCommandlet;
815
import com.devonfw.tools.ide.tool.ToolCommandlet;
916
import com.devonfw.tools.ide.variable.IdeVariables;
1017

11-
import java.nio.file.Files;
12-
import java.nio.file.Path;
13-
import java.util.HashSet;
14-
import java.util.List;
15-
import java.util.Set;
16-
18+
/**
19+
* Abstract {@link Commandlet} base-class for both {@link UpdateCommandlet} and {@link CreateCommandlet}.
20+
*/
1721
public abstract class AbstractUpdateCommandlet extends Commandlet {
1822

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

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

2833
super(context);
29-
settingsRepo = new StringProperty("", false, "settingsRepository");
34+
this.settingsRepo = new StringProperty("", false, "settingsRepository");
3035
}
3136

3237
@Override
@@ -45,7 +50,13 @@ public void run() {
4550
}
4651
}
4752

48-
setupConf(templatesFolder, this.context.getIdeHome());
53+
Step step = this.context.newStep("Copy configuration templates", templatesFolder);
54+
try {
55+
setupConf(templatesFolder, this.context.getIdeHome());
56+
step.success();
57+
} finally {
58+
step.end();
59+
}
4960
updateSoftware();
5061
}
5162

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

7889
private void updateSettings() {
7990

80-
this.context.info("Updating settings repository ...");
8191
Path settingsPath = this.context.getSettingsPath();
82-
if (Files.isDirectory(settingsPath) && !this.context.getFileAccess().isEmptyDir(settingsPath)) {
83-
// perform git pull on the settings repo
84-
this.context.getGitContext().pull(settingsPath);
85-
this.context.success("Successfully updated settings repository.");
86-
} else {
87-
// check if a settings repository is given then clone, otherwise prompt user for a repository.
88-
String repository = settingsRepo.getValue();
89-
if (repository == null) {
90-
String message = "Missing your settings at " + settingsPath + " and no SETTINGS_URL is defined.\n" +
91-
"Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.asciidoc\n" +
92-
"Please contact the technical lead of your project to get the SETTINGS_URL for your project.\n" +
93-
"In case you just want to test IDEasy you may simply hit return to install the default settings.\n" +
94-
"Settings URL [" + IdeContext.DEFAULT_SETTINGS_REPO_URL + "]:";
92+
GitContext gitContext = this.context.getGitContext();
93+
Step step = null;
94+
try {
95+
// here we do not use pullOrClone to prevent asking a pointless question for repository URL...
96+
if (Files.isDirectory(settingsPath) && !this.context.getFileAccess().isEmptyDir(settingsPath)) {
97+
step = this.context.newStep("Pull settings repository");
98+
gitContext.pull(settingsPath);
99+
} else {
100+
step = this.context.newStep("Clone settings repository");
101+
// check if a settings repository is given, otherwise prompt user for a repository.
102+
String repository = this.settingsRepo.getValue();
103+
if (repository == null) {
104+
String message = "Missing your settings at " + settingsPath + " and no SETTINGS_URL is defined.\n"
105+
+ "Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.asciidoc\n"
106+
+ "Please contact the technical lead of your project to get the SETTINGS_URL for your project.\n"
107+
+ "In case you just want to test IDEasy you may simply hit return to install the default settings.\n"
108+
+ "Settings URL [" + IdeContext.DEFAULT_SETTINGS_REPO_URL + "]:";
95109
repository = this.context.askForInput(message, IdeContext.DEFAULT_SETTINGS_REPO_URL);
110+
} else if ("-".equals(repository)) {
111+
repository = IdeContext.DEFAULT_SETTINGS_REPO_URL;
112+
}
113+
gitContext.pullOrClone(repository, settingsPath);
114+
}
115+
step.success("Successfully updated settings repository.");
116+
} finally {
117+
if (step != null) {
118+
step.end();
96119
}
97-
this.context.getGitContext().pullOrClone(repository, settingsPath);
98-
this.context.success("Successfully cloned settings repository.");
99120
}
100121
}
101122

102123
private void updateSoftware() {
103124

104-
Set<ToolCommandlet> toolCommandlets = new HashSet<>();
105-
106-
// installed tools in IDE_HOME/software
107-
List<Path> softwares = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(), Files::isDirectory);
108-
for (Path software : softwares) {
109-
String toolName = software.getFileName().toString();
110-
ToolCommandlet toolCommandlet = this.context.getCommandletManager().getToolCommandletOrNull(toolName);
111-
if (toolCommandlet != null) {
112-
toolCommandlets.add(toolCommandlet);
125+
Step step = this.context.newStep("Install or update software");
126+
try {
127+
Set<ToolCommandlet> toolCommandlets = new HashSet<>();
128+
129+
// installed tools in IDE_HOME/software
130+
List<Path> softwares = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(),
131+
Files::isDirectory);
132+
for (Path software : softwares) {
133+
String toolName = software.getFileName().toString();
134+
ToolCommandlet toolCommandlet = this.context.getCommandletManager().getToolCommandletOrNull(toolName);
135+
if (toolCommandlet != null) {
136+
toolCommandlets.add(toolCommandlet);
137+
}
113138
}
114-
}
115139

116-
// regular tools in $IDE_TOOLS
117-
List<String> regularTools = IdeVariables.IDE_TOOLS.get(this.context);
118-
if (regularTools != null) {
119-
for (String regularTool : regularTools) {
120-
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(regularTool));
140+
// regular tools in $IDE_TOOLS
141+
List<String> regularTools = IdeVariables.IDE_TOOLS.get(this.context);
142+
if (regularTools != null) {
143+
for (String regularTool : regularTools) {
144+
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(regularTool));
145+
}
121146
}
122-
}
123147

124-
// custom tools in ide-custom-tools.json
125-
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
126-
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
127-
toolCommandlets.add(customToolCommandlet);
128-
}
148+
// custom tools in ide-custom-tools.json
149+
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
150+
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
151+
toolCommandlets.add(customToolCommandlet);
152+
}
129153

130-
// update/install the toolCommandlets
131-
StepContainer container = new StepContainer(this.context);
132-
for (ToolCommandlet toolCommandlet : toolCommandlets) {
133-
try {
134-
container.startStep(toolCommandlet.getName());
154+
// update/install the toolCommandlets
155+
for (ToolCommandlet toolCommandlet : toolCommandlets) {
135156
toolCommandlet.install(false);
136-
container.endStep(toolCommandlet.getName(), true, null);
137-
} catch (Exception e) {
138-
container.endStep(toolCommandlet.getName(), false, e);
139157
}
140-
}
141-
// summary
142-
if (!toolCommandlets.isEmpty()) {
143-
container.complete();
158+
step.success();
159+
} finally {
160+
step.end();
144161
}
145162
}
146163

147164
}
148-

0 commit comments

Comments
 (0)