Skip to content

Commit

Permalink
devonfw#628: Fixed update fails on first error
Browse files Browse the repository at this point in the history
added catch of exceptions for ToolCommandlet installations
converted steps to try-with-resources
added new test for failed update substeps
added mvn and java repositories to update test-project
  • Loading branch information
jan-vcapgemini committed Sep 19, 2024
1 parent 7ac8cab commit 26b5aea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ private void updateConf() {
}
}

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

Expand Down Expand Up @@ -137,14 +134,13 @@ private void updateSettings() {

private void updateSoftware() {

Step step = this.context.newStep("Install or update software");
try {
try (Step step = this.context.newStep("Install or update software")) {
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();
List<Path> softwarePaths = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(), Files::isDirectory);
for (Path softwarePath : softwarePaths) {
String toolName = softwarePath.getFileName().toString();
ToolCommandlet toolCommandlet = this.context.getCommandletManager().getToolCommandletOrNull(toolName);
if (toolCommandlet != null) {
toolCommandlets.add(toolCommandlet);
Expand All @@ -167,11 +163,14 @@ private void updateSoftware() {

// update/install the toolCommandlets
for (ToolCommandlet toolCommandlet : toolCommandlets) {
toolCommandlet.install(false);
try {
toolCommandlet.install(false);
} catch (Exception e) {
step.error("Installation of " + toolCommandlet.getName() + " failed!", e);
}

}
step.success();
} finally {
step.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,30 @@ private void deleteTemplatesFolder(IdeContext context) throws IOException {
Files.delete(templates.getParent());
Files.delete(templates.getParent().getParent());
}

/**
* Tests if a sub step (installation of software) of update failed, the overall update process will not fail too.
* <p>
* See: <a href="https://github.com/devonfw/IDEasy/issues/628">#628</a> for reference.
*/
@Test
public void testRunUpdateSoftwareDoesNotFailOnFailedSoftwareInstallations() {

// arrange
IdeTestContext context = newContext(PROJECT_UPDATE);
Path javaRepository = context.getToolRepositoryPath().resolve("default").resolve("java");
context.getFileAccess().delete(javaRepository);
Path javaDownload = context.getIdeRoot().resolve("repository").resolve("java");
context.getFileAccess().delete(javaDownload);
UpdateCommandlet uc = context.getCommandletManager().getCommandlet(UpdateCommandlet.class);

// act
uc.run();

// assert
assertThat(context).logAtError().hasMessage("Installation of java failed!");
assertThat(context).logAtError().hasMessage("Installation of mvn failed!");
assertThat(context).logAtSuccess().hasMessage("Successfully updated settings repository.");
assertThat(context).logAtSuccess().hasMessage("Install or update software");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo java $*
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "mvn $*"

0 comments on commit 26b5aea

Please sign in to comment.