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

devonfw / IDEasy / 12765847701

14 Jan 2025 10:34AM UTC coverage: 68.082% (+0.5%) from 67.541%
12765847701

push

github

web-flow
#759: upgrade settings commandlet (#820)

2689 of 4311 branches covered (62.38%)

Branch coverage included in aggregate %.

6946 of 9841 relevant lines covered (70.58%)

3.1 hits per line

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

80.49
cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5
import java.util.List;
6

7
import com.devonfw.tools.ide.context.IdeContext;
8
import com.devonfw.tools.ide.property.RepositoryProperty;
9
import com.devonfw.tools.ide.tool.ToolCommandlet;
10

11
/**
12
 * {@link Commandlet} to setup one or multiple GIT repositories for development.
13
 */
14
public class RepositoryCommandlet extends Commandlet {
15

16
  /** the repository to setup. */
17
  public final RepositoryProperty repository;
18

19
  /**
20
   * The constructor.
21
   *
22
   * @param context the {@link IdeContext}.
23
   */
24
  public RepositoryCommandlet(IdeContext context) {
25

26
    super(context);
3✔
27
    addKeyword(getName());
4✔
28
    addKeyword("setup");
3✔
29
    this.repository = add(new RepositoryProperty("", false, "repository"));
11✔
30
  }
1✔
31

32
  @Override
33
  public String getName() {
34

35
    return "repository";
2✔
36
  }
37

38
  @Override
39
  public void run() {
40

41
    Path repositoryFile = this.repository.getValue();
5✔
42

43
    if (repositoryFile != null) {
2✔
44
      // Handle the case when a specific repository is provided
45
      doImportRepository(repositoryFile, true);
5✔
46
    } else {
47
      // If no specific repository is provided, check for repositories folder
48
      Path repositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES);
6✔
49
      Path legacyRepositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES);
6✔
50
      Path repositories;
51
      if (Files.exists(repositoriesPath)) {
5✔
52
        repositories = repositoriesPath;
3✔
53
      } else if (Files.exists(legacyRepositoriesPath)) {
5!
54
        repositories = legacyRepositoriesPath;
×
55
      } else {
56
        this.context.warning("Cannot find repositories folder nor projects folder.");
4✔
57
        return;
1✔
58
      }
59

60
      List<Path> propertiesFiles = this.context.getFileAccess()
5✔
61
          .listChildren(repositories, path -> path.getFileName().toString().endsWith(".properties"));
8✔
62

63
      boolean forceMode = this.context.isForceMode();
4✔
64
      for (Path propertiesFile : propertiesFiles) {
10✔
65
        doImportRepository(propertiesFile, forceMode);
4✔
66
      }
1✔
67
    }
68
  }
1✔
69

70
  private void doImportRepository(Path repositoryFile, boolean forceMode) {
71

72
    this.context.info("Importing repository from {} ...", repositoryFile.getFileName().toString());
12✔
73
    RepositoryConfig repositoryConfig = RepositoryConfig.loadProperties(repositoryFile);
3✔
74

75
    if (!repositoryConfig.active()) {
3!
76
      this.context.info("Repository is not active by default.");
4✔
77
      if (forceMode) {
2✔
78
        this.context.info("Repository setup is forced, hence proceeding ...");
5✔
79
      } else {
80
        this.context.info("Skipping repository - use force (-f) to setup all repositories ...");
4✔
81
        return;
1✔
82
      }
83
    }
84

85
    String repository = repositoryConfig.path();
3✔
86
    String gitUrl = repositoryConfig.gitUrl();
3✔
87
    if (repository == null || repository.isEmpty() || gitUrl == null || gitUrl.isEmpty()) {
10!
88
      this.context.warning("Invalid repository configuration {} - both 'path' and 'git-url' have to be defined.", repositoryFile.getFileName().toString());
12✔
89
      return;
1✔
90
    }
91

92
    this.context.debug(repositoryConfig.toString());
5✔
93

94
    String workspace = repositoryConfig.workspace() != null ? repositoryConfig.workspace() : "main";
7!
95
    Path workspacePath = this.context.getIdeHome().resolve("workspaces").resolve(workspace);
8✔
96
    this.context.getFileAccess().mkdirs(workspacePath);
5✔
97

98
    Path repositoryPath = workspacePath.resolve(repository);
4✔
99
    this.context.getGitContext().pullOrClone(repositoryConfig.asGitUrl(), repositoryPath);
7✔
100

101
    String buildCmd = repositoryConfig.buildCmd();
3✔
102
    this.context.debug("Building repository with ide command: {}", buildCmd);
10✔
103
    if (buildCmd != null && !buildCmd.isEmpty()) {
5!
104
      String[] command = buildCmd.split("\\s+");
×
105
      ToolCommandlet commandlet = this.context.getCommandletManager().getRequiredToolCommandlet(command[0]);
×
106

107
      for (int i = 1; i < command.length; i++) {
×
108
        commandlet.arguments.addValue(command[i]);
×
109
      }
110
      commandlet.run();
×
111
    } else {
×
112
      this.context.info("Build command not set. Skipping build for repository.");
4✔
113
    }
114

115
  }
1✔
116
}
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