PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/hudson/plugins/git/GitAPI.java

https://gitlab.com/vectorci/git-client-plugin
Java | 323 lines | 112 code | 52 blank | 159 comment | 30 complexity | fa5f2e0f0c286b0d9c319eada186a9b4 MD5 | raw file
  1. package hudson.plugins.git;
  2. import edu.umd.cs.findbugs.annotations.NonNull;
  3. import hudson.EnvVars;
  4. import hudson.FilePath;
  5. import hudson.model.TaskListener;
  6. import org.eclipse.jgit.lib.ObjectId;
  7. import org.eclipse.jgit.lib.PersonIdent;
  8. import org.eclipse.jgit.lib.Repository;
  9. import org.eclipse.jgit.transport.RefSpec;
  10. import org.eclipse.jgit.transport.URIish;
  11. import org.jenkinsci.plugins.gitclient.CliGitAPIImpl;
  12. import org.jenkinsci.plugins.gitclient.Git;
  13. import org.jenkinsci.plugins.gitclient.GitClient;
  14. import java.io.*;
  15. import java.util.List;
  16. import java.util.Set;
  17. /**
  18. * Backward compatible class to match the one some plugins used from git-plugin.
  19. * Extends CliGitAPIImpl to implement deprecated IGitAPI methods, but delegates supported methods to the selected git implementation (based on
  20. * {@link org.jenkinsci.plugins.gitclient.Git#USE_CLI}).
  21. *
  22. * New implementations should use {@link org.jenkinsci.plugins.gitclient.GitClient}.
  23. *
  24. * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
  25. * @deprecated
  26. */
  27. public class GitAPI extends CliGitAPIImpl {
  28. private static final long serialVersionUID = 1L;
  29. private final GitClient jgit;
  30. /**
  31. * Constructor for GitAPI.
  32. *
  33. * @param gitExe name of git executable (git or git.exe or jgit)
  34. * @param repository a {@link hudson.FilePath} for the repository directory
  35. * @param listener a {@link hudson.model.TaskListener} which monitors the git work
  36. * @param environment the {@link hudson.EnvVars} environment for the build
  37. * @throws java.io.IOException if any IO failure
  38. * @throws java.lang.InterruptedException if interrupted
  39. */
  40. @Deprecated
  41. public GitAPI(String gitExe, FilePath repository, TaskListener listener, EnvVars environment) throws IOException, InterruptedException {
  42. this(gitExe, new File(repository.getRemote()), listener, environment);
  43. }
  44. /**
  45. * Constructor for GitAPI.
  46. *
  47. * @param gitExe name of git executable (git or git.exe or jgit)
  48. * @param repository a {@link hudson.FilePath} for the repository directory
  49. * @param listener a {@link hudson.model.TaskListener} which monitors the git work
  50. * @param environment the {@link hudson.EnvVars} environment for the build
  51. * @param reference SHA1 for checkout
  52. * @throws java.io.IOException if any IO failure
  53. * @throws java.lang.InterruptedException if interrupted.
  54. */
  55. @Deprecated
  56. public GitAPI(String gitExe, FilePath repository, TaskListener listener, EnvVars environment, String reference) throws IOException, InterruptedException {
  57. this(gitExe, repository, listener, environment);
  58. }
  59. /**
  60. * Constructor for GitAPI.
  61. *
  62. * @param gitExe name of git executable (git or git.exe or jgit)
  63. * @param repository a {@link hudson.FilePath} for the repository directory
  64. * @param listener a {@link hudson.model.TaskListener} which monitors the git work
  65. * @param environment the {@link hudson.EnvVars} environment for the build
  66. * @throws java.io.IOException if any IO failure
  67. * @throws java.lang.InterruptedException if interrupted.
  68. */
  69. @Deprecated
  70. public GitAPI(String gitExe, File repository, TaskListener listener, EnvVars environment) throws IOException, InterruptedException {
  71. super(gitExe, repository, listener, environment);
  72. // If USE_CLI is forced, don't delegate to JGit client
  73. this.jgit = Git.USE_CLI ? null : Git.with(listener, environment).in(repository).using("jgit").getClient();
  74. }
  75. // --- delegate implemented methods to JGit client
  76. /** {@inheritDoc} */
  77. public void add(String filePattern) throws GitException, InterruptedException {
  78. if (Git.USE_CLI) super.add(filePattern); else jgit.add(filePattern);
  79. }
  80. /*
  81. public List<ObjectId> revList(String ref) throws GitException {
  82. return Git.USE_CLI ? super.revList(ref) : jgit.revList(ref);
  83. }
  84. */
  85. /** {@inheritDoc} */
  86. public String getRemoteUrl(String name) throws GitException, InterruptedException {
  87. return Git.USE_CLI ? super.getRemoteUrl(name) : jgit.getRemoteUrl(name);
  88. }
  89. /** {@inheritDoc} */
  90. public void push(String remoteName, String refspec) throws GitException, InterruptedException {
  91. if (Git.USE_CLI) super.push(remoteName, refspec); else jgit.push(remoteName, refspec);
  92. }
  93. /** {@inheritDoc} */
  94. public String getTagMessage(String tagName) throws GitException, InterruptedException {
  95. return Git.USE_CLI ? super.getTagMessage(tagName) : jgit.getTagMessage(tagName);
  96. }
  97. /*
  98. public List<ObjectId> revListAll() throws GitException {
  99. return Git.USE_CLI ? super.revListAll() : jgit.revListAll();
  100. }
  101. */
  102. /*
  103. public void addNote(String note, String namespace) throws GitException {
  104. if (Git.USE_CLI) super.addNote(note, namespace); else jgit.addNote(note, namespace);
  105. }
  106. */
  107. /*
  108. public void appendNote(String note, String namespace) throws GitException {
  109. if (Git.USE_CLI) super.appendNote(note, namespace); else jgit.appendNote(note, namespace);
  110. }
  111. */
  112. /*
  113. public void changelog(String revFrom, String revTo, OutputStream fos) throws GitException {
  114. if (Git.USE_CLI) super.changelog(revFrom, revTo, fos); else jgit.changelog(revFrom, revTo, fos);
  115. }
  116. */
  117. /*
  118. public List<IndexEntry> getSubmodules(String treeIsh) throws GitException {
  119. return Git.USE_CLI ? super.getSubmodules(treeIsh) : jgit.getSubmodules(treeIsh);
  120. }
  121. */
  122. /*
  123. public ObjectId getHeadRev(String remoteRepoUrl, String branch) throws GitException {
  124. return Git.USE_CLI ? super.getHeadRev(remoteRepoUrl, branch) : jgit.getHeadRev(remoteRepoUrl, branch);
  125. }
  126. */
  127. /*
  128. public Set<String> getTagNames(String tagPattern) throws GitException {
  129. return Git.USE_CLI ? super.getTagNames(tagPattern) : jgit.getTagNames(tagPattern);
  130. }
  131. */
  132. /** {@inheritDoc} */
  133. public GitClient subGit(String subdir) {
  134. return Git.USE_CLI ? super.subGit(subdir) : jgit.subGit(subdir);
  135. }
  136. /** {@inheritDoc} */
  137. public void setRemoteUrl(String name, String url) throws GitException, InterruptedException {
  138. if (Git.USE_CLI) super.setRemoteUrl(name, url); else jgit.setRemoteUrl(name, url);
  139. }
  140. /*
  141. public void prune(RemoteConfig repository) throws GitException {
  142. if (Git.USE_CLI) super.prune(repository); else jgit.prune(repository);
  143. }
  144. */
  145. /*
  146. public void submoduleUpdate(boolean recursive) throws GitException {
  147. if (Git.USE_CLI) super.submoduleUpdate(recursive); else jgit.submoduleUpdate(recursive);
  148. }
  149. */
  150. /*
  151. public void submoduleUpdate(boolean recursive, String reference) throws GitException {
  152. if (Git.USE_CLI) super.submoduleUpdate(recursive, String reference); else jgit.submoduleUpdate(recursive, String reference);
  153. }
  154. */
  155. /*
  156. public List<String> showRevision(ObjectId from, ObjectId to) throws GitException {
  157. return Git.USE_CLI ? super.showRevision(from, to) : jgit.showRevision(from, to);
  158. }
  159. */
  160. /*
  161. public boolean hasGitModules() throws GitException {
  162. return Git.USE_CLI ? super.hasGitModules() : jgit.hasGitModules();
  163. }
  164. */
  165. /** {@inheritDoc} */
  166. public Set<Branch> getBranches() throws GitException, InterruptedException {
  167. return Git.USE_CLI ? super.getBranches() : jgit.getBranches();
  168. }
  169. /*
  170. public void addSubmodule(String remoteURL, String subdir) throws GitException {
  171. if (Git.USE_CLI) super.addSubmodule(remoteURL, subdir); else jgit.addSubmodule(remoteURL, subdir);
  172. }
  173. */
  174. /*
  175. public void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException {
  176. if (Git.USE_CLI) super.clone(url, origin, useShallowClone, reference); else jgit.clone(url, origin, useShallowClone, reference);
  177. }
  178. */
  179. /** {@inheritDoc} */
  180. public Set<Branch> getRemoteBranches() throws GitException, InterruptedException {
  181. return Git.USE_CLI ? super.getRemoteBranches() : jgit.getRemoteBranches();
  182. }
  183. /** {@inheritDoc} */
  184. public void init() throws GitException, InterruptedException {
  185. if (Git.USE_CLI) super.init(); else jgit.init();
  186. }
  187. /** {@inheritDoc} */
  188. public void deleteBranch(String name) throws GitException, InterruptedException {
  189. if (Git.USE_CLI) super.deleteBranch(name); else jgit.deleteBranch(name);
  190. }
  191. /** {@inheritDoc} */
  192. public void checkout(String ref, String branch) throws GitException, InterruptedException {
  193. if (Git.USE_CLI) super.checkout(ref, branch); else jgit.checkout(ref, branch);
  194. }
  195. /** {@inheritDoc} */
  196. public boolean hasGitRepo() throws GitException, InterruptedException {
  197. return Git.USE_CLI ? super.hasGitRepo() : jgit.hasGitRepo();
  198. }
  199. /** {@inheritDoc} */
  200. public boolean isCommitInRepo(ObjectId commit) throws GitException, InterruptedException {
  201. return Git.USE_CLI ? super.isCommitInRepo(commit) : jgit.isCommitInRepo(commit);
  202. }
  203. /*
  204. public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException {
  205. if (Git.USE_CLI) super.setupSubmoduleUrls(rev, listener); else jgit.setupSubmoduleUrls(rev, listener);
  206. }
  207. */
  208. /** {@inheritDoc} */
  209. public void commit(String message) throws GitException, InterruptedException {
  210. if (Git.USE_CLI) super.commit(message); else jgit.commit(message);
  211. }
  212. /** {@inheritDoc} */
  213. public void commit(String message, PersonIdent author, PersonIdent committer) throws GitException, InterruptedException {
  214. if (Git.USE_CLI) super.commit(message, author, committer); else jgit.commit(message, author, committer);
  215. }
  216. /** {@inheritDoc} */
  217. public void checkout(String ref) throws GitException, InterruptedException {
  218. if (Git.USE_CLI) super.checkout(ref); else jgit.checkout(ref);
  219. }
  220. /** {@inheritDoc} */
  221. public void deleteTag(String tagName) throws GitException, InterruptedException {
  222. if (Git.USE_CLI) super.deleteTag(tagName); else jgit.deleteTag(tagName);
  223. }
  224. /** {@inheritDoc} */
  225. @NonNull
  226. public Repository getRepository() throws GitException {
  227. return Git.USE_CLI ? super.getRepository() : jgit.getRepository();
  228. }
  229. /** {@inheritDoc} */
  230. public void tag(String tagName, String comment) throws GitException, InterruptedException {
  231. if (Git.USE_CLI) super.tag(tagName, comment); else jgit.tag(tagName, comment);
  232. }
  233. /*
  234. public List<String> showRevision(ObjectId r) throws GitException {
  235. return Git.USE_CLI ? super.showRevision(r) : jgit.showRevision(r);
  236. }
  237. */
  238. /** {@inheritDoc} */
  239. public void fetch(URIish url, List<RefSpec> refspecs) throws GitException, InterruptedException {
  240. if (Git.USE_CLI) super.fetch(url, refspecs); else jgit.fetch(url, refspecs);
  241. }
  242. /** {@inheritDoc} */
  243. public void fetch(String remoteName, RefSpec... refspec) throws GitException, InterruptedException {
  244. if (Git.USE_CLI) super.fetch(remoteName, refspec); else jgit.fetch(remoteName, refspec);
  245. }
  246. /** {@inheritDoc} */
  247. public void fetch(String remoteName, RefSpec refspec) throws GitException, InterruptedException {
  248. fetch(remoteName, new RefSpec[] {refspec});
  249. }
  250. /** {@inheritDoc} */
  251. public boolean tagExists(String tagName) throws GitException, InterruptedException {
  252. return Git.USE_CLI ? super.tagExists(tagName) : jgit.tagExists(tagName);
  253. }
  254. /*
  255. public void submoduleClean(boolean recursive) throws GitException {
  256. if (Git.USE_CLI) super.submoduleClean(recursive); else jgit.submoduleClean(recursive);
  257. }
  258. */
  259. /** {@inheritDoc} */
  260. public void clean() throws GitException, InterruptedException {
  261. if (Git.USE_CLI) super.clean(); else jgit.clean();
  262. }
  263. /** {@inheritDoc} */
  264. public ObjectId revParse(String revName) throws GitException, InterruptedException {
  265. return Git.USE_CLI ? super.revParse(revName) : jgit.revParse(revName);
  266. }
  267. /** {@inheritDoc} */
  268. public void branch(String name) throws GitException, InterruptedException {
  269. if (Git.USE_CLI) super.branch(name); else jgit.branch(name);
  270. }
  271. }