Skip to content

Commit cd6b1ee

Browse files
author
Raihaan Shouhell
committed
Cleanup some deprecated code and TODOs
1 parent b3fa986 commit cd6b1ee

19 files changed

+70
-76
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hudson.plugins.git;
22

33
import hudson.MarkupText;
4+
import hudson.Plugin;
45
import hudson.model.User;
56
import hudson.plugins.git.GitSCM.DescriptorImpl;
67
import hudson.scm.ChangeLogAnnotator;
@@ -18,6 +19,7 @@
1819
import java.text.ParseException;
1920
import java.text.SimpleDateFormat;
2021
import java.util.Collection;
22+
import java.util.Collections;
2123
import java.util.Date;
2224
import java.util.HashSet;
2325
import java.util.List;
@@ -411,13 +413,13 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
411413
// Avoid exception from User.get("", false)
412414
return User.getUnknown();
413415
}
414-
user = User.get(csAuthorEmail, false);
416+
user = User.get(csAuthorEmail, false, Collections.emptyMap());
415417

416418
if (user == null) {
417419
try {
418-
user = User.get(csAuthorEmail, !useExistingAccountWithSameEmail);
420+
user = User.get(csAuthorEmail, !useExistingAccountWithSameEmail, Collections.emptyMap());
419421
boolean setUserDetails = true;
420-
if (user == null && useExistingAccountWithSameEmail && hasHudsonTasksMailer()) {
422+
if (user == null && useExistingAccountWithSameEmail && hasMailerPlugin()) {
421423
for(User existingUser : User.getAll()) {
422424
if (csAuthorEmail.equalsIgnoreCase(getMail(existingUser))) {
423425
user = existingUser;
@@ -427,11 +429,11 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
427429
}
428430
}
429431
if (user == null) {
430-
user = User.get(csAuthorEmail, true);
432+
user = User.get(csAuthorEmail, true, Collections.emptyMap());
431433
}
432434
if (setUserDetails) {
433435
user.setFullName(csAuthor);
434-
if (hasHudsonTasksMailer())
436+
if (hasMailerPlugin())
435437
setMail(user, csAuthorEmail);
436438
user.save();
437439
}
@@ -444,7 +446,7 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
444446
// Avoid exception from User.get("", false)
445447
return User.getUnknown();
446448
}
447-
user = User.get(csAuthor, false);
449+
user = User.get(csAuthor, false, Collections.emptyMap());
448450

449451
if (user == null) {
450452
if (csAuthorEmail == null || csAuthorEmail.isEmpty()) {
@@ -454,14 +456,14 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
454456
// don't mess us up.
455457
String[] emailParts = csAuthorEmail.split("@");
456458
if (emailParts.length > 0) {
457-
user = User.get(emailParts[0], true);
459+
user = User.get(emailParts[0], true, Collections.emptyMap());
458460
} else {
459461
return User.getUnknown();
460462
}
461463
}
462464
}
463465
// set email address for user if none is already available
464-
if (fixEmpty(csAuthorEmail) != null && hasHudsonTasksMailer() && !hasMail(user)) {
466+
if (fixEmpty(csAuthorEmail) != null && hasMailerPlugin() && !hasMail(user)) {
465467
try {
466468
setMail(user, csAuthorEmail);
467469
} catch (IOException e) {
@@ -491,14 +493,12 @@ private boolean hasMail(User user) {
491493
return email != null;
492494
}
493495

494-
private boolean hasHudsonTasksMailer() {
495-
// TODO convert to checking for mailer plugin as plugin migrates to 1.509+
496-
try {
497-
Class.forName("hudson.tasks.Mailer");
498-
return true;
499-
} catch (ClassNotFoundException e) {
500-
return false;
496+
private boolean hasMailerPlugin() {
497+
Plugin p = Jenkins.get().getPlugin("mailer");
498+
if (p != null) {
499+
return p.getWrapper().isActive();
501500
}
501+
return false;
502502
}
503503

504504
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,13 +1310,11 @@ private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener l
13101310
}
13111311
}
13121312

1313-
// TODO: 2.60+ Delete this override.
1314-
@Override
13151313
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
13161314
buildEnvironment(build, env);
13171315
}
13181316

1319-
// TODO: 2.60+ Switch to @Override
1317+
@Override
13201318
public void buildEnvironment(Run<?, ?> build, java.util.Map<String, String> env) {
13211319
Revision rev = fixNull(getBuildData(build)).getLastBuiltRevision();
13221320
if (rev!=null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public final class TagWorkerThread extends TaskThread {
198198
private final String comment;
199199

200200
public TagWorkerThread(Map<String, String> tagSet,String comment) {
201-
super(GitTagAction.this, ListenerAndText.forMemory());
201+
super(GitTagAction.this, ListenerAndText.forMemory(null));
202202
this.tagSet = tagSet;
203203
this.comment = comment;
204204
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void createSubmoduleCombinations() throws GitException, IOException, Inte
108108
if (min == 1) break; // look no further
109109
}
110110

111-
git.checkout(sha1.name());
111+
git.checkout().ref(sha1.name());
112112
makeCombination(combination);
113113
}
114114

src/main/java/hudson/plugins/git/extensions/impl/PreBuildMerge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient g
9191

9292
// Track whether we're trying to add a duplicate BuildData, now that it's been updated with
9393
// revision info for this build etc. The default assumption is that it's a duplicate.
94-
BuildData buildData = scm.getBuildData(build, true);
94+
BuildData buildData = scm.copyBuildData(build);
9595
boolean buildDataAlreadyPresent = false;
9696
List<BuildData> actions = build.getActions(BuildData.class);
9797
for (BuildData d: actions) {

src/main/java/hudson/plugins/git/extensions/impl/PruneStaleBranch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public PruneStaleBranch() {
2828
@Override
2929
public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException {
3030
listener.getLogger().println("Pruning obsolete local branches");
31-
cmd.prune();
31+
cmd.prune(true);
3232
}
3333

3434
/**

src/main/java/jenkins/plugins/git/GitSCMFileSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
342342
headName = branchSpec.getName();
343343
}
344344
}
345-
client.fetch_().prune().from(remoteURI, Arrays
345+
client.fetch_().prune(true).from(remoteURI, Arrays
346346
.asList(new RefSpec(
347347
"+" + Constants.R_HEADS + headName + ":" + Constants.R_REMOTES + remoteName + "/"
348348
+ headName))).execute();
@@ -388,7 +388,7 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
388388
} catch (URISyntaxException ex) {
389389
listener.getLogger().println("URI syntax exception for '" + remoteName + "' " + ex);
390390
}
391-
client.fetch_().prune().from(remoteURI, builder.asRefSpecs()).execute();
391+
client.fetch_().prune(true).from(remoteURI, builder.asRefSpecs()).execute();
392392
listener.getLogger().println("Done.");
393393
return new GitSCMFileSystem(client, gitSCMSource.getRemote(), Constants.R_REMOTES+remoteName+"/"+head.getName(),
394394
(AbstractGitSCMSource.SCMRevisionImpl) rev);

src/main/java/jenkins/plugins/git/GitSCMSource.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
import jenkins.scm.impl.trait.Discovery;
9494
import jenkins.scm.impl.trait.Selection;
9595
import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
96-
import org.acegisecurity.context.SecurityContext;
97-
import org.acegisecurity.context.SecurityContextHolder;
9896
import org.apache.commons.lang.StringUtils;
9997
import org.eclipse.jgit.transport.RefSpec;
10098
import org.eclipse.jgit.transport.URIish;

src/test/java/hudson/plugins/git/CredentialsUserRemoteConfigTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void checkoutWithValidCredentials() throws Exception {
5757
+ " [$class: 'GitSCM', \n"
5858
+ " userRemoteConfigs: [[credentialsId: 'github', url: $/" + sampleRepo + "/$]]]\n"
5959
+ " )"
60-
+ "}"));
60+
+ "}", true));
6161
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
6262
r.assertLogContains("using credential github", b);
6363
}
@@ -76,7 +76,7 @@ public void checkoutWithDifferentCredentials() throws Exception {
7676
+ " [$class: 'GitSCM', \n"
7777
+ " userRemoteConfigs: [[credentialsId: 'github', url: $/" + sampleRepo + "/$]]]\n"
7878
+ " )"
79-
+ "}"));
79+
+ "}", true));
8080
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
8181
System.out.println(JenkinsRule.getLog(b));
8282
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
@@ -96,7 +96,7 @@ public void checkoutWithInvalidCredentials() throws Exception {
9696
+ " [$class: 'GitSCM', \n"
9797
+ " userRemoteConfigs: [[credentialsId: 'github', url: $/" + sampleRepo + "/$]]]\n"
9898
+ " )"
99-
+ "}"));
99+
+ "}", true));
100100
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
101101
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
102102
}
@@ -113,7 +113,7 @@ public void checkoutWithNoCredentialsStoredButUsed() throws Exception {
113113
+ " [$class: 'GitSCM', \n"
114114
+ " userRemoteConfigs: [[credentialsId: 'github', url: $/" + sampleRepo + "/$]]]\n"
115115
+ " )"
116-
+ "}"));
116+
+ "}", true));
117117
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
118118
System.out.println(JenkinsRule.getLog(b));
119119
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
@@ -131,7 +131,7 @@ public void checkoutWithNoCredentialsSpecified() throws Exception {
131131
+ " [$class: 'GitSCM', \n"
132132
+ " userRemoteConfigs: [[url: $/" + sampleRepo + "/$]]]\n"
133133
+ " )"
134-
+ "}"));
134+
+ "}", true));
135135
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
136136
System.out.println(JenkinsRule.getLog(b));
137137
r.assertLogContains("No credentials specified", b);

src/test/java/hudson/plugins/git/MultipleSCMTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ public class MultipleSCMTest {
5252
repo0.commit("repo0-init", repo0.johnDoe, "repo0 initial commit");
5353

5454
assertTrue("scm polling should detect a change after initial commit",
55-
project.pollSCMChanges(listener));
55+
project.poll(listener).hasChanges());
5656

5757
repo1.commit("repo1-init", repo1.janeDoe, "repo1 initial commit");
5858

5959
build(project, Result.SUCCESS);
6060

6161
assertFalse("scm polling should not detect any more changes after build",
62-
project.pollSCMChanges(listener));
62+
project.poll(listener).hasChanges());
6363

6464
repo1.commit("repo1-1", repo1.johnDoe, "repo1 commit 1");
6565

6666
build(project, Result.SUCCESS);
6767

6868
assertFalse("scm polling should not detect any more changes after build",
69-
project.pollSCMChanges(listener));
69+
project.poll(listener).hasChanges());
7070

7171
repo0.commit("repo0-1", repo0.janeDoe, "repo0 commit 1");
7272

7373
build(project, Result.SUCCESS);
7474

7575
assertFalse("scm polling should not detect any more changes after build",
76-
project.pollSCMChanges(listener));
76+
project.poll(listener).hasChanges());
7777
}
7878

7979
private FreeStyleProject setupBasicProject(String name) throws IOException
@@ -113,7 +113,7 @@ private FreeStyleProject setupBasicProject(String name) throws IOException
113113

114114
private FreeStyleBuild build(final FreeStyleProject project,
115115
final Result expectedResult) throws Exception {
116-
final FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserCause()).get();
116+
final FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserIdCause()).get();
117117
if(expectedResult != null) {
118118
r.assertBuildStatus(expectedResult, build);
119119
}

0 commit comments

Comments
 (0)