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

devonfw / IDEasy / 13063227142

30 Jan 2025 11:31PM UTC coverage: 68.379% (-0.2%) from 68.557%
13063227142

Pull #990

github

web-flow
Merge dde1c0e39 into aaf4eb4e0
Pull Request #990: #954: improve repository support

2857 of 4597 branches covered (62.15%)

Branch coverage included in aggregate %.

7391 of 10390 relevant lines covered (71.14%)

3.1 hits per line

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

52.94
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 creating a project with settings inside a code repository */
21
  public final FlagProperty codeRepositoryFlag;
22

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

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

36
  @Override
37
  public String getName() {
38

39
    return "create";
2✔
40
  }
41

42
  @Override
43
  public boolean isIdeHomeRequired() {
44

45
    return false;
2✔
46
  }
47

48
  @Override
49
  public void run() {
50

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

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

61
    initializeProject(newProjectPath);
3✔
62
    this.context.setIdeHome(newProjectPath);
4✔
63
    super.run();
2✔
64
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
65
  }
1✔
66

67
  private void initializeCodeRepository(String repoUrl) {
68

69
    // clone the given repository into IDE_HOME/workspaces/main
70
    GitUrl gitUrl = GitUrl.of(repoUrl);
×
71
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
×
72
    this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);
×
73

74
    // check for settings folder and create symlink to IDE_HOME/settings
75
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
×
76
    if (Files.exists(settingsFolder)) {
×
77
      this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
×
78
      // create a file in IDE_HOME with the current local commit id
79
      this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
×
80
    } else {
81
      this.context.warning("No settings folder was found inside the code repository.");
×
82
    }
83
  }
×
84

85
  private void initializeProject(Path newInstancePath) {
86

87
    FileAccess fileAccess = this.context.getFileAccess();
4✔
88
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_SOFTWARE));
5✔
89
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_PLUGINS));
5✔
90
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_WORKSPACES).resolve(IdeContext.WORKSPACE_MAIN));
7✔
91
  }
1✔
92

93
  @Override
94
  protected void updateSettings() {
95

96
    if (this.codeRepositoryFlag.isTrue()) {
4!
97
      String codeRepository = this.settingsRepo.getValue();
×
98
      if (codeRepository == null || codeRepository.isBlank()) {
×
99
        String message = """
×
100
            No code repository was given after '--code'.
101
            Please give the code repository below that includes your settings folder.
102
            Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
103
            Code repository URL:
104
            """;
105
        codeRepository = this.context.askForInput(message);
×
106
      }
107
      initializeCodeRepository(codeRepository);
×
108
    } else {
×
109
      super.updateSettings();
2✔
110
    }
111

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