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

devonfw / IDEasy / 12356873353

16 Dec 2024 04:22PM UTC coverage: 67.215% (-0.2%) from 67.459%
12356873353

Pull #850

github

web-flow
Merge 532436561 into 52afdd7c7
Pull Request #850: #757: Settings in code repository

2574 of 4176 branches covered (61.64%)

Branch coverage included in aggregate %.

6668 of 9574 relevant lines covered (69.65%)

3.06 hits per line

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

55.93
cli/src/main/java/com/devonfw/tools/ide/commandlet/CreateCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5

6
import com.devonfw.tools.ide.context.IdeContext;
7
import com.devonfw.tools.ide.git.GitUrl;
8
import com.devonfw.tools.ide.io.FileAccess;
9
import com.devonfw.tools.ide.property.FlagProperty;
10
import com.devonfw.tools.ide.property.StringProperty;
11

12
/**
13
 * {@link Commandlet} to create a new IDEasy instance
14
 */
15
public class CreateCommandlet extends AbstractUpdateCommandlet {
16

17
  /** {@link StringProperty} for the name of the new project */
18
  public final StringProperty newProject;
19

20
  /** {@link FlagProperty} for skipping the setup of git repositories */
21
  public final FlagProperty skipRepositories;
22

23
  /** {@link FlagProperty} for creating a project with settings inside a code repository */
24
  public final FlagProperty codeRepositoryFlag;
25

26
  /**
27
   * The constructor.
28
   *
29
   * @param context the {@link IdeContext}.
30
   */
31
  public CreateCommandlet(IdeContext context) {
32

33
    super(context);
3✔
34
    this.newProject = add(new StringProperty("", true, "project"));
11✔
35
    this.skipRepositories = add(new FlagProperty("--skip-repositories"));
9✔
36
    this.codeRepositoryFlag = add(new FlagProperty("--code"));
9✔
37
    add(this.settingsRepo);
5✔
38
  }
1✔
39

40
  @Override
41
  public String getName() {
42

43
    return "create";
2✔
44
  }
45

46
  @Override
47
  public boolean isIdeHomeRequired() {
48

49
    return false;
2✔
50
  }
51

52
  @Override
53
  public void run() {
54

55
    String newProjectName = this.newProject.getValue();
5✔
56
    Path newProjectPath = this.context.getIdeRoot().resolve(newProjectName);
6✔
57

58
    this.context.info("Creating new IDEasy project in {}", newProjectPath);
10✔
59
    if (!this.context.getFileAccess().isEmptyDir(newProjectPath)) {
6!
60
      this.context.askToContinue("Directory " + newProjectPath + " already exists. Do you want to continue?");
×
61
    } else {
62
      this.context.getFileAccess().mkdirs(newProjectPath);
5✔
63
    }
64

65
    initializeProject(newProjectPath);
3✔
66
    this.context.setIdeHome(newProjectPath);
4✔
67
    super.run();
2✔
68

69
    if (this.skipRepositories.isTrue()) {
4!
70
      this.context.info("Skipping the cloning of project repositories as specified by the user.");
×
71
    } else {
72
      updateRepositories();
2✔
73
    }
74
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
75

76
  }
1✔
77

78
  private void initializeCodeRepository(String repoUrl) {
79

80
    // clone the given repository into IDE_HOME/workspaces/main
81
    GitUrl gitUrl = GitUrl.of(repoUrl);
×
82
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
×
83
    this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);
×
84

85
    // check for settings folder and create symlink to IDE_HOME/settings
86
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
×
87
    if (Files.exists(settingsFolder)) {
×
88
      this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
×
89
      // create a file in IDE_HOME with the current local commit id
90
      this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
×
91
    } else {
92
      this.context.warning("No settings folder was found inside the code repository.");
×
93
    }
94
  }
×
95

96
  private void initializeProject(Path newInstancePath) {
97

98
    FileAccess fileAccess = this.context.getFileAccess();
4✔
99
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_SOFTWARE));
5✔
100
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_PLUGINS));
5✔
101
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_WORKSPACES).resolve(IdeContext.WORKSPACE_MAIN));
7✔
102
  }
1✔
103

104
  private void updateRepositories() {
105

106
    this.context.getCommandletManager().getCommandlet(RepositoryCommandlet.class).run();
7✔
107
  }
1✔
108

109
  @Override
110
  protected void updateSettings() {
111

112
    if (codeRepositoryFlag.isTrue()) {
4!
113
      String codeRepository = this.settingsRepo.getValue();
×
114
      if (codeRepository == null || codeRepository.isBlank()) {
×
115
        String message = """
×
116
          No code repository was given after '--code'.
117
          Please give the code repository below that includes your settings folder.
118
          Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
119
          Code repository URL:
120
          """;
121
        codeRepository = this.context.askForInput(message);
×
122
      }
123
      initializeCodeRepository(codeRepository);
×
124
    } else {
×
125
      super.updateSettings();
2✔
126
    }
127

128
  }
1✔
129
}
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