11package 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 ;
410import com .devonfw .tools .ide .context .IdeContext ;
511import com .devonfw .tools .ide .property .StringProperty ;
612import com .devonfw .tools .ide .repo .CustomTool ;
13+ import com .devonfw .tools .ide .step .Step ;
714import com .devonfw .tools .ide .tool .CustomToolCommandlet ;
815import com .devonfw .tools .ide .tool .ToolCommandlet ;
916import 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+ */
1721public 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