Skip to content

Commit 21f14df

Browse files
committed
reviewed changes
1 parent e8ba8f7 commit 21f14df

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryCommandlet.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public String getName() {
4646
@Override
4747
public void run() {
4848

49-
Path repositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES);
50-
Path legacyRepositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES);
5149
Path repositoryFile = repository.getValueAsPath(context);
5250

5351
if (repositoryFile != null) {
5452
// Handle the case when a specific repository is provided
5553
doImportRepository(repositoryFile, true);
5654
} else {
5755
// If no specific repository is provided, check for repositories folder
56+
Path repositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES);
57+
Path legacyRepositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES);
5858
Path repositories;
5959
if (Files.exists(repositoriesPath)) {
6060
repositories = repositoriesPath;
@@ -99,7 +99,6 @@ private void doImportRepository(Path repositoryFile, boolean forceMode) {
9999
}
100100

101101
this.context.debug(repositoryConfig.toString());
102-
this.context.debug("Pull or clone git repository {} ...", repository);
103102

104103
String workspace = repositoryConfig.workspace() != null ? repositoryConfig.workspace() : "main";
105104
Path workspacePath = this.context.getIdeHome().resolve("workspaces").resolve(workspace);
@@ -127,10 +126,5 @@ private void doImportRepository(Path repositoryFile, boolean forceMode) {
127126
this.context.info("Build command not set. Skipping build for repository.");
128127
}
129128

130-
if (!Files.exists(repositoryPath.resolve(".project"))) {
131-
for (String ideCommandlet : repositoryConfig.imports()) {
132-
//TODO: import repository to ideCommandlet
133-
}
134-
}
135129
}
136130
}

cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static RepositoryConfig loadProperties(Path filePath) {
4545
return new RepositoryConfig(properties.getProperty("path"), properties.getProperty("workingsets"),
4646
properties.getProperty("workspace"), properties.getProperty("git_url"), properties.getProperty("git_branch"),
4747
properties.getProperty(("build_path")), properties.getProperty("build_cmd"), importsSet,
48-
Boolean.parseBoolean(properties.getProperty("active")));
48+
Boolean.parseBoolean(properties.getProperty("active").trim()));
4949
}
5050

5151
private static Set<String> getImports(Properties properties) {

cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ public void gitPullOrClone(Path target, String gitRepoUrl) {
601601
if (!gitRepoUrl.startsWith("http")) {
602602
throw new IllegalArgumentException("Invalid git URL '" + gitRepoUrl + "'!");
603603
}
604+
debug("Pull or clone git repository {} ...", gitRepoUrl);
604605
ProcessContext pc = newProcess().directory(target).executable("git");
605606
if (Files.isDirectory(target.resolve(".git"))) {
606607
ProcessResult result = pc.addArg("remote").run(true);

cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,13 @@ default void copy(Path source, Path target) {
140140
*/
141141
List<Path> getChildrenInDir(Path dir, Predicate<Path> filter);
142142

143+
/**
144+
* Finds the existing file with the specified name in the given list of directories.
145+
*
146+
* @param fileName The name of the file to find.
147+
* @param searchDirs The list of directories to search for the file.
148+
* @return The {@code Path} of the existing file, or {@code null} if the file is not found.
149+
*/
150+
Path findExistingFile(String fileName, List<Path> searchDirs);
151+
143152
}

cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,20 @@ public List<Path> getChildrenInDir(Path dir, Predicate<Path> filter) {
477477
return files;
478478
}
479479

480+
@Override
481+
public Path findExistingFile(String fileName, List<Path> searchDirs) {
482+
483+
for (Path dir : searchDirs) {
484+
Path filePath = dir.resolve(fileName);
485+
try {
486+
if (Files.exists(filePath)) {
487+
return filePath;
488+
}
489+
} catch (SecurityException e) {
490+
throw new IllegalStateException("SecurityException while checking file existence.");
491+
}
492+
}
493+
return null;
494+
}
495+
480496
}

cli/src/main/java/com/devonfw/tools/ide/property/RepositoryProperty.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.nio.file.Files;
66
import java.nio.file.Path;
7+
import java.util.Arrays;
78
import java.util.function.Consumer;
89

910
public class RepositoryProperty extends Property<String> {
@@ -47,28 +48,22 @@ public String parse(String valueAsString) {
4748

4849
public Path getValueAsPath(IdeContext context) {
4950

50-
Path repositoriesPath = context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES);
51-
Path legacyRepositoriesPath = context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES);
52-
5351
String value = getValue();
5452
if (value == null) {
5553
return null;
5654
}
55+
5756
Path repositoryFile = Path.of(value);
58-
5957
if (!Files.exists(repositoryFile)) {
60-
repositoryFile = repositoriesPath.resolve(value + ".properties");
58+
Path repositoriesPath = context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES);
59+
Path legacyRepositoriesPath = context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES);
60+
repositoryFile = context.getFileAccess().findExistingFile(value + ".properties",
61+
Arrays.asList(repositoriesPath, legacyRepositoriesPath));
6162
}
62-
if (!Files.exists(repositoryFile)) {
63-
Path legacyRepositoryFile = legacyRepositoriesPath.resolve(repositoryFile.getFileName().toString());
64-
if (Files.exists(legacyRepositoryFile)) {
65-
repositoryFile = legacyRepositoryFile;
66-
} else {
67-
throw new IllegalStateException("Could not find " + repositoryFile);
68-
}
63+
if (repositoryFile == null) {
64+
throw new IllegalStateException("Could not find " + value);
6965
}
7066
return repositoryFile;
7167
}
7268

73-
7469
}

0 commit comments

Comments
 (0)