Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Cleanup and Refactoring #15

Merged
merged 10 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Fixed display of organization website ([PR-18](https://github.com/jenkinsci/gitea-plugin/pull/18))
* Fixed repository polling with disabled issues or pull requests ([PR-17](https://github.com/jenkinsci/gitea-plugin/pull/17))
([JENKINS-54516](https://issues.jenkins-ci.org/browse/JENKINS-54516))
* Optimized imports, less redundant code and other cleanups ([PR-15](https://github.com/jenkinsci/gitea-plugin/pull/15/files))

## Version 1.1.2 (2019-05-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,12 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.scm.SCM;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadEvent;
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceEvent;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugin.gitea.client.api.GiteaEvent;
import org.jenkinsci.plugin.gitea.servers.GiteaServer;
import org.jenkinsci.plugin.gitea.servers.GiteaServers;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class BranchDiscoveryTrait extends SCMSourceTrait {
/**
* The strategy encoded as a bit-field.
*/
private int strategyId;
private final int strategyId;

/**
* Constructor for stapler.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jenkinsci/plugin/gitea/GiteaAvatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.jenkinsci.plugin.gitea;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Objects;
import jenkins.scm.api.metadata.AvatarMetadataAction;
import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean equals(Object o) {

GiteaAvatar that = (GiteaAvatar) o;

return avatar != null ? avatar.equals(that.avatar) : that.avatar == null;
return Objects.equals(avatar, that.avatar);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jenkinsci/plugin/gitea/GiteaBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private URL diffLink(Path path) throws IOException {
.fragment(UriTemplateBuilder.var("diff"))
.build()
.set("changeSet", path.getChangeSet().getId())
.set("diff", "diff-" + Integer.toString(getIndexOfPath(path) + 1))
.set("diff", "diff-" + (getIndexOfPath(path) + 1))
.expand()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
import hudson.plugins.git.GitStatus;
import hudson.plugins.git.extensions.impl.IgnoreNotifyCommit;
import hudson.scm.SCM;
import hudson.triggers.SCMTrigger;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Level;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadEvent;
import jenkins.scm.api.SCMNavigator;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/jenkinsci/plugin/gitea/GiteaSCMSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.plugin.gitea.client.api.*;
import org.jenkinsci.plugin.gitea.client.api.Gitea;
import org.jenkinsci.plugin.gitea.client.api.GiteaAuth;
import org.jenkinsci.plugin.gitea.client.api.GiteaBranch;
import org.jenkinsci.plugin.gitea.client.api.GiteaConnection;
import org.jenkinsci.plugin.gitea.client.api.GiteaIssueState;
import org.jenkinsci.plugin.gitea.client.api.GiteaOwner;
import org.jenkinsci.plugin.gitea.client.api.GiteaPullRequest;
import org.jenkinsci.plugin.gitea.client.api.GiteaRepository;
import org.jenkinsci.plugin.gitea.client.api.GiteaUser;
import org.jenkinsci.plugin.gitea.servers.GiteaServer;
import org.jenkinsci.plugin.gitea.servers.GiteaServers;
import org.kohsuke.stapler.AncestorInPath;
Expand Down Expand Up @@ -830,7 +838,7 @@ public List<NamedArrayList<? extends SCMTraitDescriptor<?>>> getTraitsDescriptor
}

public List<SCMSourceTrait> getTraitsDefaults() {
return Arrays.<SCMSourceTrait>asList( // TODO finalize
return Arrays.asList( // TODO finalize
new BranchDiscoveryTrait(true, false),
new OriginPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE)),
new ForkPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class GiteaSCMSourceContext
private boolean wantOriginPRs;
private boolean wantForkPRs;
@NonNull
private Set<ChangeRequestCheckoutStrategy> originPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
private final Set<ChangeRequestCheckoutStrategy> originPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
@NonNull
private Set<ChangeRequestCheckoutStrategy> forkPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
private final Set<ChangeRequestCheckoutStrategy> forkPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
@NonNull
private WebhookRegistration webhookRegistration = WebhookRegistration.SYSTEM;
private boolean notificationsDisabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

@Extension
public class GiteaWebhookAction extends CrumbExclusion implements UnprotectedRootAction {
private Logger LOGGER = Logger.getLogger(GiteaWebhookAction.class.getName());
private final Logger LOGGER = Logger.getLogger(GiteaWebhookAction.class.getName());

@Override
public String getIconFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,22 @@
import hudson.model.Item;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.GitStatus;
import hudson.plugins.git.extensions.impl.IgnoreNotifyCommit;
import hudson.scm.SCM;
import hudson.triggers.SCMTrigger;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.authentication.tokens.api.AuthenticationTokens;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.scm.api.SCM2;
import jenkins.scm.api.SCMNavigatorOwner;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.triggers.SCMTriggerItem;
Expand Down Expand Up @@ -80,8 +75,6 @@ public static void register(SCMNavigatorOwner owner, GiteaSCMNavigator navigator
StandardCredentials credentials;
String serverUrl = navigator.getServerUrl();
switch (mode) {
case DISABLE:
return;
case SYSTEM:
GiteaServer server = GiteaServers.get().findServer(serverUrl);
if (server == null || !server.isManageHooks()) {
Expand All @@ -92,6 +85,7 @@ public static void register(SCMNavigatorOwner owner, GiteaSCMNavigator navigator
case ITEM:
credentials = navigator.credentials(owner);
break;
case DISABLE:
default:
return;
}
Expand Down Expand Up @@ -161,8 +155,6 @@ public static void register(SCMSourceOwner owner, GiteaSCMSource source,
StandardCredentials credentials;
String serverUrl = source.getServerUrl();
switch (mode) {
case DISABLE:
return;
case SYSTEM:
GiteaServer server = GiteaServers.get().findServer(serverUrl);
if (server == null || !server.isManageHooks()) {
Expand All @@ -173,6 +165,7 @@ public static void register(SCMSourceOwner owner, GiteaSCMSource source,
case ITEM:
credentials = source.credentials();
break;
case DISABLE:
default:
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class OriginPullRequestDiscoveryTrait extends SCMSourceTrait {
/**
* The strategy encoded as a bit-field.
*/
private int strategyId;
private final int strategyId;

/**
* Constructor for stapler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class PullRequestSCMRevision extends ChangeRequestSCMRevision<PullRequestSCMHead> {

private BranchSCMRevision origin;
private final BranchSCMRevision origin;

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void setBody(String body) {
}

public List<GiteaLabel> getLabels() {
return labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<GiteaLabel>(labels);
return labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<>(labels);
}

public void setLabels(List<GiteaLabel> labels) {
this.labels = labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<GiteaLabel>(labels);
this.labels = labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<>(labels);
}

public GiteaMilestone getMilestone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setClosedAt(Date closedAt) {
}

public Date getDueOn() {
return dueOn == null ? dueOn : (Date) dueOn.clone();
return dueOn == null ? null : (Date) dueOn.clone();
}

@JsonProperty("due_on")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public void setBody(String body) {
}

public List<GiteaLabel> getLabels() {
return labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<GiteaLabel>(labels);
return labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<>(labels);
}

public void setLabels(List<GiteaLabel> labels) {
this.labels = labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<GiteaLabel>(labels);
this.labels = labels == null ? new ArrayList<GiteaLabel>() : new ArrayList<>(labels);
}

public GiteaMilestone getMilestone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.jenkinsci.plugin.gitea.client.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Gitea {@link GiteaEventType#REPOSITORY} event.
Expand Down
Loading