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

devonfw / IDEasy / 12875818493

20 Jan 2025 09:19PM UTC coverage: 68.372% (-0.1%) from 68.512%
12875818493

push

github

web-flow
#939: fix NPE on path completion and implement repository completion (#956)

2737 of 4375 branches covered (62.56%)

Branch coverage included in aggregate %.

7075 of 9976 relevant lines covered (70.92%)

3.09 hits per line

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

80.25
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.git.GitContext;
9
import com.devonfw.tools.ide.property.RepositoryProperty;
10
import com.devonfw.tools.ide.tool.ToolCommandlet;
11

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

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

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

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

33
  @Override
34
  public String getName() {
35

36
    return "repository";
2✔
37
  }
38

39
  @Override
40
  public void run() {
41

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

44
    if (repositoryFile != null) {
2✔
45
      // Handle the case when a specific repository is provided
46
      doImportRepository(repositoryFile, true);
5✔
47
    } else {
48
      // If no specific repository is provided, check for repositories folder
49
      Path repositoriesPath = this.context.getRepositoriesPath();
4✔
50
      if (repositoriesPath == null) {
2✔
51
        this.context.warning("Cannot find folder 'repositories' nor 'projects' in your settings.");
4✔
52
        return;
1✔
53
      }
54
      List<Path> propertiesFiles = this.context.getFileAccess()
5✔
55
          .listChildren(repositoriesPath, path -> path.getFileName().toString().endsWith(".properties"));
8✔
56
      boolean forceMode = this.context.isForceMode();
4✔
57
      for (Path propertiesFile : propertiesFiles) {
10✔
58
        doImportRepository(propertiesFile, forceMode);
4✔
59
      }
1✔
60
    }
61
  }
1✔
62

63
  private void doImportRepository(Path repositoryFile, boolean forceMode) {
64

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

68
    if (!repositoryConfig.active()) {
3!
69
      this.context.info("Repository is not active by default.");
4✔
70
      if (forceMode) {
2✔
71
        this.context.info("Repository setup is forced, hence proceeding ...");
5✔
72
      } else {
73
        this.context.info("Skipping repository - use force (-f) to setup all repositories ...");
4✔
74
        return;
1✔
75
      }
76
    }
77

78
    String repository = repositoryConfig.path();
3✔
79
    String gitUrl = repositoryConfig.gitUrl();
3✔
80
    if (repository == null || repository.isEmpty() || gitUrl == null || gitUrl.isEmpty()) {
10!
81
      this.context.warning("Invalid repository configuration {} - both 'path' and 'git-url' have to be defined.", repositoryFile.getFileName().toString());
12✔
82
      return;
1✔
83
    }
84

85
    this.context.debug(repositoryConfig.toString());
5✔
86

87
    String workspace = repositoryConfig.workspace();
3✔
88
    if (workspace == null) {
2!
89
      workspace = IdeContext.WORKSPACE_MAIN;
×
90
    }
91
    Path workspacePath = this.context.getIdeHome().resolve(IdeContext.FOLDER_WORKSPACES).resolve(workspace);
8✔
92
    this.context.getFileAccess().mkdirs(workspacePath);
5✔
93

94
    Path repositoryPath = workspacePath.resolve(repository);
4✔
95
    if (!Files.isDirectory(repositoryPath.resolve(GitContext.GIT_FOLDER))) {
7!
96
      this.context.getGitContext().pullOrClone(repositoryConfig.asGitUrl(), repositoryPath);
7✔
97
    }
98

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

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

113
  }
1✔
114
}
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