2525import org .json .simple .JSONObject ;
2626import org .json .simple .parser .JSONParser ;
2727import org .json .simple .parser .ParseException ;
28+ import org .telosys .tools .commons .PropertiesManager ;
29+ import org .telosys .tools .commons .cfg .TelosysToolsCfg ;
2830import org .telosys .tools .commons .http .Base64 ;
2931import org .telosys .tools .commons .http .HttpClient ;
3032import org .telosys .tools .commons .http .HttpResponse ;
3739 */
3840public class GitHubClient {
3941
40- public static final String VERSION = "2.1" ; // GitHub Client Version (for checking in CLI and Download)
42+ // public static final String VERSION = "2.1" ; // GitHub Client Version (for checking in CLI and Download)
43+ public static final String VERSION = "3 (2024-01-05)" ; // GitHub Client Version (for checking in CLI and Download)
4144
4245 public static final String GIT_HUB_HOST_URL = "https://api.github.com" ;
4346
4447 public static final String GIT_HUB_REPO_URL_PATTERN = "https://github.com/${USER}/${REPO}/archive/master.zip" ;
4548
4649
47- private final Properties proxyProperties ;
50+ // private final Properties proxyProperties ;
51+ private final String propertiesFileAbsolutePath ;
4852
49- /**
50- * Constructor
51- * @param proxyProperties
52- */
53- public GitHubClient (Properties proxyProperties ) {
53+ // /**
54+ // * Constructor
55+ // * @param proxyProperties
56+ // */
57+ // public GitHubClient(Properties proxyProperties) {
58+ // super();
59+ // this.proxyProperties = proxyProperties;
60+ // }
61+ public GitHubClient (String propertiesFileAbsolutePath ) {
5462 super ();
55- this .proxyProperties = proxyProperties ;
63+ if ( propertiesFileAbsolutePath == null ) {
64+ throw new IllegalArgumentException ("File path argument is mandatory" );
65+ }
66+ this .propertiesFileAbsolutePath = propertiesFileAbsolutePath ;
67+ }
68+
69+ private HttpClient buildHttpClient () {
70+ // TODO : load properties
71+ PropertiesManager propertiesManager = new PropertiesManager (propertiesFileAbsolutePath ) ;
72+ Properties properties = propertiesManager .load (); // Ret NULL if file not found
73+ if ( properties != null ) {
74+ return new HttpClient (properties );
75+ }
76+ else {
77+ // Properties file not found, no properties loaded : use default values
78+ return new HttpClient ();
79+ }
80+
5681 }
5782
5883 private Map <String , String > buildRequestHeaders () {
@@ -71,7 +96,8 @@ private Map<String, String> buildRequestHeaders() {
7196 }
7297
7398 private HttpResponse httpGet ( String url ) throws Exception {
74- HttpClient httpClient = new HttpClient (proxyProperties );
99+ // HttpClient httpClient = new HttpClient(proxyProperties);
100+ HttpClient httpClient = buildHttpClient ();
75101 HttpResponse response ;
76102 try {
77103 // Sometimes GitHub return a 403 status code
@@ -206,7 +232,9 @@ public final long downloadRepository(String userName, String repoName, String de
206232 String url = GitHubUtil .buildGitHubURL (userName , repoName , GIT_HUB_REPO_URL_PATTERN );
207233
208234 long bytesCount = 0 ;
209- HttpClient httpClient = new HttpClient (proxyProperties );
235+ // HttpClient httpClient = new HttpClient(proxyProperties);
236+ HttpClient httpClient = buildHttpClient ();
237+
210238 bytesCount = httpClient .downloadFile (url , destinationFile );
211239 return bytesCount ;
212240 }
0 commit comments