Skip to content

Commit

Permalink
#824: fix git url with branch (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Dec 2, 2024
1 parent d7df00d commit 886cea3
Show file tree
Hide file tree
Showing 31 changed files with 860 additions and 720 deletions.
6 changes: 4 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/cli/CliException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.devonfw.tools.ide.cli;

import com.devonfw.tools.ide.process.ProcessResult;

/**
* {@link RuntimeException} for to abort CLI process in expected situations. It allows to abort with a defined message for the end user and a defined exit code.
* Unlike other exceptions a {@link CliException} is not treated as technical error. Therefore by default (unless in debug mode) no stacktrace is printed.
Expand Down Expand Up @@ -37,8 +39,7 @@ public CliException(String message, Throwable cause) {
*/
public CliException(String message, int exitCode) {

super(message);
this.exitCode = exitCode;
this(message, exitCode, null);
}

/**
Expand All @@ -51,6 +52,7 @@ public CliException(String message, int exitCode) {
public CliException(String message, int exitCode, Throwable cause) {

super(message, cause);
assert (exitCode != ProcessResult.SUCCESS);
this.exitCode = exitCode;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.tools.ide.cli;

import java.net.URL;
import java.nio.file.Path;

import com.devonfw.tools.ide.process.ProcessResult;
Expand Down Expand Up @@ -67,7 +66,7 @@ public static CliOfflineException ofPurpose(String purpose) {
* @param repository the path, where the repository should be cloned to.
* @return A {@link CliOfflineException} with an informative message.
*/
public static CliOfflineException ofClone(URL url, Path repository) {
public static CliOfflineException ofClone(String url, Path repository) {
return new CliOfflineException("Could not clone " + url + " to " + repository + " because you are offline.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ public final class CliProcessException extends CliException {

/**
* The constructor.
*
* @param processResult the {@link #getProcessResult() process result}.
*/
public CliProcessException(ProcessResult processResult) {

this("Command " + processResult.getExecutable() + " failed with exit code " + processResult.getExitCode() + " - full commandline was "
+ processResult.getCommand(), processResult);
}

/**
* The constructor.
*
* @param processResult the {@link #getProcessResult() process result}.
*/
public CliProcessException(String message, ProcessResult processResult) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import java.util.Set;

import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.GitContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.git.GitContext;
import com.devonfw.tools.ide.git.GitUrl;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.StringProperty;
import com.devonfw.tools.ide.repo.CustomTool;
Expand Down Expand Up @@ -129,7 +130,7 @@ private void updateSettings() {
} else if ("-".equals(repository)) {
repository = IdeContext.DEFAULT_SETTINGS_REPO_URL;
}
gitContext.pullOrClone(repository, settingsPath);
gitContext.pullOrClone(GitUrl.of(repository), settingsPath);
}
step.success("Successfully updated settings repository.");
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void doImportRepository(Path repositoryFile, boolean forceMode) {

String repository = repositoryConfig.path();
String gitUrl = repositoryConfig.gitUrl();
if (repository == null || "".equals(repository) || gitUrl == null || "".equals(gitUrl)) {
if (repository == null || repository.isEmpty() || gitUrl == null || gitUrl.isEmpty()) {
this.context.warning("Invalid repository configuration {} - both 'path' and 'git-url' have to be defined.", repositoryFile.getFileName().toString());
return;
}
Expand All @@ -95,7 +95,7 @@ private void doImportRepository(Path repositoryFile, boolean forceMode) {
this.context.getFileAccess().mkdirs(workspacePath);

Path repositoryPath = workspacePath.resolve(repository);
this.context.getGitContext().pullOrClone(gitUrl, repositoryPath, repositoryConfig.gitBranch());
this.context.getGitContext().pullOrClone(repositoryConfig.asGitUrl(), repositoryPath);

String buildCmd = repositoryConfig.buildCmd();
this.context.debug("Building repository with ide command: {}", buildCmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Properties;
import java.util.Set;

import com.devonfw.tools.ide.git.GitUrl;

/**
* Represents the configuration of a repository to be used by the {@link RepositoryCommandlet}.
*
Expand All @@ -32,6 +34,18 @@ public record RepositoryConfig(
Set<String> imports,
boolean active) {

/**
* @return the {@link GitUrl} from {@link #gitUrl()} and {@link #gitBranch()}.
*/
public GitUrl asGitUrl() {

return new GitUrl(this.gitUrl, this.gitBranch);
}

/**
* @param filePath the {@link Path} to the {@link Properties} to load.
* @return the parsed {@link RepositoryConfig}.
*/
public static RepositoryConfig loadProperties(Path filePath) {

Properties properties = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.nio.file.Path;

import com.devonfw.tools.ide.context.GitContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.git.GitContext;

/**
* {@link Commandlet} to print a status report about IDEasy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.IdeSystem;
import com.devonfw.tools.ide.environment.IdeSystemImpl;
import com.devonfw.tools.ide.git.GitContext;
import com.devonfw.tools.ide.git.GitContextImpl;
import com.devonfw.tools.ide.git.GitUrl;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.FileAccessImpl;
import com.devonfw.tools.ide.log.IdeLogLevel;
Expand Down Expand Up @@ -61,7 +64,7 @@
*/
public abstract class AbstractIdeContext implements IdeContext {

private static final String IDE_URLS_GIT = "https://github.com/devonfw/ide-urls.git";
private static final GitUrl IDE_URLS_GIT = new GitUrl("https://github.com/devonfw/ide-urls.git", null);

private final IdeStartContextImpl startContext;

Expand Down
218 changes: 0 additions & 218 deletions cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java

This file was deleted.

Loading

0 comments on commit 886cea3

Please sign in to comment.