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

devonfw / IDEasy / 15254705198

26 May 2025 01:05PM UTC coverage: 67.739% (+0.02%) from 67.716%
15254705198

Pull #1328

github

web-flow
Merge 73f7c0060 into f36571941
Pull Request #1328: #1292: logs potential welcome file to info level

3161 of 5070 branches covered (62.35%)

Branch coverage included in aggregate %.

8104 of 11560 relevant lines covered (70.1%)

3.07 hits per line

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

53.03
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
import java.util.function.Predicate;
6

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

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

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

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

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

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

38
  @Override
39
  public String getName() {
40

41
    return "create";
2✔
42
  }
43

44
  @Override
45
  public boolean isIdeHomeRequired() {
46

47
    return false;
2✔
48
  }
49

50
  @Override
51
  public void run() {
52

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

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

63
    initializeProject(newProjectPath);
3✔
64
    this.context.setIdeHome(newProjectPath);
4✔
65
    this.context.verifyIdeMinVersion(true);
4✔
66
    super.run();
2✔
67
    this.context.verifyIdeMinVersion(true);
4✔
68
    this.context.getFileAccess().writeFileContent(IdeVersion.getVersionString(), newProjectPath.resolve(IdeContext.FILE_SOFTWARE_VERSION));
8✔
69
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
70

71
    GitUrl gitUrl = GitUrl.of(newProjectPath.toString());
4✔
72
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
7✔
73
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
4✔
74
    if (Files.exists(settingsFolder)) {
5!
75
      Predicate<Path> welcomePredicate = path -> String.valueOf(path.getFileName()).startsWith("welcome.");
×
76
      Path welcomeFilePath = this.context.getFileAccess().findFirst(settingsFolder, welcomePredicate, false);
×
77
      if (welcomeFilePath != null) {
×
78
        this.context.info(this.context.getFileAccess().readFileContent(welcomeFilePath));
×
79
      }
80
    }
81
  }
1✔
82

83
  private void initializeCodeRepository(String repoUrl) {
84

85
    // clone the given repository into IDE_HOME/workspaces/main
86
    GitUrl gitUrl = GitUrl.of(repoUrl);
×
87
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
×
88
    this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);
×
89

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

101
  private void initializeProject(Path newInstancePath) {
102

103
    FileAccess fileAccess = this.context.getFileAccess();
4✔
104
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_SOFTWARE));
5✔
105
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_PLUGINS));
5✔
106
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_WORKSPACES).resolve(IdeContext.WORKSPACE_MAIN));
7✔
107
  }
1✔
108

109
  @Override
110
  protected void updateSettings() {
111

112
    if (this.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