Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0cf4211

Browse filesBrowse files
committed
Merged GHLicense & GHLicenseBase
Elsewhere in this library, whenever there are multiple forms of the same object, we map that to the same class and use lazy data retrieval to fill missing fields.
1 parent 1de02a5 commit 0cf4211
Copy full SHA for 0cf4211

File tree

Expand file treeCollapse file tree

7 files changed

+123
-165
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+123
-165
lines changed
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* {@link GHContent} with license information.
5+
*
6+
* @author Kohsuke Kawaguchi
7+
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
8+
* @see GHRepository#getLicense()
9+
*/
10+
@Preview @Deprecated
11+
class GHContentWithLicense extends GHContent {
12+
GHLicense license;
13+
14+
@Override
15+
GHContentWithLicense wrap(GHRepository owner) {
16+
super.wrap(owner);
17+
return this;
18+
}
19+
}

‎src/main/java/org/kohsuke/github/GHLicense.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHLicense.java
+77-26Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,87 +24,138 @@
2424

2525
package org.kohsuke.github;
2626

27+
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
2728
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2829

30+
import java.io.IOException;
2931
import java.net.URL;
3032
import java.util.ArrayList;
3133
import java.util.List;
3234

3335
/**
3436
* The GitHub Preview API's license information
3537
* <p>
36-
* WARNING: This uses a PREVIEW API - you must use {@link org.kohsuke.github.extras.PreviewHttpConnector}
38+
* WARNING: This uses a PREVIEW API - subject to change.
3739
*
3840
* @author Duncan Dickinson
3941
* @see GitHub#getLicense(String)
40-
* @see GHRepository#getFullLicense()
42+
* @see GHRepository#getLicense()
4143
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
4244
*/
45+
@Preview @Deprecated
4346
@SuppressWarnings({"UnusedDeclaration"})
4447
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
4548
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
46-
public class GHLicense extends GHLicenseBase {
49+
public class GHLicense extends GHObject {
50+
/*package almost final*/ GitHub root;
51+
52+
// these fields are always present, even in the short form
53+
protected String key, name;
54+
55+
// the rest is only after populated
56+
protected Boolean featured;
4757

4858
protected String html_url, description, category, implementation, body;
4959

5060
protected List<String> required = new ArrayList<String>();
5161
protected List<String> permitted = new ArrayList<String>();
5262
protected List<String> forbidden = new ArrayList<String>();
5363

54-
public URL getHtmlUrl() {
64+
/**
65+
* @return a mnemonic for the license
66+
*/
67+
public String getKey() {
68+
return key;
69+
}
70+
71+
/**
72+
* @return the license name
73+
*/
74+
public String getName() {
75+
return name;
76+
}
77+
78+
/**
79+
* @return API URL of this object.
80+
*/
81+
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
82+
public URL getUrl() {
83+
return GitHub.parseURL(url);
84+
}
85+
86+
/**
87+
* Featured licenses are bold in the new repository drop-down
88+
*
89+
* @return True if the license is featured, false otherwise
90+
*/
91+
public Boolean isFeatured() throws IOException {
92+
populate();
93+
return featured;
94+
}
95+
96+
public URL getHtmlUrl() throws IOException {
97+
populate();
5598
return GitHub.parseURL(html_url);
5699
}
57100

58-
public String getDescription() {
101+
public String getDescription() throws IOException {
102+
populate();
59103
return description;
60104
}
61105

62-
public String getCategory() {
106+
public String getCategory() throws IOException {
107+
populate();
63108
return category;
64109
}
65110

66-
public String getImplementation() {
111+
public String getImplementation() throws IOException {
112+
populate();
67113
return implementation;
68114
}
69115

70-
public List<String> getRequired() {
116+
public List<String> getRequired() throws IOException {
117+
populate();
71118
return required;
72119
}
73120

74-
public List<String> getPermitted() {
121+
public List<String> getPermitted() throws IOException {
122+
populate();
75123
return permitted;
76124
}
77125

78-
public List<String> getForbidden() {
126+
public List<String> getForbidden() throws IOException {
127+
populate();
79128
return forbidden;
80129
}
81130

82-
public String getBody() {
131+
public String getBody() throws IOException {
132+
populate();
83133
return body;
84134
}
85135

86-
@Override
87-
public String toString() {
88-
return "GHLicense{" +
89-
"html_url='" + html_url + '\'' +
90-
", description='" + description + '\'' +
91-
", category='" + category + '\'' +
92-
", implementation='" + implementation + '\'' +
93-
", body='" + body + '\'' +
94-
", required=" + required +
95-
", permitted=" + permitted +
96-
", forbidden=" + forbidden +
97-
", htmlUrl=" + getHtmlUrl() +
98-
"} " + super.toString();
136+
/**
137+
* Fully populate the data by retrieving missing data.
138+
*
139+
* Depending on the original API call where this object is created, it may not contain everything.
140+
*/
141+
protected synchronized void populate() throws IOException {
142+
if (description!=null) return; // already populated
143+
144+
root.retrieve().to(url, this);
99145
}
100146

101147
@Override
102148
public boolean equals(Object o) {
103-
return super.equals(o);
149+
if (this == o) return true;
150+
if (!(o instanceof GHLicense)) return false;
151+
152+
GHLicense that = (GHLicense) o;
153+
return this.url.equals(that.url);
104154
}
105155

106156
@Override
107157
public int hashCode() {
108-
return super.hashCode();
158+
return url.hashCode();
109159
}
160+
110161
}

‎src/main/java/org/kohsuke/github/GHLicenseBase.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHLicenseBase.java
-107Lines changed: 0 additions & 107 deletions
This file was deleted.

‎src/main/java/org/kohsuke/github/GHObject.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHObject.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public URL getUrl() {
5151
* URL of this object for humans, which renders some HTML.
5252
*/
5353
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
54-
public abstract URL getHtmlUrl();
54+
public abstract URL getHtmlUrl() throws IOException;
5555

5656
/**
5757
* When was this resource last updated?

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+9-18Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public class GHRepository extends GHObject {
7070
*
7171
* See: https://developer.github.com/v3/licenses/
7272
*/
73-
/**
74-
* The basic license details as returned from {@link GitHub#getRepository(String)}
75-
*/
76-
private GHLicenseBase license;
73+
private GHLicense license;
7774

7875
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
7976
private GHUser owner; // not fully populated. beware.
@@ -849,6 +846,8 @@ protected void wrapUp(GHCommitComment[] page) {
849846
}
850847
};
851848
}
849+
850+
/**
852851
* Gets the basic license details for the repository.
853852
* <p>
854853
* This is a preview item and requires you to use {@link org.kohsuke.github.extras.PreviewHttpConnector}
@@ -858,20 +857,12 @@ protected void wrapUp(GHCommitComment[] page) {
858857
*
859858
* @throws IOException as usual but also if you don't use the preview connector
860859
*/
861-
public GHLicenseBase getLicense() {
862-
return license;
863-
}
864-
865-
/**
866-
* Access the full license details - makes an additional API call
867-
* <p>
868-
* This is a preview item and requires you to use {@link org.kohsuke.github.extras.PreviewHttpConnector}
869-
*
870-
* @return the license details
871-
* @throws IOException as usual but also if you don't use the preview connector
872-
*/
873-
public GHLicense getFullLicense() throws IOException {
874-
return root.getLicense(license.getKey());
860+
@Preview @Deprecated
861+
public GHLicense getLicense() throws IOException{
862+
return root.retrieve()
863+
.withHeader("Accept","application/vnd.github.drax-preview+json")
864+
.to(getApiTailUrl("license"), GHContentWithLicense.class)
865+
.wrap(this).license;
875866
}
876867

877868
/**

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,28 +340,32 @@ public GHRepository getRepository(String name) throws IOException {
340340
String[] tokens = name.split("/");
341341
return retrieve().to("/repos/" + tokens[0] + '/' + tokens[1], GHRepository.class).wrap(this);
342342
}
343+
/**
343344
* Returns a list of popular open source licenses
344345
*
345-
* WARNING: This uses a PREVIEW API - you must use {@link org.kohsuke.github.extras.PreviewHttpConnector}
346+
* WARNING: This uses a PREVIEW API.
346347
*
347348
* @see <a href="https://developer.github.com/v3/licenses/">GitHub API - Licenses</a>
348349
*
349350
* @return a list of popular open source licenses
350351
* @throws IOException if the HttpConnector doesn't pass in the preview header or other IO issue
351352
*/
352-
public List<GHLicenseBase> listLicenses() throws IOException {
353-
return Arrays.asList(retrieve().to("/licenses", GHLicenseBase[].class));
353+
@Preview @Deprecated
354+
public List<GHLicense> listLicenses() throws IOException {
355+
return Arrays.asList(retrieve().to("/licenses", GHLicense[].class));
354356
}
355357

356358
/**
357359
* Returns the full details for a license
358360
*
359-
* WARNING: This uses a PREVIEW API - you must use {@link org.kohsuke.github.extras.PreviewHttpConnector}
361+
* WARNING: This uses a PREVIEW API.
360362
*
361363
* @param key The license key provided from the API
362364
* @return The license details
363365
* @throws IOException
366+
* @see GHLicense#getKey()
364367
*/
368+
@Preview @Deprecated
365369
public GHLicense getLicense(String key) throws IOException {
366370
return retrieve().to("/licenses/" + key, GHLicense.class);
367371
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.