1
1
package org .jenkinsci .plugins .gitserver ;
2
2
3
+ import jakarta .servlet .http .HttpServletRequest ;
3
4
import jenkins .model .Jenkins ;
4
- import org .acegisecurity .Authentication ;
5
5
import org .eclipse .jgit .api .AddCommand ;
6
6
import org .eclipse .jgit .api .CommitCommand ;
7
7
import org .eclipse .jgit .api .Git ;
11
11
import org .eclipse .jgit .lib .PersonIdent ;
12
12
import org .eclipse .jgit .lib .Repository ;
13
13
import org .eclipse .jgit .storage .file .FileRepositoryBuilder ;
14
- import org .eclipse .jgit .transport .PostReceiveHook ;
15
- import org .eclipse .jgit .transport .ReceiveCommand ;
16
14
import org .eclipse .jgit .transport .ReceivePack ;
17
15
import org .eclipse .jgit .transport .UploadPack ;
18
16
import org .eclipse .jgit .transport .resolver .ServiceNotAuthorizedException ;
19
17
import org .eclipse .jgit .transport .resolver .ServiceNotEnabledException ;
18
+ import org .springframework .security .core .Authentication ;
20
19
21
- import javax .servlet .http .HttpServletRequest ;
22
20
import java .io .File ;
23
21
import java .io .IOException ;
24
22
import java .io .PrintWriter ;
25
23
import java .io .StringWriter ;
26
- import java .util .Collection ;
27
24
import java .util .logging .Level ;
28
25
import java .util .logging .Logger ;
29
26
@@ -63,6 +60,7 @@ public Repository openRepository() throws IOException {
63
60
/**
64
61
* Called when there's no .git directory to create one.
65
62
*
63
+ * <p>
66
64
* This implementation also imports whatever currently in there into the repository.
67
65
*/
68
66
protected void createInitialRepository (Repository r ) throws IOException {
@@ -80,14 +78,15 @@ protected void createInitialRepository(Repository r) throws IOException {
80
78
co .setMessage ("Initial import of the existing contents" );
81
79
co .call ();
82
80
} catch (GitAPIException e ) {
83
- LOGGER .log (Level .WARNING , "Initial import of " +workspace +" into Git repository failed" , e );
81
+ LOGGER .log (Level .WARNING , e , () -> "Initial import of " +workspace +" into Git repository failed" );
84
82
}
85
83
}
86
84
87
85
/**
88
86
* This default implementation allows read access to anyone
89
87
* who can access the HTTP URL this repository is bound to.
90
88
*
89
+ * <p>
91
90
* For example, if this object is used as a project action,
92
91
* and the project isn't readable to Alice, then Alice won't be
93
92
* able to pull from this repository (think of a POSIX file system
@@ -103,7 +102,7 @@ public UploadPack createUploadPack(HttpServletRequest context, Repository db) th
103
102
*/
104
103
@ Override
105
104
public ReceivePack createReceivePack (HttpServletRequest context , Repository db ) throws ServiceNotEnabledException , ServiceNotAuthorizedException {
106
- Authentication a = Jenkins .getAuthentication ();
105
+ Authentication a = Jenkins .getAuthentication2 ();
107
106
108
107
ReceivePack rp = createReceivePack (db );
109
108
@@ -118,15 +117,13 @@ public ReceivePack createReceivePack(Repository db) {
118
117
ReceivePack rp = new ReceivePack (db );
119
118
120
119
// update userContent after the push
121
- rp .setPostReceiveHook (new PostReceiveHook () {
122
- public void onPostReceive (ReceivePack rp , Collection <ReceiveCommand > commands ) {
123
- try {
124
- updateWorkspace (rp .getRepository ());
125
- } catch (Exception e ) {
126
- StringWriter sw = new StringWriter ();
127
- e .printStackTrace (new PrintWriter (sw ));
128
- rp .sendMessage ("Failed to update workspace: " +sw );
129
- }
120
+ rp .setPostReceiveHook ((rp1 , commands ) -> {
121
+ try {
122
+ updateWorkspace (rp1 .getRepository ());
123
+ } catch (Exception e ) {
124
+ StringWriter sw = new StringWriter ();
125
+ e .printStackTrace (new PrintWriter (sw ));
126
+ rp1 .sendMessage ("Failed to update workspace: " +sw );
130
127
}
131
128
});
132
129
return rp ;
@@ -136,7 +133,7 @@ public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
136
133
* Called when new ref is pushed to update the {@linkplain #workspace local workspace}.
137
134
* The default implementation does "git reset --hard main"
138
135
*/
139
- protected void updateWorkspace (Repository repo ) throws IOException , GitAPIException {
136
+ protected void updateWorkspace (Repository repo ) throws GitAPIException {
140
137
ResetCommand cmd = new Git (repo ).reset ();
141
138
cmd .setMode (ResetType .HARD );
142
139
cmd .setRef ("master" );
0 commit comments