1
1
package com .devonfw .tools .ide .commandlet ;
2
2
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 ;
4
10
import com .devonfw .tools .ide .context .IdeContext ;
5
11
import com .devonfw .tools .ide .property .StringProperty ;
6
12
import com .devonfw .tools .ide .repo .CustomTool ;
13
+ import com .devonfw .tools .ide .step .Step ;
7
14
import com .devonfw .tools .ide .tool .CustomToolCommandlet ;
8
15
import com .devonfw .tools .ide .tool .ToolCommandlet ;
9
16
import com .devonfw .tools .ide .variable .IdeVariables ;
10
17
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
+ */
17
21
public abstract class AbstractUpdateCommandlet extends Commandlet {
18
22
23
+ /** {@link StringProperty} for the settings repository URL. */
19
24
protected final StringProperty settingsRepo ;
20
25
21
26
/**
@@ -26,7 +31,7 @@ public abstract class AbstractUpdateCommandlet extends Commandlet {
26
31
public AbstractUpdateCommandlet (IdeContext context ) {
27
32
28
33
super (context );
29
- settingsRepo = new StringProperty ("" , false , "settingsRepository" );
34
+ this . settingsRepo = new StringProperty ("" , false , "settingsRepository" );
30
35
}
31
36
32
37
@ Override
@@ -45,7 +50,13 @@ public void run() {
45
50
}
46
51
}
47
52
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
+ }
49
60
updateSoftware ();
50
61
}
51
62
@@ -77,72 +88,77 @@ private void setupConf(Path template, Path conf) {
77
88
78
89
private void updateSettings () {
79
90
80
- this .context .info ("Updating settings repository ..." );
81
91
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 + "]:" ;
95
109
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 ();
96
119
}
97
- this .context .getGitContext ().pullOrClone (repository , settingsPath );
98
- this .context .success ("Successfully cloned settings repository." );
99
120
}
100
121
}
101
122
102
123
private void updateSoftware () {
103
124
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
+ }
113
138
}
114
- }
115
139
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
+ }
121
146
}
122
- }
123
147
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
+ }
129
153
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 ) {
135
156
toolCommandlet .install (false );
136
- container .endStep (toolCommandlet .getName (), true , null );
137
- } catch (Exception e ) {
138
- container .endStep (toolCommandlet .getName (), false , e );
139
157
}
140
- }
141
- // summary
142
- if (!toolCommandlets .isEmpty ()) {
143
- container .complete ();
158
+ step .success ();
159
+ } finally {
160
+ step .end ();
144
161
}
145
162
}
146
163
147
164
}
148
-
0 commit comments