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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

79.01
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().listChildren(repositories, path -> path.getFileName().toString().endsWith(".properties"));
13✔
61

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

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

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

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

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

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

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

97
    Path repositoryPath = workspacePath.resolve(repository);
4✔
98
    this.context.getGitContext().pullOrClone(gitUrl, repositoryConfig.gitBranch(), repositoryPath);
8✔
99

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

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

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

© 2025 Coveralls, Inc