Skip to content
Snippets Groups Projects
Commit 7bcddd72 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

differentiate between failure modes in the logging done in importRepository(),...

differentiate between failure modes in the logging done in importRepository(), try and use the canonical file path for the URL as a fallback
parent 764ee71d
No related branches found
No related tags found
No related merge requests found
...@@ -6,11 +6,13 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ToolNotWorkingException; ...@@ -6,11 +6,13 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ToolNotWorkingException;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolWrapper; import de.uni_passau.fim.seibt.gitwrapper.process.ToolWrapper;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Scanner; import java.util.Scanner;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -135,24 +137,39 @@ public class GitWrapper extends ToolWrapper { ...@@ -135,24 +137,39 @@ public class GitWrapper extends ToolWrapper {
*/ */
public Optional<Repository> importRepository(File directory) { public Optional<Repository> importRepository(File directory) {
if (!isGitDir(directory)) { if (!isGitDir(directory)) {
LOG.warning(() -> directory + " does not contain a git repository.");
return Optional.empty(); return Optional.empty();
} }
// TODO add fallback method for determining URL Optional<ExecRes> originURL = exec(directory, "config", "--get", "remote.origin.url");
Function<ExecRes, Repository> toRepository = res -> {
Optional<ExecRes> result = exec(directory, "config", "--get", "remote.origin.url");
Optional<String> url = result.map(res -> {
String repoUrl = null; String repoUrl = null;
if (failed(res) || (repoUrl = res.getStdOutTrimmed()).isEmpty()) { if (failed(res)) {
// there was no remote url LOG.warning(() -> String.format("Failed to get the origin url for the repository in %s. Using the " +
LOG.fine(String.format("Repository %s does not hab an origin url, using the local path", directory)); "canonical directory path.", directory));
repoUrl = directory.getAbsolutePath(); } else if (res.getStdOutTrimmed().isEmpty()) {
LOG.warning(() -> String.format("Repository in %s does not have an origin url. Using the canonical " +
"directory path.", directory));
} else {
repoUrl = res.getStdOutTrimmed();
}
if (repoUrl == null) {
try {
repoUrl = directory.getCanonicalPath();
} catch (IOException e) {
LOG.log(Level.WARNING, e, () -> "Exception computing the canonical path for " + directory +
". Using the absolute path instead.");
repoUrl = directory.getAbsolutePath();
}
} }
return repoUrl; return new Repository(this, repoUrl, directory);
}); };
return Optional.of(new Repository(this, url.orElse(""), directory));
return originURL.map(toRepository);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment