From 8320dd2b1adf8d2d3b4e193bf7e97612dcf866d5 Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 18:48:06 +0200 Subject: [PATCH 1/8] Version 1.1: allows to modify git executable --- pom.xml | 1 - .../java/com/symplegit/api/GitCommander.java | 8 +++-- .../java/com/symplegit/api/SympleGit.java | 32 ++++++++++++++++--- .../symplegit/util/version/VersionValues.java | 4 +-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index e17968f..6427854 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,6 @@ com.symplegit symplegit 1.0 - commons-io diff --git a/src/main/java/com/symplegit/api/GitCommander.java b/src/main/java/com/symplegit/api/GitCommander.java index 2d84a29..01d191c 100644 --- a/src/main/java/com/symplegit/api/GitCommander.java +++ b/src/main/java/com/symplegit/api/GitCommander.java @@ -186,7 +186,11 @@ private void writeErrorInTempFile() { private void executeInThread(String... command) { builder.redirectErrorStream(true); + if (! sympleGit.getGitExecutable().equals("git")) { + command[0] = sympleGit.getGitExecutable(); + } + debug("paramsOk : " + paramsOk); debug("Git command: " + removeCommas(Arrays.toString(command))); @@ -219,11 +223,11 @@ private void executeInThread(String... command) { } /** - * Check basic parameters of the Git command. (It must start with "git", etc.). + * Check basic parameters of the Git command. (It must contains "git", etc.). * @param command */ private boolean basicParamsCheks(String... command) { - return command == null || command.length == 0 || ! command[0].equals("git") ? false : true; + return command == null || command.length == 0 || ! command[0].toLowerCase().contains("git") ? false : true; } /** diff --git a/src/main/java/com/symplegit/api/SympleGit.java b/src/main/java/com/symplegit/api/SympleGit.java index 7246bb4..96c9d6a 100644 --- a/src/main/java/com/symplegit/api/SympleGit.java +++ b/src/main/java/com/symplegit/api/SympleGit.java @@ -72,8 +72,10 @@ public class SympleGit implements AutoCloseable { private static final int DEFAULT_TIMEOUT_SECONDS = 0; private final File directory; - private int timeout; - private TimeUnit unit; + private final String gitExecutable; + + private final int timeout; + private final TimeUnit unit; private List tempFiles = new ArrayList<>(); @@ -86,6 +88,7 @@ private SympleGit(Builder builder) { this.directory = builder.directory; this.timeout = builder.timeout; this.unit = builder.unit; + this.gitExecutable = builder.gitExecutable; } /** @@ -125,7 +128,14 @@ public TimeUnit getUnit() { return unit; } - // Additional methods or functionality as needed + /** + * Gets the path to the Git executable. + * + * @return The path to the Git executable. + */ + public String getGitExecutable() { + return gitExecutable; + } /** * Builder class for SympleGit. Provides methods to configure SympleGit @@ -136,7 +146,8 @@ public static class Builder { private File directory; private int timeout = DEFAULT_TIMEOUT_SECONDS; private TimeUnit unit = TimeUnit.SECONDS; - + private String gitExecutable = "git"; // Default to 'git', can be overridden + /** * Sets the directory path for the Git repository. * @@ -174,6 +185,19 @@ public Builder setTimeout(int timeout, TimeUnit unit) { return this; } + /** + * Sets the Git executable to be used. This is useful when SympleGit is + * being used with a non-standard Git installation. + *
If not provided, SympleGit will use the default 'git' executable. + * + * @param gitExecutable The path to the Git executable. + * @return The Builder instance for chaining. + */ + public Builder setGitExecutable(String gitExecutable) { + this.gitExecutable = gitExecutable; + return this; + } + /** * Builds and returns a SympleGit instance with the current configuration. * diff --git a/src/main/java/com/symplegit/util/version/VersionValues.java b/src/main/java/com/symplegit/util/version/VersionValues.java index 6133ee2..0bcd7d7 100644 --- a/src/main/java/com/symplegit/util/version/VersionValues.java +++ b/src/main/java/com/symplegit/util/version/VersionValues.java @@ -24,6 +24,6 @@ */ public class VersionValues { - public static final String VERSION = "v1.0"; - public static final String DATE = "19-Jan-2024"; + public static final String VERSION = "v1.1"; + public static final String DATE = "15-Sep-2024"; } From 4966fecf453034507ab9c77a29d1f607b664c342 Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:09:27 +0200 Subject: [PATCH 2/8] Readme update --- README.md | 15 +++++++++++++-- pom.xml | 3 ++- .../examples/misc/GitBranchTest.java | 1 + .../symplegit/unit/test/GitVersionTest.java | 19 +++++++++++++++---- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6647b45..7732af0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/d14142d5d6f04ba891d505e2e47b417d)](https://www.codacy.com/gh/kawansoft/SympleGit-Java?utm_source=github.com&utm_medium=referral&utm_content=kawansoft/SympleGit-Java&utm_campaign=Badge_Grade) ![GitHub contributors](https://img.shields.io/github/contributors/kawansoft/SympleGit-Java) -# SympleGit v1.0 - January 19, 2024 +# SympleGit v1.1 - September 19, 2024 @@ -24,6 +24,7 @@ Table of Contents * [The GitCommander API](#the-gitcommander-api) * [Short Output](#short-output) * [Large Output](#large-output) + * [Setting a Custom Git Executable](#setting-a-custom-git-executable) * [Setting a Timeout](#setting-a-timeout) * [Releasing Resources by Closing the SympleGit Instance](#releasing-resources-by-closing-the-symplegit-instance) * [The Facilitator API](#the-facilitator-api) @@ -58,7 +59,7 @@ SympleGit requires Java version 11 or newer. ```xml com.symplegit symplegit -1.0 +1.1 ``` ## Why Choose SympleGit Over JGit? @@ -223,6 +224,16 @@ if (gitCommander.getSize() <= 1 * 1024 * 1024) { } ``` +### Setting a Custom Git Executable + +To enhance flexibility and ensure compatibility across various environments, SympleGit provides the option to specify a custom path for the Git executable. This feature is particularly useful if the default Git installation path is not in your system's `PATH` environment variable, or if you wish to use a specific version of Git. + +```java +final Git sympleGit = SympleGit.custom() + .setGitExecutable("/usr/local/bin/git") // Specify the full path to the Git executable + .build(); +``` + ### Setting a Timeout SympleGit enables setting a timeout for the Git process with `Builder.setTimeout`: diff --git a/pom.xml b/pom.xml index 6427854..36456cd 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,8 @@ com.symplegit symplegit - 1.0 + 1.1 + commons-io diff --git a/src/test/java/com/symplegit/examples/misc/GitBranchTest.java b/src/test/java/com/symplegit/examples/misc/GitBranchTest.java index 3151681..a6ed4d6 100644 --- a/src/test/java/com/symplegit/examples/misc/GitBranchTest.java +++ b/src/test/java/com/symplegit/examples/misc/GitBranchTest.java @@ -38,6 +38,7 @@ public static void main(String[] args) throws IOException { String repoDirectoryPath = "I:\\_dev_sqlephant_tests\\Java"; final SympleGit sympleGit = SympleGit.custom() + .setGitExecutable("\\toto\\git.exe") .setDirectory(repoDirectoryPath) .build(); diff --git a/src/test/java/com/symplegit/unit/test/GitVersionTest.java b/src/test/java/com/symplegit/unit/test/GitVersionTest.java index 22d9618..c593e07 100644 --- a/src/test/java/com/symplegit/unit/test/GitVersionTest.java +++ b/src/test/java/com/symplegit/unit/test/GitVersionTest.java @@ -24,10 +24,12 @@ import java.io.File; import java.io.IOException; +import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.symplegit.api.SympleGit; +import com.symplegit.api.SympleGit.Builder; import com.symplegit.api.facilitator.GitVersion; import com.symplegit.test.util.GitTestUtils; @@ -35,14 +37,21 @@ public class GitVersionTest { private GitVersion gitVersion; private File repoDir; - + private SympleGit sympleGit; + @BeforeEach public void setUp() throws IOException { // Create a temporary Git repository repoDir = GitTestUtils.createIfNotTexistsTemporaryGitRepo(); - final SympleGit sympleGit = SympleGit.custom() - .setDirectory(repoDir) - .build(); + + Builder builder = SympleGit.custom(); + builder.setDirectory(repoDir); + + if (SystemUtils.IS_OS_WINDOWS) { + builder.setGitExecutable("C:\\Program Files\\Git\\bin\\git.exe"); + } + + sympleGit= builder.build(); gitVersion = new GitVersion(sympleGit); } @@ -54,5 +63,7 @@ public void testGetVersion() throws IOException { // Check that the returned version string is not null and contains expected content assertNotNull(gitVersion, "Git version should not be null"); assert(gitVersion.contains("git version")); + System.out.println("Git executable: " + sympleGit.getGitExecutable()); + System.out.println("Git version : " + gitVersion); } } From 8a6bdd2fb9a9ee6499241dc5e34cee52aaf8af2d Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:22:27 +0200 Subject: [PATCH 3/8] Fix javadoc missing params --- pom.xml | 25 +++++++++++++++++++ .../symplegit/api/facilitator/GitCommit.java | 2 +- .../com/symplegit/util/GitProjectUtil.java | 6 ++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 36456cd..2f8b683 100644 --- a/pom.xml +++ b/pom.xml @@ -67,12 +67,37 @@ + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + generate-javadoc + package + + jar + + + + ${project.build.directory}/apidocs + true + true + true + + + + + + 11 11 + true Symple Git diff --git a/src/main/java/com/symplegit/api/facilitator/GitCommit.java b/src/main/java/com/symplegit/api/facilitator/GitCommit.java index 6e59bfc..412feee 100644 --- a/src/main/java/com/symplegit/api/facilitator/GitCommit.java +++ b/src/main/java/com/symplegit/api/facilitator/GitCommit.java @@ -88,7 +88,7 @@ public void amendCommit(String message) throws IOException { /** * Retrieves the commit history of the current branch as String. Will throw an - * IOException if the result is > 10Mb. + * IOException if the result is > 10Mb. * * @return A String containing the commit history. * @throws IOException If an error occurs during command execution. diff --git a/src/main/java/com/symplegit/util/GitProjectUtil.java b/src/main/java/com/symplegit/util/GitProjectUtil.java index 92149da..9bce09e 100644 --- a/src/main/java/com/symplegit/util/GitProjectUtil.java +++ b/src/main/java/com/symplegit/util/GitProjectUtil.java @@ -66,9 +66,9 @@ public static boolean isValidGitHubRepoName(String repoName) { * If the passed file is root of a Git project, this will return it's name. * Otw, will return repoDirectoryPath.getName() * - * @param repoDirectoryPath - * @return - * @throws IOException + * @param repoDirectoryPath the directory where the Git repository is located. + * @return the project name or repoDirectoryPath.getName() if not a Git project. + * @throws IOException if an error occurs while executing the command. */ public static String getGitProjectName(File repoDirectoryPath) { From 7b93afba0029d6aecd03f35493c316f29315e65f Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:24:04 +0200 Subject: [PATCH 4/8] Fox Javadoc --- src/main/java/com/symplegit/util/GitProjectUtil.java | 1 - src/main/java/com/symplegit/util/version/Version.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/symplegit/util/GitProjectUtil.java b/src/main/java/com/symplegit/util/GitProjectUtil.java index 9bce09e..4caa89b 100644 --- a/src/main/java/com/symplegit/util/GitProjectUtil.java +++ b/src/main/java/com/symplegit/util/GitProjectUtil.java @@ -68,7 +68,6 @@ public static boolean isValidGitHubRepoName(String repoName) { * * @param repoDirectoryPath the directory where the Git repository is located. * @return the project name or repoDirectoryPath.getName() if not a Git project. - * @throws IOException if an error occurs while executing the command. */ public static String getGitProjectName(File repoDirectoryPath) { diff --git a/src/main/java/com/symplegit/util/version/Version.java b/src/main/java/com/symplegit/util/version/Version.java index c611ddb..0c8cf94 100644 --- a/src/main/java/com/symplegit/util/version/Version.java +++ b/src/main/java/com/symplegit/util/version/Version.java @@ -52,10 +52,11 @@ public String toString() { } + /** - * MAIN + * Main method for testing the Version class. + * @param args the arguments passed to the program. Not used in this example. */ - public static void main(String[] args) { System.out.println(getVersion()); } From 4dfd28335d4fa07f8ab7472d8c07a5b3ff9f2718 Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:27:10 +0200 Subject: [PATCH 5/8] Javadoc --- .../com/symplegit/util/version/package.html | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/symplegit/util/version/package.html diff --git a/src/main/java/com/symplegit/util/version/package.html b/src/main/java/com/symplegit/util/version/package.html new file mode 100644 index 0000000..7d3a8b0 --- /dev/null +++ b/src/main/java/com/symplegit/util/version/package.html @@ -0,0 +1,23 @@ + + + + + + +Offers facilitator classes for the simplified execution of Git commands. + From 8f2a8cf708cd9bdb72577e44c7c72758e152c598 Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:28:41 +0200 Subject: [PATCH 6/8] Javadoc update --- src/main/java/com/symplegit/util/version/package.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/symplegit/util/version/package.html b/src/main/java/com/symplegit/util/version/package.html index 7d3a8b0..5e4e924 100644 --- a/src/main/java/com/symplegit/util/version/package.html +++ b/src/main/java/com/symplegit/util/version/package.html @@ -19,5 +19,5 @@ --> -Offers facilitator classes for the simplified execution of Git commands. +Version info From be297faa5d8e6c76c03d078cbe0b55ea81e5ae0e Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 19:29:37 +0200 Subject: [PATCH 7/8] pom.xml: disable Javadoc generation --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 2f8b683..2cb9698 100644 --- a/pom.xml +++ b/pom.xml @@ -67,11 +67,11 @@
- + + 3.3.1 generate-javadoc @@ -80,7 +80,7 @@ jar - + ${project.build.directory}/apidocs true true @@ -89,7 +89,7 @@ - +--> From fab402d33d7cc535604db84a9011b1642fb9436b Mon Sep 17 00:00:00 2001 From: Nicolas de Pomereu Date: Sun, 15 Sep 2024 20:22:14 +0200 Subject: [PATCH 8/8] Readme updated --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7732af0..43db1f3 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,7 @@ To enhance flexibility and ensure compatibility across various environments, Sym ```java final Git sympleGit = SympleGit.custom() + .setDirectory(repoDirectoryPath) .setGitExecutable("/usr/local/bin/git") // Specify the full path to the Git executable .build(); ```