@@ -170,44 +170,18 @@ private void handleReplacementPatternsFiles() {
170
170
171
171
private void checkForXmlNamespace () {
172
172
this .context .info ("Scanning XML files..." );
173
- Path settingsDirectory = context .getIdeHome (). resolve ( "settings" );
173
+ Path settingsDirectory = context .getSettingsPath ( );
174
174
AtomicBoolean missingNamespaceFound = new AtomicBoolean (false );
175
175
176
176
try {
177
- Files .walk (settingsDirectory )
178
- .filter (path -> Files .isDirectory (path ) && path .getFileName ().toString ().equals ("workspace" ))
179
- .forEach (workspaceDir -> {
180
- try {
181
- Files .walk (workspaceDir )
182
- .filter (file -> Files .isRegularFile (file ) && file .toString ().endsWith (".xml" ))
183
- .forEach (file -> {
184
- try (BufferedReader reader = Files .newBufferedReader (file )) {
185
- String line ;
186
- int linesRead = 0 ;
187
- boolean namespaceFound = false ;
188
-
189
- while ((line = reader .readLine ()) != null && linesRead < 3 ) {
190
- linesRead ++;
191
- if (line .contains ("\" https://github.com/devonfw/IDEasy/merge\" " )) {
192
- namespaceFound = true ;
193
- break ;
194
- }
195
- }
196
-
197
- if (!namespaceFound ) {
198
- this .context .warning ("The XML file " + file + " does not contain the required 'xmlns:merge' attribute." );
199
- missingNamespaceFound .set (true );
200
- }
177
+ List <Path > workspaceDirs = findWorkspaceDirectories (settingsDirectory );
201
178
202
- } catch (IOException e ) {
203
- this .context .error ("Error reading the file: " + file , e );
204
- }
205
- });
206
- } catch (IOException e ) {
207
- this .context .error ("Error processing the workspace: " + workspaceDir , e );
208
- }
209
- });
179
+ for (Path workspaceDir : workspaceDirs ) {
180
+ missingNamespaceFound .set (
181
+ checkXmlFilesForNamespace (workspaceDir , missingNamespaceFound .get ()));
182
+ }
210
183
184
+ // Output the result
211
185
if (missingNamespaceFound .get ()) {
212
186
this .context .warning ("For further information, please visit https://github.com/devonfw/IDEasy/blob/main/documentation/configurator.adoc#xml-merger" );
213
187
} else {
@@ -219,6 +193,60 @@ private void checkForXmlNamespace() {
219
193
}
220
194
}
221
195
196
+ private List <Path > findWorkspaceDirectories (Path settingsDirectory ) throws IOException {
197
+ List <Path > workspaceDirs = new ArrayList <>();
198
+ Files .walk (settingsDirectory )
199
+ .filter (path -> Files .isDirectory (path ) && path .getFileName ().toString ().equals ("workspace" ))
200
+ .forEach (workspaceDirs ::add );
201
+ return workspaceDirs ;
202
+ }
203
+
204
+ private boolean checkXmlFilesForNamespace (Path workspaceDir , boolean missingNamespaceFound ) {
205
+ try {
206
+ List <Path > xmlFiles = findXmlFilesInDirectory (workspaceDir );
207
+
208
+ for (Path xmlFile : xmlFiles ) {
209
+ missingNamespaceFound = checkXmlNamespaceInFile (xmlFile , missingNamespaceFound );
210
+ }
211
+ } catch (IOException e ) {
212
+ this .context .error ("Error processing workspace directory: " + workspaceDir , e );
213
+ }
214
+ return missingNamespaceFound ;
215
+ }
216
+
217
+ private List <Path > findXmlFilesInDirectory (Path directory ) throws IOException {
218
+ List <Path > xmlFiles = new ArrayList <>();
219
+ Files .walk (directory )
220
+ .filter (file -> Files .isRegularFile (file ) && file .toString ().endsWith (".xml" ))
221
+ .forEach (xmlFiles ::add );
222
+ return xmlFiles ;
223
+ }
224
+
225
+ private boolean checkXmlNamespaceInFile (Path xmlFile , boolean missingNamespaceFound ) {
226
+ try (BufferedReader reader = Files .newBufferedReader (xmlFile )) {
227
+ String line ;
228
+ int linesRead = 0 ;
229
+ boolean namespaceFound = false ;
230
+
231
+ while ((line = reader .readLine ()) != null && linesRead < 3 ) {
232
+ linesRead ++;
233
+ if (line .contains ("\" https://github.com/devonfw/IDEasy/merge\" " )) {
234
+ namespaceFound = true ;
235
+ break ;
236
+ }
237
+ }
238
+
239
+ if (!namespaceFound ) {
240
+ this .context .warning ("The XML file " + xmlFile + " does not contain the required 'xmlns:merge' attribute." );
241
+ missingNamespaceFound = true ;
242
+ }
243
+
244
+ } catch (IOException e ) {
245
+ this .context .error ("Error reading the file: " + xmlFile , e );
246
+ }
247
+ return missingNamespaceFound ;
248
+ }
249
+
222
250
223
251
private void createCustomToolsJson (String variable ) {
224
252
try (FileWriter writer = new FileWriter (context .getIdeHome ().resolve ("settings/custom-tools.json" ).toString ())) {
0 commit comments