Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#931: enhance settings in code repository #983

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public AbstractUpdateCommandlet(IdeContext context) {
@Override
public void run() {

updateSettings();
if (!this.context.isSettingsRepositorySymlink() || this.context.isForceMode()) {
updateSettings();
}
updateConf();
reloadContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private void logSettingsGitStatus() {
if (settingsPath != null) {
GitContext gitContext = this.context.getGitContext();
if (gitContext.isRepositoryUpdateAvailable(settingsPath, this.context.getSettingsCommitIdPath())) {
this.context.warning("Your settings are not up-to-date, please run 'ide update'.");
if (!this.context.isSettingsRepositorySymlink()) {
this.context.warning("Your settings are not up-to-date, please run 'ide update'.");
}
} else {
this.context.success("Your settings are up-to-date.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private Path findIdeRoot(Path ideHomePath) {
}

private Path getIdeRootPathFromEnv() {

String root = getSystem().getEnv(IdeVariables.IDE_ROOT.getName());
if (root != null) {
Path rootPath = Path.of(root);
Expand Down Expand Up @@ -280,11 +281,13 @@ private String getMessageIdeHomeNotFound() {
}

private String getMessageIdeRootNotFound() {

String root = getSystem().getEnv("IDE_ROOT");
if (root == null) {
return "The environment variable IDE_ROOT is undefined. Please reinstall IDEasy or manually repair IDE_ROOT variable.";
} else {
return "The environment variable IDE_ROOT is pointing to an invalid path " + root + ". Please reinstall IDEasy or manually repair IDE_ROOT variable.";
return "The environment variable IDE_ROOT is pointing to an invalid path " + root
+ ". Please reinstall IDEasy or manually repair IDE_ROOT variable.";
hohwille marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -301,7 +304,6 @@ protected SystemPath computeSystemPath() {
return new SystemPath(this);
}


private boolean isIdeHome(Path dir) {

if (!Files.isDirectory(dir.resolve("workspaces"))) {
Expand Down Expand Up @@ -429,15 +431,21 @@ public Path getSettingsGitRepository() {
return null;
}

// check whether the settings path has a .git folder only if its not a symbolic link
if (!Files.exists(settingsPath.resolve(".git")) && !Files.isSymbolicLink(settingsPath)) {
// check whether the settings path has a .git folder only if its not a symbolic link or junction
if (!Files.exists(settingsPath.resolve(".git")) && !isSettingsRepositorySymlink()) {
error("Settings repository exists but is not a git repository.");
return null;
}

return settingsPath;
}

public boolean isSettingsRepositorySymlink() {

Path settingsPath = getSettingsPath();
hohwille marked this conversation as resolved.
Show resolved Hide resolved
return Files.isSymbolicLink(settingsPath) || getFileAccess().isJunction(settingsPath);
}

@Override
public Path getSettingsCommitIdPath() {

Expand Down Expand Up @@ -557,6 +565,7 @@ public boolean isOfflineMode() {

@Override
public boolean isSkipUpdatesMode() {

return this.startContext.isSkipUpdatesMode();
}

Expand All @@ -583,6 +592,7 @@ public boolean isOnline() {
}

private void configureNetworkProxy() {

if (this.networkProxy == null) {
this.networkProxy = new NetworkProxy(this);
this.networkProxy.configure();
Expand All @@ -609,7 +619,8 @@ public DirectoryMerger getWorkspaceMerger() {
}

/**
* @return the {@link #getDefaultExecutionDirectory() default execution directory} in which a command process is executed.
* @return the {@link #getDefaultExecutionDirectory() default execution directory} in which a command process is
* executed.
*/
@Override
public Path getDefaultExecutionDirectory() {
Expand Down Expand Up @@ -792,7 +803,8 @@ public void endStep(StepImpl step) {
}

/**
* Finds the matching {@link Commandlet} to run, applies {@link CliArguments} to its {@link Commandlet#getProperties() properties} and will execute it.
* Finds the matching {@link Commandlet} to run, applies {@link CliArguments} to its
* {@link Commandlet#getProperties() properties} and will execute it.
*
* @param arguments the {@link CliArgument}.
* @return the return code of the execution.
Expand Down Expand Up @@ -839,9 +851,10 @@ public int run(CliArguments arguments) {
}

/**
* @param cmd the potential {@link Commandlet} to {@link #apply(CliArguments, Commandlet) apply} and {@link Commandlet#run() run}.
* @return {@code true} if the given {@link Commandlet} matched and did {@link Commandlet#run() run} successfully, {@code false} otherwise (the
* {@link Commandlet} did not match and we have to try a different candidate).
* @param cmd the potential {@link Commandlet} to {@link #apply(CliArguments, Commandlet) apply} and
* {@link Commandlet#run() run}.
* @return {@code true} if the given {@link Commandlet} matched and did {@link Commandlet#run() run} successfully,
* {@code false} otherwise (the {@link Commandlet} did not match and we have to try a different candidate).
*/
private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) {

Expand Down Expand Up @@ -873,10 +886,17 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) {
}
Path settingsRepository = getSettingsGitRepository();
if (settingsRepository != null) {
if (getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()) ||
(getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(settingsRepository,
getSettingsCommitIdPath()))) {
interaction("Updates are available for the settings repository. If you want to apply the latest changes, call \"ide update\"");
if (getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()) || (
getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(
settingsRepository, getSettingsCommitIdPath()))) {
if (isSettingsRepositorySymlink()) {
interaction(
"Updates are available for the settings repository. Please pull the latest changes by yourself or by calling \"ide -f update\" to apply them.");

} else {
interaction(
"Updates are available for the settings repository. If you want to apply the latest changes, call \"ide update\"");
}
}
}
}
Expand Down Expand Up @@ -933,8 +953,8 @@ This product (with its included 3rd party components) is open-source software an
You will be able to find it online under the following URL:
""").append(LICENSE_URL);
if (this.ideRoot != null) {
sb.append("\n\nAlso it is included in the documentation that you can find here:\n").
append(this.ideRoot.resolve(FOLDER_IDE).resolve("IDEasy.pdf").toString()).append("\n");
sb.append("\n\nAlso it is included in the documentation that you can find here:\n")
.append(this.ideRoot.resolve(FOLDER_IDE).resolve("IDEasy.pdf").toString()).append("\n");
}
info(sb.toString());
askToContinue("Do you accept these terms of use and all license agreements?");
Expand All @@ -958,14 +978,15 @@ This product (with its included 3rd party components) is open-source software an
}

private void verifyIdeRoot() {

if (!isTest()) {
if (this.ideRoot == null) {
warning("Variable IDE_ROOT is undefined. Please check your installation or run setup script again.");
} else if (this.ideHome != null) {
Path ideRootPath = getIdeRootPathFromEnv();
if (!this.ideRoot.equals(ideRootPath)) {
warning("Variable IDE_ROOT is set to '{}' but for your project '{}' the path '{}' would have been expected.", ideRootPath,
this.ideHome.getFileName(), this.ideRoot);
warning("Variable IDE_ROOT is set to '{}' but for your project '{}' the path '{}' would have been expected.",
ideRootPath, this.ideHome.getFileName(), this.ideRoot);
}
}
}
Expand All @@ -977,6 +998,7 @@ private void verifyIdeRoot() {
* @return the {@link List} of {@link CompletionCandidate}s to suggest.
*/
public List<CompletionCandidate> complete(CliArguments arguments, boolean includeContextOptions) {

CompletionCandidateCollector collector = new CompletionCandidateCollectorDefault(this);
if (arguments.current().isStart()) {
arguments.next();
Expand Down Expand Up @@ -1004,6 +1026,7 @@ public List<CompletionCandidate> complete(CliArguments arguments, boolean includ
}

private void completeCommandlet(CliArguments arguments, Commandlet cmd, CompletionCandidateCollector collector) {

trace("Trying to match arguments for auto-completion for commandlet {}", cmd.getName());
Iterator<Property<?>> valueIterator = cmd.getValues().iterator();
valueIterator.next(); // skip first property since this is the keyword property that already matched to find the commandlet
Expand Down Expand Up @@ -1060,12 +1083,12 @@ private void completeCommandlet(CliArguments arguments, Commandlet cmd, Completi
}
}


/**
* @param arguments the {@link CliArguments} to apply. Will be {@link CliArguments#next() consumed} as they are matched. Consider passing a
* {@link CliArguments#copy() copy} as needed.
* @param arguments the {@link CliArguments} to apply. Will be {@link CliArguments#next() consumed} as they are
* matched. Consider passing a {@link CliArguments#copy() copy} as needed.
* @param cmd the potential {@link Commandlet} to match.
* @return the {@link ValidationResult} telling if the {@link CliArguments} can be applied successfully or if validation errors ocurred.
* @return the {@link ValidationResult} telling if the {@link CliArguments} can be applied successfully or if
* validation errors ocurred.
*/
public ValidationResult apply(CliArguments arguments, Commandlet cmd) {

Expand Down Expand Up @@ -1179,6 +1202,7 @@ private String findBashOnWindows() {

@Override
public WindowsPathSyntax getPathSyntax() {

return this.pathSyntax;
}

Expand All @@ -1202,6 +1226,7 @@ public IdeStartContextImpl getStartContext() {
* Reloads this context and re-initializes the {@link #getVariables() variables}.
*/
public void reload() {

this.variables = null;
this.customToolRepository = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ default Path getRepositoriesPath() {
*/
Path getSettingsGitRepository();

/**
* @return {@code true} if the settings repository is a symlink or a junction.
*/
boolean isSettingsRepositorySymlink();
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return the {@link Path} to the file containing the last tracked commit Id of the settings repository.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private boolean isNeeded(Path targetRepository, IdeContext context) {
}
if (!hasGitDirectory) {
if (isRequireGitFolder()) {
context.warning("Missing .git folder in {}.", targetRepository);
if (context.getSettingsGitRepository() == null) {
context.warning("Missing .git folder in {}.", targetRepository);
}
} else {
logEnforceGitOperationBecauseGitFolderNotPresent(targetRepository, context);
}
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,10 @@ default void makeExecutable(Path file) {
*/
String readFileContent(Path file);

/**
* @param path that is checked whether it is a junction or not.
* @return {@code true} if the given {@link Path} is a junction, false otherwise.
*/
boolean isJunction(Path path);

}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public String checksum(Path file) {
}
}

private boolean isJunction(Path path) {
public boolean isJunction(Path path) {

if (!SystemInfoImpl.INSTANCE.isWindows()) {
return false;
Expand Down
Loading