• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 21013659204

14 Jan 2026 11:29PM UTC coverage: 70.365% (+0.5%) from 69.904%
21013659204

Pull #1675

github

web-flow
Merge 7a3aa598b into fcadaae82
Pull Request #1675: #1298: support ide-extra-tools.json #1658: prevent Jackson reflection

4015 of 6292 branches covered (63.81%)

Branch coverage included in aggregate %.

10440 of 14251 relevant lines covered (73.26%)

3.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.23
cli/src/main/java/com/devonfw/tools/ide/commandlet/AbstractUpdateCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.io.IOException;
4
import java.nio.file.Files;
5
import java.nio.file.Path;
6
import java.util.HashSet;
7
import java.util.Iterator;
8
import java.util.List;
9
import java.util.Set;
10
import java.util.stream.Stream;
11

12
import com.devonfw.tools.ide.cli.CliException;
13
import com.devonfw.tools.ide.context.AbstractIdeContext;
14
import com.devonfw.tools.ide.context.IdeContext;
15
import com.devonfw.tools.ide.context.IdeStartContextImpl;
16
import com.devonfw.tools.ide.git.GitContext;
17
import com.devonfw.tools.ide.git.GitUrl;
18
import com.devonfw.tools.ide.git.repository.RepositoryCommandlet;
19
import com.devonfw.tools.ide.io.FileAccess;
20
import com.devonfw.tools.ide.property.FlagProperty;
21
import com.devonfw.tools.ide.property.StringProperty;
22
import com.devonfw.tools.ide.step.Step;
23
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
24
import com.devonfw.tools.ide.tool.ToolCommandlet;
25
import com.devonfw.tools.ide.tool.ToolEdition;
26
import com.devonfw.tools.ide.tool.ToolEditionAndVersion;
27
import com.devonfw.tools.ide.tool.ToolInstallRequest;
28
import com.devonfw.tools.ide.tool.custom.CustomToolCommandlet;
29
import com.devonfw.tools.ide.tool.custom.CustomToolMetadata;
30
import com.devonfw.tools.ide.tool.extra.ExtraToolInstallation;
31
import com.devonfw.tools.ide.tool.extra.ExtraTools;
32
import com.devonfw.tools.ide.tool.extra.ExtraToolsMapper;
33
import com.devonfw.tools.ide.variable.IdeVariables;
34
import com.devonfw.tools.ide.version.VersionIdentifier;
35

36
/**
37
 * Abstract {@link Commandlet} base-class for both {@link UpdateCommandlet} and {@link CreateCommandlet}.
38
 */
39
public abstract class AbstractUpdateCommandlet extends Commandlet {
40

41
  private static final String MESSAGE_CODE_REPO_URL = """
42
      No code repository was given after '--code'.
43
      Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
44
      Please enter the code repository below that includes your settings folder.""";
45

46
  private static final String MESSAGE_SETTINGS_REPO_URL = """
47
      No settings found at {} and no SETTINGS_URL is defined.
48
      Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
49
      Please contact the technical lead of your project to get the SETTINGS_URL for your project to enter.
50
      In case you just want to test IDEasy you may simply hit return to install the default settings.""";
51

52
  /** {@link StringProperty} for the settings repository URL. */
53
  public final StringProperty settingsRepo;
54

55
  /** {@link FlagProperty} for skipping installation/updating of tools. */
56
  public final FlagProperty skipTools;
57

58
  /** {@link FlagProperty} for skipping the setup of git repositories. */
59
  public final FlagProperty skipRepositories;
60

61
  /** {@link FlagProperty} to force the update of the settings git repository. */
62
  public final FlagProperty forcePull;
63

64
  /** {@link FlagProperty} to force the installation/update of plugins. */
65
  public final FlagProperty forcePlugins;
66

67
  /** {@link FlagProperty} to force the setup of git repositories. */
68
  public final FlagProperty forceRepositories;
69

70
  /**
71
   * The constructor.
72
   *
73
   * @param context the {@link IdeContext}.
74
   */
75
  public AbstractUpdateCommandlet(IdeContext context) {
76

77
    super(context);
3✔
78
    addKeyword(getName());
4✔
79
    this.skipTools = add(new FlagProperty("--skip-tools"));
9✔
80
    this.skipRepositories = add(new FlagProperty("--skip-repositories"));
9✔
81
    this.forcePull = add(new FlagProperty("--force-pull"));
9✔
82
    this.forcePlugins = add(new FlagProperty("--force-plugins"));
9✔
83
    this.forceRepositories = add(new FlagProperty("--force-repositories"));
9✔
84
    this.settingsRepo = new StringProperty("", false, "settingsRepository");
8✔
85
  }
1✔
86

87
  @Override
88
  public void run() {
89

90
    IdeStartContextImpl startContext = ((AbstractIdeContext) this.context).getStartContext();
5✔
91
    startContext.setForcePull(forcePull.isTrue());
5✔
92
    startContext.setForcePlugins(forcePlugins.isTrue());
5✔
93
    startContext.setForceRepositories(forceRepositories.isTrue());
5✔
94

95
    if (!this.context.isSettingsRepositorySymlinkOrJunction() || this.context.isForceMode() || forcePull.isTrue()) {
4!
96
      updateSettings();
2✔
97
    }
98
    updateConf();
2✔
99
    reloadContext();
2✔
100

101
    updateSoftware();
2✔
102
    updateRepositories();
2✔
103
    createStartScripts();
2✔
104
  }
1✔
105

106
  private void reloadContext() {
107

108
    ((AbstractIdeContext) this.context).reload();
4✔
109
  }
1✔
110

111
  private void updateConf() {
112

113
    Path templatesFolder = this.context.getSettingsPath().resolve(IdeContext.FOLDER_TEMPLATES);
6✔
114
    if (!Files.exists(templatesFolder)) {
5✔
115
      Path legacyTemplatesFolder = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_TEMPLATES);
6✔
116
      if (Files.exists(legacyTemplatesFolder)) {
5!
117
        templatesFolder = legacyTemplatesFolder;
×
118
      } else {
119
        this.context.warning("Templates folder is missing in settings repository.");
4✔
120
        return;
1✔
121
      }
122
    }
123

124
    Step step = this.context.newStep("Copy configuration templates", templatesFolder);
11✔
125
    final Path finalTemplatesFolder = templatesFolder;
2✔
126
    step.run(() -> setupConf(finalTemplatesFolder, this.context.getIdeHome()));
13✔
127
  }
1✔
128

129
  private void setupConf(Path template, Path conf) {
130

131
    List<Path> children = this.context.getFileAccess().listChildren(template, f -> true);
9✔
132
    for (Path child : children) {
10✔
133

134
      String basename = child.getFileName().toString();
4✔
135
      Path confPath = conf.resolve(basename);
4✔
136

137
      if (Files.isDirectory(child)) {
5✔
138
        if (!Files.isDirectory(confPath)) {
5!
139
          this.context.getFileAccess().mkdirs(confPath);
5✔
140
        }
141
        setupConf(child, confPath);
5✔
142
      } else if (Files.isRegularFile(child)) {
5!
143
        if (Files.isRegularFile(confPath)) {
5!
144
          this.context.debug("Configuration {} already exists - skipping to copy from {}", confPath, child);
×
145
        } else {
146
          if (!basename.equals("settings.xml")) {
4!
147
            this.context.info("Copying template {} to {}.", child, conf);
14✔
148
            this.context.getFileAccess().copy(child, conf);
6✔
149
          }
150
        }
151
      }
152
    }
1✔
153
  }
1✔
154

155
  /**
156
   * Updates the settings repository in IDE_HOME/settings by either cloning if no such repository exists or pulling if the repository exists then saves the
157
   * latest current commit ID in the file ".commit.id".
158
   */
159
  protected void updateSettings() {
160

161
    this.context.newStep(getStepMessage()).run(this::updateSettingsInStep);
9✔
162
  }
1✔
163

164
  protected String getStepMessage() {
165

166
    return "update (pull) settings repository";
2✔
167
  }
168

169
  private void updateSettingsInStep() {
170
    Path settingsPath = this.context.getSettingsPath();
4✔
171
    GitContext gitContext = this.context.getGitContext();
4✔
172
    // here we do not use pullOrClone to prevent asking a pointless question for repository URL...
173
    if (Files.isDirectory(settingsPath) && !this.context.getFileAccess().isEmptyDir(settingsPath)) {
11!
174
      if (this.context.isForcePull() || this.context.isForceMode() || Files.isDirectory(settingsPath.resolve(GitContext.GIT_FOLDER))) {
15!
175
        gitContext.pull(settingsPath);
×
176
        this.context.getGitContext().saveCurrentCommitId(settingsPath, this.context.getSettingsCommitIdPath());
×
177
      } else {
178
        this.context.info("Skipping git pull in settings due to code repository. Use --force-pull to enforce pulling.");
5✔
179
      }
180
    } else {
181
      String repositoryUrl = getOrAskSettingsUrl();
3✔
182
      GitUrl gitUrl = GitUrl.of(repositoryUrl);
3✔
183
      checkProjectNameConvention(gitUrl.getProjectName());
4✔
184
      initializeRepository(gitUrl);
3✔
185
    }
186
  }
1✔
187

188
  private String getOrAskSettingsUrl() {
189

190
    String repository = this.settingsRepo.getValue();
5✔
191
    repository = handleDefaultRepository(repository);
4✔
192
    String userPromt;
193
    String defaultUrl;
194
    if (isCodeRepository()) {
3✔
195
      userPromt = "Code repository URL:";
2✔
196
      defaultUrl = null;
2✔
197
      this.context.info(MESSAGE_CODE_REPO_URL);
5✔
198
    } else {
199
      userPromt = "Settings URL [" + IdeContext.DEFAULT_SETTINGS_REPO_URL + "]:";
2✔
200
      defaultUrl = IdeContext.DEFAULT_SETTINGS_REPO_URL;
2✔
201
      this.context.info(MESSAGE_SETTINGS_REPO_URL, this.context.getSettingsPath());
12✔
202
    }
203
    while (repository == null || repository.isBlank()) {
5!
204
      repository = this.context.askForInput(userPromt, defaultUrl);
6✔
205
      repository = handleDefaultRepository(repository);
5✔
206
    }
207
    return repository;
2✔
208
  }
209

210
  private String handleDefaultRepository(String repository) {
211
    if ("-".equals(repository)) {
4✔
212
      if (isCodeRepository()) {
3✔
213
        this.context.warning("'-' is found after '--code'. This is invalid.");
4✔
214
        repository = null;
3✔
215
      } else {
216
        this.context.info("'-' was found for settings repository, the default settings repository '{}' will be used.", IdeContext.DEFAULT_SETTINGS_REPO_URL);
10✔
217
        repository = IdeContext.DEFAULT_SETTINGS_REPO_URL;
2✔
218
      }
219
    }
220
    return repository;
2✔
221
  }
222

223
  private void checkProjectNameConvention(String projectName) {
224
    boolean isSettingsRepo = projectName.contains(IdeContext.SETTINGS_REPOSITORY_KEYWORD);
4✔
225
    boolean codeRepository = isCodeRepository();
3✔
226
    if (isSettingsRepo == codeRepository) {
3✔
227
      String warningTemplate;
228
      if (codeRepository) {
2✔
229
        warningTemplate = """
3✔
230
            Your git URL is pointing to the project name {} that contains the keyword '{}'.
231
            Therefore we assume that you did a mistake by adding the '--code' option to the ide project creation.
232
            Do you really want to create the project?""";
233
      } else {
234
        warningTemplate = """
2✔
235
            Your git URL is pointing to the project name {} that does not contain the keyword ''{}''.
236
            Therefore we assume that you forgot to add the '--code' option to the ide project creation.
237
            Do you really want to create the project?""";
238
      }
239
      this.context.askToContinue(warningTemplate, projectName,
14✔
240
          IdeContext.SETTINGS_REPOSITORY_KEYWORD);
241
    }
242
  }
1✔
243

244
  private void initializeRepository(GitUrl gitUrl) {
245

246
    GitContext gitContext = this.context.getGitContext();
4✔
247
    Path settingsPath = this.context.getSettingsPath();
4✔
248
    Path repoPath = settingsPath;
2✔
249
    boolean codeRepository = isCodeRepository();
3✔
250
    if (codeRepository) {
2✔
251
      // clone the given code repository into IDE_HOME/workspaces/main
252
      repoPath = context.getWorkspacePath().resolve(gitUrl.getProjectName());
7✔
253
    }
254
    gitContext.pullOrClone(gitUrl, repoPath);
4✔
255
    if (codeRepository) {
2✔
256
      // check for settings folder and create symlink to IDE_HOME/settings
257
      Path settingsFolder = repoPath.resolve(IdeContext.FOLDER_SETTINGS);
4✔
258
      if (Files.exists(settingsFolder)) {
5!
259
        context.getFileAccess().symlink(settingsFolder, settingsPath);
×
260
      } else {
261
        throw new CliException("Invalid code repository " + gitUrl + ": missing a settings folder at " + settingsFolder);
9✔
262
      }
263
    }
264
    this.context.getGitContext().saveCurrentCommitId(settingsPath, this.context.getSettingsCommitIdPath());
8✔
265
  }
1✔
266

267

268
  private void updateSoftware() {
269

270
    if (this.skipTools.isTrue()) {
4✔
271
      this.context.info("Skipping installation/update of tools as specified by the user.");
4✔
272
      return;
1✔
273
    }
274
    Step step = this.context.newStep("Install or update software");
5✔
275
    step.run(() -> doUpdateSoftwareStep(step));
10✔
276
  }
1✔
277

278
  private void doUpdateSoftwareStep(Step step) {
279

280
    Set<ToolCommandlet> toolCommandlets = new HashSet<>();
4✔
281
    CommandletManager commandletManager = this.context.getCommandletManager();
4✔
282
    // installed tools in IDE_HOME/software
283
    List<Path> softwarePaths = this.context.getFileAccess().listChildren(this.context.getSoftwarePath(), Files::isDirectory);
14✔
284
    for (Path softwarePath : softwarePaths) {
10✔
285
      String toolName = softwarePath.getFileName().toString();
4✔
286
      ToolCommandlet toolCommandlet = commandletManager.getToolCommandlet(toolName);
4✔
287
      if (toolCommandlet != null) {
2!
288
        toolCommandlets.add(toolCommandlet);
4✔
289
      }
290
    }
1✔
291

292
    // regular tools in $IDE_TOOLS
293
    List<String> regularTools = IdeVariables.IDE_TOOLS.get(this.context);
6✔
294
    if (regularTools != null) {
2!
295
      for (String regularTool : regularTools) {
10✔
296
        ToolCommandlet toolCommandlet = commandletManager.getToolCommandlet(regularTool);
4✔
297
        if (toolCommandlet == null) {
2!
298
          String displayName = (regularTool == null || regularTool.isBlank()) ? "<empty>" : "'" + regularTool + "'";
×
299
          this.context.error("Cannot install or update tool '{}''. No matching commandlet found. Please check your IDE_TOOLS configuration.", displayName);
×
300
        } else {
×
301
          toolCommandlets.add(toolCommandlet);
4✔
302
        }
303
      }
1✔
304
    }
305

306
    // custom tools in ide-custom-tools.json
307
    for (CustomToolMetadata customTool : this.context.getCustomToolRepository().getTools()) {
9!
308
      CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
×
309
      toolCommandlets.add(customToolCommandlet);
×
310
    }
×
311

312
    // update/install the toolCommandlets
313
    for (ToolCommandlet toolCommandlet : toolCommandlets) {
10✔
314
      this.context.newStep("Install " + toolCommandlet.getName()).run(() -> toolCommandlet.install(false));
15✔
315
    }
1✔
316

317
    ExtraTools extraTools = ExtraToolsMapper.get().loadJsonFromFolder(this.context.getSettingsPath());
7✔
318
    if (extraTools != null) {
2✔
319
      List<String> toolNames = extraTools.getSortedToolNames();
3✔
320
      this.context.info("Found extra installation of the following tools: {}", toolNames);
10✔
321
      for (String tool : toolNames) {
10✔
322
        List<ExtraToolInstallation> installations = extraTools.getExtraInstallations(tool);
4✔
323
        this.context.newStep("Install extra version(s) of " + tool).run(() -> installExtraToolInstallations(tool, installations));
16✔
324
      }
1✔
325
    }
326
  }
1✔
327

328
  private void installExtraToolInstallations(String tool, List<ExtraToolInstallation> extraInstallations) {
329

330
    CommandletManager commandletManager = this.context.getCommandletManager();
4✔
331
    FileAccess fileAccess = this.context.getFileAccess();
4✔
332
    Path extraPath = this.context.getSoftwareExtraPath();
4✔
333
    LocalToolCommandlet toolCommandlet = commandletManager.getRequiredLocalToolCommandlet(tool);
4✔
334
    for (ExtraToolInstallation extraInstallation : extraInstallations) {
10✔
335
      ToolInstallRequest request = new ToolInstallRequest(false);
5✔
336
      String edition = extraInstallation.edition();
3✔
337
      if (edition == null) {
2✔
338
        edition = toolCommandlet.getConfiguredEdition();
3✔
339
      }
340
      ToolEdition toolEdition = new ToolEdition(tool, edition);
6✔
341
      VersionIdentifier version = extraInstallation.version();
3✔
342
      request.setRequested(new ToolEditionAndVersion(toolEdition, version));
7✔
343
      Path extraToolPath = extraPath.resolve(tool);
4✔
344
      Path toolPath = extraToolPath.resolve(extraInstallation.name());
5✔
345
      request.setToolPathForExtraInstallation(toolPath);
3✔
346
      toolCommandlet.install(request);
4✔
347
    }
1✔
348
  }
1✔
349

350
  private void updateRepositories() {
351

352
    if (this.skipRepositories.isTrue()) {
4!
353
      if (this.forceRepositories.isTrue()) {
×
354
        this.context.warning("Options to skip and force repositories are incompatible and should not be combined. Ignoring --force-repositories to proceed.");
×
355
      }
356
      this.context.info("Skipping setup of repositories as specified by the user.");
×
357
      return;
×
358
    }
359
    RepositoryCommandlet repositoryCommandlet = this.context.getCommandletManager().getCommandlet(RepositoryCommandlet.class);
7✔
360
    repositoryCommandlet.reset();
2✔
361
    repositoryCommandlet.run();
2✔
362
  }
1✔
363

364
  private void createStartScripts() {
365

366
    List<String> ides = IdeVariables.CREATE_START_SCRIPTS.get(this.context);
6✔
367
    if (ides == null) {
2✔
368
      this.context.info("Variable CREATE_START_SCRIPTS is undefined - skipping start script creation.");
4✔
369
      return;
1✔
370
    }
371
    for (String ide : ides) {
10✔
372
      ToolCommandlet tool = this.context.getCommandletManager().getToolCommandlet(ide);
6✔
373
      if (tool == null) {
2!
374
        this.context.error("Undefined IDE '{}' configured in variable CREATE_START_SCRIPTS.");
×
375
      } else {
376
        createStartScript(ide);
3✔
377
      }
378
    }
1✔
379
  }
1✔
380

381
  private void createStartScript(String ide) {
382

383
    this.context.info("Creating start scripts for {}", ide);
10✔
384
    Path workspaces = this.context.getIdeHome().resolve(IdeContext.FOLDER_WORKSPACES);
6✔
385
    try (Stream<Path> childStream = Files.list(workspaces)) {
3✔
386
      Iterator<Path> iterator = childStream.iterator();
3✔
387
      while (iterator.hasNext()) {
3✔
388
        Path child = iterator.next();
4✔
389
        if (Files.isDirectory(child)) {
5!
390
          createStartScript(ide, child.getFileName().toString());
6✔
391
        }
392
      }
1✔
393
    } catch (IOException e) {
×
394
      throw new RuntimeException("Failed to list children of directory " + workspaces, e);
×
395
    }
1✔
396
  }
1✔
397

398
  private void createStartScript(String ide, String workspace) {
399

400
    Path ideHome = this.context.getIdeHome();
4✔
401
    String scriptName = ide + "-" + workspace;
4✔
402
    boolean windows = this.context.getSystemInfo().isWindows();
5✔
403
    if (windows) {
2!
404
      scriptName = scriptName + ".bat";
×
405
    } else {
406
      scriptName = scriptName + ".sh";
3✔
407
    }
408
    Path scriptPath = ideHome.resolve(scriptName);
4✔
409
    if (Files.exists(scriptPath)) {
5!
410
      return;
×
411
    }
412
    String scriptContent;
413
    if (windows) {
2!
414
      scriptContent = "@echo off\r\n"
×
415
          + "pushd %~dp0\r\n"
416
          + "cd workspaces/" + workspace + "\r\n"
417
          + "call ide " + ide + "\r\n"
418
          + "popd\r\n";
419
    } else {
420
      scriptContent = "#!/usr/bin/env bash\n"
4✔
421
          + "cd \"$(dirname \"$0\")\"\n"
422
          + "cd workspaces/" + workspace + "\n"
423
          + "ideasy " + ide + "\n";
424
    }
425
    FileAccess fileAccess = this.context.getFileAccess();
4✔
426
    fileAccess.writeFileContent(scriptContent, scriptPath);
4✔
427
    fileAccess.makeExecutable(scriptPath);
3✔
428
  }
1✔
429

430
  /**
431
   * Judge if the repository is a code repository.
432
   *
433
   * @return true when the repository is a code repository, otherwise false.
434
   */
435
  protected boolean isCodeRepository() {
436
    return false;
2✔
437
  }
438

439
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc