1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.git.jgit;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.function.Consumer;
26
27 import org.apache.maven.scm.provider.ScmProvider;
28 import org.apache.maven.scm.provider.git.command.GitCommand;
29 import org.apache.maven.scm.provider.git.jgit.command.CustomizableSshSessionFactoryCommand;
30 import org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
31 import org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand;
32 import org.apache.maven.scm.provider.git.jgit.command.checkout.JGitCheckOutCommand;
33 import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
34 import org.apache.maven.scm.provider.git.jgit.command.tag.JGitTagCommand;
35 import org.apache.maven.scm.provider.git.jgit.command.untag.JGitUntagCommand;
36 import org.codehaus.plexus.components.interactivity.Prompter;
37 import org.eclipse.jgit.api.TransportCommand;
38 import org.eclipse.sisu.Priority;
39
40
41
42
43 @Singleton
44 @Named("jgit")
45 @Priority(1)
46 public class JGitTestScmProvider extends JGitScmProvider implements ScmProvider {
47 private Consumer<? super JGitCheckInCommand> checkInCommandCallback;
48 private Consumer<? super JGitCheckOutCommand> checkOutCommandCallback;
49 private Consumer<? super JGitRemoteInfoCommand> remoteInfoCommandCallback;
50 private Consumer<? super JGitTagCommand> tagCommandCallback;
51 private Consumer<? super JGitUntagCommand> untagCommandCallback;
52 private Consumer<? super JGitBranchCommand> branchCommandCallback;
53
54 @Inject
55 public JGitTestScmProvider(Prompter prompter) {
56 super(prompter);
57 }
58
59 public void registerCheckInCommandCallback(Consumer<? super JGitCheckInCommand> gitCommandConsumer) {
60 checkInCommandCallback = gitCommandConsumer;
61 }
62
63 public void registerCheckOutCommandCallback(Consumer<? super JGitCheckOutCommand> gitCommandConsumer) {
64 checkOutCommandCallback = gitCommandConsumer;
65 }
66
67 public void registerRemoteInfoCommandCallback(Consumer<? super JGitRemoteInfoCommand> gitCommandConsumer) {
68 remoteInfoCommandCallback = gitCommandConsumer;
69 }
70
71 public void registerTagCommandCallback(Consumer<? super JGitTagCommand> gitCommandConsumer) {
72 tagCommandCallback = gitCommandConsumer;
73 }
74
75 public void registerUntagCommandCallback(Consumer<? super JGitUntagCommand> gitCommandConsumer) {
76 untagCommandCallback = gitCommandConsumer;
77 }
78
79 public void registerBranchCommandCallback(Consumer<? super JGitBranchCommand> gitCommandConsumer) {
80 branchCommandCallback = gitCommandConsumer;
81 }
82
83 @Override
84 protected GitCommand getCheckInCommand() {
85 JGitCheckInCommand command = (JGitCheckInCommand) super.getCheckInCommand();
86 if (checkInCommandCallback != null) {
87 checkInCommandCallback.accept(command);
88 }
89 return command;
90 }
91
92 @Override
93 protected GitCommand getCheckOutCommand() {
94 JGitCheckOutCommand command = (JGitCheckOutCommand) super.getCheckOutCommand();
95 if (checkOutCommandCallback != null) {
96 checkOutCommandCallback.accept(command);
97 }
98 return command;
99 }
100
101 @Override
102 protected GitCommand getRemoteInfoCommand() {
103 JGitRemoteInfoCommand command = (JGitRemoteInfoCommand) super.getRemoteInfoCommand();
104 if (remoteInfoCommandCallback != null) {
105 remoteInfoCommandCallback.accept(command);
106 }
107 return command;
108 }
109
110 @Override
111 protected GitCommand getBranchCommand() {
112 JGitBranchCommand command = (JGitBranchCommand) super.getBranchCommand();
113 if (branchCommandCallback != null) {
114 branchCommandCallback.accept(command);
115 }
116 return command;
117 }
118
119 @Override
120 protected GitCommand getTagCommand() {
121 JGitTagCommand command = (JGitTagCommand) super.getTagCommand();
122 if (tagCommandCallback != null) {
123 tagCommandCallback.accept(command);
124 }
125 return command;
126 }
127
128 @Override
129 protected GitCommand getUntagCommand() {
130 JGitUntagCommand command = (JGitUntagCommand) super.getUntagCommand();
131 if (untagCommandCallback != null) {
132 untagCommandCallback.accept(command);
133 }
134 return command;
135 }
136
137
138
139
140
141 public void useLenientSshdSessionFactory() {
142 Consumer<CustomizableSshSessionFactoryCommand> configureLenientSshSessionFactory = command -> {
143 command.setSshSessionFactorySupplier(AcceptAllHostsSshdSessionFactory::new);
144 };
145 registerCheckOutCommandCallback(configureLenientSshSessionFactory);
146 registerCheckInCommandCallback(configureLenientSshSessionFactory);
147 registerBranchCommandCallback(configureLenientSshSessionFactory);
148 registerTagCommandCallback(configureLenientSshSessionFactory);
149 registerUntagCommandCallback(configureLenientSshSessionFactory);
150 }
151 }