Merge pull request #1004 from bitwiseman/object-base

Make root field transient in all classes
This commit is contained in:
Liam Newman
2020-12-28 16:05:48 -08:00
committed by GitHub
62 changed files with 139 additions and 163 deletions

View File

@@ -38,7 +38,7 @@ import javax.annotation.Nonnull;
* Intermediate return type for this builder returned by calls to {@link #with(String, Object)}. If {@link S}
* the same as {@link R}, this builder will commit changes after each call to {@link #with(String, Object)}.
*/
abstract class AbstractBuilder<R, S> {
abstract class AbstractBuilder<R, S> extends GitHubInteractiveObject {
@Nonnull
private final Class<R> returnType;
@@ -75,6 +75,7 @@ abstract class AbstractBuilder<R, S> {
@Nonnull Class<S> intermediateReturnType,
@Nonnull GitHub root,
@CheckForNull R baseInstance) {
super(root);
this.requester = root.createRequest();
this.returnType = finalReturnType;
this.commitChangesImmediately = returnType.equals(intermediateReturnType);

View File

@@ -15,7 +15,6 @@ import static org.kohsuke.github.Previews.MACHINE_MAN;
*/
public class GHApp extends GHObject {
private GitHub root;
private GHUser owner;
private String name;
private String description;

View File

@@ -14,8 +14,7 @@ import static org.kohsuke.github.Previews.MACHINE_MAN;
* @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map)
* @see GHAppInstallation#createToken() GHAppInstallation#createToken()
*/
public class GHAppCreateTokenBuilder {
private final GitHub root;
public class GHAppCreateTokenBuilder extends GitHubInteractiveObject {
protected final Requester builder;
private final String apiUrlTail;

View File

@@ -22,7 +22,6 @@ import static org.kohsuke.github.Previews.MACHINE_MAN;
* @see GHApp#getInstallationByUser(String) GHApp#getInstallationByUser(String)
*/
public class GHAppInstallation extends GHObject {
private GitHub root;
private GHUser account;
@JsonProperty("access_tokens_url")

View File

@@ -14,9 +14,7 @@ import java.util.Map;
* @author Paulo Miguel Almeida
* @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map)
*/
public class GHAppInstallationToken {
private GitHub root;
public class GHAppInstallationToken extends GitHubInteractiveObject {
private String token;
protected String expires_at;
private Map<String, String> permissions;

View File

@@ -9,7 +9,6 @@ import java.net.URL;
* @see GHRelease#getAssets() GHRelease#getAssets()
*/
public class GHAsset extends GHObject {
GitHub root;
GHRepository owner;
private String name;
private String label;

View File

@@ -33,7 +33,6 @@ public class GHAuthorization extends GHObject {
public static final String WRITE_KEY = "write:public_key";
public static final String ADMIN_KEY = "admin:public_key";
private GitHub root;
private List<String> scopes;
private String token;
private String token_last_eight;

View File

@@ -20,8 +20,7 @@ import javax.annotation.CheckForNull;
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
"URF_UNREAD_FIELD" },
justification = "JSON API")
public class GHBranch {
private GitHub root;
public class GHBranch extends GitHubInteractiveObject {
private GHRepository owner;
private String name;

View File

@@ -17,14 +17,12 @@ import static org.kohsuke.github.Previews.ZZZAX;
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
"URF_UNREAD_FIELD" },
justification = "JSON API")
public class GHBranchProtection {
public class GHBranchProtection extends GitHubInteractiveObject {
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
@JsonProperty
private EnforceAdmins enforceAdmins;
private GitHub root;
@JsonProperty("required_pull_request_reviews")
private RequiredReviews requiredReviews;

View File

@@ -22,7 +22,6 @@ public class GHCheckRun extends GHObject {
@JsonProperty("repository")
GHRepository owner;
GitHub root;
private String status;
private String conclusion;

View File

@@ -8,7 +8,7 @@ import javax.annotation.Nonnull;
* Iterable for check-runs listing.
*/
class GHCheckRunsIterable extends PagedIterable<GHCheckRun> {
private GitHub root;
private final transient GitHub root;
private final GitHubRequest request;
private GHCheckRunsPage result;

View File

@@ -21,7 +21,6 @@ public class GHCheckSuite extends GHObject {
@JsonProperty("repository")
GHRepository owner;
GitHub root;
private String nodeId;
private String headBranch;

View File

@@ -18,8 +18,6 @@ public class GHCommitStatus extends GHObject {
String context;
GHUser creator;
private GitHub root;
GHCommitStatus wrapUp(GitHub root) {
if (creator != null)
creator.wrapUp(root);

View File

@@ -15,15 +15,13 @@ import java.util.Base64;
* @see GHRepository#getFileContent(String) GHRepository#getFileContent(String)
*/
@SuppressWarnings({ "UnusedDeclaration" })
public class GHContent implements Refreshable {
public class GHContent extends GitHubInteractiveObject implements Refreshable {
/*
* In normal use of this class, repository field is set via wrap(), but in the code search API, there's a nested
* 'repository' field that gets populated from JSON.
*/
private GHRepository repository;
private GitHub root;
private String type;
private String encoding;
private long size;

View File

@@ -10,8 +10,7 @@ import static org.kohsuke.github.Previews.BAPTISTE;
*
* @author Kohsuke Kawaguchi
*/
public class GHCreateRepositoryBuilder {
private final GitHub root;
public class GHCreateRepositoryBuilder extends GitHubInteractiveObject {
protected final Requester builder;
private String apiUrlTail;

View File

@@ -14,7 +14,6 @@ import java.util.Map;
*/
public class GHDeployment extends GHObject {
private GHRepository owner;
private GitHub root;
protected String sha;
protected String ref;
protected String task;

View File

@@ -8,7 +8,6 @@ import java.util.Locale;
*/
public class GHDeploymentStatus extends GHObject {
private GHRepository owner;
private GitHub root;
protected GHUser creator;
protected String state;
protected String description;

View File

@@ -1,6 +1,5 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.IOException;
@@ -18,8 +17,6 @@ import javax.annotation.Nonnull;
*/
public class GHDiscussion extends GHObject {
@JacksonInject
private GitHub root;
private GHTeam team;
private long number;
private String body, title, htmlUrl;

View File

@@ -12,9 +12,7 @@ import java.util.Date;
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
public class GHEventInfo {
private GitHub root;
public class GHEventInfo extends GitHubInteractiveObject {
// we don't want to expose Jackson dependency to the user. This needs databinding
private ObjectNode payload;

View File

@@ -17,9 +17,7 @@ import java.util.List;
*/
@SuppressWarnings("UnusedDeclaration")
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
public class GHEventPayload {
protected GitHub root;
public class GHEventPayload extends GitHubInteractiveObject {
// https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-object-common-properties
// Webhook payload object common properties: action, sender, repository, organization, installation
private String action;

View File

@@ -23,7 +23,6 @@ import java.util.Map.Entry;
public class GHGist extends GHObject {
final GHUser owner;
final GitHub root;
private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url;

View File

@@ -13,7 +13,6 @@ import javax.annotation.Nonnull;
* @see GitHub#createGist() GitHub#createGist()
*/
public class GHGistBuilder {
private final GitHub root;
private final Requester req;
private final LinkedHashMap<String, Object> files = new LinkedHashMap<String, Object>();
@@ -24,7 +23,6 @@ public class GHGistBuilder {
* the root
*/
public GHGistBuilder(GitHub root) {
this.root = root;
req = root.createRequest().method("POST");
}

View File

@@ -12,8 +12,7 @@ import java.util.Map;
* functionality
*/
class GHHooks {
static abstract class Context {
private final GitHub root;
static abstract class Context extends GitHubInteractiveObject {
private Context(GitHub root) {
this.root = root;

View File

@@ -16,7 +16,6 @@ import java.net.URL;
"UUF_UNUSED_FIELD" },
justification = "JSON API")
public class GHInvitation extends GHObject {
/* package almost final */ GitHub root;
private int id;
private GHRepository repository;

View File

@@ -53,7 +53,6 @@ import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
public class GHIssue extends GHObject implements Reactable {
private static final String ASSIGNEES = "assignees";
GitHub root;
GHRepository owner;
// API v3

View File

@@ -9,9 +9,7 @@ import java.util.Date;
*
* @author Martin van Zijl
*/
public class GHIssueEvent {
private GitHub root;
public class GHIssueEvent extends GitHubInteractiveObject {
private long id;
private String node_id;
private String url;

View File

@@ -9,9 +9,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
public class GHKey {
/* package almost final */ GitHub root;
public class GHKey extends GitHubInteractiveObject {
protected String url, key, title;
protected boolean verified;
protected int id;

View File

@@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
* @see GHIssue#getLabels() GHIssue#getLabels()
* @see GHRepository#listLabels() GHRepository#listLabels()
*/
public class GHLabel {
public class GHLabel extends GitHubInteractiveObject {
@Nonnull
private String url, name, color;
@@ -28,9 +28,6 @@ public class GHLabel {
@CheckForNull
private String description;
@Nonnull
private final GitHub root;
@JsonCreator
private GHLabel(@JacksonInject @Nonnull GitHub root) {
this.root = root;

View File

@@ -44,9 +44,6 @@ import java.util.Objects;
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHLicense extends GHObject {
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
// root is set before the object is returned to the app
/* package almost final */ GitHub root;
// these fields are always present, even in the short form
protected String key, name;

View File

@@ -9,9 +9,7 @@ import java.net.URL;
* @see GitHub#getMyMarketplacePurchases()
* @see GHMarketplaceListAccountBuilder#createRequest()
*/
public class GHMarketplaceAccount {
protected GitHub root;
public class GHMarketplaceAccount extends GitHubInteractiveObject {
private String url;
private long id;
private String login;

View File

@@ -8,8 +8,7 @@ import java.io.IOException;
* @author Paulo Miguel Almeida
* @see GHMarketplacePlan#listAccounts()
*/
public class GHMarketplaceListAccountBuilder {
private final GitHub root;
public class GHMarketplaceListAccountBuilder extends GitHubInteractiveObject {
private final Requester builder;
private final long planId;

View File

@@ -10,8 +10,7 @@ import java.util.Date;
* @author Paulo Miguel Almeida
* @see GHMarketplaceListAccountBuilder#createRequest()
*/
public class GHMarketplacePendingChange {
private GitHub root;
public class GHMarketplacePendingChange extends GitHubInteractiveObject {
private long id;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
private Long unitCount;

View File

@@ -11,9 +11,7 @@ import java.util.List;
* @author Paulo Miguel Almeida
* @see GitHub#listMarketplacePlans()
*/
public class GHMarketplacePlan {
private GitHub root;
public class GHMarketplacePlan extends GitHubInteractiveObject {
private String url;
private String accountsUrl;
private long id;

View File

@@ -10,9 +10,8 @@ import java.util.Date;
* @author Paulo Miguel Almeida
* @see GHMarketplaceListAccountBuilder#createRequest() GHMarketplaceListAccountBuilder#createRequest()
*/
public class GHMarketplacePurchase {
public class GHMarketplacePurchase extends GitHubInteractiveObject {
private GitHub root;
private String billingCycle;
private String nextBillingDate;
private boolean onFreeTrial;

View File

@@ -10,8 +10,7 @@ import java.util.Date;
* @author Paulo Miguel Almeida
* @see GitHub#getMyMarketplacePurchases()
*/
public class GHMarketplaceUserPurchase {
protected GitHub root;
public class GHMarketplaceUserPurchase extends GitHubInteractiveObject {
private String billingCycle;
private String nextBillingDate;
private boolean onFreeTrial;

View File

@@ -10,9 +10,7 @@ import java.util.Locale;
* @author Kohsuke Kawaguchi
* @see GHMyself#listOrgMemberships() GHMyself#listOrgMemberships()
*/
public class GHMembership /* extends GHObject --- but it doesn't have id, created_at, etc. */ {
GitHub root;
public class GHMembership extends GitHubInteractiveObject {
String url;
String state;
String role;

View File

@@ -11,7 +11,6 @@ import java.util.Locale;
* @author Yusuke Kokubo
*/
public class GHMilestone extends GHObject {
GitHub root;
GHRepository owner;
GHUser creator;

View File

@@ -23,9 +23,7 @@ import java.util.NoSuchElementException;
* @see GitHub#listNotifications() GitHub#listNotifications()
* @see GHRepository#listNotifications() GHRepository#listNotifications()
*/
public class GHNotificationStream implements Iterable<GHThread> {
private final GitHub root;
public class GHNotificationStream extends GitHubInteractiveObject implements Iterable<GHThread> {
private Boolean all, participating;
private String since;
private String apiUrl;

View File

@@ -20,7 +20,7 @@ import javax.annotation.CheckForNull;
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public abstract class GHObject {
public abstract class GHObject extends GitHubInteractiveObject {
/**
* Capture response HTTP headers on the state object.
*/

View File

@@ -18,7 +18,6 @@ import java.util.TreeMap;
* @author Kohsuke Kawaguchi
*/
public abstract class GHPerson extends GHObject {
/* package almost final */ GitHub root;
// core data fields that exist even for "small" user data (such as the user info in pull request)
protected String login, avatar_url;

View File

@@ -37,7 +37,6 @@ import static org.kohsuke.github.Previews.INERTIA;
* @see <a href="https://developer.github.com/v3/projects/">Projects</a>
*/
public class GHProject extends GHObject {
protected GitHub root;
protected GHObject owner;
private String owner_url;

View File

@@ -14,7 +14,6 @@ import static org.kohsuke.github.Previews.INERTIA;
* @author Gunnar Skjold
*/
public class GHProjectCard extends GHObject {
private GitHub root;
private GHProject project;
private GHProjectColumn column;

View File

@@ -12,7 +12,6 @@ import static org.kohsuke.github.Previews.INERTIA;
* @author Gunnar Skjold
*/
public class GHProjectColumn extends GHObject {
protected GitHub root;
protected GHProject project;
private String name;

View File

@@ -7,8 +7,7 @@ package org.kohsuke.github;
* the type parameter
* @author Kohsuke Kawaguchi
*/
public abstract class GHQueryBuilder<T> {
protected final GitHub root;
public abstract class GHQueryBuilder<T> extends GitHubInteractiveObject {
protected final Requester req;
GHQueryBuilder(GitHub root) {

View File

@@ -14,7 +14,6 @@ import static org.kohsuke.github.Previews.*;
@Preview(SQUIRREL_GIRL)
@Deprecated
public class GHReaction extends GHObject {
private GitHub root;
private GHUser user;
private ReactionContent content;

View File

@@ -11,9 +11,7 @@ import java.net.URL;
*
* @author Michael Clarke
*/
public class GHRef {
/* package almost final */ GitHub root;
public class GHRef extends GitHubInteractiveObject {
private String ref, url;
private GHObject object;

View File

@@ -19,7 +19,6 @@ import static java.lang.String.*;
* @see GHRepository#createRelease(String) GHRepository#createRelease(String)
*/
public class GHRelease extends GHObject {
GitHub root;
GHRepository owner;
private String html_url;

View File

@@ -66,7 +66,6 @@ import static org.kohsuke.github.Previews.*;
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHRepository extends GHObject {
/* package almost final */ transient GitHub root;
private String nodeId, description, homepage, name, full_name;
@@ -2202,7 +2201,12 @@ public class GHRepository extends GHObject {
justification = "It causes a performance degradation, but we have already exposed it to the API")
@Deprecated
public Set<URL> getPostCommitHooks() {
return postCommitHooks;
synchronized (this) {
if (postCommitHooks == null) {
postCommitHooks = setupPostCommitHooks();
}
return postCommitHooks;
}
}
/**
@@ -2211,57 +2215,63 @@ public class GHRepository extends GHObject {
@SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS",
justification = "It causes a performance degradation, but we have already exposed it to the API")
@SkipFromToString
private final Set<URL> postCommitHooks = new AbstractSet<URL>() {
private List<URL> getPostCommitHooks() {
try {
List<URL> r = new ArrayList<>();
for (GHHook h : getHooks()) {
if (h.getName().equals("web")) {
r.add(new URL(h.getConfig().get("url")));
private /* final */ transient Set<URL> postCommitHooks;
@SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS",
justification = "It causes a performance degradation, but we have already exposed it to the API")
private Set<URL> setupPostCommitHooks() {
return new AbstractSet<URL>() {
private List<URL> getPostCommitHooks() {
try {
List<URL> r = new ArrayList<>();
for (GHHook h : getHooks()) {
if (h.getName().equals("web")) {
r.add(new URL(h.getConfig().get("url")));
}
}
return r;
} catch (IOException e) {
throw new GHException("Failed to retrieve post-commit hooks", e);
}
return r;
} catch (IOException e) {
throw new GHException("Failed to retrieve post-commit hooks", e);
}
}
@Override
public Iterator<URL> iterator() {
return getPostCommitHooks().iterator();
}
@Override
public int size() {
return getPostCommitHooks().size();
}
@Override
public boolean add(URL url) {
try {
createWebHook(url);
return true;
} catch (IOException e) {
throw new GHException("Failed to update post-commit hooks", e);
@Override
public Iterator<URL> iterator() {
return getPostCommitHooks().iterator();
}
}
@Override
public boolean remove(Object url) {
try {
String _url = ((URL) url).toExternalForm();
for (GHHook h : getHooks()) {
if (h.getName().equals("web") && h.getConfig().get("url").equals(_url)) {
h.delete();
return true;
@Override
public int size() {
return getPostCommitHooks().size();
}
@Override
public boolean add(URL url) {
try {
createWebHook(url);
return true;
} catch (IOException e) {
throw new GHException("Failed to update post-commit hooks", e);
}
}
@Override
public boolean remove(Object url) {
try {
String _url = ((URL) url).toExternalForm();
for (GHHook h : getHooks()) {
if (h.getName().equals("web") && h.getConfig().get("url").equals(_url)) {
h.delete();
return true;
}
}
return false;
} catch (IOException e) {
throw new GHException("Failed to update post-commit hooks", e);
}
return false;
} catch (IOException e) {
throw new GHException("Failed to update post-commit hooks", e);
}
}
};
};
}
GHRepository wrap(GitHub root) {
this.root = root;

View File

@@ -16,10 +16,9 @@ import java.util.NoSuchElementException;
*
* @author Martin van Zijl
*/
public class GHRepositoryStatistics {
public class GHRepositoryStatistics extends GitHubInteractiveObject {
private final GHRepository repo;
private final GitHub root;
private static final int MAX_WAIT_ITERATIONS = 3;
private static final int WAIT_SLEEP_INTERVAL = 5000;
@@ -99,7 +98,6 @@ public class GHRepositoryStatistics {
"URF_UNREAD_FIELD" },
justification = "JSON API")
public static class ContributorStats extends GHObject {
/* package almost final */ private GitHub root;
private GHUser author;
private int total;
private List<Week> weeks;
@@ -255,7 +253,6 @@ public class GHRepositoryStatistics {
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public static class CommitActivity extends GHObject {
/* package almost final */ private GitHub root;
private List<Integer> days;
private int total;
private long week;
@@ -398,7 +395,6 @@ public class GHRepositoryStatistics {
* The type Participation.
*/
public static class Participation extends GHObject {
/* package almost final */ private GitHub root;
private List<Integer> all;
private List<Integer> owner;

View File

@@ -8,7 +8,6 @@ import java.net.URL;
justification = "JSON API")
public class GHRequestedAction extends GHObject {
private GHRepository owner;
private GitHub root;
private String identifier;
private String label;
private String description;

View File

@@ -10,11 +10,10 @@ import java.util.Date;
* @see GHRepository#getSubscription() GHRepository#getSubscription()
* @see GHThread#getSubscription() GHThread#getSubscription()
*/
public class GHSubscription {
public class GHSubscription extends GitHubInteractiveObject {
private String created_at, url, repository_url, reason;
private boolean subscribed, ignored;
private GitHub root;
private GHRepository repo;
/**

View File

@@ -9,9 +9,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHTag {
public class GHTag extends GitHubInteractiveObject {
private GHRepository owner;
private GitHub root;
private String name;
private GHCommit commit;

View File

@@ -9,9 +9,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHTagObject {
public class GHTagObject extends GitHubInteractiveObject {
private GHRepository owner;
private GitHub root;
private String tag;
private String sha;

View File

@@ -24,8 +24,6 @@ public class GHTeam extends GHObject implements Refreshable {
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together
protected /* final */ GitHub root;
public enum Privacy {
SECRET, // only visible to organization owners and members of this team.
CLOSED // visible to all members of this organization.

View File

@@ -7,9 +7,7 @@ import java.io.IOException;
*
* https://developer.github.com/v3/teams/#create-team
*/
public class GHTeamBuilder {
private final GitHub root;
public class GHTeamBuilder extends GitHubInteractiveObject {
protected final Requester builder;
private final String orgName;

View File

@@ -17,7 +17,6 @@ import java.util.Date;
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHThread extends GHObject {
private GitHub root;
private GHRepository repository;
private Subject subject;
private String reason;

View File

@@ -1208,26 +1208,34 @@ public class GitHub {
}
/**
* Do not use this method. This method will be removed and should never have been needed in the first place.
* Gets an {@link ObjectWriter} that can be used to convert data objects in this library to JSON.
*
* If you must convert data object in this library to JSON, the {@link ObjectWriter} returned by this method is the
* only supported way of doing so. This {@link ObjectWriter} can be used to convert any library data object to JSON
* without throwing an exception.
*
* WARNING: While the JSON generated is generally expected to be stable, it is not part of the API of this library
* and may change without warning. Use with extreme caution.
*
* @return an {@link ObjectWriter} instance that can be further configured.
* @deprecated DO NOT USE THIS METHOD. Provided for backward compatibility with projects that did their own jackson
* mapping of this project's data objects, such as Jenkins Blue Ocean.
*/
@Deprecated
@Nonnull
public static ObjectWriter getMappingObjectWriter() {
return GitHubClient.getMappingObjectWriter();
}
/**
* Do not use this method. This method will be removed and should never have been needed in the first place.
* Gets an {@link ObjectReader} that can be used to convert JSON into library data objects.
*
* If you must manually create library data objects from JSON, the {@link ObjectReader} returned by this method is
* the only supported way of doing so.
*
* WARNING: Objects generated from this method have limited functionality. They will not throw when being crated
* from valid JSON matching the expected object, but they are not guaranteed to be usable beyond that. Use with
* extreme caution.
*
* @return an {@link ObjectReader} instance that can be further configured.
* @deprecated DO NOT USE THIS METHOD. Provided for backward compatibility with projects that did their own jackson
* mapping of this project's data objects, such as Jenkins Blue Ocean.
*/
@Deprecated
@Nonnull
public static ObjectReader getMappingObjectReader() {
return GitHubClient.getMappingObjectReader(GitHub.offline());

View File

@@ -0,0 +1,23 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JacksonInject;
/**
* Defines a base class that all classes in this library that interact with GitHub inherit from.
*
* Ensures that all data references to GitHub connection are transient.
*
* Classes that do not need to interact with GitHub after they are instantiated do not need to inherit from this class.
*/
abstract class GitHubInteractiveObject {
@JacksonInject
/* package almost final */ transient GitHub root;
GitHubInteractiveObject() {
root = null;
}
GitHubInteractiveObject(GitHub root) {
this.root = root;
}
}

View File

@@ -18,7 +18,7 @@ import javax.annotation.Nonnull;
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
justification = "Constructed by JSON API")
public class PagedSearchIterable<T> extends PagedIterable<T> {
private final GitHub root;
private final transient GitHub root;
private final GitHubRequest request;

View File

@@ -40,7 +40,7 @@ import javax.annotation.Nonnull;
* @author Kohsuke Kawaguchi
*/
class Requester extends GitHubRequest.Builder<Requester> {
/* private */ final GitHubClient client;
/* private */ final transient GitHubClient client;
Requester(GitHubClient client) {
this.client = client;

View File

@@ -220,6 +220,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.getIssues(GHIssueState.CLOSED);
// prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues
assertTrue(closedIssues.size() > 150);
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(closedIssues.get(0));
}
private GHRepository getTestRepository() throws IOException {

View File

@@ -226,15 +226,25 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
GHRepository repo = getTempRepository();
assertThat(repo.root, not(nullValue()));
assertThat(repo.getResponseHeaderFields(), not(nullValue()));
String repoString = GitHub.getMappingObjectWriter().writeValueAsString(repo);
assertThat(repoString, not(nullValue()));
assertThat(repoString, containsString("testMappingReaderWriter"));
GHRepository readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);
GHRepository readRepo = GitHubClient.getMappingObjectReader((GitHubResponse.ResponseInfo) null)
.forType(GHRepository.class)
.readValue(repoString);
// This should never happen if these methods aren't used
// This should never happen if the internal method isn't used
assertThat(readRepo.root, nullValue());
assertThat(readRepo.getResponseHeaderFields(), nullValue());
readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);
// This should never happen if the internal method isn't used
assertThat(readRepo.root.getConnector(), equalTo(HttpConnector.OFFLINE));
assertThat(readRepo.getResponseHeaderFields(), nullValue());
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(readRepo);
assertThat(readRepoString, equalTo(repoString));