8000 Merge pull request #79 from jenkinsci/attempt-memory-fix · jpigree/github-oauth-plugin@87863d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87863d7

Browse files
authored
Merge pull request jenkinsci#79 from jenkinsci/attempt-memory-fix
Attempt memory fix
2 parents 3eeba9c + 14ab1fe commit 87863d7

File tree

6 files changed

+236
-72
lines changed

6 files changed

+236
-72
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@
112112
<version>1.7</version>
113113
</dependency>
114114

115+
<dependency>
116+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
117+
<artifactId>workflow-multibranch</artifactId>
118+
<version>2.9</version>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.jenkins-ci.plugins</groupId>
122+
<artifactId>github-branch-source</artifactId>
123+
<version>1.9</version>
124+
</dependency>
115125
<dependency>
116126
<groupId>org.jenkins-ci.plugins</groupId>
117127
<artifactId>git</artifactId>
@@ -137,6 +147,13 @@
137147
<version>4.12</version>
138148
<scope>test</scope>
139149
</dependency>
150+
<!-- This is to fix JENKINS-36875 when using hpi:run -->
151+
<dependency>
152+
<groupId>org.jenkins-ci.plugins</groupId>
153+
<artifactId>external-monitor-job</artifactId>
154+
<version>1.6</version>
155+
<scope>test</scope>
156+
</dependency>
140157
</dependencies>
141158

142159
<build>
@@ -157,6 +174,13 @@
157174
<additionalparam>${javadoc.opts}</additionalparam>
158175
</configuration>
159176
</plugin>
177+
<plugin>
178+
<groupId>org.apache.maven.plugins</groupId>
179+
<artifactId>maven-surefire-plugin</artifactId>
180+
<configuration>
181+
<argLine>-Xmx256m -XX:MaxPermSize=128m -Djava.awt.headless=true</argLine>
182+
</configuration>
183+
</plugin>
160184
</plugins>
161185

162186
<pluginManagement>

src/main/java/org/jenkinsci/plugins/GithubAuthenticationToken.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ of this software and associated documentation files (the "Software"), to deal
4343
import org.kohsuke.github.GitHubBuilder;
4444
import org.kohsuke.github.RateLimitHandler;
4545

46+
4647
import java.io.IOException;
4748
import java.util.ArrayList;
4849
import java.util.Collection;
@@ -57,6 +58,7 @@ of this software and associated documentation files (the "Software"), to deal
5758
import java.util.logging.Level;
5859
import java.util.logging.Logger;
5960

61+
6062
/**
6163
* @author mocleiri
6264
*

src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ of this software and associated documentation files (the "Software"), to deal
2727
package org.jenkinsci.plugins;
2828

2929
import com.google.common.collect.ImmutableList;
30+
31+
import org.apache.commons.lang.StringUtils;
32+
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
33+
import org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty;
34+
import org.kohsuke.stapler.DataBoundConstructor;
35+
36+
import java.util.Collection;
37+
38+
import javax.annotation.Nonnull;
39+
3040
import hudson.Extension;
41+
import hudson.model.AbstractItem;
3142
import hudson.model.AbstractProject;
3243
import hudson.model.Descriptor;
3344
import hudson.model.Job;
3445
import hudson.security.ACL;
3546
import hudson.security.AuthorizationStrategy;
36-
import org.apache.commons.lang.StringUtils;
37-
import org.kohsuke.stapler.DataBoundConstructor;
38-
39-
import javax.annotation.Nonnull;
40-
import java.util.Collection;
47+
import jenkins.branch.MultiBranchProject;
4148

4249
/**
4350
* @author mocleiri
@@ -83,12 +90,21 @@ public ACL getRootACL() {
8390
return rootACL;
8491
}
8592

93+
@Nonnull
94+
public ACL getACL(@Nonnull AbstractItem item) {
95+
F438 if(item instanceof MultiBranchProject) {
96+
GithubRequireOrganizationMembershipACL githubACL = (GithubRequireOrganizationMembershipACL) getRootACL();
97+
return githubACL.cloneForProject(item);
98+
} else {
99+
return getRootACL();
100+
}
101+
}
102+
86103
@Nonnull
87104
public ACL getACL(@Nonnull Job<?,?> job) {
88-
if(job instanceof AbstractProject) {
89-
AbstractProject project = (AbstractProject)job;
105+
if(job instanceof WorkflowJob && job.getProperty(BranchJobProperty.class) != null || job instanceof AbstractProject) {
90106
GithubRequireOrganizationMembershipACL githubACL = (GithubRequireOrganizationMembershipACL) getRootACL();
91-
return githubACL.cloneForProject(project);
107+
return githubACL.cloneForProject(job);
92108
} else {
93109
return getRootACL();
94110
}

src/main/java/org/jenkinsci/plugins/GithubOAuthGroupDetails.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
*/
44
package org.jenkinsci.plugins;
55

6-
import hudson.security.GroupDetails;
76
import org.kohsuke.github.GHOrganization;
87
import org.kohsuke.github.GHTeam;
98

9+
import hudson.security.GroupDetails;
10+
1011
/**
1112
* @author Mike
1213
*

src/main/java/org/jenkinsci/plugins/GithubRequireOrganizationMembershipACL.java

Lines changed: 64 additions & 40 deletions
< 10000 td data-grid-cell-id="diff-cc7ab75bded9621aa042633b3d55ab401e4141ae1ab84e22b3b1a00dac737148-27-27-1" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">27
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,32 @@ of this software and associated documentation files (the "Software"), to deal
2626
*/
27
package org.jenkinsci.plugins;
2828

29-
import hudson.model.AbstractProject;
30-
import hudson.model.Item;
31-
import hudson.plugins.git.GitSCM;
32-
import hudson.plugins.git.UserRemoteConfig;
33-
import hudson.scm.SCM;
34-
import hudson.security.ACL;
35-
import hudson.security.Permission;
36-
import jenkins.model.Jenkins;
3729
import org.acegisecurity.Authentication;
30+
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSource;
31+
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
32+
import org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty;
3833
import org.kohsuke.stapler.Stapler;
3934
import org.kohsuke.stapler.StaplerRequest;
4035

41-
import javax.annotation.Nonnull;
4236
import java.net.URI;
4337
import java.util.LinkedList;
4438
import java.util.List;
4539
import java.util.logging.Logger;
4640

41+
import javax.annotation.Nonnull;
42+
43+
import hudson.model.AbstractItem;
44+
import hudson.model.AbstractProject;
45+
import hudson.model.Describable;
46+
import hudson.model.Item;
47+
import hudson.plugins.git.GitSCM;
48+
import hudson.plugins.git.UserRemoteConfig;
49+
import hudson.security.ACL;
50+
import hudson.security.Permission;
51+
import jenkins.branch.MultiBranchProject;
52+
import jenkins.model.Jenkins;
53+
import jenkins.scm.api.SCMSource;
54+
4755
/**
4856
* @author Mike
4957
*
@@ -62,7 +70,7 @@ public class GithubRequireOrganizationMembershipACL extends ACL {
6270
private final boolean allowCcTrayPermission;
6371
private final boolean allowAnonymousReadPermission;
6472
private final boolean allowAnonymousJobStatusPermission;
65-
private final AbstractProject project;
73+
private final AbstractItem item;
6674

6775
/*
6876
* (non-Javadoc)
@@ -86,19 +94,19 @@ public boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission perm
8694
return true;
8795
}
8896

89-
if (this.project != null) {
97+
if (this.item != null) {
9098
if (useRepositoryPermissions) {
9199
if(hasRepositoryPermission(authenticationToken, permission)) {
92100
log.finest("Granting Authenticated User " + permission.getId() +
93-
" permission on project " + project.getName() +
101+
" permission on project " + item.getName() +
94102
"to user " + candidateName);
95103
return true;
96104
}
97105
} else {
98106
if (authenticatedUserReadPermission) {
99107
if (checkReadPermission(permission)) {
100108
log.finest("Granting Authenticated User read permission " +
101-
"on project " + project.getName() +
109+
"on project " + item.getName() +
102110
"to user " + candidateName);
103111
return true;
104112
}
@@ -270,18 +278,34 @@ public boolean hasRepositoryPermission(GithubAuthenticationToken authenticationT
270278

271279
private String getRepositoryName() {
272280
String repositoryName = null;
273-
SCM scm = this.project.getScm();
274-
if (scm instanceof GitSCM) {
275-
GitSCM git = (GitSCM)scm;
281+
String repoUrl = null;
282+
Describable scm = null;
283+
if (this.item instanceof WorkflowJob) {
284+
WorkflowJob project = (WorkflowJob) item;
285+
scm = project.getProperty(BranchJobProperty.class).getBranch().getScm();
286+
} else if (this.item instanceof MultiBranchProject) {
287+
MultiBranchProject project = (MultiBranchProject) item;
288+
scm = (SCMSource) project.getSCMSources().get(0);
289+
} else if (this.item instanceof AbstractProject) {
290+
AbstractProject project = (AbstractProject) item;
291+
scm = project.getScm();
292+
}
293+
if (scm instanceof GitHubSCMSource) {
294+
GitHubSCMSource git = (GitHubSCMSource) scm;
295+
repoUrl = git.getRemote();
296+
} else if (scm instanceof GitSCM) {
297+
GitSCM git = (GitSCM) scm;
276298
List<UserRemoteConfig> userRemoteConfigs = git.getUserRemoteConfigs();
277299
if (!userRemoteConfigs.isEmpty()) {
278-
String repoUrl = userRemoteConfigs.get(0).getUrl();
279-
if (repoUrl != null) {
280-
GitHubRepositoryName githubRepositoryName = GitHubRepositoryName.create(repoUrl);
281-
if (githubRepositoryName != null) {
282-
repositoryName = githubRepositoryName.userName + "/" + githubRepositoryName.repositoryName;
283-
}
284-
}
300+
repoUrl = userRemoteConfigs.get(0).getUrl();
301+
}
302+
}
303+
if (repoUrl != null) {
304+
GitHubRepositoryName githubRepositoryName =
305+
GitHubRepositoryName.create(repoUrl);
306+
if (githubRepositoryName != null) {
307+
repositoryName = githubRepositoryName.userName + "/"
308+
+ githubRepositoryName.repositoryName;
285309
}
286310
}
287311
return repositoryName;
@@ -321,7 +345,21 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
321345
organizationNameList.add(part.trim());
322346
}
323347

324-
this.project = null;
348+
this.item = null;
349+
}
350+
351+
public GithubRequireOrganizationMembershipACL cloneForProject(AbstractItem item) {
352+
return new GithubRequireOrganizationMembershipACL(
353+
this.adminUserNameList,
354+
this.organizationNameList,
355+
this.authenticatedUserReadPermission,
356+
this.useRepositoryPermissions,
357+
this.authenticatedUserCreateJobPermission,
358+
this.allowGithubWebHookPermission,
359+
this.allowCcTrayPermission,
360+
this.allowAnonymousReadPermission,
361+
this.allowAnonymousJobStatusPermission,
362+
item);
325363
}
326364

327365
public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
@@ -333,7 +371,7 @@ public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
333371
boolean allowCcTrayPermission,
334372
boolean allowAnonymousReadPermission,
335373
boolean allowAnonymousJobStatusPermission,
336-
AbstractProject project) {
374+
AbstractItem item) {
337375
super();
338376

339377
this.adminUserNameList = adminUserNameList;
@@ -345,21 +383,7 @@ public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
345383
this.allowCcTrayPermission = allowCcTrayPermission;
346384
this.allowAnonymousReadPermission = allowAnonymousReadPermission;
347385
this.allowAnonymousJobStatusPermission = allowAnonymousJobStatusPermission;
348-
this.project = project;
349-
}
350-
351-
public GithubRequireOrganizationMembershipACL cloneForProject(AbstractProject project) {
352-
return new GithubRequireOrganizationMembershipACL(
353-
this.adminUserNameList,
354-
this.organizationNameList,
355-
this.authenticatedUserReadPermission,
356-
this.useRepositoryPermissions,
357-
this.authenticatedUserCreateJobPermission,
358-
this.allowGithubWebHookPermission,
359-
this.allowCcTrayPermission,
360-
this.allowAnonymousReadPermission,
361-
this.allowAnonymousJobStatusPermission,
362-
project);
386+
this.item = item;
363387
}
364388

365389
public List<String> getOrganizationNameList() {

0 commit comments

Comments
 (0)
0