Skip to content

Commit cdd7ffc

Browse files
committed
Run Spotless Apply
1 parent 6f78adb commit cdd7ffc

File tree

12 files changed

+170
-163
lines changed

12 files changed

+170
-163
lines changed

pom.xml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<parent>
56
<groupId>org.jenkins-ci.plugins</groupId>
67
<artifactId>plugin</artifactId>
78
<version>4.86</version>
8-
<relativePath/>
9+
<relativePath />
910
</parent>
1011

1112
<artifactId>git-server</artifactId>
@@ -15,21 +16,6 @@
1516
<name>Jenkins Git server Plugin</name>
1617
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
1718

18-
<properties>
19-
<changelist>999999-SNAPSHOT</changelist>
20-
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
21-
<jenkins.baseline>2.440</jenkins.baseline>
22-
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
23-
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
24-
</properties>
25-
26-
<scm>
27-
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
28-
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
29-
<url>https://github.com/${gitHubRepo}</url>
30-
<tag>${scmTag}</tag>
31-
</scm>
32-
3319
<licenses>
3420
<license>
3521
<name>The MIT license</name>
@@ -38,14 +24,29 @@
3824
</license>
3925
</licenses>
4026

27+
<scm>
28+
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
29+
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
30+
<tag>${scmTag}</tag>
31+
<url>https://github.com/${gitHubRepo}</url>
32+
</scm>
33+
34+
<properties>
35+
<changelist>999999-SNAPSHOT</changelist>
36+
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
37+
<jenkins.baseline>2.440</jenkins.baseline>
38+
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
39+
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
40+
</properties>
41+
4142
<dependencyManagement>
4243
<dependencies>
4344
<dependency>
4445
<groupId>io.jenkins.tools.bom</groupId>
4546
<artifactId>bom-${jenkins.baseline}.x</artifactId>
4647
<version>3234.v5ca_5154341ef</version>
47-
<scope>import</scope>
4848
<type>pom</type>
49+
<scope>import</scope>
4950
</dependency>
5051
</dependencies>
5152
</dependencyManagement>

src/main/java/org/jenkinsci/plugins/gitserver/CSRFExclusionImpl.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22

33
import hudson.Extension;
44
import hudson.security.csrf.CrumbExclusion;
5-
5+
import java.io.IOException;
6+
import java.util.Collections;
7+
import java.util.Enumeration;
8+
import java.util.Map;
9+
import java.util.Vector;
610
import javax.servlet.FilterChain;
711
import javax.servlet.ReadListener;
812
import javax.servlet.ServletException;
913
import javax.servlet.ServletInputStream;
1014
import javax.servlet.http.HttpServletRequest;
1115
import javax.servlet.http.HttpServletRequestWrapper;
1216
import javax.servlet.http.HttpServletResponse;
13-
import java.io.IOException;
14-
import java.util.Collections;
15-
import java.util.Enumeration;
16-
import java.util.Map;
17-
import java.util.Vector;
1817

1918
/**
2019
* CSRF exclusion for git-upload-pack.
21-
*
20+
*
2221
* <p>
2322
* We do some basic checks to significantly limit the scope of exclusion, but
2423
* because of the dynamic nature of the URL structure, this doesn't guarantee
2524
* that we have no leak.
2625
*
2726
* So to further protect Jenkins, we pass through a fake {@link HttpServletRequest}
2827
* that masks the values of the submission.
29-
*
28+
*
3029
* <p>
3130
* If the fake request is routed to {@link HttpGitRepository}, which is
3231
* the only legitimate destination of the request, we'll unwrap this fake request
@@ -35,19 +34,19 @@
3534
* <p>
3635
* In this way, even if an attacker manages to route the request to elsewhere in Jenkins,
3736
* that request will not be interpreted as a POST request.
38-
*
37+
*
3938
* @author Kohsuke Kawaguchi
4039
*/
4140
@Extension
4241
public class CSRFExclusionImpl extends CrumbExclusion {
4342

44-
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
45-
if (!"application/x-git-receive-pack-request".equals(request.getHeader("Content-Type")))
46-
return false;
43+
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
44+
throws IOException, ServletException {
45+
if (!"application/x-git-receive-pack-request".equals(request.getHeader("Content-Type"))) return false;
4746

48-
// String path = request.getPathInfo();
49-
// if(!path.contains("/repo.git/") || !path.endsWith("/git-receive-pack"))
50-
// return false;
47+
// String path = request.getPathInfo();
48+
// if(!path.contains("/repo.git/") || !path.endsWith("/git-receive-pack"))
49+
// return false;
5150

5251
HttpServletRequestWrapper w = new HttpServletRequestWrapper(request) {
5352
@Override
@@ -72,7 +71,7 @@ public Enumeration getParameterNames() {
7271

7372
@Override
7473
public String[] getParameterValues(String name) {
75-
return new String[]{"bogus"};
74+
return new String[] {"bogus"};
7675
}
7776

7877
@Override
@@ -105,13 +104,13 @@ public void setReadListener(ReadListener readListener) {
105104
};
106105
}
107106
};
108-
w.setAttribute(ORIGINAL_REQUEST,request);
109-
110-
chain.doFilter(w,response);
107+
w.setAttribute(ORIGINAL_REQUEST, request);
108+
109+
chain.doFilter(w, response);
111110
return true;
112111
}
113112

114-
static final String ORIGINAL_REQUEST = CSRFExclusionImpl.class.getName()+".originalRequest";
113+
static final String ORIGINAL_REQUEST = CSRFExclusionImpl.class.getName() + ".originalRequest";
115114

116115
public static HttpServletRequest unwrapRequest(HttpServletRequest req) {
117116
return (HttpServletRequest) req.getAttribute(CSRFExclusionImpl.ORIGINAL_REQUEST);

src/main/java/org/jenkinsci/plugins/gitserver/ChannelTransport.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.jenkinsci.plugins.gitserver;
22

33
import hudson.FilePath;
4-
import hudson.FilePath.FileCallable;
54
import hudson.remoting.Pipe;
65
import hudson.remoting.VirtualChannel;
6+
import java.io.BufferedInputStream;
7+
import java.io.BufferedOutputStream;
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.net.URISyntaxException;
711
import jenkins.MasterToSlaveFileCallable;
812
import org.apache.commons.io.IOUtils;
913
import org.eclipse.jgit.errors.NotSupportedException;
@@ -20,12 +24,6 @@
2024
import org.eclipse.jgit.transport.URIish;
2125
import org.eclipse.jgit.transport.UploadPack;
2226

23-
import java.io.BufferedInputStream;
24-
import java.io.BufferedOutputStream;
25-
import java.io.File;
26-
import java.io.IOException;
27-
import java.net.URISyntaxException;
28-
2927
/**
3028
* {@link Transport} implementation across pipes.
3129
*
@@ -34,15 +32,14 @@
3432
public class ChannelTransport extends Transport implements PackTransport {
3533
private final FilePath remoteRepository;
3634

37-
public static Transport open(Repository local, FilePath remoteRepository) throws NotSupportedException, URISyntaxException, TransportException {
38-
if (remoteRepository.isRemote())
39-
return new ChannelTransport(local,remoteRepository);
40-
else
41-
return Transport.open(local,remoteRepository.getRemote());
35+
public static Transport open(Repository local, FilePath remoteRepository)
36+
throws NotSupportedException, URISyntaxException, TransportException {
37+
if (remoteRepository.isRemote()) return new ChannelTransport(local, remoteRepository);
38+
else return Transport.open(local, remoteRepository.getRemote());
4239
}
4340

4441
public ChannelTransport(Repository local, FilePath remoteRepository) throws URISyntaxException {
45-
super(local, new URIish("channel:"+remoteRepository.getRemote()));
42+
super(local, new URIish("channel:" + remoteRepository.getRemote()));
4643
this.remoteRepository = remoteRepository;
4744
}
4845

@@ -54,15 +51,17 @@ public FetchConnection openFetch() throws NotSupportedException, TransportExcept
5451
try {
5552
remoteRepository.actAsync(new GitFetchTask(l2r, r2l));
5653
} catch (IOException e) {
57-
throw new TransportException("Failed to open a fetch connection",e);
54+
throw new TransportException("Failed to open a fetch connection", e);
5855
} catch (InterruptedException e) {
59-
throw new TransportException("Failed to open a fetch connection",e);
56+
throw new TransportException("Failed to open a fetch connection", e);
6057
}
6158

62-
return new BasePackFetchConnection(this) {{
63-
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
64-
readAdvertisedRefs();
65-
}};
59+
return new BasePackFetchConnection(this) {
60+
{
61+
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
62+
readAdvertisedRefs();
63+
}
64+
};
6665
}
6766

6867
@Override
@@ -73,15 +72,17 @@ public PushConnection openPush() throws NotSupportedException, TransportExceptio
7372
try {
7473
remoteRepository.actAsync(new GitPushTask(l2r, r2l));
7574
} catch (IOException e) {
76-
throw new TransportException("Failed to open a fetch connection",e);
75+
throw new TransportException("Failed to open a fetch connection", e);
7776
} catch (InterruptedException e) {
78-
throw new TransportException("Failed to open a fetch connection",e);
77+
throw new TransportException("Failed to open a fetch connection", e);
7978
}
8079

81-
return new BasePackPushConnection(this) {{
82-
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
83-
readAdvertisedRefs();
84-
}};
80+
return new BasePackPushConnection(this) {
81+
{
82+
init(new BufferedInputStream(r2l.getIn()), new BufferedOutputStream(l2r.getOut()));
83+
readAdvertisedRefs();
84+
}
85+
};
8586
}
8687

8788
@Override

src/main/java/org/jenkinsci/plugins/gitserver/FileBackedHttpGitRepository.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package org.jenkinsci.plugins.gitserver;
22

3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.io.PrintWriter;
6+
import java.io.StringWriter;
7+
import java.util.Collection;
8+
import java.util.logging.Level;
9+
import java.util.logging.Logger;
10+
import javax.servlet.http.HttpServletRequest;
311
import jenkins.model.Jenkins;
412
import org.acegisecurity.Authentication;
513
import org.eclipse.jgit.api.AddCommand;
@@ -18,15 +26,6 @@
1826
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
1927
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
2028

21-
import javax.servlet.http.HttpServletRequest;
22-
import java.io.File;
23-
import java.io.IOException;
24-
import java.io.PrintWriter;
25-
import java.io.StringWriter;
26-
import java.util.Collection;
27-
import java.util.logging.Level;
28-
import java.util.logging.Logger;
29-
3029
/**
3130
* Convenient subtype of {@link HttpGitRepository} where the repository
3231
* is non-bare, resides in a directory local to the controller, and you maintain
@@ -76,11 +75,11 @@ protected void createInitialRepository(Repository r) throws IOException {
7675
cmd.call();
7776

7877
CommitCommand co = git.commit();
79-
co.setAuthor("Jenkins","noreply@jenkins-ci.org");
78+
co.setAuthor("Jenkins", "noreply@jenkins-ci.org");
8079
co.setMessage("Initial import of the existing contents");
8180
co.call();
8281
} catch (GitAPIException e) {
83-
LOGGER.log(Level.WARNING, "Initial import of "+workspace+" into Git repository failed",e);
82+
LOGGER.log(Level.WARNING, "Initial import of " + workspace + " into Git repository failed", e);
8483
}
8584
}
8685

@@ -94,20 +93,22 @@ protected void createInitialRepository(Repository r) throws IOException {
9493
* where /foo/bar is rwx------ and /foo/bar/zot is rwxrwxrwx.)
9594
*/
9695
@Override
97-
public UploadPack createUploadPack(HttpServletRequest context, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
96+
public UploadPack createUploadPack(HttpServletRequest context, Repository db)
97+
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
9898
return new UploadPack(db);
9999
}
100100

101101
/**
102102
* Requires the admin access to be able to push
103103
*/
104104
@Override
105-
public ReceivePack createReceivePack(HttpServletRequest context, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
105+
public ReceivePack createReceivePack(HttpServletRequest context, Repository db)
106+
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
106107
Authentication a = Jenkins.getAuthentication();
107108

108109
ReceivePack rp = createReceivePack(db);
109110

110-
rp.setRefLogIdent(new PersonIdent(a.getName(), a.getName()+"@"+context.getRemoteAddr()));
111+
rp.setRefLogIdent(new PersonIdent(a.getName(), a.getName() + "@" + context.getRemoteAddr()));
111112

112113
return rp;
113114
}
@@ -125,7 +126,7 @@ public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
125126
} catch (Exception e) {
126127
StringWriter sw = new StringWriter();
127128
e.printStackTrace(new PrintWriter(sw));
128-
rp.sendMessage("Failed to update workspace: "+sw);
129+
rp.sendMessage("Failed to update workspace: " + sw);
129130
}
130131
}
131132
});

0 commit comments

Comments
 (0)