├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── api └── src │ └── main │ └── java │ └── com │ └── jfrog │ └── bintray │ └── client │ └── api │ ├── BintrayCallException.java │ ├── BintrayClientConstatnts.java │ ├── MultipleBintrayCallException.java │ ├── ObjectMapperHelper.java │ ├── details │ ├── Attribute.java │ ├── PackageDetails.java │ ├── ProductDetails.java │ ├── RepositoryDetails.java │ ├── SubjectDetails.java │ └── VersionDetails.java │ ├── handle │ ├── AttributesSearchQuery.java │ ├── AttributesSearchQueryClause.java │ ├── Bintray.java │ ├── Handle.java │ ├── PackageHandle.java │ ├── ProductHandle.java │ ├── RepositoryHandle.java │ ├── SubjectHandle.java │ └── VersionHandle.java │ └── model │ ├── Pkg.java │ ├── Product.java │ ├── Repository.java │ ├── Subject.java │ └── Version.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── impl └── src │ ├── main │ └── java │ │ └── com │ │ └── jfrog │ │ └── bintray │ │ └── client │ │ └── impl │ │ ├── BintrayClient.java │ │ ├── HttpClientConfigurator.java │ │ ├── handle │ │ ├── AttributesSearchQueryClauseImpl.java │ │ ├── AttributesSearchQueryImpl.java │ │ ├── BintrayImpl.java │ │ ├── PackageHandleImpl.java │ │ ├── ProductHandleImpl.java │ │ ├── RepositoryHandleImpl.java │ │ ├── SubjectHandleImpl.java │ │ └── VersionHandleImpl.java │ │ ├── model │ │ ├── PackageImpl.java │ │ ├── ProductImpl.java │ │ ├── RepositoryImpl.java │ │ ├── SubjectImpl.java │ │ └── VersionImpl.java │ │ └── util │ │ ├── URI.java │ │ └── URIUtil.java │ └── test │ ├── groovy │ └── com │ │ └── jfrog │ │ └── bintray │ │ └── client │ │ └── test │ │ ├── BintraySpecSuite.groovy │ │ └── spec │ │ ├── BintrayClientSpec.groovy │ │ ├── PackageSpec.groovy │ │ ├── ProductSpec.groovy │ │ ├── RepoSpec.groovy │ │ ├── SpecialArtifactUploadSpec.groovy │ │ └── VersionSpec.groovy │ └── resources │ ├── planckdb_amd64.deb │ ├── simplelog.properties │ ├── testJar1.jar │ ├── testJar2.jar │ └── trusty64.box └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | impl\src\test\resources\bintray-client.properties 2 | Recursive 3 | target 4 | build 5 | *.iml 6 | *.ipr 7 | *.iws 8 | cobertura.ser 9 | DS_Store 10 | .gradle 11 | .vagrant 12 | BINTRAY_HOME 13 | out 14 | atlassian-*.xml 15 | .idea/ 16 | .project 17 | .classpath 18 | .settings -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # JFrog welcomes community contribution! 2 | 3 | Before we can accept your contribution, process your GitHub pull requests, and thank you full heartedly, we request that you will fill out and submit JFrog's Contributor License Agreement (CLA). 4 | 5 | [Click here](https://secure.echosign.com/public/hostedForm?formid=5IYKLZ2RXB543N) to submit the JFrog CLA. 6 | This should only take a minute to complete and is a one-time process. 7 | 8 | *Thanks for Your Contribution to the Community!* :-) 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bintray-client-java 2 | =================== 3 | Java client for working with Bintray.com 4 | 5 | [![Download From Bintray](https://www.bintray.com/docs/images/bintray_badge_color.png)](https://bintray.com/jfrog/bintray-tools/bintray-client-java?bdg=1) 6 | 7 | [![Build Status](https://drone.io/github.com/bintray/bintray-client-java/status.png)](https://drone.io/github.com/bintray/bintray-client-java/latest) 8 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/BintrayCallException.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | import org.apache.http.HttpResponse; 5 | import org.apache.http.HttpStatus; 6 | import org.apache.http.client.HttpResponseException; 7 | import org.codehaus.jackson.JsonNode; 8 | import org.codehaus.jackson.map.ObjectMapper; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * An exception thrown for failed operations against the Bintray api. 14 | * 15 | * @author danf 16 | */ 17 | public class BintrayCallException extends HttpResponseException { 18 | 19 | private int statusCode; 20 | private String reason; 21 | private String message; 22 | 23 | public BintrayCallException(int statusCode, String reason, String message) { 24 | super(statusCode, reason); 25 | this.statusCode = statusCode; 26 | this.reason = reason; 27 | this.message = message; 28 | } 29 | 30 | public BintrayCallException(HttpResponse response) { 31 | super(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); 32 | String message = " "; 33 | String entity = null; 34 | int statusCode = response.getStatusLine().getStatusCode(); 35 | if (response.getEntity() != null && statusCode != 405 && statusCode != 500) { 36 | try { 37 | entity = IOUtils.toString(response.getEntity().getContent()); 38 | ObjectMapper mapper = ObjectMapperHelper.get(); 39 | JsonNode node = mapper.readTree(entity); 40 | message = node.get("message").getTextValue(); 41 | } catch (IOException | NullPointerException e) { 42 | //Null entity? 43 | if (entity != null) { 44 | message = entity; 45 | } 46 | } 47 | } 48 | this.statusCode = statusCode; 49 | this.reason = response.getStatusLine().getReasonPhrase(); 50 | this.message = message; 51 | } 52 | 53 | public BintrayCallException(Exception e) { 54 | super(HttpStatus.SC_BAD_REQUEST, e.getMessage()); 55 | this.statusCode = HttpStatus.SC_BAD_REQUEST; 56 | this.reason = e.getMessage(); 57 | this.message = (e.getCause() == null) ? " " : " : " + e.getCause().getMessage(); 58 | } 59 | 60 | public int getStatusCode() { 61 | return statusCode; 62 | } 63 | 64 | public String getReason() { 65 | return reason; 66 | } 67 | 68 | @Override 69 | public String getMessage() { 70 | return message; 71 | } 72 | 73 | public void setMessage(String newMessage) { 74 | this.message = newMessage; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return statusCode + ", " + reason + " " + message; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/BintrayClientConstatnts.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api; 2 | 3 | /** 4 | * Holds Bintray REST API related constants 5 | * 6 | * @author Dan Feldman 7 | */ 8 | public interface BintrayClientConstatnts { 9 | 10 | String API_USERS = "users/"; 11 | String API_REPOS = "repos/"; 12 | String API_PKGS = "packages/"; 13 | String API_VER = "versions/"; 14 | String API_GPG = "gpg/"; 15 | String API_CONTENT = "content/"; 16 | String API_PRODUCTS = "products/"; 17 | 18 | String API_PUBLISH = "/publish"; 19 | String API_ATTR = "/attributes"; 20 | 21 | String GPG_SIGN_HEADER = "X-GPG-PASSPHRASE"; 22 | } 23 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/MultipleBintrayCallException.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * An Exception that aggregates multiple BintrayCallExceptions for async operations 8 | * 9 | * @author danf 10 | */ 11 | public class MultipleBintrayCallException extends Exception { 12 | 13 | List exceptions; 14 | 15 | public MultipleBintrayCallException() { 16 | super(); 17 | exceptions = new ArrayList<>(); 18 | } 19 | 20 | public MultipleBintrayCallException(List exceptions) { 21 | super(); 22 | this.exceptions = exceptions; 23 | } 24 | 25 | public List getExceptions() { 26 | return exceptions; 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/ObjectMapperHelper.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api; 2 | 3 | import org.codehaus.jackson.JsonFactory; 4 | import org.codehaus.jackson.map.DeserializationConfig; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.codehaus.jackson.map.SerializationConfig; 7 | import org.codehaus.jackson.map.annotate.JsonSerialize; 8 | 9 | /** 10 | * Helper class that provides the ObjectMapper for all Details classes 11 | * 12 | * @author Dan Feldman 13 | */ 14 | public class ObjectMapperHelper { 15 | 16 | public static ObjectMapper get() { 17 | return buildDetailsMapper(); 18 | } 19 | 20 | private static ObjectMapper buildDetailsMapper() { 21 | ObjectMapper mapper = new ObjectMapper(new JsonFactory()); 22 | 23 | // TODO: when moving to Jackson 2.x these can be replaced with JodaModule 24 | mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); 25 | mapper.configure(SerializationConfig.Feature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false); 26 | 27 | //Don't include keys with null values implicitly, only explicitly set values should be sent over 28 | mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, false); 29 | mapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false); 30 | mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); 31 | return mapper; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/Attribute.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 5 | import org.codehaus.jackson.annotate.*; 6 | import org.codehaus.jackson.map.ObjectMapper; 7 | import org.codehaus.jackson.type.TypeReference; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.util.List; 14 | 15 | import static java.util.Arrays.asList; 16 | 17 | /** 18 | * This class represents an attribute (version or package) 19 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 20 | * 21 | * @author Dan Feldman 22 | */ 23 | @JsonPropertyOrder({"name", "values", "type"}) 24 | @JsonIgnoreProperties(ignoreUnknown = true) 25 | public class Attribute { 26 | private static final Logger log = LoggerFactory.getLogger(Attribute.class); 27 | @JsonProperty("name") 28 | private String name; 29 | @JsonProperty("values") 30 | private List values; 31 | @JsonProperty("type") 32 | private Type type; 33 | 34 | @SafeVarargs 35 | public Attribute(String name, T... values) { 36 | this(name, null, asList(values)); 37 | } 38 | 39 | 40 | @SafeVarargs 41 | public Attribute(String name, Type type, T... values) { 42 | this(name, type, asList(values)); 43 | } 44 | 45 | @JsonCreator 46 | public Attribute(@JsonProperty("name") String name, @JsonProperty("type") Type type, @JsonProperty("values") List values) { 47 | this.name = name; 48 | if (type == null) { 49 | type = Type.string; //Type defaults to string 50 | } 51 | this.type = type; 52 | this.values = values; 53 | } 54 | 55 | public static ObjectMapper getObjectMapper() { 56 | return ObjectMapperHelper.get(); 57 | } 58 | 59 | /** 60 | * Produces a json from a list of attributes 61 | * 62 | * @param attributeDetails List of attributes to serialize 63 | * @return A string representing the json 64 | * @throws IOException 65 | */ 66 | @JsonIgnore 67 | public static String getJsonFromAttributeList(List attributeDetails) throws IOException { 68 | ObjectMapper mapper = ObjectMapperHelper.get(); 69 | String jsonContent; 70 | try { 71 | jsonContent = mapper.writeValueAsString(attributeDetails); 72 | } catch (IOException e) { 73 | log.error("Can't process the json file: " + e.getMessage()); 74 | throw e; 75 | } 76 | return jsonContent; 77 | } 78 | 79 | @JsonIgnore 80 | public static List getAttributeListFromJson(InputStream inputStream) throws IOException { 81 | ObjectMapper mapper = ObjectMapperHelper.get(); 82 | List attributes; 83 | try { 84 | attributes = mapper.readValue(inputStream, new TypeReference>() { 85 | }); 86 | } catch (IOException e) { 87 | log.error("Can't process the json file: " + e.getMessage()); 88 | throw e; 89 | } 90 | return attributes; 91 | } 92 | 93 | public String getName() { 94 | return name; 95 | } 96 | 97 | public List getValues() { 98 | return values; 99 | } 100 | 101 | public Type getType() { 102 | return type; 103 | } 104 | 105 | @Override 106 | public boolean equals(Object o) { 107 | if (this == o) return true; 108 | if (o == null || getClass() != o.getClass()) return false; 109 | 110 | Attribute attribute = (Attribute) o; 111 | 112 | if (!name.equals(attribute.name)) return false; 113 | if (!values.equals(attribute.values)) return false; 114 | 115 | return true; 116 | } 117 | 118 | @Override 119 | public int hashCode() { 120 | int result = name.hashCode(); 121 | result = 31 * result + type.hashCode(); 122 | result = 31 * result + values.hashCode(); 123 | return result; 124 | } 125 | 126 | @Override 127 | public String toString() { 128 | return "{" + 129 | "Name='" + name + '\'' + 130 | ", Type=" + type + 131 | ", Values=" + values + 132 | '}'; 133 | } 134 | 135 | public enum Type { 136 | string, date, number, Boolean 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/PackageDetails.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import org.codehaus.jackson.annotate.*; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.joda.time.DateTime; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * This class is used to serialize and deserialize the needed json to 14 | * pass to or receive from Bintray when performing actions on a package 15 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 16 | * 17 | * @author Dan Feldman 18 | */ 19 | @JsonIgnoreProperties(ignoreUnknown = true) 20 | public class PackageDetails { 21 | 22 | //Properties marked with @JsonPropery here are serialized to the create \ update package requests, the rest are 23 | // only deserialized when getting the package info 24 | @JsonProperty(value = "name") 25 | private String name; 26 | @JsonIgnore 27 | private String repo; 28 | @JsonIgnore 29 | private String owner; 30 | @JsonIgnore 31 | private String subject; 32 | @JsonProperty(value = "desc") 33 | private String description; 34 | @JsonProperty(value = "labels") 35 | private List labels; 36 | @JsonIgnore 37 | private List attributeNames; 38 | @JsonIgnore 39 | private Integer followersCount; 40 | @JsonIgnore 41 | private DateTime created; 42 | @JsonProperty(value = "website_url") 43 | private String websiteUrl; 44 | @JsonProperty(value = "issue_tracker_url") 45 | private String issueTrackerUrl; 46 | @JsonProperty(value = "github_repo") 47 | private String gitHubRepo; 48 | @JsonProperty(value = "github_release_notes_file") 49 | private String releaseNotesFile; 50 | @JsonProperty(value = "public_download_numbers") 51 | private Boolean publicDownloadNumbers; 52 | @JsonProperty(value = "public_stats") 53 | private Boolean publicStats; 54 | @JsonIgnore 55 | private List linkedRepos; 56 | @JsonIgnore 57 | private List versions; 58 | @JsonProperty(value = "licenses") 59 | private List licenses; 60 | @JsonIgnore 61 | private String latestVersion; 62 | @JsonIgnore 63 | private DateTime updated; 64 | @JsonIgnore 65 | private Integer rating; 66 | @JsonIgnore 67 | private Integer ratingCount; 68 | @JsonIgnore 69 | private List systemIds; 70 | @JsonProperty(value = "vcs_url") 71 | private String vcsUrl; 72 | @JsonIgnore 73 | private List attributes; 74 | 75 | //All other props that don't have specific fields 76 | private Map other = new HashMap<>(); 77 | 78 | @JsonAnySetter 79 | public void set(String name, Object value) { 80 | other.put(name, value); 81 | } 82 | 83 | @JsonAnyGetter 84 | public Map other() { 85 | return other; 86 | } 87 | 88 | @JsonCreator 89 | public PackageDetails() { 90 | } 91 | 92 | public PackageDetails(String name) { 93 | this.name = name; 94 | } 95 | 96 | public static ObjectMapper getObjectMapper() { 97 | return ObjectMapperHelper.get(); 98 | } 99 | 100 | public PackageDetails name(String name) { 101 | this.name = name; 102 | return this; 103 | } 104 | 105 | public PackageDetails description(String description) { 106 | this.description = description; 107 | return this; 108 | } 109 | 110 | public PackageDetails labels(List labels) { 111 | this.labels = labels; 112 | return this; 113 | } 114 | 115 | public PackageDetails websiteUrl(String websiteUrl) { 116 | this.websiteUrl = websiteUrl; 117 | return this; 118 | } 119 | 120 | public PackageDetails issueTrackerUrl(String issueTrackerUrl) { 121 | this.issueTrackerUrl = issueTrackerUrl; 122 | return this; 123 | } 124 | 125 | public PackageDetails gitHubRepo(String gitHubRepo) { 126 | this.gitHubRepo = gitHubRepo; 127 | return this; 128 | } 129 | 130 | public PackageDetails releaseNotesFile(String releaseNotesFile) { 131 | this.releaseNotesFile = releaseNotesFile; 132 | return this; 133 | } 134 | 135 | public PackageDetails publicDownloadNumbers(Boolean publicDownloadNumbers) { 136 | this.publicDownloadNumbers = publicDownloadNumbers; 137 | return this; 138 | } 139 | 140 | public PackageDetails publicStats(Boolean publicStats) { 141 | this.publicStats = publicStats; 142 | return this; 143 | } 144 | 145 | public PackageDetails licenses(List licenses) { 146 | this.licenses = licenses; 147 | return this; 148 | } 149 | 150 | public PackageDetails vcsUrl(String vcsUrl) { 151 | this.vcsUrl = vcsUrl; 152 | return this; 153 | } 154 | 155 | public PackageDetails attributes(List attributes) { 156 | this.attributes = attributes; 157 | return this; 158 | } 159 | 160 | public String getName() { 161 | return name; 162 | } 163 | 164 | public void setName(String name) { 165 | this.name = name; 166 | } 167 | 168 | @JsonIgnore 169 | public String getRepo() { 170 | return repo; 171 | } 172 | 173 | @JsonProperty(value = "repo") 174 | public void setRepo(String repo) { 175 | this.repo = repo; 176 | } 177 | 178 | @JsonIgnore 179 | public String getOwner() { 180 | return owner; 181 | } 182 | 183 | @JsonProperty(value = "owner") 184 | public void setOwner(String owner) { 185 | this.owner = owner; 186 | } 187 | 188 | @JsonIgnore 189 | public String getSubject() { 190 | return subject; 191 | } 192 | 193 | @JsonProperty(value = "subject") 194 | public void setSubject(String subject) { 195 | this.subject = subject; 196 | } 197 | 198 | public String getDescription() { 199 | return description; 200 | } 201 | 202 | public void setDescription(String description) { 203 | this.description = description; 204 | } 205 | 206 | public List getLabels() { 207 | return labels; 208 | } 209 | 210 | public void setLabels(List labels) { 211 | this.labels = labels; 212 | } 213 | 214 | @JsonIgnore 215 | public List getAttributeNames() { 216 | return attributeNames; 217 | } 218 | 219 | @JsonProperty(value = "attribute_names") 220 | public void setAttributeNames(List attributeNames) { 221 | this.attributeNames = attributeNames; 222 | } 223 | 224 | @JsonIgnore 225 | public Integer getFollowersCount() { 226 | return followersCount; 227 | } 228 | 229 | @JsonProperty(value = "followers_count") 230 | public void setFollowersCount(Integer followersCount) { 231 | this.followersCount = followersCount; 232 | } 233 | 234 | @JsonIgnore 235 | public DateTime getCreated() { 236 | return created; 237 | } 238 | 239 | @JsonProperty(value = "created") 240 | public void setCreated(DateTime created) { 241 | this.created = created; 242 | } 243 | 244 | public String getWebsiteUrl() { 245 | return websiteUrl; 246 | } 247 | 248 | public void setWebsiteUrl(String websiteUrl) { 249 | this.websiteUrl = websiteUrl; 250 | } 251 | 252 | public String getIssueTrackerUrl() { 253 | return issueTrackerUrl; 254 | } 255 | 256 | public void setIssueTrackerUrl(String issueTrackerUrl) { 257 | this.issueTrackerUrl = issueTrackerUrl; 258 | } 259 | 260 | public String getGitHubRepo() { 261 | return gitHubRepo; 262 | } 263 | 264 | public void setGitHubRepo(String gitHubRepo) { 265 | this.gitHubRepo = gitHubRepo; 266 | } 267 | 268 | public String getReleaseNotesFile() { 269 | return releaseNotesFile; 270 | } 271 | 272 | public void setReleaseNotesFile(String releaseNotesFile) { 273 | this.releaseNotesFile = releaseNotesFile; 274 | } 275 | 276 | public Boolean getPublicDownloadNumbers() { 277 | return publicDownloadNumbers; 278 | } 279 | 280 | public void setPublicDownloadNumbers(Boolean publicDownloadNumbers) { 281 | this.publicDownloadNumbers = publicDownloadNumbers; 282 | } 283 | 284 | public Boolean getPublicStats() { 285 | return publicStats; 286 | } 287 | 288 | public void setPublicStats(Boolean publicStats) { 289 | this.publicStats = publicStats; 290 | } 291 | 292 | @JsonIgnore 293 | public List getLinkedRepos() { 294 | return linkedRepos; 295 | } 296 | 297 | @JsonProperty("linked_to_repos") 298 | public void setLinkedRepos(List linkedRepos) { 299 | this.linkedRepos = linkedRepos; 300 | } 301 | 302 | @JsonIgnore 303 | public List getVersions() { 304 | return versions; 305 | } 306 | 307 | @JsonProperty("versions") 308 | public void setVersions(List versions) { 309 | this.versions = versions; 310 | } 311 | 312 | public List getLicenses() { 313 | return licenses; 314 | } 315 | 316 | public void setLicenses(List licenses) { 317 | this.licenses = licenses; 318 | } 319 | 320 | @JsonIgnore 321 | public String getLatestVersion() { 322 | return latestVersion; 323 | } 324 | 325 | @JsonProperty(value = "latest_version") 326 | public void setLatestVersion(String latestVersion) { 327 | this.latestVersion = latestVersion; 328 | } 329 | 330 | @JsonIgnore 331 | public DateTime getUpdated() { 332 | return updated; 333 | } 334 | 335 | @JsonProperty(value = "updated") 336 | public void setUpdated(DateTime updated) { 337 | this.updated = updated; 338 | } 339 | 340 | @JsonIgnore 341 | public Integer getRating() { 342 | return rating; 343 | } 344 | 345 | @JsonProperty(value = "rating") 346 | public void setRating(Integer rating) { 347 | this.rating = rating; 348 | } 349 | 350 | @JsonIgnore 351 | public Integer getRatingCount() { 352 | return ratingCount; 353 | } 354 | 355 | @JsonProperty(value = "rating_count") 356 | public void setRatingCount(Integer ratingCount) { 357 | this.ratingCount = ratingCount; 358 | } 359 | 360 | @JsonIgnore 361 | public List getSystemIds() { 362 | return systemIds; 363 | } 364 | 365 | @JsonProperty(value = "system_ids") 366 | public void setSystemIds(List systemIds) { 367 | this.systemIds = systemIds; 368 | } 369 | 370 | public String getVcsUrl() { 371 | return vcsUrl; 372 | } 373 | 374 | public void setVcsUrl(String vcsUrl) { 375 | this.vcsUrl = vcsUrl; 376 | } 377 | 378 | @JsonIgnore 379 | public List getAttributes() { 380 | return attributes; 381 | } 382 | 383 | @JsonProperty("attributes") 384 | public void setAttributes(List attributes) { 385 | this.attributes = attributes; 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/ProductDetails.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import org.codehaus.jackson.annotate.*; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.joda.time.DateTime; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * This class is used to serialize and deserialize the needed json to 14 | * pass to or receive from Bintray when performing actions on a product 15 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 16 | * 17 | * @author Dan Feldman 18 | */ 19 | @JsonIgnoreProperties(ignoreUnknown = true) 20 | public class ProductDetails { 21 | 22 | //Properties marked with @JsonPropery here are serialized to the create \ update version requests, the rest are 23 | // only deserialized when getting the version info 24 | @JsonProperty 25 | String name; 26 | @JsonIgnore 27 | String owner; 28 | @JsonProperty(value = "desc") 29 | String description; 30 | @JsonIgnore 31 | DateTime created; 32 | @JsonProperty(value = "website_url") 33 | String websiteUrl; 34 | @JsonProperty(value = "vcs_url") 35 | String vcsUrl; 36 | @JsonProperty 37 | List packages; 38 | @JsonIgnore 39 | List versions; 40 | @JsonProperty(value = "sign_url_expiry") 41 | Integer signUrlExpiry; 42 | 43 | //All other props that don't have specific fields 44 | private Map other = new HashMap<>(); 45 | 46 | @JsonAnySetter 47 | public void set(String name, Object value) { 48 | other.put(name, value); 49 | } 50 | 51 | @JsonAnyGetter 52 | public Map other() { 53 | return other; 54 | } 55 | 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | 64 | public String getOwner() { 65 | return owner; 66 | } 67 | 68 | public void setOwner(String owner) { 69 | this.owner = owner; 70 | } 71 | 72 | public String getDescription() { 73 | return description; 74 | } 75 | 76 | public void setDescription(String description) { 77 | this.description = description; 78 | } 79 | 80 | @JsonIgnore 81 | public DateTime getCreated() { 82 | return created; 83 | } 84 | 85 | @JsonProperty(value = "created") 86 | public void setCreated(DateTime created) { 87 | this.created = created; 88 | } 89 | 90 | public String getWebsiteUrl() { 91 | return websiteUrl; 92 | } 93 | 94 | public void setWebsiteUrl(String websiteUrl) { 95 | this.websiteUrl = websiteUrl; 96 | } 97 | 98 | public String getVcsUrl() { 99 | return vcsUrl; 100 | } 101 | 102 | public void setVcsUrl(String vcsUrl) { 103 | this.vcsUrl = vcsUrl; 104 | } 105 | 106 | public List getPackages() { 107 | return packages; 108 | } 109 | 110 | public void setPackages(List packages) { 111 | this.packages = packages; 112 | } 113 | 114 | @JsonIgnore 115 | public List getVersions() { 116 | return versions; 117 | } 118 | 119 | @JsonProperty 120 | public void setVersions(List versions) { 121 | this.versions = versions; 122 | } 123 | 124 | public Integer getSignUrlExpiry() { 125 | return signUrlExpiry; 126 | } 127 | 128 | public void setSignUrlExpiry(Integer signUrlExpiry) { 129 | this.signUrlExpiry = signUrlExpiry; 130 | } 131 | 132 | public static ObjectMapper getObjectMapper() { 133 | return ObjectMapperHelper.get(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/RepositoryDetails.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import org.codehaus.jackson.annotate.*; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.joda.time.DateTime; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * This class is used to serialize and deserialize the needed json to 14 | * pass to or receive from Bintray when performing actions on a repository 15 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 16 | * 17 | * @author Dan Feldman 18 | */ 19 | @JsonIgnoreProperties(ignoreUnknown = true) 20 | public class RepositoryDetails { 21 | 22 | //Properties marked with @JsonPropery here are serialized to the create \ update version requests, the rest are 23 | // only deserialized when getting the repo info 24 | @JsonIgnore 25 | String name; 26 | @JsonIgnore 27 | String owner; 28 | @JsonProperty 29 | String type; 30 | @JsonProperty(value = "private") 31 | Boolean isPrivate; 32 | @JsonProperty 33 | Boolean premium; 34 | @JsonProperty(value = "desc") 35 | String description; 36 | @JsonProperty 37 | List labels; 38 | @JsonProperty 39 | Integer yum_metadata_depth; 40 | @JsonIgnore 41 | DateTime created; 42 | @JsonIgnore 43 | Integer packageCount; 44 | @JsonIgnore 45 | Boolean updateExisting; //Property is not used in the Bintray API but Artifactory uses is in it's Bintray integration 46 | 47 | //All other props that don't have specific fields 48 | private Map other = new HashMap<>(); 49 | 50 | @JsonAnySetter 51 | public void set(String name, Object value) { 52 | other.put(name, value); 53 | } 54 | 55 | @JsonAnyGetter 56 | public Map other() { 57 | return other; 58 | } 59 | 60 | public static ObjectMapper getObjectMapper() { 61 | return ObjectMapperHelper.get(); 62 | } 63 | 64 | @JsonIgnore 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | @JsonProperty(value = "name") 70 | public RepositoryDetails setName(String name) { 71 | this.name = name; 72 | return this; 73 | } 74 | 75 | public String getType() { 76 | return type; 77 | } 78 | 79 | public Boolean getIsPrivate() { 80 | return isPrivate; 81 | } 82 | 83 | public RepositoryDetails setIsPrivate(Boolean isPrivate) { 84 | this.isPrivate = isPrivate; 85 | return this; 86 | } 87 | 88 | public Boolean getPremium() { 89 | return premium; 90 | } 91 | 92 | public RepositoryDetails setPremium(Boolean premium) { 93 | this.premium = premium; 94 | return this; 95 | } 96 | 97 | public RepositoryDetails setType(String type) { 98 | this.type = type; 99 | return this; 100 | } 101 | 102 | public Integer getYumMetadataDepth() { 103 | return yum_metadata_depth; 104 | } 105 | 106 | public RepositoryDetails setYumMetadataDepth(Integer yum_metadata_depth) { 107 | this.yum_metadata_depth = yum_metadata_depth; 108 | return this; 109 | } 110 | 111 | public String getOwner() { 112 | return owner; 113 | } 114 | 115 | public RepositoryDetails setOwner(String owner) { 116 | this.owner = owner; 117 | return this; 118 | } 119 | 120 | public String getDescription() { 121 | return description; 122 | } 123 | 124 | public RepositoryDetails setDescription(String description) { 125 | this.description = description; 126 | return this; 127 | } 128 | 129 | @JsonIgnore 130 | public DateTime getCreated() { 131 | return created; 132 | } 133 | 134 | @JsonProperty(value = "created") 135 | public RepositoryDetails setCreated(DateTime created) { 136 | this.created = created; 137 | return this; 138 | } 139 | 140 | public List getLabels() { 141 | return labels; 142 | } 143 | 144 | public RepositoryDetails setLabels(List labels) { 145 | this.labels = labels; 146 | return this; 147 | } 148 | 149 | @JsonIgnore 150 | public Integer getPackageCount() { 151 | return packageCount; 152 | } 153 | 154 | @JsonProperty(value = "package_count") 155 | public void setPackageCount(Integer packageCount) { 156 | this.packageCount = packageCount; 157 | } 158 | 159 | @JsonIgnore 160 | public Boolean getUpdateExisting() { 161 | return updateExisting; 162 | } 163 | 164 | @JsonProperty(value = "updateExisting") 165 | public void setUpdateExisting(Boolean updateExisting) { 166 | this.updateExisting = updateExisting; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/SubjectDetails.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import org.codehaus.jackson.annotate.JsonAnyGetter; 5 | import org.codehaus.jackson.annotate.JsonAnySetter; 6 | import org.codehaus.jackson.annotate.JsonIgnoreProperties; 7 | import org.codehaus.jackson.annotate.JsonProperty; 8 | import org.codehaus.jackson.map.ObjectMapper; 9 | import org.joda.time.DateTime; 10 | 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * This class is used to serialize and deserialize the needed json to 17 | * pass to or receive from Bintray when performing actions on a subject 18 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 19 | * 20 | * @author Dan Feldman 21 | */ 22 | @JsonIgnoreProperties(ignoreUnknown = true) 23 | public class SubjectDetails { 24 | 25 | @JsonProperty("name") 26 | String name; 27 | @JsonProperty("full_name") 28 | String fullName; 29 | @JsonProperty("gravatar_id") 30 | String gravatarId; 31 | @JsonProperty("repos") 32 | List repos; 33 | @JsonProperty("organizations") 34 | List organizations; 35 | @JsonProperty("followers_count") 36 | Integer followersCount; 37 | @JsonProperty("registered") 38 | DateTime registered; 39 | @JsonProperty("quota_used_bytes") 40 | Long quotaUsedBytes; 41 | 42 | //All other props that don't have specific fields 43 | private Map other = new HashMap<>(); 44 | 45 | @JsonAnySetter 46 | public void set(String name, Object value) { 47 | other.put(name, value); 48 | } 49 | 50 | @JsonAnyGetter 51 | public Map other() { 52 | return other; 53 | } 54 | 55 | public static ObjectMapper getObjectMapper() { 56 | return ObjectMapperHelper.get(); 57 | } 58 | 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | 67 | public String getFullName() { 68 | return fullName; 69 | } 70 | 71 | public void setFullName(String fullName) { 72 | this.fullName = fullName; 73 | } 74 | 75 | public String getGravatarId() { 76 | return gravatarId; 77 | } 78 | 79 | public void setGravatarId(String gravatarId) { 80 | this.gravatarId = gravatarId; 81 | } 82 | 83 | public List getRepos() { 84 | return repos; 85 | } 86 | 87 | public void setRepos(List repos) { 88 | this.repos = repos; 89 | } 90 | 91 | public List getOrganizations() { 92 | return organizations; 93 | } 94 | 95 | public void setOrganizations(List organizations) { 96 | this.organizations = organizations; 97 | } 98 | 99 | public Integer getFollowersCount() { 100 | return followersCount; 101 | } 102 | 103 | public void setFollowersCount(Integer followersCount) { 104 | this.followersCount = followersCount; 105 | } 106 | 107 | public DateTime getRegistered() { 108 | return registered; 109 | } 110 | 111 | public void setRegistered(DateTime registered) { 112 | this.registered = registered; 113 | } 114 | 115 | public Long getQuotaUsedBytes() { 116 | return quotaUsedBytes; 117 | } 118 | 119 | public void setQuotaUsedBytes(Long quotaUsedBytes) { 120 | this.quotaUsedBytes = quotaUsedBytes; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/details/VersionDetails.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.details; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import org.codehaus.jackson.annotate.*; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.joda.time.DateTime; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * This class is used to serialize and deserialize the needed json to 14 | * pass to or receive from Bintray when performing actions on a subject 15 | * NOTE: when serializing this class use getObjectMapper to obtain a suitable mapper for this class 16 | * 17 | * @author Dan Feldman 18 | */ 19 | @JsonIgnoreProperties(ignoreUnknown = true) 20 | public class VersionDetails { 21 | 22 | //Properties marked with @JsonPropery here are serialized to the create \ update version requests, the rest are 23 | // only deserialized when getting the version info 24 | @JsonProperty("name") 25 | String name; 26 | @JsonProperty("desc") 27 | String description; 28 | @JsonIgnore 29 | String pkg; 30 | @JsonIgnore 31 | String repo; 32 | @JsonIgnore 33 | String owner; 34 | @JsonIgnore 35 | List labels; 36 | @JsonIgnore 37 | List attributeNames; 38 | @JsonIgnore 39 | DateTime created; 40 | @JsonIgnore 41 | DateTime updated; 42 | @JsonProperty("released") 43 | DateTime released; 44 | @JsonIgnore 45 | Integer ordinal; 46 | @JsonIgnore 47 | List attributes; 48 | @JsonIgnore 49 | boolean gpgSign; 50 | @JsonProperty(value = "github_release_notes_file") 51 | private String releaseNotesFile; 52 | @JsonProperty(value = "github_use_tag_release_notes") 53 | private Boolean useTagReleaseNotes; 54 | @JsonProperty("vcs_tag") 55 | private String vcsTag; 56 | 57 | //All other props that don't have specific fields 58 | private Map other = new HashMap<>(); 59 | 60 | @JsonAnySetter 61 | public void set(String name, Object value) { 62 | other.put(name, value); 63 | } 64 | 65 | @JsonAnyGetter 66 | public Map other() { 67 | return other; 68 | } 69 | 70 | public VersionDetails() { 71 | 72 | } 73 | 74 | public VersionDetails(String name) { 75 | this.name = name; 76 | } 77 | 78 | public static ObjectMapper getObjectMapper() { 79 | return ObjectMapperHelper.get(); 80 | } 81 | 82 | public VersionDetails description(String description) { 83 | this.description = description; 84 | return this; 85 | } 86 | 87 | public VersionDetails released(DateTime released) { 88 | this.released = released; 89 | return this; 90 | } 91 | 92 | public VersionDetails releaseNotesFile(String releaseNotesFile) { 93 | this.releaseNotesFile = releaseNotesFile; 94 | return this; 95 | } 96 | 97 | public VersionDetails useTagReleaseNotes(Boolean useTagReleaseNotes) { 98 | this.useTagReleaseNotes = useTagReleaseNotes; 99 | return this; 100 | } 101 | 102 | public VersionDetails vcsTag(String vcsTag) { 103 | this.vcsTag = vcsTag; 104 | return this; 105 | } 106 | 107 | public VersionDetails gpgSign(boolean gpgSign) { 108 | this.gpgSign = gpgSign; 109 | return this; 110 | } 111 | 112 | public String getName() { 113 | return name; 114 | } 115 | 116 | public void setName(String name) { 117 | this.name = name; 118 | } 119 | 120 | public String getDescription() { 121 | return description; 122 | } 123 | 124 | public void setDescription(String description) { 125 | this.description = description; 126 | } 127 | 128 | @JsonIgnore 129 | public String getPkg() { 130 | return pkg; 131 | } 132 | 133 | @JsonProperty("package") 134 | public void setPkg(String pkg) { 135 | this.pkg = pkg; 136 | } 137 | 138 | @JsonIgnore 139 | public String getRepo() { 140 | return repo; 141 | } 142 | 143 | @JsonProperty("repo") 144 | public void setRepo(String repo) { 145 | this.repo = repo; 146 | } 147 | 148 | @JsonIgnore 149 | public String getOwner() { 150 | return owner; 151 | } 152 | 153 | @JsonProperty("owner") 154 | public void setOwner(String owner) { 155 | this.owner = owner; 156 | } 157 | 158 | @JsonIgnore 159 | public List getLabels() { 160 | return labels; 161 | } 162 | 163 | @JsonProperty("labels") 164 | public void setLabels(List labels) { 165 | this.labels = labels; 166 | } 167 | 168 | @JsonIgnore 169 | public List getAttributeNames() { 170 | return attributeNames; 171 | } 172 | 173 | @JsonProperty("attribute_names") 174 | public void setAttributeNames(List attributeNames) { 175 | this.attributeNames = attributeNames; 176 | } 177 | 178 | @JsonIgnore 179 | public DateTime getCreated() { 180 | return created; 181 | } 182 | 183 | @JsonProperty("created") 184 | public void setCreated(DateTime created) { 185 | this.created = created; 186 | } 187 | 188 | @JsonIgnore 189 | public DateTime getUpdated() { 190 | return updated; 191 | } 192 | 193 | @JsonProperty("updated") 194 | public void setUpdated(DateTime updated) { 195 | this.updated = updated; 196 | } 197 | 198 | public DateTime getReleased() { 199 | return released; 200 | } 201 | 202 | public void setReleased(DateTime released) { 203 | this.released = released; 204 | } 205 | 206 | @JsonIgnore 207 | public Integer getOrdinal() { 208 | return ordinal; 209 | } 210 | 211 | @JsonProperty("ordinal") 212 | public void setOrdinal(Integer ordinal) { 213 | this.ordinal = ordinal; 214 | } 215 | 216 | public String getReleaseNotesFile() { 217 | return releaseNotesFile; 218 | } 219 | 220 | public void setReleaseNotesFile(String releaseNotesFile) { 221 | this.releaseNotesFile = releaseNotesFile; 222 | } 223 | 224 | public Boolean getUseTagReleaseNotes() { 225 | return useTagReleaseNotes; 226 | } 227 | 228 | public void setUseTagReleaseNotes(Boolean useTagReleaseNotes) { 229 | this.useTagReleaseNotes = useTagReleaseNotes; 230 | } 231 | 232 | public String getVcsTag() { 233 | return vcsTag; 234 | } 235 | 236 | public void setVcsTag(String vcsTag) { 237 | this.vcsTag = vcsTag; 238 | } 239 | 240 | @JsonIgnore 241 | public List getAttributes() { 242 | return attributes; 243 | } 244 | 245 | @JsonProperty("attributes") 246 | public void setAttributes(List attributes) { 247 | this.attributes = attributes; 248 | } 249 | 250 | @JsonIgnore 251 | public boolean isGpgSign() { 252 | return gpgSign; 253 | } 254 | 255 | @JsonProperty("gpgSign") 256 | public void setGpgSign(boolean gpgSign) { 257 | this.gpgSign = gpgSign; 258 | } 259 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/AttributesSearchQuery.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | /** 4 | * @author jbaruch 5 | * @since 13/11/13 6 | */ 7 | public interface AttributesSearchQuery { 8 | AttributesSearchQueryClause byAttributeName(String name); 9 | } 10 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/AttributesSearchQueryClause.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.model.Pkg; 4 | import com.jfrog.bintray.client.api.model.Version; 5 | import org.joda.time.DateTime; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | 10 | /** 11 | * @author jbaruch 12 | * @since 13/11/13 13 | */ 14 | public interface AttributesSearchQueryClause { 15 | 16 | AttributesSearchQueryClause in(String... values); 17 | 18 | AttributesSearchQueryClause equalsVal(Object value); 19 | 20 | AttributesSearchQueryClause greaterThan(int value); 21 | 22 | AttributesSearchQueryClause greaterOrEqualsTo(int value); 23 | 24 | AttributesSearchQueryClause lessThan(int value); 25 | 26 | AttributesSearchQueryClause lessOrEquals(int value); 27 | 28 | AttributesSearchQueryClause before(DateTime value); 29 | 30 | AttributesSearchQueryClause beforeOrAt(DateTime value); 31 | 32 | AttributesSearchQueryClause at(DateTime value); 33 | 34 | AttributesSearchQueryClause after(DateTime value); 35 | 36 | AttributesSearchQueryClause afterOrAt(DateTime value); 37 | 38 | AttributesSearchQuery and(); 39 | 40 | List searchPackage() throws IOException; 41 | 42 | List searchVersion() throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/Bintray.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.MultipleBintrayCallException; 5 | import org.apache.http.HttpResponse; 6 | 7 | import java.io.Closeable; 8 | import java.io.InputStream; 9 | import java.util.Map; 10 | 11 | /** 12 | * @author Noam Y. Tenne 13 | */ 14 | public interface Bintray extends Closeable { 15 | 16 | SubjectHandle subject(String subject); 17 | 18 | RepositoryHandle repository(String repositoryPath); 19 | 20 | PackageHandle pkg(String packagePath); 21 | 22 | VersionHandle version(String versionPath); 23 | 24 | /** 25 | * Following are generic HTTP requests you can perform against Bintray's API, as defined in your created client 26 | * (so the uri parameter should be the required path after api.bintray.com). 27 | * You can also optionally add your own headers to the requests. 28 | */ 29 | 30 | HttpResponse get(String uri, Map headers) throws BintrayCallException; 31 | 32 | HttpResponse head(String uri, Map headers) throws BintrayCallException; 33 | 34 | HttpResponse post(String uri, Map headers, InputStream elementInputStream) throws BintrayCallException; 35 | 36 | HttpResponse patch(String uri, Map headers, InputStream elementInputStream) throws BintrayCallException; 37 | 38 | HttpResponse delete(String uri, Map headers) throws BintrayCallException; 39 | 40 | /** 41 | * PUT single item 42 | */ 43 | HttpResponse put(String uri, Map headers, InputStream elementInputStream) throws BintrayCallException; 44 | 45 | /** 46 | * Concurrently executes a list of {@link org.apache.http.client.methods.HttpPut} requests, which are not handled by 47 | * the default response handler to avoid any BintrayCallExceptions being thrown before all requests have executed. 48 | * 49 | * @return A list of all errors thrown while performing the requests or empty list if all requests finished OK 50 | */ 51 | HttpResponse put(Map uriAndStreamMap, Map headers) throws MultipleBintrayCallException; 52 | 53 | @Override 54 | void close(); 55 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/Handle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * @author Noam Y. Tenne 7 | */ 8 | public interface Handle { 9 | 10 | String name(); 11 | 12 | T get() throws IOException; 13 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/PackageHandle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.details.Attribute; 5 | import com.jfrog.bintray.client.api.details.PackageDetails; 6 | import com.jfrog.bintray.client.api.details.VersionDetails; 7 | import com.jfrog.bintray.client.api.model.Pkg; 8 | 9 | import java.io.IOException; 10 | import java.util.List; 11 | 12 | /** 13 | * @author Noam Y. Tenne 14 | */ 15 | public interface PackageHandle extends Handle { 16 | 17 | RepositoryHandle repository(); 18 | 19 | VersionHandle version(String versionName); 20 | 21 | Pkg get() throws IOException, BintrayCallException; 22 | 23 | PackageHandle update(PackageDetails packageDetails) throws IOException, BintrayCallException; 24 | 25 | PackageHandle delete() throws BintrayCallException; 26 | 27 | boolean exists() throws BintrayCallException; 28 | 29 | VersionHandle createVersion(VersionDetails versionDetails) throws IOException, BintrayCallException; 30 | 31 | PackageHandle setAttributes(PackageDetails packageDetails) throws IOException, BintrayCallException; 32 | 33 | PackageHandle setAttributes(List attributes) throws IOException, BintrayCallException; 34 | 35 | PackageHandle updateAttributes(PackageDetails packageDetails) throws IOException, BintrayCallException; 36 | 37 | PackageHandle updateAttributes(List attributes) throws IOException, BintrayCallException; 38 | 39 | String name(); 40 | 41 | String getCurrentPackageUri(); 42 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/ProductHandle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.details.ProductDetails; 5 | import com.jfrog.bintray.client.api.model.Product; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Dan Feldman 12 | */ 13 | public interface ProductHandle extends Handle { 14 | 15 | String name(); 16 | 17 | SubjectHandle owner(); 18 | 19 | Product get() throws IOException, BintrayCallException; 20 | 21 | ProductHandle update(ProductDetails productDetails) throws IOException, BintrayCallException; 22 | 23 | ProductHandle addPackages(List packages) throws IOException, BintrayCallException; 24 | 25 | ProductHandle delete() throws BintrayCallException; 26 | 27 | boolean exists() throws BintrayCallException; 28 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/RepositoryHandle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.details.PackageDetails; 5 | import com.jfrog.bintray.client.api.details.RepositoryDetails; 6 | import com.jfrog.bintray.client.api.model.Repository; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author Noam Y. Tenne 12 | */ 13 | public interface RepositoryHandle extends Handle { 14 | 15 | SubjectHandle owner(); 16 | 17 | Repository get() throws IOException, BintrayCallException; 18 | 19 | RepositoryHandle update(RepositoryDetails repositoryDetails) throws IOException, BintrayCallException; 20 | 21 | PackageHandle pkg(String name); 22 | 23 | PackageHandle createPkg(PackageDetails packageDetails) throws IOException, BintrayCallException; 24 | 25 | String name(); 26 | 27 | AttributesSearchQuery searchForPackage(); 28 | 29 | RepositoryHandle delete() throws BintrayCallException; 30 | 31 | boolean exists() throws BintrayCallException; 32 | 33 | String getRepositoryUri(); 34 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/SubjectHandle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.details.ProductDetails; 5 | import com.jfrog.bintray.client.api.details.RepositoryDetails; 6 | import com.jfrog.bintray.client.api.model.Subject; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author Noam Y. Tenne 12 | */ 13 | public interface SubjectHandle extends Handle { 14 | 15 | String name(); 16 | 17 | Subject get() throws IOException, BintrayCallException; 18 | 19 | RepositoryHandle repository(String name); 20 | 21 | RepositoryHandle createRepo(RepositoryDetails repoDetails) throws IOException, BintrayCallException; 22 | 23 | ProductHandle product(String name); 24 | 25 | ProductHandle createProduct(ProductDetails productDetails) throws IOException, BintrayCallException; 26 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/handle/VersionHandle.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.MultipleBintrayCallException; 5 | import com.jfrog.bintray.client.api.details.Attribute; 6 | import com.jfrog.bintray.client.api.details.VersionDetails; 7 | import com.jfrog.bintray.client.api.model.Version; 8 | 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author Noam Y. Tenne 16 | */ 17 | public interface VersionHandle extends Handle { 18 | 19 | PackageHandle pkg(); 20 | 21 | Version get() throws IOException, BintrayCallException; 22 | 23 | VersionHandle update(VersionDetails versionDetails) throws IOException, BintrayCallException; 24 | 25 | VersionHandle delete() throws BintrayCallException; 26 | 27 | boolean exists() throws BintrayCallException; 28 | 29 | VersionHandle setAttributes(VersionDetails versionDetails) throws IOException, BintrayCallException; 30 | 31 | VersionHandle setAttributes(List attributes) throws IOException, BintrayCallException; 32 | 33 | VersionHandle updateAttributes(VersionDetails versionDetails) throws IOException, BintrayCallException; 34 | 35 | VersionHandle updateAttributes(List attributes) throws IOException, BintrayCallException; 36 | 37 | VersionHandle upload(Map content) throws MultipleBintrayCallException; 38 | 39 | VersionHandle upload(Map content, boolean overrideExisting) throws MultipleBintrayCallException; 40 | 41 | VersionHandle upload(String path, InputStream content) throws BintrayCallException; 42 | 43 | VersionHandle upload(String path, InputStream content, boolean overrideExisting) throws BintrayCallException; 44 | 45 | VersionHandle uploadVagrant(String path, String boxProvider, InputStream content) throws BintrayCallException; 46 | 47 | VersionHandle uploadVagrant(String path, String boxProvider, InputStream content, boolean overrideExisting) throws BintrayCallException; 48 | 49 | VersionHandle uploadDebian(String path, String distribution, String component, String architecture, 50 | InputStream content) throws BintrayCallException; 51 | 52 | VersionHandle uploadDebian(String path, String distribution, String component, String architecture, 53 | InputStream content, boolean overrideExisting) throws BintrayCallException; 54 | 55 | VersionHandle uploadDebian(String path, List distributions, List components, 56 | List architectures, InputStream content) throws BintrayCallException; 57 | 58 | VersionHandle uploadDebian(String path, List distributions, List components, 59 | List architectures, InputStream content, boolean overrideExisting) throws BintrayCallException; 60 | 61 | VersionHandle publish() throws BintrayCallException; 62 | 63 | VersionHandle publish(String gpgPassphrase) throws BintrayCallException; 64 | 65 | VersionHandle publishSync() throws BintrayCallException; 66 | 67 | VersionHandle discard() throws BintrayCallException; 68 | 69 | VersionHandle sign(String passphrase, int fileCount) throws BintrayCallException; 70 | 71 | VersionHandle sign(int fileCount) throws BintrayCallException; 72 | 73 | String getVersionUri(); 74 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/model/Pkg.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.model; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Noam Y. Tenne 9 | */ 10 | public interface Pkg { 11 | 12 | String name(); 13 | 14 | String repository(); 15 | 16 | String owner(); 17 | 18 | String description(); 19 | 20 | List labels(); 21 | 22 | List attributeNames(); 23 | 24 | Integer rating(); 25 | 26 | Integer ratingCount(); 27 | 28 | Integer followersCount(); 29 | 30 | DateTime created(); 31 | 32 | List versions(); 33 | 34 | String latestVersion(); 35 | 36 | DateTime updated(); 37 | 38 | List linkedToRepos(); 39 | 40 | List systemIds(); 41 | 42 | List licenses(); 43 | 44 | String vcsUrl(); 45 | 46 | Object getFieldByKey(String key); 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.model; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Dan Feldman 9 | */ 10 | public interface Product { 11 | 12 | String getName(); 13 | 14 | String getOwner(); 15 | 16 | String getDescription(); 17 | 18 | DateTime getCreated(); 19 | 20 | String getWebsiteUrl(); 21 | 22 | String getVcsUrl(); 23 | 24 | List getPackages(); 25 | 26 | List getVersions(); 27 | 28 | Object getFieldByKey(String key); 29 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/model/Repository.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.model; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Noam Y. Tenne 9 | */ 10 | public interface Repository { 11 | 12 | String getName(); 13 | 14 | String getOwner(); 15 | 16 | String getType(); 17 | 18 | Boolean isPrivate(); 19 | 20 | Boolean isPremium(); 21 | 22 | String getDesc(); 23 | 24 | List getLabels(); 25 | 26 | DateTime getCreated(); 27 | 28 | Integer getPackageCount(); 29 | 30 | Object getFieldByKey(String key); 31 | } -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/model/Subject.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.model; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * @author Noam Y. Tenne 9 | */ 10 | public interface Subject { 11 | 12 | String getName(); 13 | 14 | String getFullName(); 15 | 16 | String getGravatarId(); 17 | 18 | Collection getRepositories(); 19 | 20 | Collection getOrganizations(); 21 | 22 | Integer getFollowersCount(); 23 | 24 | DateTime getRegistered(); 25 | 26 | Long getQuotaUsedBytes(); 27 | 28 | Object getFieldByKey(String key); 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/com/jfrog/bintray/client/api/model/Version.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.api.model; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Noam Y. Tenne 9 | */ 10 | public interface Version { 11 | 12 | String name(); 13 | 14 | String description(); 15 | 16 | String pkg(); 17 | 18 | String repository(); 19 | 20 | String owner(); 21 | 22 | List labels(); 23 | 24 | List attributeNames(); 25 | 26 | DateTime created(); 27 | 28 | DateTime updated(); 29 | 30 | DateTime released(); 31 | 32 | Integer ordinal(); 33 | 34 | String vcsTag(); 35 | 36 | Object getFieldByKey(String key); 37 | } 38 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import static java.lang.System.getenv 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.3') 10 | } 11 | } 12 | 13 | allprojects { 14 | apply plugin: 'idea' 15 | apply plugin: 'maven-publish' 16 | apply plugin: 'com.jfrog.artifactory' 17 | 18 | group = 'com.jfrog.bintray.client' 19 | 20 | artifactory { 21 | contextUrl = 'https://oss.jfrog.org' 22 | resolve { 23 | repository { 24 | repoKey = 'libs-release' 25 | } 26 | } 27 | 28 | publish { 29 | repository { 30 | repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to 31 | username = project.hasProperty('bintrayUser') ? project.bintrayUser : getenv()['BINTRAY_USER'] 32 | password = project.hasProperty('bintrayKey') ? project.bintrayKey : getenv()['BINTRAY_KEY'] 33 | } 34 | defaults { 35 | publications 'main' 36 | properties = ['bintray.repo': 'jfrog/bintray-tools', 'bintray.package': 'bintray-client-java', 'bintray.version': version.toString()] 37 | } 38 | } 39 | } 40 | } 41 | 42 | artifactoryPublish.skip = true 43 | 44 | subprojects() { 45 | apply plugin: 'java' 46 | sourceCompatibility = 1.7 47 | targetCompatibility = 1.7 48 | 49 | dependencies { 50 | compile addSlf4J('slf4j-api') 51 | compile addSlf4J('log4j-over-slf4j') 52 | compile addSlf4J('jcl-over-slf4j') 53 | compile 'ch.qos.logback:logback-classic:1.0.10' 54 | compile 'joda-time:joda-time:2.2' 55 | compile 'commons-io:commons-io:2.1' 56 | compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.5' 57 | compile("org.apache.httpcomponents:httpclient:4.5.1") { 58 | exclude group: 'commons-logging' //DO NOT REMOVE 59 | } 60 | } 61 | 62 | task sourcesJar(type: Jar) { 63 | from sourceSets.main.allSource 64 | classifier = 'sources' 65 | } 66 | 67 | task javadocJar(type: Jar, dependsOn: javadoc) { 68 | classifier = 'javadoc' 69 | from javadoc.destinationDir 70 | } 71 | 72 | task testResultsZip(type: Zip) { 73 | classifier = 'testreports' 74 | from testReportDir 75 | 76 | } 77 | 78 | test { 79 | jvmArgs (['-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog', 80 | '-Dorg.apache.commons.logging.simplelog.showdatetime=true', 81 | '-Dorg.apache.commons.logging.simplelog.log.org.apache.http=ERROR', 82 | '-Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=ERROR']) 83 | testLogging { 84 | exceptionFormat "full" 85 | events "started", "passed", "skipped", "failed", "standardOut", "standardError" 86 | minGranularity 0 87 | } 88 | //Have the BintraySpecSuite run all tests 89 | exclude 'com/jfrog/bintray/client/test/spec' 90 | 91 | finalizedBy(testResultsZip) 92 | } 93 | 94 | 95 | publishing { 96 | publications { 97 | main(MavenPublication) { 98 | from components.java 99 | artifact sourcesJar 100 | artifact javadocJar 101 | if (testResultsZip.archivePath.exists()) { 102 | artifact testResultsZip 103 | } 104 | 105 | pom.withXml { 106 | asNode().with { 107 | appendNode('packaging', 'jar') 108 | appendNode('name', 'Bintray Java client') 109 | appendNode('description', 'Java client for working with Bintray') 110 | appendNode('url', 'https://github.com/bintray/bintray-client-java') 111 | appendNode('licenses').with { 112 | appendNode('license').with { 113 | appendNode('name', 'The Apache Software License, Version 2.0') 114 | appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0') 115 | } 116 | } 117 | appendNode('developers').with { 118 | appendNode('developer').with { 119 | appendNode('id', 'NoamTenne') 120 | appendNode('name', 'Noam Tenne') 121 | appendNode('email', 'NoamT@jfrog.com') 122 | } 123 | appendNode('developer').with { 124 | appendNode('id', 'jbaruch') 125 | appendNode('name', 'Baruch Sadogursky') 126 | appendNode('email', 'jbaruch@jfrog.com') 127 | } 128 | appendNode('developer').with { 129 | appendNode('id', 'danf') 130 | appendNode('name', 'Dan Feldman') 131 | appendNode('email', 'danf@jfrog.com') 132 | } 133 | } 134 | appendNode('scm').with { 135 | appendNode('connection', 'git@github.com:JFrogDev/bintray/bintray-client-java.git') 136 | appendNode('developerConnection', 'git@github.com:bintray/bintray-client-java.git') 137 | appendNode('url', 'https://github.com/bintray/bintray-client-java') 138 | } 139 | } 140 | asNode().dependencies.'*'.findAll() { 141 | it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep -> 142 | dep.name == it.artifactId.text() 143 | } 144 | }.each() { 145 | it.scope*.value = 'compile' 146 | } 147 | } 148 | } 149 | } 150 | } 151 | } 152 | 153 | project(':bintray-client-java-service') { 154 | dependencies { 155 | compile project(':bintray-client-java-api') 156 | compile 'commons-lang:commons-lang:2.6' 157 | testCompile group: 'com.timgroup', name: 'jgravatar', version: '1.0' 158 | testCompile("org.spockframework:spock-core:0.7-groovy-2.0") 159 | } 160 | } 161 | 162 | project(':bintray-client-java-api') { 163 | apply plugin: 'java' 164 | sourceCompatibility = 1.7 165 | targetCompatibility = 1.7 166 | } 167 | 168 | project(':bintray-client-java-service') { 169 | apply plugin: 'groovy' 170 | } 171 | 172 | def addSlf4J(name) { 173 | [group: 'org.slf4j', name: name, version: '1.7.5'] 174 | } 175 | 176 | task wrapper(type: Wrapper) { 177 | gradleVersion = '2.4' 178 | } 179 | 180 | idea { 181 | project { 182 | jdkName = '1.7' 183 | languageLevel = '1.7' 184 | wildcards += '?*.gradle' 185 | ipr { 186 | withXml { provider -> 187 | def node = provider.asNode() 188 | // Use git 189 | def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' } 190 | vcsConfig.mapping[0].'@vcs' = 'Git' 191 | } 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.9.2-SNAPSHOT 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bintray/bintray-client-java/93e9aad0f7451399d6a64533ecde9b01bb490572/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 12 10:28:06 IDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/BintrayClient.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl; 2 | 3 | import com.jfrog.bintray.client.api.handle.Bintray; 4 | import com.jfrog.bintray.client.impl.handle.BintrayImpl; 5 | import org.apache.http.auth.UsernamePasswordCredentials; 6 | import org.apache.http.impl.client.CloseableHttpClient; 7 | 8 | /** 9 | * Creates a client to perform api actions with, can be configured with\without proxy (can be passed as null) 10 | * By default, https://api.bintray.com is used, unless specified otherwise (i.e. can be configured to work 11 | * with https://dl.bintray.com/). 12 | * 13 | * @author Dan Feldman 14 | */ 15 | public class BintrayClient { 16 | 17 | public static final int DEFAULT_TIMEOUT = 150000; 18 | public static final String BINTRAY_API_URL = "https://api.bintray.com"; 19 | public static final String USER_AGENT = "BintrayJavaClient/0.9.2-SNAPSHOT"; // TODO: make dynamic 20 | private static final int DEFAULT_THREAD_POOL_SIZE = 5; //Don't mess with this - its here for a reason 21 | private static final int DEFAULT_SIGN_REQUEST_TIMEOUT_PER_FILE = 90000; //1.5 min per file 22 | 23 | //Mainly used by Artifactory to avoid all of the configuration, but you can specify your own too 24 | static public Bintray create(CloseableHttpClient preConfiguredClient, String url, int threadPoolSize, 25 | int signRequestTimeoutPerFile) { 26 | return new BintrayImpl(preConfiguredClient, url, threadPoolSize, signRequestTimeoutPerFile); 27 | } 28 | 29 | /** 30 | * Username and API key, no proxy 31 | */ 32 | static public Bintray create(String userName, String apiKey) { 33 | return create(BINTRAY_API_URL, userName, apiKey); 34 | } 35 | 36 | /** 37 | * Username, API key, and custom url 38 | */ 39 | static public Bintray create(String url, String userName, String apiKey) { 40 | UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userName, apiKey); 41 | return new BintrayImpl(createClient(creds, null, url), url, DEFAULT_THREAD_POOL_SIZE, 42 | DEFAULT_SIGN_REQUEST_TIMEOUT_PER_FILE); 43 | } 44 | 45 | /** 46 | * Credentials with proxy 47 | */ 48 | static public Bintray create(UsernamePasswordCredentials creds, HttpClientConfigurator.ProxyConfig proxyConfig) { 49 | return new BintrayImpl(createClient(creds, proxyConfig, BINTRAY_API_URL), BINTRAY_API_URL, 50 | DEFAULT_THREAD_POOL_SIZE, DEFAULT_SIGN_REQUEST_TIMEOUT_PER_FILE); 51 | } 52 | 53 | /** 54 | * Username, API key, proxy and custom url 55 | */ 56 | static public Bintray create(String bintrayUserName, String bintrayApiKey, 57 | HttpClientConfigurator.ProxyConfig proxyConfig, String url) { 58 | UsernamePasswordCredentials creds = new UsernamePasswordCredentials(bintrayUserName, bintrayApiKey); 59 | return new BintrayImpl(createClient(creds, proxyConfig, url), url, DEFAULT_THREAD_POOL_SIZE, 60 | DEFAULT_SIGN_REQUEST_TIMEOUT_PER_FILE); 61 | } 62 | 63 | 64 | private static CloseableHttpClient createClient(UsernamePasswordCredentials creds, 65 | HttpClientConfigurator.ProxyConfig proxyConfig, String url) { 66 | 67 | return new HttpClientConfigurator() 68 | .hostFromUrl(url) 69 | .soTimeout(DEFAULT_TIMEOUT) 70 | .connectionTimeout(DEFAULT_TIMEOUT) 71 | .noRetry() 72 | .proxy(proxyConfig) 73 | .authentication(creds) 74 | .maxTotalConnections(50) 75 | .defaultMaxConnectionsPerHost(30) 76 | .getClient(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/AttributesSearchQueryClauseImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.details.Attribute; 4 | import com.jfrog.bintray.client.api.handle.AttributesSearchQuery; 5 | import com.jfrog.bintray.client.api.handle.AttributesSearchQueryClause; 6 | import com.jfrog.bintray.client.api.model.Pkg; 7 | import com.jfrog.bintray.client.api.model.Version; 8 | import org.codehaus.jackson.annotate.JsonIgnore; 9 | import org.joda.time.DateTime; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | 14 | /** 15 | * @author jbaruch 16 | * @author Dan Feldman 17 | * @since 13/11/13 18 | */ 19 | class AttributesSearchQueryClauseImpl implements AttributesSearchQueryClause { 20 | 21 | @JsonIgnore 22 | private final AttributesSearchQueryImpl query; 23 | @JsonIgnore 24 | private Object clauseValue; 25 | @JsonIgnore 26 | private Attribute.Type type; 27 | 28 | 29 | AttributesSearchQueryClauseImpl(AttributesSearchQueryImpl query) { 30 | this.query = query; 31 | } 32 | 33 | public Object getClauseValue() { 34 | return clauseValue; 35 | } 36 | 37 | public Attribute.Type getType() { 38 | return type; 39 | } 40 | 41 | @Override 42 | @SuppressWarnings("unchecked") 43 | public AttributesSearchQueryClause equalsVal(Object value) { 44 | Attribute attribute = new Attribute("TypeTest", value); //This validates proper value type 45 | type = attribute.getType(); 46 | clauseValue = value; 47 | return this; 48 | } 49 | 50 | @Override 51 | public AttributesSearchQuery and() { 52 | query.addQueryClause(this); 53 | return query; 54 | } 55 | 56 | @Override 57 | public List searchPackage() throws IOException { 58 | query.addQueryClause(this); 59 | return query.searchPackage(); 60 | } 61 | 62 | @Override 63 | public List searchVersion() throws IOException { 64 | query.addQueryClause(this); 65 | return query.searchVersion(); 66 | } 67 | 68 | @Override 69 | public AttributesSearchQueryClause lessThan(int value) { 70 | //TODO implement 71 | return this; 72 | } 73 | 74 | @Override 75 | public AttributesSearchQueryClause lessOrEquals(int value) { 76 | //TODO implement 77 | return this; 78 | } 79 | 80 | @Override 81 | public AttributesSearchQueryClause before(DateTime value) { 82 | //TODO implement 83 | return this; 84 | } 85 | 86 | @Override 87 | public AttributesSearchQueryClause beforeOrAt(DateTime value) { 88 | //TODO implement 89 | return this; 90 | } 91 | 92 | @Override 93 | public AttributesSearchQueryClause at(DateTime value) { 94 | //TODO implement 95 | return this; 96 | } 97 | 98 | @Override 99 | public AttributesSearchQueryClause after(DateTime value) { 100 | //TODO implement 101 | return this; 102 | } 103 | 104 | @Override 105 | public AttributesSearchQueryClause afterOrAt(DateTime value) { 106 | //TODO implement 107 | return this; 108 | } 109 | 110 | @Override 111 | public AttributesSearchQueryClause greaterThan(int value) { 112 | //TODO implement 113 | return this; 114 | } 115 | 116 | @Override 117 | public AttributesSearchQueryClause greaterOrEqualsTo(int value) { 118 | //TODO implement 119 | return this; 120 | } 121 | 122 | @Override 123 | public AttributesSearchQueryClause in(String... values) { 124 | //TODO implement 125 | return this; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/AttributesSearchQueryImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.details.Attribute; 5 | import com.jfrog.bintray.client.api.handle.AttributesSearchQuery; 6 | import com.jfrog.bintray.client.api.handle.AttributesSearchQueryClause; 7 | import com.jfrog.bintray.client.api.model.Pkg; 8 | import com.jfrog.bintray.client.api.model.Version; 9 | import org.codehaus.jackson.JsonGenerator; 10 | import org.codehaus.jackson.JsonProcessingException; 11 | import org.codehaus.jackson.map.JsonSerializer; 12 | import org.codehaus.jackson.map.SerializerProvider; 13 | import org.codehaus.jackson.map.annotate.JsonSerialize; 14 | 15 | import java.io.IOException; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * @author jbaruch 21 | * @author Dan Feldman 22 | * @since 13/11/13 23 | */ 24 | @JsonSerialize(using = AttributesSearchQueryImpl.AttributeSearchQuerySerializer.class) 25 | class AttributesSearchQueryImpl implements AttributesSearchQuery { 26 | 27 | private final RepositoryHandleImpl repositoryHandle; 28 | private final PackageHandleImpl packageHandle; 29 | private String attributeName; 30 | private List queryClauses = new ArrayList<>(); 31 | 32 | /** 33 | * Creates an AttributesSearchQuery object that will search for a version 34 | * 35 | * @param repositoryHandle repository to search in 36 | */ 37 | public AttributesSearchQueryImpl(RepositoryHandleImpl repositoryHandle) { 38 | this.repositoryHandle = repositoryHandle; 39 | this.packageHandle = null; 40 | } 41 | 42 | /** 43 | * Creates an AttributesSearchQuery object that will search for a version 44 | * 45 | * @param packageHandle version to search in 46 | */ 47 | public AttributesSearchQueryImpl(PackageHandleImpl packageHandle) { 48 | this.packageHandle = packageHandle; 49 | this.repositoryHandle = null; 50 | } 51 | 52 | public void addQueryClause(AttributesSearchQueryClauseImpl clause) { 53 | queryClauses.add(clause); 54 | } 55 | 56 | public List getQueryClauses() { 57 | return queryClauses; 58 | } 59 | 60 | @Override 61 | public AttributesSearchQueryClause byAttributeName(String attributeName) { 62 | this.attributeName = attributeName; 63 | return new AttributesSearchQueryClauseImpl(this); 64 | } 65 | 66 | public List searchPackage() throws IOException, BintrayCallException { 67 | repositoryHandle.addQuery(this); 68 | return repositoryHandle.attributeSearch(); 69 | } 70 | 71 | public List searchVersion() throws IOException, BintrayCallException { 72 | packageHandle.addQuery(this); 73 | return packageHandle.attributeSearch(); 74 | } 75 | 76 | public static class AttributeSearchQuerySerializer extends JsonSerializer { 77 | 78 | // TODO: add support for other search methods (greater, less than etc.) with Bintray's search syntax 79 | @Override 80 | public void serialize(AttributesSearchQueryImpl value, JsonGenerator jgen, SerializerProvider provider) 81 | throws IOException, JsonProcessingException { 82 | 83 | jgen.writeStartArray(); 84 | jgen.writeStartObject(); 85 | jgen.writeArrayFieldStart(value.attributeName); 86 | 87 | @SuppressWarnings("unchecked") 88 | List clauses = value.getQueryClauses(); 89 | for (AttributesSearchQueryClauseImpl clause : clauses) { 90 | if (clause.getType().equals(Attribute.Type.Boolean)) { 91 | jgen.writeBoolean((Boolean) clause.getClauseValue()); 92 | } else if (clause.getType().equals(Attribute.Type.number)) { 93 | jgen.writeNumber(String.valueOf(clause.getClauseValue())); 94 | } else { //String or Date 95 | jgen.writeString((String) clause.getClauseValue()); 96 | } 97 | } 98 | jgen.writeEndArray(); 99 | jgen.writeEndObject(); 100 | jgen.writeEndArray(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/PackageHandleImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 5 | import com.jfrog.bintray.client.api.details.Attribute; 6 | import com.jfrog.bintray.client.api.details.PackageDetails; 7 | import com.jfrog.bintray.client.api.details.VersionDetails; 8 | import com.jfrog.bintray.client.api.handle.PackageHandle; 9 | import com.jfrog.bintray.client.api.handle.RepositoryHandle; 10 | import com.jfrog.bintray.client.api.handle.VersionHandle; 11 | import com.jfrog.bintray.client.api.model.Pkg; 12 | import com.jfrog.bintray.client.api.model.Version; 13 | import com.jfrog.bintray.client.impl.model.PackageImpl; 14 | import com.jfrog.bintray.client.impl.model.VersionImpl; 15 | import org.apache.commons.io.IOUtils; 16 | import org.apache.http.HttpHeaders; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.entity.ContentType; 19 | import org.codehaus.jackson.map.ObjectMapper; 20 | import org.codehaus.jackson.type.TypeReference; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import java.io.IOException; 25 | import java.io.StringWriter; 26 | import java.util.ArrayList; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS; 32 | 33 | /** 34 | * @author Dan Feldman 35 | */ 36 | class PackageHandleImpl implements PackageHandle { 37 | private static final Logger log = LoggerFactory.getLogger(PackageHandleImpl.class); 38 | 39 | private BintrayImpl bintrayHandle; 40 | private RepositoryHandle repositoryHandle; 41 | private String name; 42 | private AttributesSearchQueryImpl searchQuery = null; 43 | 44 | PackageHandleImpl(BintrayImpl bintrayHandle, RepositoryHandle repositoryHandle, String name) { 45 | this.bintrayHandle = bintrayHandle; 46 | this.repositoryHandle = repositoryHandle; 47 | this.name = name; 48 | } 49 | 50 | @Override 51 | public RepositoryHandle repository() { 52 | return repositoryHandle; 53 | } 54 | 55 | @Override 56 | public VersionHandle version(String versionName) { 57 | return new VersionHandleImpl(bintrayHandle, this, versionName); 58 | } 59 | 60 | @Override 61 | public Pkg get() throws IOException, BintrayCallException { 62 | HttpResponse response = bintrayHandle.get(getCurrentPackageUri(), null); 63 | PackageDetails pkgDetails; 64 | String jsonContentStream = IOUtils.toString(response.getEntity().getContent()); 65 | ObjectMapper mapper = ObjectMapperHelper.get(); 66 | try { 67 | pkgDetails = mapper.readValue(jsonContentStream, PackageDetails.class); 68 | } catch (IOException e) { 69 | log.error("Can't parse the json file: " + e.getMessage()); 70 | throw e; 71 | } 72 | return new PackageImpl(pkgDetails); 73 | } 74 | 75 | @Override 76 | public PackageHandle update(PackageDetails packageDetails) throws IOException, BintrayCallException { 77 | Map headers = new HashMap<>(); 78 | String jsonContent = PackageImpl.getCreateUpdateJson(packageDetails); 79 | BintrayImpl.addContentTypeJsonHeader(headers); 80 | bintrayHandle.patch(getCurrentPackageUri(), headers, IOUtils.toInputStream(jsonContent)); 81 | 82 | return this.updateAttributes(packageDetails); 83 | } 84 | 85 | @Override 86 | public PackageHandle delete() throws BintrayCallException { 87 | bintrayHandle.delete(getCurrentPackageUri(), null); 88 | return this; 89 | } 90 | 91 | @Override 92 | public boolean exists() throws BintrayCallException { 93 | try { 94 | bintrayHandle.head(getCurrentPackageUri(), null); 95 | } catch (BintrayCallException e) { 96 | if (e.getStatusCode() == 404) { 97 | return false; 98 | } 99 | throw e; 100 | } 101 | return true; 102 | } 103 | 104 | @Override 105 | public VersionHandle createVersion(VersionDetails versionDetails) throws IOException, BintrayCallException { 106 | Map headers = new HashMap<>(); 107 | String jsonContent = VersionImpl.getCreateUpdateJson(versionDetails); 108 | BintrayImpl.addContentTypeJsonHeader(headers); 109 | bintrayHandle.post(getCurrentPackageUri() + "/versions", headers, IOUtils.toInputStream(jsonContent)); 110 | 111 | return new VersionHandleImpl(bintrayHandle, this, versionDetails.getName()).setAttributes(versionDetails); 112 | } 113 | 114 | 115 | @Override 116 | public PackageHandle setAttributes(PackageDetails packageDetails) throws IOException, BintrayCallException { 117 | return setAttributes(packageDetails.getAttributes()); 118 | } 119 | 120 | @Override 121 | public PackageHandle setAttributes(List attributes) throws IOException, BintrayCallException { 122 | if (attributes == null) { 123 | return this; 124 | } 125 | Map headers = new HashMap<>(); 126 | String jsonContent = Attribute.getJsonFromAttributeList(attributes); 127 | BintrayImpl.addContentTypeJsonHeader(headers); 128 | bintrayHandle.post(getCurrentPackageUri() + "/attributes", headers, IOUtils.toInputStream(jsonContent)); 129 | 130 | return this; 131 | } 132 | 133 | @Override 134 | public PackageHandle updateAttributes(PackageDetails packageDetails) throws IOException, BintrayCallException { 135 | return updateAttributes(packageDetails.getAttributes()); 136 | } 137 | 138 | @Override 139 | public PackageHandle updateAttributes(List attributes) throws IOException, BintrayCallException { 140 | if (attributes == null) { 141 | return this; 142 | } 143 | Map headers = new HashMap<>(); 144 | String jsonContent = Attribute.getJsonFromAttributeList(attributes); 145 | BintrayImpl.addContentTypeJsonHeader(headers); 146 | bintrayHandle.patch(getCurrentPackageUri() + "/attributes", headers, IOUtils.toInputStream(jsonContent)); 147 | 148 | return this; 149 | } 150 | 151 | public void addQuery(AttributesSearchQueryImpl query) { 152 | searchQuery = query; 153 | } 154 | 155 | /** 156 | * Searches for versions according to the attribute search query supplied to addQuery 157 | * 158 | * @return a list of packages that were returned by Bintray's search 159 | * @throws BintrayCallException 160 | */ 161 | public List attributeSearch() throws BintrayCallException { 162 | ObjectMapper mapper = ObjectMapperHelper.get(); 163 | StringWriter writer = new StringWriter(); 164 | try { 165 | mapper.writeValue(writer, searchQuery); 166 | } catch (IOException e) { 167 | log.error("Error writing search query to json: ", e); 168 | return null; 169 | } 170 | 171 | Map headers = new HashMap<>(); 172 | headers.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()); 173 | HttpResponse response = bintrayHandle.post("/search/attributes/" + repositoryHandle.owner().name() + 174 | "/" + repositoryHandle.name() + "/" + name + "/versions", headers, 175 | IOUtils.toInputStream(writer.toString())); 176 | 177 | List answer = new ArrayList<>(); 178 | 179 | try { 180 | answer = mapper.readValue(response.getEntity().getContent(), new TypeReference>() { 181 | }); 182 | } catch (IOException e) { 183 | log.error("Error parsing query response"); 184 | } 185 | 186 | List packages = new ArrayList<>(); 187 | for (VersionDetails verDetails : answer) { 188 | packages.add(new VersionImpl(verDetails)); 189 | } 190 | searchQuery = null; 191 | return packages; 192 | } 193 | 194 | @Override 195 | public String getCurrentPackageUri() { 196 | return String.format(API_PKGS + "%s/%s/%s", repositoryHandle.owner().name(), repositoryHandle.name(), name); 197 | } 198 | 199 | @Override 200 | public String name() { 201 | return name; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/ProductHandleImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 5 | import com.jfrog.bintray.client.api.details.ProductDetails; 6 | import com.jfrog.bintray.client.api.handle.ProductHandle; 7 | import com.jfrog.bintray.client.api.handle.SubjectHandle; 8 | import com.jfrog.bintray.client.api.model.Product; 9 | import com.jfrog.bintray.client.impl.model.ProductImpl; 10 | import org.apache.commons.io.IOUtils; 11 | import org.apache.http.HttpResponse; 12 | import org.codehaus.jackson.map.ObjectMapper; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.io.IOException; 17 | import java.io.InputStream; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PRODUCTS; 23 | 24 | /** 25 | * @author Dan Feldman 26 | */ 27 | class ProductHandleImpl implements ProductHandle { 28 | private static final Logger log = LoggerFactory.getLogger(ProductHandleImpl.class); 29 | 30 | private BintrayImpl bintrayHandle; 31 | private SubjectHandleImpl owner; 32 | private String name; 33 | 34 | public ProductHandleImpl(BintrayImpl bintrayHandle, SubjectHandleImpl owner, String productName) { 35 | this.bintrayHandle = bintrayHandle; 36 | this.owner = owner; 37 | this.name = productName; 38 | } 39 | 40 | @Override 41 | public String name() { 42 | return name; 43 | } 44 | 45 | 46 | @Override 47 | public SubjectHandle owner() { 48 | return owner; 49 | } 50 | 51 | @Override 52 | public Product get() throws IOException, BintrayCallException { 53 | ProductDetails productDetails = getProductDetails(); 54 | return new ProductImpl(productDetails); 55 | } 56 | 57 | @Override 58 | public ProductHandle update(ProductDetails productDetails) throws IOException, BintrayCallException { 59 | Map headers = new HashMap<>(); 60 | String jsonContent = ObjectMapperHelper.get().writeValueAsString(productDetails); 61 | BintrayImpl.addContentTypeJsonHeader(headers); 62 | bintrayHandle.patch(getProductUri(), headers, IOUtils.toInputStream(jsonContent)); 63 | return this; 64 | } 65 | 66 | @Override 67 | public ProductHandle addPackages(List packages) throws IOException, BintrayCallException { 68 | ProductDetails details = getProductDetails(); 69 | packages.addAll(details.getPackages()); 70 | details.setPackages(packages); 71 | update(details); 72 | return this; 73 | } 74 | 75 | @Override 76 | public ProductHandle delete() throws BintrayCallException { 77 | bintrayHandle.delete(getProductUri(), null); 78 | return this; 79 | } 80 | 81 | @Override 82 | public boolean exists() throws BintrayCallException { 83 | try { 84 | bintrayHandle.get(getProductUri(), null); 85 | } catch (BintrayCallException e) { 86 | if (e.getStatusCode() == 404) { 87 | return false; 88 | } 89 | throw e; 90 | } 91 | return true; 92 | } 93 | 94 | private ProductDetails getProductDetails() throws IOException { 95 | HttpResponse response = bintrayHandle.get(getProductUri(), null); 96 | ProductDetails productDetails; 97 | InputStream jsonContentStream = response.getEntity().getContent(); 98 | ObjectMapper mapper = ObjectMapperHelper.get(); 99 | try { 100 | productDetails = mapper.readValue(jsonContentStream, ProductDetails.class); 101 | } catch (IOException e) { 102 | log.error("Can't parse the json file: " + e.getMessage()); 103 | throw e; 104 | } 105 | return productDetails; 106 | } 107 | 108 | private String getProductUri() { 109 | return String.format(API_PRODUCTS + "%s/%s", owner.name(), name); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/RepositoryHandleImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 5 | import com.jfrog.bintray.client.api.details.PackageDetails; 6 | import com.jfrog.bintray.client.api.details.RepositoryDetails; 7 | import com.jfrog.bintray.client.api.handle.AttributesSearchQuery; 8 | import com.jfrog.bintray.client.api.handle.PackageHandle; 9 | import com.jfrog.bintray.client.api.handle.RepositoryHandle; 10 | import com.jfrog.bintray.client.api.handle.SubjectHandle; 11 | import com.jfrog.bintray.client.api.model.Pkg; 12 | import com.jfrog.bintray.client.api.model.Repository; 13 | import com.jfrog.bintray.client.impl.model.PackageImpl; 14 | import com.jfrog.bintray.client.impl.model.RepositoryImpl; 15 | import org.apache.commons.io.IOUtils; 16 | import org.apache.http.HttpHeaders; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.entity.ContentType; 19 | import org.codehaus.jackson.map.ObjectMapper; 20 | import org.codehaus.jackson.type.TypeReference; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.StringWriter; 27 | import java.util.ArrayList; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS; 33 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_REPOS; 34 | 35 | /** 36 | * @author Dan Feldman 37 | */ 38 | class RepositoryHandleImpl implements RepositoryHandle { 39 | private static final Logger log = LoggerFactory.getLogger(RepositoryHandleImpl.class); 40 | 41 | private BintrayImpl bintrayHandle; 42 | private SubjectHandleImpl owner; 43 | private String name; 44 | private AttributesSearchQueryImpl searchQuery = null; 45 | 46 | public RepositoryHandleImpl(BintrayImpl bintrayHandle, SubjectHandleImpl owner, String repoName) { 47 | this.bintrayHandle = bintrayHandle; 48 | this.owner = owner; 49 | this.name = repoName; 50 | } 51 | 52 | @Override 53 | public SubjectHandle owner() { 54 | return owner; 55 | } 56 | 57 | @Override 58 | public Repository get() throws IOException, BintrayCallException { 59 | HttpResponse response = bintrayHandle.get(getRepositoryUri(), null); 60 | RepositoryDetails repoDetails; 61 | InputStream jsonContentStream = response.getEntity().getContent(); 62 | ObjectMapper mapper = ObjectMapperHelper.get(); 63 | try { 64 | repoDetails = mapper.readValue(jsonContentStream, RepositoryDetails.class); 65 | } catch (IOException e) { 66 | log.error("Can't parse the json file: " + e.getMessage()); 67 | throw e; 68 | } 69 | return new RepositoryImpl(repoDetails); 70 | } 71 | 72 | @Override 73 | public RepositoryHandle update(RepositoryDetails repositoryDetails) throws IOException, BintrayCallException { 74 | Map headers = new HashMap<>(); 75 | String jsonContent = RepositoryImpl.getUpdateJson(repositoryDetails); 76 | BintrayImpl.addContentTypeJsonHeader(headers); 77 | bintrayHandle.patch(getRepositoryUri(), headers, IOUtils.toInputStream(jsonContent)); 78 | return this; 79 | } 80 | 81 | @Override 82 | public PackageHandle pkg(String packageName) { 83 | return new PackageHandleImpl(bintrayHandle, this, packageName); 84 | } 85 | 86 | @Override 87 | public PackageHandle createPkg(PackageDetails packageDetails) throws IOException, BintrayCallException { 88 | String jsonContent = PackageImpl.getCreateUpdateJson(packageDetails); 89 | bintrayHandle.post(String.format(API_PKGS + "%s/%s", owner.name(), name), null, IOUtils.toInputStream(jsonContent)); 90 | return new PackageHandleImpl(bintrayHandle, this, packageDetails.getName()).setAttributes(packageDetails); 91 | } 92 | 93 | @Override 94 | public AttributesSearchQuery searchForPackage() { 95 | return new AttributesSearchQueryImpl(this); 96 | } 97 | 98 | @Override 99 | public RepositoryHandle delete() throws BintrayCallException { 100 | bintrayHandle.delete(getRepositoryUri(), null); 101 | return this; 102 | } 103 | 104 | @Override 105 | public String name() { 106 | return name; 107 | } 108 | 109 | @Override 110 | public boolean exists() throws BintrayCallException { 111 | try { 112 | bintrayHandle.head(getRepositoryUri(), null); 113 | } catch (BintrayCallException e) { 114 | if (e.getStatusCode() == 404) { 115 | return false; 116 | } 117 | throw e; 118 | } 119 | return true; 120 | } 121 | 122 | @Override 123 | public String getRepositoryUri() { 124 | return String.format(API_REPOS + "%s/%s", owner.name(), name); 125 | } 126 | 127 | public void addQuery(AttributesSearchQueryImpl query) { 128 | searchQuery = query; 129 | } 130 | 131 | /** 132 | * Searches for packages according to the attribute search query supplied to addQuery 133 | * 134 | * @return a list of packages that were returned by Bintray's search 135 | * @throws IOException 136 | * @throws BintrayCallException 137 | */ 138 | public List attributeSearch() throws IOException, BintrayCallException { 139 | ObjectMapper mapper = ObjectMapperHelper.get(); 140 | StringWriter writer = new StringWriter(); 141 | try { 142 | mapper.writeValue(writer, searchQuery); 143 | } catch (IOException e) { 144 | log.error("Error writing search query to json: ", e); 145 | throw e; 146 | } 147 | 148 | Map headers = new HashMap<>(); 149 | headers.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()); 150 | HttpResponse response = bintrayHandle.post("/search/attributes/" + owner.name() + "/" + name, headers, 151 | IOUtils.toInputStream(writer.toString())); 152 | 153 | List answer; 154 | answer = mapper.readValue(response.getEntity().getContent(), new TypeReference>() { 155 | }); 156 | 157 | List packages = new ArrayList<>(); 158 | for (PackageDetails pkgDetails : answer) { 159 | packages.add(new PackageImpl(pkgDetails)); 160 | } 161 | searchQuery = null; 162 | return packages; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/SubjectHandleImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 5 | import com.jfrog.bintray.client.api.details.ProductDetails; 6 | import com.jfrog.bintray.client.api.details.RepositoryDetails; 7 | import com.jfrog.bintray.client.api.details.SubjectDetails; 8 | import com.jfrog.bintray.client.api.handle.ProductHandle; 9 | import com.jfrog.bintray.client.api.handle.RepositoryHandle; 10 | import com.jfrog.bintray.client.api.handle.SubjectHandle; 11 | import com.jfrog.bintray.client.api.model.Subject; 12 | import com.jfrog.bintray.client.impl.model.RepositoryImpl; 13 | import com.jfrog.bintray.client.impl.model.SubjectImpl; 14 | import org.apache.commons.io.IOUtils; 15 | import org.apache.http.HttpResponse; 16 | import org.codehaus.jackson.map.ObjectMapper; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.*; 26 | 27 | /** 28 | * @author Dan Feldman 29 | */ 30 | class SubjectHandleImpl implements SubjectHandle { 31 | private static final Logger log = LoggerFactory.getLogger(SubjectHandleImpl.class); 32 | 33 | private BintrayImpl bintrayHandle; 34 | private String subject; 35 | 36 | SubjectHandleImpl(BintrayImpl bintrayHandle, String subject) { 37 | this.bintrayHandle = bintrayHandle; 38 | this.subject = subject; 39 | } 40 | 41 | @Override 42 | public String name() { 43 | return subject; 44 | } 45 | 46 | @Override 47 | public RepositoryHandle repository(String repoName) { 48 | return new RepositoryHandleImpl(bintrayHandle, this, repoName); 49 | } 50 | 51 | @Override 52 | public RepositoryHandle createRepo(RepositoryDetails repoDetails) throws IOException, BintrayCallException { 53 | Map headers = new HashMap<>(); 54 | String jsonContent = RepositoryImpl.getCreateJson(repoDetails); 55 | BintrayImpl.addContentTypeJsonHeader(headers); 56 | bintrayHandle.post(getRepoUri(repoDetails), headers, IOUtils.toInputStream(jsonContent)); 57 | return new RepositoryHandleImpl(bintrayHandle, this, repoDetails.getName()); 58 | } 59 | 60 | @Override 61 | public ProductHandle product(String name) { 62 | return new ProductHandleImpl(bintrayHandle, this, name); 63 | } 64 | 65 | @Override 66 | public ProductHandle createProduct(ProductDetails productDetails) throws IOException, BintrayCallException { 67 | Map headers = new HashMap<>(); 68 | String jsonContent = ObjectMapperHelper.get().writeValueAsString(productDetails); 69 | BintrayImpl.addContentTypeJsonHeader(headers); 70 | bintrayHandle.post(getProductUri(), headers, IOUtils.toInputStream(jsonContent)); 71 | return new ProductHandleImpl(bintrayHandle, this, productDetails.getName()); 72 | } 73 | 74 | @Override 75 | public Subject get() throws IOException, BintrayCallException { 76 | HttpResponse response = bintrayHandle.get(API_USERS + subject, null); 77 | SubjectDetails subjectDetails; 78 | InputStream jsonContentStream = response.getEntity().getContent(); 79 | ObjectMapper mapper = ObjectMapperHelper.get(); 80 | try { 81 | subjectDetails = mapper.readValue(jsonContentStream, SubjectDetails.class); 82 | } catch (IOException e) { 83 | log.error("Can't process the json file: " + e.getMessage()); 84 | throw e; 85 | } 86 | return new SubjectImpl(subjectDetails); 87 | } 88 | 89 | private String getRepoUri(RepositoryDetails repoDetails) { 90 | return String.format(API_REPOS + "%s/%s", subject, repoDetails.getName()); 91 | } 92 | 93 | private String getProductUri() { 94 | return API_PRODUCTS + "/" + subject; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/handle/VersionHandleImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.handle; 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException; 4 | import com.jfrog.bintray.client.api.MultipleBintrayCallException; 5 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 6 | import com.jfrog.bintray.client.api.details.Attribute; 7 | import com.jfrog.bintray.client.api.details.VersionDetails; 8 | import com.jfrog.bintray.client.api.handle.PackageHandle; 9 | import com.jfrog.bintray.client.api.handle.VersionHandle; 10 | import com.jfrog.bintray.client.api.model.Version; 11 | import com.jfrog.bintray.client.impl.model.VersionImpl; 12 | import org.apache.commons.io.IOUtils; 13 | import org.apache.commons.lang.StringUtils; 14 | import org.apache.http.HttpResponse; 15 | import org.codehaus.jackson.map.ObjectMapper; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.*; 26 | 27 | /** 28 | * @author Dan Feldman 29 | */ 30 | class VersionHandleImpl implements VersionHandle { 31 | private static final Logger log = LoggerFactory.getLogger(VersionHandleImpl.class); 32 | 33 | private static final String OVERRIDE_HEADER = "X-Bintray-Override"; 34 | private static final String DEB_DIST_HEADER = "X-Bintray-Debian-Distribution"; 35 | private static final String DEB_COMP_HEADER = "X-Bintray-Debian-Component"; 36 | private static final String DEB_ARCH_HEADER = "X-Bintray-Debian-Architecture"; 37 | 38 | private BintrayImpl bintrayHandle; 39 | private String name; 40 | private PackageHandle packageHandle; 41 | 42 | public VersionHandleImpl(BintrayImpl bintrayHandle, PackageHandle packageHandle, String versionName) { 43 | this.bintrayHandle = bintrayHandle; 44 | this.packageHandle = packageHandle; 45 | this.name = versionName; 46 | } 47 | 48 | @Override 49 | public PackageHandle pkg() { 50 | return packageHandle; 51 | } 52 | 53 | @Override 54 | public String name() { 55 | return name; 56 | } 57 | 58 | @Override 59 | public Version get() throws BintrayCallException, IOException { 60 | HttpResponse response = bintrayHandle.get(getVersionUri(), null); 61 | VersionDetails versionDetails; 62 | ObjectMapper mapper = ObjectMapperHelper.get(); 63 | try { 64 | InputStream jsonContentStream = response.getEntity().getContent(); 65 | versionDetails = mapper.readValue(jsonContentStream, VersionDetails.class); 66 | } catch (IOException e) { 67 | log.debug("{}", e); 68 | log.error("Can't process the json file: {}", e.getMessage()); 69 | throw e; 70 | } 71 | return new VersionImpl(versionDetails); 72 | } 73 | 74 | @Override 75 | public VersionHandle update(VersionDetails versionDetails) throws IOException, BintrayCallException { 76 | Map headers = new HashMap<>(); 77 | String jsonContent = VersionImpl.getCreateUpdateJson(versionDetails); 78 | BintrayImpl.addContentTypeJsonHeader(headers); 79 | bintrayHandle.patch(getVersionUri(), headers, IOUtils.toInputStream(jsonContent)); 80 | 81 | return this.updateAttributes(versionDetails); 82 | } 83 | 84 | @Override 85 | public VersionHandle delete() throws BintrayCallException { 86 | bintrayHandle.delete(getVersionUri(), null); 87 | return this; 88 | } 89 | 90 | @Override 91 | public boolean exists() throws BintrayCallException { 92 | try { 93 | bintrayHandle.head(getVersionUri(), null); 94 | } catch (BintrayCallException e) { 95 | if (e.getStatusCode() == 404) { 96 | return false; 97 | } 98 | throw e; 99 | } 100 | return true; 101 | } 102 | 103 | @Override 104 | public VersionHandle setAttributes(VersionDetails versionDetails) throws IOException, BintrayCallException { 105 | return setAttributes(versionDetails.getAttributes()); 106 | } 107 | 108 | @Override 109 | public VersionHandle setAttributes(List attributes) throws IOException, BintrayCallException { 110 | if (attributes == null) { 111 | return this; 112 | } 113 | Map headers = new HashMap<>(); 114 | String jsonContent = Attribute.getJsonFromAttributeList(attributes); 115 | BintrayImpl.addContentTypeJsonHeader(headers); 116 | bintrayHandle.post(getVersionUri() + API_ATTR, headers, IOUtils.toInputStream(jsonContent)); 117 | return this; 118 | } 119 | 120 | @Override 121 | public VersionHandle updateAttributes(VersionDetails versionDetails) throws IOException, BintrayCallException { 122 | return updateAttributes(versionDetails.getAttributes()); 123 | } 124 | 125 | @Override 126 | public VersionHandle updateAttributes(List attributes) throws IOException, BintrayCallException { 127 | if (attributes == null) { 128 | return this; 129 | } 130 | Map headers = new HashMap<>(); 131 | String jsonContent = Attribute.getJsonFromAttributeList(attributes); 132 | BintrayImpl.addContentTypeJsonHeader(headers); 133 | bintrayHandle.patch(getVersionUri() + API_ATTR, headers, IOUtils.toInputStream(jsonContent)); 134 | return this; 135 | } 136 | 137 | @Override 138 | public VersionHandle upload(Map content) throws MultipleBintrayCallException { 139 | return upload(content, false); 140 | } 141 | 142 | @Override 143 | public VersionHandle upload(Map content, boolean overrideExisting) throws MultipleBintrayCallException { 144 | Map uriConvertedContent = new HashMap<>(); 145 | for (String path : content.keySet()) { 146 | uriConvertedContent.put(getUploadUriWithPath(path), content.get(path)); 147 | } 148 | Map headers = null; 149 | if (overrideExisting) { 150 | headers = getOverrideHeader(); 151 | } 152 | bintrayHandle.putBinary(uriConvertedContent, headers); 153 | return this; 154 | } 155 | 156 | @Override 157 | public VersionHandle upload(String path, InputStream content) throws BintrayCallException { 158 | return upload(path, content, false); 159 | } 160 | 161 | @Override 162 | public VersionHandle upload(String path, InputStream content, boolean overrideExisting) throws BintrayCallException { 163 | Map headers = null; 164 | if (overrideExisting) { 165 | headers = getOverrideHeader(); 166 | } 167 | bintrayHandle.putBinary(getUploadUriWithPath(path), headers, content); 168 | return this; 169 | } 170 | 171 | @Override 172 | public VersionHandle uploadVagrant(String path, String boxProvider, InputStream content) throws BintrayCallException { 173 | return uploadVagrant(path, boxProvider, content, false); 174 | } 175 | 176 | @Override 177 | public VersionHandle uploadVagrant(String path, String boxProvider, InputStream content, boolean overrideExisting) throws BintrayCallException { 178 | Map headers = null; 179 | if (overrideExisting) { 180 | headers = getOverrideHeader(); 181 | } 182 | bintrayHandle.putBinary(getVagrantUploadUri(path, boxProvider), headers, content); 183 | return this; 184 | } 185 | 186 | @Override 187 | public VersionHandle uploadDebian(String path, String distribution, String component, String architecture, 188 | InputStream content) throws BintrayCallException { 189 | return uploadDebian(path, distribution, component, architecture, content, false); 190 | } 191 | 192 | @Override 193 | public VersionHandle uploadDebian(String path, String distribution, String component, String architecture, 194 | InputStream content, boolean overrideExisting) throws BintrayCallException { 195 | Map headers = getDebianCoordinatesHeaders(distribution, component, architecture); 196 | if (overrideExisting) { 197 | headers.putAll(getOverrideHeader()); 198 | } 199 | bintrayHandle.putBinary(getUploadUriWithPath(path), headers, content); 200 | return this; 201 | } 202 | 203 | public VersionHandle uploadDebian(String path, List distributions, List components, 204 | List architectures, InputStream content) throws BintrayCallException { 205 | return uploadDebian(path, distributions, components, architectures, content, false); 206 | } 207 | 208 | @Override 209 | public VersionHandle uploadDebian(String path, List distributions, List components, 210 | List architectures, InputStream content, boolean overrideExisting) throws BintrayCallException { 211 | Map headers = getDebianCoordinatesHeaders(distributions, components, architectures); 212 | if (overrideExisting) { 213 | headers.putAll(getOverrideHeader()); 214 | } 215 | bintrayHandle.putBinary(getUploadUriWithPath(path), headers, content); 216 | return this; 217 | } 218 | 219 | @Override 220 | public VersionHandle publish() throws BintrayCallException { 221 | return publish(null); 222 | } 223 | 224 | @Override 225 | public VersionHandle publish(String gpgPassphrase) throws BintrayCallException { 226 | Map headers = null; 227 | if (StringUtils.isNotBlank(gpgPassphrase)) { 228 | headers = new HashMap<>(); 229 | headers.put(GPG_SIGN_HEADER, gpgPassphrase); 230 | } 231 | bintrayHandle.post(getCurrentVersionContentUri() + API_PUBLISH, headers); 232 | return this; 233 | } 234 | 235 | @Override 236 | public VersionHandle publishSync() throws BintrayCallException { 237 | Map headers = new HashMap<>(); 238 | BintrayImpl.addContentTypeJsonHeader(headers); 239 | int timeout = -1; 240 | String wait = "{\"publish_wait_for_secs\":" + timeout + "}"; 241 | bintrayHandle.post(getCurrentVersionContentUri() + API_PUBLISH, headers, IOUtils.toInputStream(wait)); 242 | return this; 243 | } 244 | 245 | @Override 246 | public VersionHandle discard() throws BintrayCallException { 247 | Map headers = new HashMap<>(); 248 | BintrayImpl.addContentTypeJsonHeader(headers); 249 | String discard = "{\n\"discard\":true\n}"; 250 | bintrayHandle.post(getCurrentVersionContentUri() + API_PUBLISH, headers, IOUtils.toInputStream(discard)); 251 | return this; 252 | } 253 | 254 | 255 | @Override 256 | public VersionHandle sign(int fileCount) throws BintrayCallException { 257 | return sign(null, fileCount); 258 | } 259 | 260 | @Override 261 | public VersionHandle sign(String passphrase, int fileCount) throws BintrayCallException { 262 | Map headers = new HashMap<>(); 263 | if (!(passphrase == null) && !passphrase.equals("")) { 264 | headers.put(GPG_SIGN_HEADER, passphrase); 265 | } 266 | bintrayHandle.sign(getCurrentVersionGpgUri(), headers, fileCount); 267 | return null; 268 | } 269 | 270 | /** 271 | * @return packages/$owner/$repo/$package/versions/$version/ 272 | */ 273 | @Override 274 | public String getVersionUri() { 275 | return API_PKGS + getCurrentVersionFullyQualifiedUri(); 276 | } 277 | 278 | /** 279 | * @return gpg/$owner/$repo/$package/versions/$version/ 280 | */ 281 | public String getCurrentVersionGpgUri() { 282 | return API_GPG + getCurrentVersionFullyQualifiedUri(); 283 | } 284 | 285 | /** 286 | * @return content/$owner/$repo/$package/$version/ 287 | */ 288 | public String getCurrentVersionContentUri() { 289 | return String.format(API_CONTENT + "%s/%s/%s/%s", packageHandle.repository().owner().name(), 290 | packageHandle.repository().name(), packageHandle.name(), name); 291 | } 292 | 293 | /** 294 | * @return $owner/$repo/$package/versions/$version/ 295 | */ 296 | private String getCurrentVersionFullyQualifiedUri() { 297 | return String.format("%s/%s/%s/" + API_VER + "%s", packageHandle.repository().owner().name(), 298 | packageHandle.repository().name(), packageHandle.name(), name); 299 | } 300 | 301 | private String getVagrantUploadUri(String path, String boxProvider) { 302 | return getUploadUriWithPath(path) + "?box_provider=" + boxProvider; 303 | } 304 | 305 | private String getUploadUriWithPath(String path) { 306 | return getCurrentVersionContentUri() + "/" + path; 307 | } 308 | 309 | private Map getDebianCoordinatesHeaders(List distributions, List components, 310 | List architectures) { 311 | return getDebianCoordinatesHeaders(StringUtils.join(distributions, ","), StringUtils.join(components, ","), 312 | StringUtils.join(architectures, ",")); 313 | } 314 | 315 | private Map getDebianCoordinatesHeaders(String distribution, String component, 316 | String architecture) { 317 | Map coordinatesHeaders = new HashMap<>(); 318 | coordinatesHeaders.put(DEB_DIST_HEADER, distribution); 319 | coordinatesHeaders.put(DEB_COMP_HEADER, component); 320 | coordinatesHeaders.put(DEB_ARCH_HEADER, architecture); 321 | return coordinatesHeaders; 322 | } 323 | 324 | private Map getOverrideHeader() { 325 | Map headers = new HashMap<>(); 326 | headers.put(OVERRIDE_HEADER, "1"); 327 | return headers; 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/model/PackageImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.model; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import com.jfrog.bintray.client.api.details.PackageDetails; 5 | import com.jfrog.bintray.client.api.model.Pkg; 6 | import org.codehaus.jackson.map.ObjectMapper; 7 | import org.joda.time.DateTime; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author Noam Y. Tenne 17 | */ 18 | public class PackageImpl implements Pkg { 19 | private static final Logger log = LoggerFactory.getLogger(PackageImpl.class); 20 | 21 | private String name; 22 | private String repository; 23 | private String owner; 24 | private String description; 25 | private List labels; 26 | private List attributeNames; 27 | private Integer rating; 28 | private Integer ratingCount; 29 | private Integer followersCount; 30 | private DateTime created; 31 | private List versions; 32 | private String latestVersion; 33 | private DateTime updated; 34 | private List linkedToRepos; 35 | private List systemIds; 36 | private List licenses; 37 | private String vcsUrl; 38 | private Map other; 39 | 40 | public PackageImpl(PackageDetails packageDetails) { 41 | this.name = packageDetails.getName(); 42 | this.repository = packageDetails.getRepo(); 43 | this.owner = packageDetails.getOwner(); 44 | this.description = packageDetails.getDescription(); 45 | this.labels = packageDetails.getLabels(); 46 | this.attributeNames = packageDetails.getAttributeNames(); 47 | this.ratingCount = packageDetails.getRatingCount(); 48 | this.followersCount = packageDetails.getFollowersCount(); 49 | this.created = packageDetails.getCreated(); 50 | this.versions = packageDetails.getVersions(); 51 | this.latestVersion = packageDetails.getLatestVersion(); 52 | this.updated = packageDetails.getUpdated(); 53 | this.linkedToRepos = packageDetails.getLinkedRepos(); 54 | this.systemIds = packageDetails.getSystemIds(); 55 | this.licenses = packageDetails.getLicenses(); 56 | this.vcsUrl = packageDetails.getVcsUrl(); 57 | this.other = packageDetails.other(); 58 | } 59 | 60 | public PackageImpl(String name, String repository, String owner, String description, List labels, 61 | List attributeNames, Integer rating, Integer ratingCount, Integer followersCount, 62 | DateTime created, List versions, String latestVersion, DateTime updated, 63 | List linkedToRepos, List systemIds) { 64 | this.name = name; 65 | this.repository = repository; 66 | this.owner = owner; 67 | this.description = description; 68 | this.labels = labels; 69 | this.attributeNames = attributeNames; 70 | this.rating = rating; 71 | this.ratingCount = ratingCount; 72 | this.followersCount = followersCount; 73 | this.created = created; 74 | this.versions = versions; 75 | this.latestVersion = latestVersion; 76 | this.updated = updated; 77 | this.linkedToRepos = linkedToRepos; 78 | this.systemIds = systemIds; 79 | } 80 | 81 | public static String getCreateUpdateJson(PackageDetails packageDetails) throws IOException { 82 | ObjectMapper mapper = ObjectMapperHelper.get(); 83 | String jsonContent; 84 | try { 85 | jsonContent = mapper.writeValueAsString(packageDetails); 86 | } catch (IOException e) { 87 | log.error("Can't process the json file: " + e.getMessage()); 88 | throw e; 89 | } 90 | return jsonContent; 91 | } 92 | 93 | @Override 94 | public String name() { 95 | return name; 96 | } 97 | 98 | @Override 99 | public String repository() { 100 | return repository; 101 | } 102 | 103 | @Override 104 | public String owner() { 105 | return owner; 106 | } 107 | 108 | @Override 109 | public String description() { 110 | return description; 111 | } 112 | 113 | @Override 114 | public List labels() { 115 | return labels; 116 | } 117 | 118 | @Override 119 | public List attributeNames() { 120 | return attributeNames; 121 | } 122 | 123 | @Override 124 | public Integer rating() { 125 | return rating; 126 | } 127 | 128 | @Override 129 | public Integer ratingCount() { 130 | return ratingCount; 131 | } 132 | 133 | @Override 134 | public Integer followersCount() { 135 | return followersCount; 136 | } 137 | 138 | @Override 139 | public DateTime created() { 140 | return created; 141 | } 142 | 143 | @Override 144 | public List versions() { 145 | return versions; 146 | } 147 | 148 | @Override 149 | public String latestVersion() { 150 | return latestVersion; 151 | } 152 | 153 | @Override 154 | public DateTime updated() { 155 | return updated; 156 | } 157 | 158 | @Override 159 | public List linkedToRepos() { 160 | return linkedToRepos; 161 | } 162 | 163 | @Override 164 | public List systemIds() { 165 | return systemIds; 166 | } 167 | 168 | @Override 169 | public List licenses() { 170 | return licenses; 171 | } 172 | 173 | @Override 174 | public String vcsUrl() { 175 | return vcsUrl; 176 | } 177 | 178 | @Override 179 | public Object getFieldByKey(String key) { 180 | return other.get(key); 181 | } 182 | 183 | @Override 184 | public boolean equals(Object o) { 185 | if (this == o) return true; 186 | if (o == null || getClass() != o.getClass()) return false; 187 | 188 | PackageImpl aPackage = (PackageImpl) o; 189 | 190 | if (!name.equals(aPackage.name)) return false; 191 | 192 | return true; 193 | } 194 | 195 | @Override 196 | public int hashCode() { 197 | return name.hashCode(); 198 | } 199 | 200 | @Override 201 | public String toString() { 202 | return "Package{" + 203 | "getName='" + name + '\'' + 204 | ", repository='" + repository + '\'' + 205 | ", owner='" + owner + '\'' + 206 | ", description='" + description + '\'' + 207 | ", labels=" + labels + 208 | ", attributeNames=" + attributeNames + 209 | ", rating=" + rating + 210 | ", ratingCount=" + ratingCount + 211 | ", followersCount=" + followersCount + 212 | ", created=" + created + 213 | ", versions=" + versions + 214 | ", latestVersion='" + latestVersion + '\'' + 215 | ", updated=" + updated + 216 | ", linkedToRepos='" + linkedToRepos + '\'' + 217 | ", systemIds=" + systemIds + 218 | '}'; 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/model/ProductImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.model; 2 | 3 | import com.jfrog.bintray.client.api.details.ProductDetails; 4 | import com.jfrog.bintray.client.api.model.Product; 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author Dan Feldman 12 | */ 13 | public class ProductImpl implements Product { 14 | 15 | private String name; 16 | private String owner; 17 | private String description; 18 | private DateTime created; 19 | private String websiteUrl; 20 | private String vcsUrl; 21 | private List packages; 22 | private List versions; 23 | private Map other; 24 | 25 | public ProductImpl() { 26 | } 27 | 28 | public ProductImpl(ProductDetails productDetails) { 29 | this.name = productDetails.getName(); 30 | this.owner = productDetails.getOwner(); 31 | this.description = productDetails.getDescription(); 32 | this.created = productDetails.getCreated(); 33 | this.websiteUrl = productDetails.getWebsiteUrl(); 34 | this.vcsUrl = productDetails.getVcsUrl(); 35 | this.packages = productDetails.getPackages(); 36 | this.versions = productDetails.getVersions(); 37 | this.other = productDetails.other(); 38 | } 39 | 40 | public ProductImpl(String name, String owner, String description, List packages, List versions, 41 | DateTime created, String websiteUrl, String vcsUrl) { 42 | this.name = name; 43 | this.owner = owner; 44 | this.description = description; 45 | this.created = created; 46 | this.websiteUrl = websiteUrl; 47 | this.vcsUrl = vcsUrl; 48 | this.packages = packages; 49 | this.versions = versions; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public String getOwner() { 57 | return owner; 58 | } 59 | 60 | @Override 61 | public String getDescription() { 62 | return description; 63 | } 64 | 65 | @Override 66 | public DateTime getCreated() { 67 | return created; 68 | } 69 | 70 | @Override 71 | public String getWebsiteUrl() { 72 | return websiteUrl; 73 | } 74 | 75 | @Override 76 | public String getVcsUrl() { 77 | return vcsUrl; 78 | } 79 | 80 | @Override 81 | public List getPackages() { 82 | return packages; 83 | } 84 | 85 | @Override 86 | public List getVersions() { 87 | return versions; 88 | } 89 | 90 | @Override 91 | public Object getFieldByKey(String key) { 92 | return other.get(key); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/model/RepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.model; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import com.jfrog.bintray.client.api.details.RepositoryDetails; 5 | import com.jfrog.bintray.client.api.model.Repository; 6 | import org.codehaus.jackson.JsonGenerator; 7 | import org.codehaus.jackson.map.ObjectMapper; 8 | import org.joda.time.DateTime; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.io.IOException; 13 | import java.io.StringWriter; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @author Noam Y. Tenne 19 | */ 20 | public class RepositoryImpl implements Repository { 21 | private static final Logger log = LoggerFactory.getLogger(RepositoryImpl.class); 22 | 23 | private String name; 24 | private String owner; 25 | private String type; 26 | private Boolean isPrivate; 27 | private Boolean premium; 28 | private String desc; 29 | private List labels; 30 | private DateTime created; 31 | private Integer packageCount; 32 | private Map other; 33 | 34 | public RepositoryImpl() { 35 | } 36 | 37 | public RepositoryImpl(RepositoryDetails repositoryDetails) { 38 | this.name = repositoryDetails.getName(); 39 | this.owner = repositoryDetails.getOwner(); 40 | this.type = repositoryDetails.getType(); 41 | this.isPrivate = repositoryDetails.getIsPrivate(); 42 | this.premium = repositoryDetails.getPremium(); 43 | this.desc = repositoryDetails.getDescription(); 44 | this.labels = repositoryDetails.getLabels(); 45 | this.created = repositoryDetails.getCreated(); 46 | this.packageCount = repositoryDetails.getPackageCount(); 47 | this.other = repositoryDetails.other(); 48 | } 49 | 50 | public RepositoryImpl(String name, String owner, String type, Boolean isPrivate, Boolean premium, String desc, 51 | List labels, DateTime created, Integer packageCount) { 52 | this.name = name; 53 | this.owner = owner; 54 | this.type = type; 55 | this.isPrivate = isPrivate; 56 | this.premium = premium; 57 | this.desc = desc; 58 | this.labels = labels; 59 | this.created = created; 60 | this.packageCount = packageCount; 61 | } 62 | 63 | public static String getCreateJson(RepositoryDetails repositoryDetails) throws IOException { 64 | ObjectMapper mapper = ObjectMapperHelper.get(); 65 | try { 66 | return mapper.writeValueAsString(repositoryDetails); 67 | } catch (IOException e) { 68 | log.error("Can't process the json file: " + e.getMessage()); 69 | log.debug("{}", e); 70 | throw e; 71 | } 72 | } 73 | 74 | /** 75 | * PATCH repo only accepts description and label updates, name is needed for URL creation, because of the special 76 | * ignore and property structure of the RepositoryDetails class this method just uses a json generator to write 77 | * the update json. 78 | */ 79 | public static String getUpdateJson(RepositoryDetails repositoryDetails) throws IOException { 80 | StringWriter writer = new StringWriter(); 81 | JsonGenerator jGen = ObjectMapperHelper.get().getJsonFactory().createJsonGenerator(writer); 82 | jGen.writeStartObject(); 83 | jGen.writeStringField("name", repositoryDetails.getName()); 84 | jGen.writeStringField("desc", repositoryDetails.getDescription()); 85 | if (repositoryDetails.getLabels().size() > 0) { 86 | jGen.writeArrayFieldStart("labels"); 87 | for (String label : repositoryDetails.getLabels()) { 88 | jGen.writeString(label); 89 | } 90 | jGen.writeEndArray(); 91 | } 92 | jGen.writeEndObject(); 93 | jGen.close(); 94 | writer.close(); 95 | return writer.toString(); 96 | } 97 | 98 | 99 | @Override 100 | public String getName() { 101 | return name; 102 | } 103 | 104 | @Override 105 | public String getOwner() { 106 | return owner; 107 | } 108 | 109 | @Override 110 | public String getType() { 111 | return type; 112 | } 113 | 114 | @Override 115 | public Boolean isPrivate() { 116 | return isPrivate; 117 | } 118 | 119 | @Override 120 | public Boolean isPremium() { 121 | return premium; 122 | } 123 | 124 | @Override 125 | public String getDesc() { 126 | return desc; 127 | } 128 | 129 | @Override 130 | public List getLabels() { 131 | return labels; 132 | } 133 | 134 | @Override 135 | public DateTime getCreated() { 136 | return created; 137 | } 138 | 139 | @Override 140 | public Integer getPackageCount() { 141 | return packageCount; 142 | } 143 | 144 | @Override 145 | public Object getFieldByKey(String key) { 146 | return other.get(key); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/model/SubjectImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.model; 2 | 3 | import com.jfrog.bintray.client.api.details.SubjectDetails; 4 | import com.jfrog.bintray.client.api.model.Subject; 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.Collection; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author Noam Y. Tenne 12 | */ 13 | public class SubjectImpl implements Subject { 14 | 15 | private String name; 16 | private String fullName; 17 | private String gravatarId; 18 | private Collection repositories; 19 | private Collection organizations; 20 | private Integer followersCount; 21 | private DateTime registered; 22 | private Long quotaUsedBytes; 23 | private Map other; 24 | 25 | public SubjectImpl() { 26 | } 27 | 28 | public SubjectImpl(SubjectDetails subjectDetails) { 29 | this.name = subjectDetails.getName(); 30 | this.fullName = subjectDetails.getFullName(); 31 | this.gravatarId = subjectDetails.getGravatarId(); 32 | this.repositories = subjectDetails.getRepos(); 33 | this.organizations = subjectDetails.getOrganizations(); 34 | this.followersCount = subjectDetails.getFollowersCount(); 35 | this.registered = subjectDetails.getRegistered(); 36 | this.quotaUsedBytes = subjectDetails.getQuotaUsedBytes(); 37 | this.other = subjectDetails.other(); 38 | } 39 | 40 | public SubjectImpl(String name, String fullName, String gravatarId, Collection repositories, 41 | Collection organizations, Integer followersCount, DateTime registered, Long quotaUsedBytes) { 42 | this.name = name; 43 | this.fullName = fullName; 44 | this.gravatarId = gravatarId; 45 | this.repositories = repositories; 46 | this.organizations = organizations; 47 | this.followersCount = followersCount; 48 | this.registered = registered; 49 | this.quotaUsedBytes = quotaUsedBytes; 50 | } 51 | 52 | @Override 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | @Override 58 | public String getFullName() { 59 | return fullName; 60 | } 61 | 62 | @Override 63 | public String getGravatarId() { 64 | return gravatarId; 65 | } 66 | 67 | @Override 68 | public Collection getRepositories() { 69 | return repositories; 70 | } 71 | 72 | @Override 73 | public Collection getOrganizations() { 74 | return organizations; 75 | } 76 | 77 | @Override 78 | public Integer getFollowersCount() { 79 | return followersCount; 80 | } 81 | 82 | @Override 83 | public DateTime getRegistered() { 84 | return registered; 85 | } 86 | 87 | @Override 88 | public Long getQuotaUsedBytes() { 89 | return quotaUsedBytes; 90 | } 91 | 92 | @Override 93 | public Object getFieldByKey(String key) { 94 | return other.get(key); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/model/VersionImpl.java: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.impl.model; 2 | 3 | import com.jfrog.bintray.client.api.ObjectMapperHelper; 4 | import com.jfrog.bintray.client.api.details.VersionDetails; 5 | import com.jfrog.bintray.client.api.model.Version; 6 | import org.codehaus.jackson.map.ObjectMapper; 7 | import org.joda.time.DateTime; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author Noam Y. Tenne 17 | */ 18 | public class VersionImpl implements Version { 19 | private static final Logger log = LoggerFactory.getLogger(VersionImpl.class); 20 | 21 | private String name; 22 | private String description; 23 | private String pkg; 24 | private String repository; 25 | private String owner; 26 | private List labels; 27 | private List attributeNames; 28 | private DateTime created; 29 | private DateTime updated; 30 | private DateTime released; 31 | private Integer ordinal; 32 | private String vcsTag; 33 | private Map other; 34 | 35 | public VersionImpl() { 36 | } 37 | 38 | public VersionImpl(VersionDetails versionDetails) { 39 | this.name = versionDetails.getName(); 40 | this.description = versionDetails.getDescription(); 41 | this.pkg = versionDetails.getPkg(); 42 | this.repository = versionDetails.getRepo(); 43 | this.owner = versionDetails.getOwner(); 44 | this.labels = versionDetails.getLabels(); 45 | this.attributeNames = versionDetails.getAttributeNames(); 46 | this.created = versionDetails.getCreated(); 47 | this.updated = versionDetails.getUpdated(); 48 | this.released = versionDetails.getReleased(); 49 | this.ordinal = versionDetails.getOrdinal(); 50 | this.vcsTag = versionDetails.getVcsTag(); 51 | this.other = versionDetails.other(); 52 | } 53 | 54 | public VersionImpl(String name, String description, String pkg, String repository, String owner, List labels, 55 | List attributeNames, DateTime created, DateTime updated, DateTime released, int ordinal, String vcsTag) { 56 | this.name = name; 57 | this.description = description; 58 | this.pkg = pkg; 59 | this.repository = repository; 60 | this.owner = owner; 61 | this.labels = labels; 62 | this.attributeNames = attributeNames; 63 | this.created = created; 64 | this.updated = updated; 65 | this.released = released; 66 | this.ordinal = ordinal; 67 | this.vcsTag = vcsTag; 68 | } 69 | 70 | public static String getCreateUpdateJson(VersionDetails versionDetails) throws IOException { 71 | ObjectMapper mapper = ObjectMapperHelper.get(); 72 | String jsonContent; 73 | try { 74 | jsonContent = mapper.writeValueAsString(versionDetails); 75 | } catch (IOException e) { 76 | log.error("Can't process the json file: " + e.getMessage()); 77 | log.debug("{}", e); 78 | throw e; 79 | } 80 | return jsonContent; 81 | } 82 | 83 | @Override 84 | public String name() { 85 | return name; 86 | } 87 | 88 | @Override 89 | public String description() { 90 | return description; 91 | } 92 | 93 | @Override 94 | public String pkg() { 95 | return pkg; 96 | } 97 | 98 | @Override 99 | public String repository() { 100 | return repository; 101 | } 102 | 103 | @Override 104 | public String owner() { 105 | return owner; 106 | } 107 | 108 | @Override 109 | public List labels() { 110 | return labels; 111 | } 112 | 113 | @Override 114 | public List attributeNames() { 115 | return attributeNames; 116 | } 117 | 118 | @Override 119 | public DateTime created() { 120 | return created; 121 | } 122 | 123 | @Override 124 | public DateTime updated() { 125 | return updated; 126 | } 127 | 128 | @Override 129 | public DateTime released() { 130 | return released; 131 | } 132 | 133 | @Override 134 | public Integer ordinal() { 135 | return ordinal; 136 | } 137 | 138 | @Override 139 | public String vcsTag() { 140 | return vcsTag; 141 | } 142 | 143 | public Object getFieldByKey(String key) { 144 | return other.get(key); 145 | } 146 | 147 | @Override 148 | public boolean equals(Object o) { 149 | if (this == o) return true; 150 | if (o == null || getClass() != o.getClass()) return false; 151 | 152 | VersionImpl version = (VersionImpl) o; 153 | 154 | if (!name.equals(version.name)) return false; 155 | 156 | return true; 157 | } 158 | 159 | @Override 160 | public int hashCode() { 161 | return name.hashCode(); 162 | } 163 | 164 | @Override 165 | public String toString() { 166 | return "Version{" + 167 | "getName='" + name + '\'' + 168 | ", description='" + description + '\'' + 169 | ", pkg='" + pkg + '\'' + 170 | ", repository='" + repository + '\'' + 171 | ", owner='" + owner + '\'' + 172 | ", labels=" + labels + 173 | ", attributeNames=" + attributeNames + 174 | ", created=" + created + 175 | ", updated=" + updated + 176 | ", released=" + released + 177 | ", ordinal=" + ordinal + 178 | '}'; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /impl/src/main/java/com/jfrog/bintray/client/impl/util/URIUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v 1.27 2004/05/05 20:34:01 olegk Exp $ 3 | * $Revision: 507321 $ 4 | * $Date: 2007-02-14 01:10:51 +0100 (Wed, 14 Feb 2007) $ 5 | * 6 | * ==================================================================== 7 | * 8 | * Licensed to the Apache Software Foundation (ASF) under one or more 9 | * contributor license agreements. See the NOTICE file distributed with 10 | * this work for additional information regarding copyright ownership. 11 | * The ASF licenses this file to You under the Apache License, Version 2.0 12 | * (the "License"); you may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * ==================================================================== 23 | * 24 | * This software consists of voluntary contributions made by many 25 | * individuals on behalf of the Apache Software Foundation. For more 26 | * information on the Apache Software Foundation, please see 27 | * . 28 | * 29 | */ 30 | /* 31 | * Based on apache-httpclient 3.1 org.apache.commons.httpclient.util.URIUtil.java 32 | * Additional contributors: 33 | * JFrog Ltd. 34 | */ 35 | package com.jfrog.bintray.client.impl.util; 36 | 37 | import org.apache.commons.codec.DecoderException; 38 | import org.apache.commons.codec.net.URLCodec; 39 | import org.apache.http.HttpException; 40 | import org.apache.http.util.EncodingUtils; 41 | 42 | import java.util.BitSet; 43 | 44 | /** 45 | * The URI escape and character encoding and decoding utility. 46 | * It's compatible with {org.apache.commons.httpclient.HttpURL} rather 47 | * than {org.apache.commons.httpclient.URI}. 48 | * 49 | * @author Sung-Gu 50 | * @version $Revision: 507321 $ $Date: 2002/03/14 15:14:01 51 | */ 52 | public class URIUtil { 53 | 54 | private static final String UTF8_CHARSET_NAME = "UTF-8"; 55 | 56 | /** 57 | * Escape and encode a string regarded as the query component of an URI with 58 | * the default protocol charset. 59 | * When a query string is not misunderstood the reserved special characters 60 | * ("&", "=", "+", ",", and "$") within a query component, this method 61 | * is recommended to use in encoding the whole query. 62 | * 63 | * @param unescaped an unescaped string 64 | * @return the escaped string 65 | * @throws HttpException if the default protocol charset is not supported 66 | * @see #encode 67 | */ 68 | public static String encodeQuery(String unescaped) throws HttpException { 69 | return encodeQuery(unescaped, UTF8_CHARSET_NAME); 70 | } 71 | 72 | 73 | /** 74 | * Escape and encode a string regarded as the query component of an URI with 75 | * a given charset. 76 | * When a query string is not misunderstood the reserved special characters 77 | * ("&", "=", "+", ",", and "$") within a query component, this method 78 | * is recommended to use in encoding the whole query. 79 | * 80 | * @param unescaped an unescaped string 81 | * @param charset the charset 82 | * @return the escaped string 83 | * @throws HttpException if the charset is not supported 84 | * @see #encode 85 | */ 86 | public static String encodeQuery(String unescaped, String charset) 87 | throws HttpException { 88 | 89 | return encode(unescaped, URI.allowed_query, charset); 90 | } 91 | 92 | 93 | /** 94 | * Escape and encode a given string with allowed characters not to be 95 | * escaped and the default protocol charset. 96 | * 97 | * @param unescaped a string 98 | * @param allowed allowed characters not to be escaped 99 | * @return the escaped string 100 | * @throws HttpException if the default protocol charset is not supported 101 | */ 102 | public static String encode(String unescaped, BitSet allowed) 103 | throws HttpException { 104 | 105 | return encode(unescaped, allowed, UTF8_CHARSET_NAME); 106 | } 107 | 108 | 109 | /** 110 | * Escape and encode a given string with allowed characters not to be 111 | * escaped and a given charset. 112 | * 113 | * @param unescaped a string 114 | * @param allowed allowed characters not to be escaped 115 | * @param charset the charset 116 | * @return the escaped string 117 | */ 118 | public static String encode(String unescaped, BitSet allowed, 119 | String charset) throws HttpException { 120 | byte[] rawdata = URLCodec.encodeUrl(allowed, 121 | EncodingUtils.getBytes(unescaped, charset)); 122 | return EncodingUtils.getAsciiString(rawdata); 123 | } 124 | 125 | 126 | /** 127 | * Unescape and decode a given string regarded as an escaped string with the 128 | * default protocol charset. 129 | * 130 | * @param escaped a string 131 | * @return the unescaped string 132 | * @throws HttpException if the string cannot be decoded (invalid) 133 | */ 134 | public static String decode(String escaped) throws HttpException { 135 | try { 136 | byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped)); 137 | return EncodingUtils.getString(rawdata, UTF8_CHARSET_NAME); 138 | } catch (DecoderException e) { 139 | throw new HttpException(e.getMessage()); 140 | } 141 | } 142 | 143 | 144 | /** 145 | * Unescape and decode a given string regarded as an escaped string. 146 | * 147 | * @param escaped a string 148 | * @param charset the charset 149 | * @return the unescaped string 150 | * @throws HttpException if the charset is not supported 151 | */ 152 | public static String decode(String escaped, String charset) 153 | throws HttpException { 154 | 155 | return URI.decode(escaped.toCharArray(), charset); 156 | } 157 | } 158 | 159 | -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/BintraySpecSuite.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test 2 | 3 | import ch.qos.logback.classic.Level 4 | import ch.qos.logback.classic.Logger 5 | import ch.qos.logback.classic.LoggerContext 6 | import com.jfrog.bintray.client.api.BintrayCallException 7 | import com.jfrog.bintray.client.api.details.Attribute 8 | import com.jfrog.bintray.client.api.details.PackageDetails 9 | import com.jfrog.bintray.client.api.details.RepositoryDetails 10 | import com.jfrog.bintray.client.api.details.VersionDetails 11 | import com.jfrog.bintray.client.api.handle.Bintray 12 | import com.jfrog.bintray.client.impl.BintrayClient 13 | import com.jfrog.bintray.client.impl.HttpClientConfigurator 14 | import com.jfrog.bintray.client.impl.handle.BintrayImpl 15 | import com.jfrog.bintray.client.test.spec.* 16 | import org.apache.http.auth.UsernamePasswordCredentials 17 | import org.codehaus.jackson.map.ObjectMapper 18 | import org.junit.BeforeClass 19 | import org.junit.runner.RunWith 20 | import org.junit.runners.Suite 21 | import org.slf4j.LoggerFactory 22 | import spock.lang.Shared 23 | 24 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_REPOS 25 | 26 | /** 27 | * @author Dan Feldman 28 | */ 29 | @RunWith(Suite) 30 | @Suite.SuiteClasses([RepoSpec.class, PackageSpec.class, VersionSpec.class, BintrayClientSpec.class, ProductSpec.class, SpecialArtifactUploadSpec.class]) 31 | class BintraySpecSuite { 32 | 33 | public static final String REPO_CREATE_NAME = 'repoTest' 34 | public static final String TEST_PRODUCT_NAME = 'test-product' 35 | public static final String REPO_NAME = 'generic' 36 | public static final String PKG_NAME = 'bla' 37 | public static final String VERSION = '1.0' 38 | public static final String ATTRIBUTE_NAME = 'att1' 39 | public static final String ATTRIBUTE_VALUE = 'bla' 40 | @Shared 41 | public static Properties connectionProperties 42 | @Shared 43 | public static Bintray bintray 44 | @Shared 45 | public static BintrayImpl restClient 46 | @Shared 47 | public static PackageDetails pkgBuilder 48 | @Shared 49 | public static VersionDetails versionBuilder 50 | @Shared 51 | public static String tempPkgName = "PkgTest" 52 | @Shared 53 | public static String tempVerName = "3.0" 54 | @Shared 55 | public static String pkgJson 56 | @Shared 57 | public static String verJson 58 | @Shared 59 | public static String repoJson 60 | @Shared 61 | public static String genericRepoJson 62 | @Shared 63 | public static String productJson 64 | 65 | public static ArrayList> attributes = [ 66 | new Attribute('a', Attribute.Type.string, "ay1", "ay2"), 67 | new Attribute('b', 'b', 'e'), 68 | new Attribute('c', 'cee')] 69 | 70 | 71 | public static String expectedPkgAttributes = 72 | '[[values:[ay1, ay2], name:a, type:string], [values:[cee], name:c, type:string], [values:[e, b], name:b, type:string]]' 73 | public static String expectedVerAttributes = 74 | '[[values:[ay1, ay2], name:a, type:string], [values:[cee], name:c, type:string], [values:[e, b], name:b, type:string]]' 75 | 76 | public 77 | static String assortedAttributes = "[{\"name\":\"verAttr2\",\"values\":[\"val1\",\"val2\"],\"type\":\"string\"}," + 78 | "{\"name\":\"verAttr3\",\"values\":[1,2.2,4],\"type\":\"number\"},{\"name\":\"verAttr2\"," + 79 | "\"values\":[\"2011-07-14T19:43:37+0100\"],\"type\":\"date\"}]" 80 | 81 | @BeforeClass 82 | def static void setup() { 83 | connectionProperties = new Properties() 84 | def streamFromProperties = this.class.getResourceAsStream('/bintray-client.properties') 85 | if (streamFromProperties) { 86 | streamFromProperties.withStream { 87 | connectionProperties.load(it) 88 | } 89 | } 90 | def usernameFromEnv = System.getenv('BINTRAY_USERNAME') 91 | if (usernameFromEnv) { 92 | connectionProperties.username = usernameFromEnv 93 | } 94 | def apiKeyFromEnv = System.getenv('BINTRAY_API_KEY') 95 | if (apiKeyFromEnv) { 96 | connectionProperties.apiKey = apiKeyFromEnv 97 | } 98 | def orgFromEnv = System.getenv('BINTRAY_ORG') 99 | if (orgFromEnv) { 100 | connectionProperties.org = orgFromEnv 101 | } 102 | assert connectionProperties 103 | assert connectionProperties.username 104 | assert connectionProperties.apiKey 105 | 106 | bintray = BintrayClient.create(getApiUrl(), 107 | connectionProperties.username as String, 108 | connectionProperties.apiKey as String) 109 | 110 | restClient = createClient() 111 | 112 | pkgBuilder = new PackageDetails(PKG_NAME).description('bla-bla').labels(['l1', 'l2']) 113 | .licenses(['Apache-2.0']).vcsUrl("https://github.com/bintray/bintray-client-java.git") 114 | 115 | versionBuilder = new VersionDetails(VERSION).description('versionDesc') 116 | 117 | pkgJson = "{\n" + 118 | "\t\t\"name\": \"" + tempPkgName + "\",\n" + 119 | "\t\t\"repo\": \"generic\",\n" + 120 | "\t\t\"owner\": \"" + connectionProperties.username + "\",\n" + 121 | "\t\t\"desc\": \"Bintray Client Java\",\n" + 122 | "\t\t\"website_url\": \"http://www.jfrog.com\",\n" + 123 | "\t\t\"issue_tracker_url\": \"https://github.com/bintray/bintray-client-java/issues\",\n" + 124 | "\t\t\"vcs_url\": \"https://github.com/bintray/bintray-client-java.git\",\n" + 125 | "\t\t\"licenses\": [\"MIT\"],\n" + 126 | "\t\t\"labels\": [\"cool\", \"awesome\", \"gorilla\"],\n" + 127 | "\t\t\"public_download_numbers\": false,\n" + 128 | "\t\t\"attributes\": [{\"name\": \"att1\", \"values\" : [\"val1\"], \"type\": \"string\"},\n" + 129 | "\t\t\t\t\t {\"name\": \"att3\", \"values\" : [1, 3.3, 5], \"type\": \"number\"},\n" + 130 | "\t\t\t\t\t {\"name\": \"att5\", \"values\" : [\"2011-07-14T19:43:37+0100\"], \"type\": \"date\"}]\n" + 131 | "}" 132 | 133 | verJson = "{\n" + 134 | " \"name\": \"" + tempVerName + "\",\n" + 135 | " \"desc\": \"Version Test\",\n" + 136 | " \"package\": \"" + tempPkgName + "\",\n" + 137 | " \"repo\": \"generic\",\n" + 138 | " \"owner\": \"" + connectionProperties.username + "\",\n" + 139 | " \"labels\": [\"cool\",\"awesome\",\"gorilla\"],\n" + 140 | " \"attribute_names\": [\"verAtt1\",\"verAtt2\",\"verAtt3\"],\n" + 141 | " \"released\": \" 2015-01-07T18:00:00.000-06:00\",\n" + 142 | " \"github_use_tag_release_notes\": false,\n" + 143 | " \"vcs_tag\": \"3.8\",\n" + 144 | " \"ordinal\": 0,\n" + 145 | " \"attributes\": [{\"name\": \"VerAtt1\",\"values\": [\"VerVal1\"],\"type\": \"string\"},\n" + 146 | " {\"name\": \"VerAtt2\",\"values\": [1,3.3,5],\"type\": \"number\"},\n" + 147 | " {\"name\": \"VerAtt3\",\"values\": [\"2015-01-01T19:43:37+0100\"],\"type\": \"date\"}]\n" + 148 | "}" 149 | 150 | repoJson = "{\n" + 151 | " \"name\": \"" + REPO_CREATE_NAME + "\",\n" + 152 | " \"type\": \"maven\",\n" + 153 | " \"private\": false,\n" + 154 | " \"premium\": false,\n" + 155 | " \"desc\": \"Test Repo\",\n" + 156 | " \"labels\":[\"lable1\", \"label2\"]\n" + 157 | "}" 158 | 159 | genericRepoJson = "{\n" + 160 | " \"name\": \"" + REPO_NAME + "\",\n" + 161 | " \"type\": \"generic\",\n" + 162 | " \"private\": false,\n" + 163 | " \"premium\": false,\n" + 164 | " \"desc\": \"Generic Test Repo\",\n" + 165 | " \"labels\":[\"testLabel1\", \"testLabel2\"]\n" + 166 | "}" 167 | 168 | productJson = "{\n" + 169 | " \"name\": \"" + TEST_PRODUCT_NAME + "\",\n" + 170 | " \"desc\": \"product description\",\n" + 171 | " \"website_url\": \"http://great-prod.io\",\n" + 172 | " \"vcs_url\": \"https://github.com/bintray/bintray-client-java\",\n" + 173 | " \"sign_url_expiry\": 10\n" + 174 | "}" 175 | 176 | LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); 177 | //Set level for root logger 178 | loggerContext.getLogger("ROOT").setLevel(Level.INFO) 179 | //Disable debug for org.apache.http - you can tweak the level here 180 | Logger httpLogger = loggerContext.getLogger("org.apache.http"); 181 | httpLogger.setLevel(Level.INFO); 182 | } 183 | 184 | public static BintrayImpl createClient() { 185 | return createClient(null) 186 | } 187 | 188 | public static BintrayImpl createClient(String url) { 189 | url = (url ?: getApiUrl()) 190 | UsernamePasswordCredentials creds = new UsernamePasswordCredentials(connectionProperties.username as String, 191 | connectionProperties.apiKey as String) 192 | 193 | HttpClientConfigurator conf = new HttpClientConfigurator() 194 | return new BintrayImpl(conf.hostFromUrl(url).noRetry().authentication(creds).getClient(), url, 5, 90000) 195 | } 196 | 197 | public static String getApiUrl() { 198 | return connectionProperties.bintrayUrl ?: BintrayClient.BINTRAY_API_URL 199 | } 200 | 201 | public static String getDownloadUrl() { 202 | return connectionProperties.bintrayDownloadUrl ?: 'https://dl.bintray.com' 203 | } 204 | 205 | public static void createRepoIfNeeded(String repoName, String repoJson) { 206 | if (!bintray.subject(connectionProperties.username).repository(repoName).exists()) { 207 | ObjectMapper mapper = new ObjectMapper() 208 | RepositoryDetails repositoryDetails = mapper.readValue(repoJson, RepositoryDetails.class) 209 | bintray.subject(connectionProperties.username).createRepo(repositoryDetails) 210 | } 211 | } 212 | 213 | public static void deleteRepo(String repoName) { 214 | try { 215 | String repo = "/" + API_REPOS + connectionProperties.username + "/" + repoName 216 | restClient.delete(repo, null) 217 | } catch (BintrayCallException bce) { 218 | if (bce.getStatusCode() != 404) { 219 | System.err.println("cleanup: " + bce) 220 | } 221 | } catch (Exception e) { 222 | System.err.println("cleanup: " + e) 223 | } 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/BintrayClientSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException 4 | import com.jfrog.bintray.client.api.ObjectMapperHelper 5 | import com.jfrog.bintray.client.api.details.Attribute 6 | import com.jfrog.bintray.client.api.details.PackageDetails 7 | import com.jfrog.bintray.client.api.details.VersionDetails 8 | import com.jfrog.bintray.client.api.handle.Bintray 9 | import com.jfrog.bintray.client.api.handle.PackageHandle 10 | import com.jfrog.bintray.client.api.handle.RepositoryHandle 11 | import com.jfrog.bintray.client.api.handle.VersionHandle 12 | import com.jfrog.bintray.client.impl.BintrayClient 13 | import com.jfrog.bintray.client.impl.HttpClientConfigurator 14 | import com.jfrog.bintray.client.impl.handle.BintrayImpl 15 | import com.jfrog.bintray.client.impl.model.PackageImpl 16 | import com.jfrog.bintray.client.impl.model.VersionImpl 17 | import org.apache.commons.io.IOUtils 18 | import org.codehaus.jackson.map.ObjectMapper 19 | import spock.lang.Shared 20 | import spock.lang.Specification 21 | 22 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS 23 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 24 | import static org.apache.http.HttpStatus.SC_NOT_FOUND 25 | import static org.apache.http.HttpStatus.SC_OK 26 | 27 | /** 28 | * @author Noam Y. Tenne 29 | * @author Dan Feldman 30 | * 31 | */ 32 | class BintrayClientSpec extends Specification { 33 | 34 | @Shared 35 | private static Map files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 36 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 37 | 38 | def void setup() { 39 | createRepoIfNeeded(REPO_NAME, genericRepoJson) 40 | } 41 | 42 | def 'Test correct URL encoding'() { 43 | setup: 44 | def path1 = "content/user/" + REPO_NAME + "/" + PKG_NAME + "/" + VERSION + "/com/jfrog/bintray/bintray-test/1.0/bintray-test-1.0.pom;publish=1" 45 | def path2 = "docker/bla/dockertest/v1/repositories/library/ubuntu" 46 | def path3 = "docker/bla/dockertest/v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json with space.ext" 47 | def path4 = "bla/someUser/test?a=b&c=d" 48 | def path5 = "bla/someUser/testMatrix;a+=b" 49 | def path6 = "t%st/spe^al/ch&ar\$/*()!#/ok?" 50 | 51 | when: 52 | def encodedPath1 = ((BintrayImpl) bintray).createUrl(path1) 53 | def encodedPath2 = ((BintrayImpl) bintray).createUrl(path2) 54 | def encodedPath3 = ((BintrayImpl) bintray).createUrl(path3) 55 | def encodedPath4 = ((BintrayImpl) bintray).createUrl(path4) 56 | def encodedPath5 = ((BintrayImpl) bintray).createUrl(path5) 57 | def encodedPath6 = ((BintrayImpl) bintray).createUrl(path6) 58 | 59 | then: 60 | String url = getApiUrl() 61 | encodedPath1.toString().equals(url + "/content/user/generic/bla/1.0/com/jfrog/bintray/bintray-test/1.0/bintray-test-1.0.pom;publish=1") 62 | encodedPath2.toString().equals(url + "/docker/bla/dockertest/v1/repositories/library/ubuntu") 63 | encodedPath3.toString().equals(url + "/docker/bla/dockertest/v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json%20with%20space.ext") 64 | encodedPath4.toString().equals(url + "/bla/someUser/test?a=b&c=d") 65 | encodedPath5.toString().equals(url + "/bla/someUser/testMatrix;a+=b") 66 | encodedPath6.toString().equals(url + "/t%25st/spe%5Eal/ch&ar\$/*()!%23/ok?") 67 | } 68 | 69 | def 'on error response is returned without parsing'() { 70 | setup: 71 | Bintray wrongBintray = BintrayClient.create(getApiUrl(), 72 | connectionProperties.username as String, 73 | connectionProperties.apiKey as String) 74 | when: 75 | wrongBintray.subject('bla').get() 76 | then: 77 | BintrayCallException e = thrown() 78 | e.statusCode == SC_NOT_FOUND 79 | e.reason == 'Not Found' 80 | } 81 | 82 | def 'wrong subject gives 404'() { 83 | when: 84 | bintray.subject('bla').get() 85 | then: 86 | BintrayCallException e = thrown() 87 | e.statusCode == SC_NOT_FOUND 88 | } 89 | 90 | def 'files uploaded and can be accessed by the author'() { 91 | setup: 92 | def ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder) 93 | def downloadServerClient = createClient(getDownloadUrl()) 94 | files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 95 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 96 | 97 | when: 98 | ver.upload(files) 99 | sleep(4000) 100 | def get1 = downloadServerClient.get("/" + connectionProperties.username + "/" + REPO_NAME + "/" + files.keySet().asList().get(0), null) 101 | def get2 = downloadServerClient.get("/" + connectionProperties.username + "/" + REPO_NAME + "/" + files.keySet().asList().get(1), null) 102 | 103 | then: 104 | get1.getStatusLine().getStatusCode() == SC_OK 105 | and: 106 | get2.getStatusLine().getStatusCode() == SC_OK 107 | } 108 | 109 | def 'unpublished files can\'t be seen by anonymous'() { 110 | setup: 111 | sleep(15000) //wait for previous deletions to propagate 112 | def ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder) 113 | HttpClientConfigurator conf = new HttpClientConfigurator(); 114 | String url = getDownloadUrl() 115 | def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl(url).noRetry().noCookies().getClient(), url, 5, 90000) 116 | files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 117 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 118 | 119 | when: 120 | sleep(10000) 121 | ver.upload(files) 122 | sleep(20000) 123 | anonymousDownloadServerClient.get("/" + connectionProperties.username + "/" + REPO_NAME + "/" + files.keySet().asList().get(0), null) 124 | 125 | then: 126 | BintrayCallException bce = thrown() 127 | bce.getStatusCode().equals(401) 128 | } 129 | 130 | def 'publish artifacts'() { 131 | setup: 132 | files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 133 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 134 | VersionHandle ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder).upload(files) 135 | HttpClientConfigurator conf = new HttpClientConfigurator(); 136 | 137 | String url = getDownloadUrl() 138 | def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl(url).noRetry().getClient(), url, 5, 90000) 139 | 140 | when: 141 | sleep(5000) 142 | ver.publish() 143 | sleep(30000) 144 | def response = restClient.get("/" + connectionProperties.username + "/" + REPO_NAME + "/" + files.keySet().asList().get(0), null) 145 | 146 | then: 147 | response.getStatusLine().getStatusCode() == SC_OK 148 | } 149 | 150 | def 'sync-publish artifacts'() { 151 | setup: 152 | files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 153 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 154 | VersionHandle ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder).upload(files) 155 | HttpClientConfigurator conf = new HttpClientConfigurator(); 156 | 157 | String url = getDownloadUrl() 158 | def anonymousDownloadServerClient = new BintrayImpl(conf.hostFromUrl(url).noRetry().getClient(), url, 5, 90000) 159 | 160 | when: 161 | sleep(5000) 162 | try { 163 | ver.publishSync() 164 | } catch (BintrayCallException bce) { 165 | System.err.println("error while waiting for publish: " + bce) 166 | } 167 | sleep(30000) 168 | def response = restClient.get("/" + connectionProperties.username + "/" + REPO_NAME + "/" + files.keySet().asList().get(0), null) 169 | 170 | then: 171 | response.getStatusLine().getStatusCode() == SC_OK 172 | } 173 | 174 | def 'discard artifacts'() { 175 | setup: 176 | files = ['com/bla/bintray-client-java-api.jar' : getClass().getResourceAsStream('/testJar1.jar'), 177 | 'org/foo/bar/bintray-client-java-service.jar': getClass().getResourceAsStream('/testJar2.jar')] 178 | VersionHandle ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder).upload(files) 179 | 180 | when: 181 | sleep(4000) 182 | ver.discard() 183 | sleep(4000) //wait for propagation to dl and stuff 184 | 185 | String url = getDownloadUrl() 186 | "$url/$connectionProperties.username/$REPO_NAME/${files.keySet().asList().get(0)}".toURL().content 187 | 188 | then: 189 | IOException ioe = thrown() 190 | ioe.getMessage().contains("401") || ioe instanceof FileNotFoundException 191 | } 192 | 193 | def 'Attribute Serialization and Deserialization'() { 194 | setup: 195 | String attrs = assortedAttributes 196 | 197 | when: 198 | List attributes = Attribute.getAttributeListFromJson(IOUtils.toInputStream(attrs)) 199 | String out = Attribute.getJsonFromAttributeList(attributes) 200 | 201 | then: 202 | attributes.size == 3 203 | attributes.get(0).getName().equals("verAttr2") 204 | attributes.get(0).getType().equals(Attribute.Type.string) 205 | attributes.get(0).getValues() == ["val1", "val2"] 206 | out.equals(attrs) 207 | } 208 | 209 | def 'send empty values - verify they are not null'() { 210 | 211 | String minimalPkgName = "MyPackage" 212 | 213 | String minimalPkgJson = "{\n" + 214 | "\t\t\"name\": \"" + minimalPkgName + "\",\n" + 215 | "\t\t\"repo\": \"" + REPO_NAME + "\",\n" + 216 | "\t\t\"owner\": \"" + connectionProperties.username + "\",\n" + 217 | "\t\t\"desc\": \"\",\n" + 218 | "\t\t\"website_url\": \"\",\n" + 219 | "\t\t\"labels\": [],\n" + 220 | "\t\t\"vcs_url\": \"https://github.com/bintray/bintray-client-java.git\",\n" + 221 | "\t\t\"licenses\": [\"MIT\"]\n" + 222 | "}" 223 | 224 | String minimalVerJson = "{\n" + 225 | "\t\t\"name\": \"3.3.3\",\n" + 226 | "\t\t\"vcs_tag\": \"\",\n" + 227 | "\t\t\"labels\": null,\n" + 228 | "\t\t\"description\": \"\"\n" + 229 | "}" 230 | 231 | setup: 232 | ObjectMapper mapper = ObjectMapperHelper.get() 233 | 234 | ArrayList licenses = new ArrayList<>(); 235 | licenses.add("Apache-2.0") 236 | PackageDetails newPkgDetails = new PackageDetails(minimalPkgName); 237 | newPkgDetails.licenses(licenses); 238 | newPkgDetails.setRepo(REPO_NAME) 239 | newPkgDetails.setSubject(connectionProperties.username) 240 | newPkgDetails.setVcsUrl("https://github.com/bintray/bintray-client-java.git") 241 | newPkgDetails.setDescription("") 242 | 243 | VersionDetails newVerDetails = new VersionDetails("2.2.0") 244 | newVerDetails.setDescription("") 245 | 246 | PackageDetails pkgDetailsFromJson = mapper.readValue(minimalPkgJson, PackageDetails.class) 247 | VersionDetails verDetailsFromJson = mapper.readValue(minimalVerJson, VersionDetails.class) 248 | 249 | when: 250 | RepositoryHandle repo = bintray.subject(connectionProperties.username).repository(REPO_NAME) 251 | 252 | PackageHandle pkg = repo.createPkg(newPkgDetails) 253 | VersionHandle ver = pkg.createVersion(newVerDetails) 254 | 255 | pkg.update(pkgDetailsFromJson) 256 | ver.update(verDetailsFromJson) 257 | 258 | String pkgJsonContent = PackageImpl.getCreateUpdateJson(pkgDetailsFromJson); 259 | String verJsonContent = VersionImpl.getCreateUpdateJson(verDetailsFromJson); 260 | 261 | then: 262 | pkgJsonContent.equals("{\"name\":\"MyPackage\",\"labels\":[],\"licenses\":[\"MIT\"],\"desc\":\"\",\"website_url\":\"\",\"vcs_url\":\"https://github.com/bintray/bintray-client-java.git\"}") 263 | verJsonContent.contentEquals("{\"name\":\"3.3.3\",\"vcs_tag\":\"\"}") 264 | 265 | cleanup: 266 | try { 267 | String cleanPkg = "/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + minimalPkgName 268 | restClient.delete(cleanPkg, null) 269 | } catch (BintrayCallException bce) { 270 | if (bce.getStatusCode() != 404) { 271 | System.err.println("cleanup: " + bce) 272 | } 273 | } catch (Exception e) { 274 | System.err.println("cleanup: " + e) 275 | } 276 | } 277 | 278 | def cleanup() { 279 | deleteRepo(REPO_NAME) 280 | } 281 | } -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/PackageSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException 4 | import com.jfrog.bintray.client.api.details.Attribute 5 | import com.jfrog.bintray.client.api.details.PackageDetails 6 | import com.jfrog.bintray.client.api.handle.PackageHandle 7 | import com.jfrog.bintray.client.api.model.Pkg 8 | import com.jfrog.bintray.client.impl.model.PackageImpl 9 | import groovy.json.JsonSlurper 10 | import org.apache.commons.io.IOUtils 11 | import org.apache.http.HttpHeaders 12 | import org.codehaus.jackson.map.ObjectMapper 13 | import org.joda.time.DateTime 14 | import org.joda.time.format.ISODateTimeFormat 15 | import spock.lang.Specification 16 | 17 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_CONTENT 18 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS 19 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 20 | import static org.apache.http.HttpStatus.SC_NOT_FOUND 21 | 22 | /** 23 | * @author Dan Feldman 24 | */ 25 | class PackageSpec extends Specification { 26 | 27 | def void setup() { 28 | createRepoIfNeeded(REPO_NAME, genericRepoJson) 29 | } 30 | 31 | def 'Package created'() { 32 | setup: 33 | bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder) 34 | 35 | Map headers = new HashMap<>(); 36 | String auth = (connectionProperties.username + ":" + connectionProperties.apiKey) 37 | headers.put(HttpHeaders.AUTHORIZATION, "Basic " + auth.bytes.encodeBase64()) 38 | String path = "/" + API_CONTENT + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME + "/" + VERSION + "/com/jfrog/bintray/bintray-test/1.0/bintray-test-1.0.pom;publish=1" 39 | restClient.putBinary(path, headers, new ByteArrayInputStream('bla'.bytes)) 40 | 41 | when: 42 | Pkg pkg = bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).get() 43 | JsonSlurper slurper = new JsonSlurper() 44 | def actual = slurper.parseText(IOUtils.toString(restClient.get("/packages/$connectionProperties.username/$REPO_NAME/$PKG_NAME", null).entity.content)) 45 | 46 | then: 47 | pkg.name() == actual.name 48 | pkg.repository() == actual.repo 49 | pkg.owner() == actual.owner 50 | pkg.description() == actual.desc 51 | pkg.labels() == actual.labels 52 | pkg.attributeNames() == actual.attribute_names 53 | pkg.rating() == actual.rating?.toInteger() 54 | pkg.ratingCount() == actual.rating_count?.toInteger() 55 | pkg.followersCount() == actual.followers_count?.toInteger() 56 | pkg.created() == ISODateTimeFormat.dateTime().parseDateTime(actual.created as String) 57 | pkg.versions() == actual.versions 58 | pkg.latestVersion() == actual.latest_version 59 | pkg.updated() == ISODateTimeFormat.dateTime().parseDateTime(actual.updated as String) 60 | pkg.linkedToRepos() == actual.linked_to_repos 61 | pkg.systemIds() == actual.system_ids 62 | } 63 | 64 | def 'package exists'() { 65 | when: 66 | // Create the package: 67 | bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder) 68 | 69 | then: 70 | // Check that the package exists: 71 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).exists() 72 | 73 | when: 74 | // Delete the package: 75 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).delete() 76 | 77 | then: 78 | // Check that the package does not exist: 79 | !bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).exists() 80 | } 81 | 82 | def 'attributes set on package'() { 83 | setup: 84 | def pkg = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder) 85 | 86 | when: 87 | pkg.setAttributes(attributes) 88 | 89 | JsonSlurper slurper = new JsonSlurper() 90 | def actualPackage = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME, null).getEntity().getContent())) 91 | def actualAttributes = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME + "/attributes", null).getEntity().getContent())) 92 | 93 | then: 94 | ['a', 'b', 'c'] == actualPackage.attribute_names.sort() 95 | and: 96 | expectedPkgAttributes.equalsIgnoreCase(actualAttributes.sort().toString()) 97 | } 98 | 99 | def 'wrong package gives 404'() { 100 | when: 101 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg('bla').get() 102 | then: 103 | BintrayCallException e = thrown() 104 | e.statusCode == SC_NOT_FOUND 105 | } 106 | 107 | def 'Package Creation Using PackageDetails'() { 108 | setup: 109 | ObjectMapper mapper = new ObjectMapper(); 110 | PackageDetails pkgDetailsFromJson = mapper.readValue(pkgJson, PackageDetails.class) 111 | 112 | List attrs = new ArrayList<>(); 113 | attrs.add(new Attribute("att1", Attribute.Type.string, "val1")) 114 | attrs.add(new Attribute("att3", Attribute.Type.number, 1, 3.3, 5)) 115 | attrs.add(new Attribute("att5", Attribute.Type.date, DateTime.parse("2011-07-14T19:43:37+0100"))) 116 | 117 | PackageDetails pkgDetails = new PackageDetails(tempPkgName).description("Bintray Client Java").websiteUrl("http://www.jfrog.com") 118 | .issueTrackerUrl("https://github.com/bintray/bintray-client-java/issues").vcsUrl("https://github.com/bintray/bintray-client-java.git") 119 | .licenses(["MIT"]).labels(["cool", "awesome", "gorilla"]).publicDownloadNumbers(false).attributes(attrs) 120 | pkgDetails.setRepo("generic") 121 | pkgDetails.setOwner(bintray.subject(connectionProperties.username).name()) 122 | PackageImpl locallyCreated = new PackageImpl(pkgDetails); 123 | 124 | when: 125 | JsonSlurper slurper = new JsonSlurper() 126 | PackageHandle pkgHandle = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgDetailsFromJson) 127 | PackageImpl pkg = pkgHandle.get() 128 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName, null).getEntity().getContent())) 129 | List attributes = Attribute.getAttributeListFromJson(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName + "/attributes", null).getEntity().getContent()) 130 | 131 | then: 132 | //PackageImpl 133 | locallyCreated.equals(pkg) 134 | 135 | //jsons 136 | pkgDetailsFromJson.getName().equals(directJson.name) 137 | pkgDetailsFromJson.getRepo().equals(directJson.repo) 138 | pkgDetailsFromJson.getOwner().equals(directJson.owner) 139 | pkgDetailsFromJson.getDescription().equals(directJson.desc) 140 | pkgDetailsFromJson.getWebsiteUrl().equals(directJson.website_url) 141 | pkgDetailsFromJson.getIssueTrackerUrl().equals(directJson.issue_tracker_url) 142 | pkgDetailsFromJson.getVcsUrl().equals(directJson.vcs_url) 143 | for (int i = 0; i < pkgDetails.getLabels().size(); i++) { 144 | pkgDetails.getLabels().sort().get(i).equalsIgnoreCase(directJson.labels.sort()[i]) 145 | } 146 | pkgDetailsFromJson.getPublicDownloadNumbers().equals(directJson.public_download_numbers) 147 | 148 | //Attributes 149 | for (Attribute attr : attributes) { 150 | attr.equals(attrs.get(0)) || attr.equals(attrs.get(1)) || attr.equals(attrs.get(2)) 151 | } 152 | 153 | cleanup: 154 | try { 155 | String cleanPkg = "/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName 156 | restClient.delete(cleanPkg, null) 157 | } catch (BintrayCallException bce) { 158 | if (bce.getStatusCode() != 404) { 159 | System.err.println("cleanup: " + bce) 160 | } 161 | } catch (Exception e) { 162 | System.err.println("cleanup: " + e) 163 | } 164 | } 165 | 166 | def cleanup() { 167 | deleteRepo(REPO_NAME) 168 | } 169 | } -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/ProductSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException 4 | import com.jfrog.bintray.client.api.details.PackageDetails 5 | import com.jfrog.bintray.client.api.details.ProductDetails 6 | import com.jfrog.bintray.client.api.details.RepositoryDetails 7 | import com.jfrog.bintray.client.api.handle.ProductHandle 8 | import com.jfrog.bintray.client.api.handle.RepositoryHandle 9 | import com.jfrog.bintray.client.impl.model.ProductImpl 10 | import groovy.json.JsonSlurper 11 | import org.apache.commons.io.IOUtils 12 | import org.codehaus.jackson.map.ObjectMapper 13 | import spock.lang.IgnoreIf 14 | import spock.lang.Specification 15 | 16 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PRODUCTS 17 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 18 | 19 | /** 20 | * @author Dan Feldman 21 | */ 22 | class ProductSpec extends Specification { 23 | 24 | @IgnoreIf({ !testOrgDefined() }) 25 | def 'Product creation using ProductDetails'() { 26 | setup: 27 | ObjectMapper mapper = new ObjectMapper() 28 | ProductDetails productDetails = mapper.readValue(productJson, ProductDetails.class) 29 | 30 | when: 31 | JsonSlurper slurper = new JsonSlurper() 32 | ProductHandle productHandle = bintray.subject(connectionProperties.org).createProduct(productDetails) 33 | ProductImpl locallyCreated = new ProductImpl(productDetails); 34 | 35 | ProductImpl product = productHandle.get() as ProductImpl 36 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PRODUCTS + connectionProperties.org + "/" + TEST_PRODUCT_NAME, null).getEntity().getContent())) 37 | 38 | then: 39 | //ProductImpl 40 | locallyCreated.getName().equals(product.getName()) 41 | locallyCreated.getDescription().equals(product.getDescription()) 42 | locallyCreated.getOwner().equals(product.getOwner()) 43 | product.getPackages().isEmpty() 44 | locallyCreated.getVcsUrl().equals(product.getVcsUrl()) 45 | locallyCreated.getWebsiteUrl().equals(product.getWebsiteUrl()) 46 | 47 | and: 48 | //jsons 49 | TEST_PRODUCT_NAME.equals(directJson.name) 50 | productDetails.getDescription().equals(directJson.desc) 51 | productDetails.getOwner().equals(directJson.owner) 52 | productDetails.getVcsUrl().equals(directJson.vcs_url) 53 | productDetails.getWebsiteUrl().equals(directJson.website_url) 54 | } 55 | 56 | @IgnoreIf({ !testOrgDefined() }) 57 | def 'Product update using ProductDetails'() { 58 | setup: 59 | ObjectMapper mapper = new ObjectMapper() 60 | ProductDetails productDetails = mapper.readValue(productJson, ProductDetails.class) 61 | RepositoryDetails repositoryDetails = mapper.readValue(repoJson, RepositoryDetails.class) 62 | repositoryDetails.setPremium(true) 63 | PackageDetails packageDetails = mapper.readValue(pkgJson, PackageDetails.class) 64 | ProductHandle productHandle = bintray.subject(connectionProperties.org).createProduct(productDetails) 65 | RepositoryHandle repoHandle = bintray.subject(connectionProperties.org).createRepo(repositoryDetails) 66 | repoHandle.createPkg(packageDetails) 67 | 68 | productDetails.setDescription("new Description") 69 | List pkgs = new ArrayList(); 70 | pkgs.add(repoHandle.name() + "/" + packageDetails.name) 71 | productDetails.setPackages(pkgs) 72 | 73 | when: 74 | productHandle.update(productDetails) 75 | JsonSlurper slurper = new JsonSlurper() 76 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PRODUCTS + connectionProperties.org + "/" + TEST_PRODUCT_NAME, null).getEntity().getContent())) 77 | 78 | then: 79 | productDetails.getName().equals(directJson.name) 80 | productDetails.getDescription().equals(directJson.desc) 81 | productDetails.getPackages().equals(directJson.packages) 82 | } 83 | 84 | @IgnoreIf({ !testOrgDefined() }) 85 | def 'Delete product'() { 86 | setup: 87 | ObjectMapper mapper = new ObjectMapper() 88 | ProductDetails productDetails = mapper.readValue(productJson, ProductDetails.class) 89 | ProductHandle productHandle = bintray.subject(connectionProperties.org).createProduct(productDetails) 90 | 91 | when: 92 | bintray.subject(connectionProperties.org).product(productHandle.name()).exists() 93 | bintray.subject(connectionProperties.org).product((productHandle.name())).delete() 94 | 95 | then: 96 | !bintray.subject(connectionProperties.org).product((productHandle.name())).exists() 97 | } 98 | 99 | def cleanup() { 100 | String delProduct = "/" + API_PRODUCTS + connectionProperties.org + "/" + TEST_PRODUCT_NAME 101 | try { 102 | restClient.delete(delProduct, null) 103 | } catch (BintrayCallException bce) { 104 | if (bce.getStatusCode() != 404) { 105 | System.err.println("cleanup: " + bce) 106 | } 107 | } catch (Exception e) { 108 | System.err.println("cleanup: " + e) 109 | } 110 | 111 | deleteRepo(REPO_CREATE_NAME) 112 | } 113 | 114 | public static boolean testOrgDefined() { 115 | def tempConnProps = new Properties() 116 | def streamFromProperties = this.class.getResourceAsStream('/bintray-client.properties') 117 | if (streamFromProperties) { 118 | streamFromProperties.withStream { 119 | tempConnProps.load(it) 120 | } 121 | } 122 | def orgFromEnv = System.getenv('BINTRAY_ORG') 123 | if (orgFromEnv) { 124 | tempConnProps.org = orgFromEnv 125 | } 126 | tempConnProps.org != null; 127 | } 128 | } -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/RepoSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException 4 | import com.jfrog.bintray.client.api.details.RepositoryDetails 5 | import com.jfrog.bintray.client.api.handle.RepositoryHandle 6 | import com.jfrog.bintray.client.api.model.Pkg 7 | import com.jfrog.bintray.client.impl.model.RepositoryImpl 8 | import groovy.json.JsonSlurper 9 | import org.apache.commons.io.IOUtils 10 | import org.apache.http.HttpHeaders 11 | import org.apache.http.entity.ContentType 12 | import org.codehaus.jackson.map.ObjectMapper 13 | import spock.lang.Specification 14 | 15 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS 16 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_REPOS 17 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 18 | import static org.apache.http.HttpStatus.SC_NOT_FOUND 19 | 20 | /** 21 | * @author Dan Feldman 22 | */ 23 | class RepoSpec extends Specification { 24 | 25 | def void setup() { 26 | createRepoIfNeeded(REPO_NAME, genericRepoJson) 27 | } 28 | 29 | def 'Default Repos exist'(String repoName, def _) { 30 | expect: 31 | bintray.subject(connectionProperties.username).repository(repoName) 32 | 33 | where: 34 | repoName | _ 35 | 'maven' | _ 36 | 'rpm' | _ 37 | 'deb' | _ 38 | 'generic' | _ 39 | 'boxes' | _ 40 | 'registry'| _ 41 | 'nuget' | _ 42 | 'opkg' | _ 43 | } 44 | 45 | def 'search by attributes'() { 46 | setup: 47 | def repo = bintray.subject(connectionProperties.username).repository(REPO_NAME) 48 | 49 | repo.createPkg(pkgBuilder) 50 | String attributesQuery = "[{\"name\": \"" + ATTRIBUTE_NAME + "\", \"values\" : [\"" + ATTRIBUTE_VALUE + "\"], \"type\": \"string\"}]" 51 | def headers = new HashMap(); 52 | headers.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()); 53 | restClient.post("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME + "/" + "attributes", headers, 54 | new ByteArrayInputStream(attributesQuery.getBytes())) 55 | 56 | when: 57 | List results = repo.searchForPackage().byAttributeName(ATTRIBUTE_NAME).equalsVal(ATTRIBUTE_VALUE).searchPackage() 58 | 59 | then: 60 | results 61 | results.size() == 1 62 | Pkg pkg = results[0] 63 | pkg.name() == PKG_NAME 64 | pkg.attributeNames()[0] == ATTRIBUTE_NAME 65 | } 66 | 67 | def 'wrong repository gives 404'() { 68 | when: 69 | bintray.subject(connectionProperties.username).repository('bla').get() 70 | then: 71 | BintrayCallException e = thrown() 72 | e.statusCode == SC_NOT_FOUND 73 | } 74 | 75 | def 'Repo creation using RepositoryDetails'() { 76 | setup: 77 | ObjectMapper mapper = new ObjectMapper() 78 | RepositoryDetails repositoryDetails = mapper.readValue(repoJson, RepositoryDetails.class) 79 | 80 | when: 81 | JsonSlurper slurper = new JsonSlurper() 82 | RepositoryHandle repoHandle = bintray.subject(connectionProperties.username).createRepo(repositoryDetails) 83 | RepositoryImpl locallyCreated = new RepositoryImpl(repositoryDetails); 84 | 85 | RepositoryImpl repo = repoHandle.get() 86 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_REPOS + connectionProperties.username + "/" + REPO_CREATE_NAME, null).getEntity().getContent())) 87 | 88 | then: 89 | //RepoImpl 90 | locallyCreated.getType().equals(repo.getType()) 91 | locallyCreated.getName().equals(repo.getName()) 92 | locallyCreated.getIsPrivate().equals(repo.getIsPrivate()) 93 | locallyCreated.getPremium().equals(repo.getPremium()) 94 | locallyCreated.getDesc().equals(repo.getDesc()) 95 | locallyCreated.getLabels().sort().equals(repo.getLabels().sort()) 96 | 97 | and: 98 | //jsons 99 | REPO_CREATE_NAME.equals(directJson.name) 100 | repositoryDetails.getDescription().equals(directJson.desc) 101 | repositoryDetails.getIsPrivate().equals(directJson.private) 102 | repositoryDetails.getPremium().equals(directJson.premium) 103 | repositoryDetails.getType().equals(directJson.type) 104 | for (int i = 0; i < repositoryDetails.getLabels().size(); i++) { 105 | repositoryDetails.getLabels().sort().get(i).equalsIgnoreCase(directJson.labels.sort()[i]) 106 | } 107 | 108 | cleanup: 109 | try { 110 | String delRepo = "/" + API_REPOS + connectionProperties.username + "/" + REPO_CREATE_NAME 111 | restClient.delete(delRepo, null) 112 | } catch (Exception e) { 113 | System.err.println("cleanup: " + e) 114 | } 115 | } 116 | 117 | def 'Repo update using RepositoryDetails'() { 118 | setup: 119 | ObjectMapper mapper = new ObjectMapper() 120 | RepositoryDetails repositoryDetails = mapper.readValue(repoJson, RepositoryDetails.class) 121 | RepositoryHandle repoHandle = bintray.subject(connectionProperties.username).createRepo(repositoryDetails) 122 | 123 | def newLabels = ['newLabel1', 'newLabel2'] 124 | def newDescription = 'A new description for the updated repo' 125 | //Set repository details, user need to be trial\premium for private and premium feature 126 | repositoryDetails.setLabels(newLabels).setDescription(newDescription).setPremium(true).setIsPrivate(true) 127 | String updateDetailsJson = RepositoryImpl.getUpdateJson(repositoryDetails) 128 | RepositoryDetails updateDetails = mapper.readValue(updateDetailsJson, RepositoryDetails.class) 129 | 130 | when: 131 | repoHandle.update(updateDetails) 132 | JsonSlurper slurper = new JsonSlurper() 133 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_REPOS + connectionProperties.username + "/" + REPO_CREATE_NAME, null).getEntity().getContent())) 134 | 135 | then: 136 | //PackageImpl 137 | 'maven'.equals(directJson.type) 138 | updateDetails.getName().equals(directJson.name) 139 | false.equals(directJson.private) 140 | false.equals(directJson.premium) 141 | updateDetails.getDescription().equals(directJson.desc) 142 | updateDetails.getLabels().sort().equals(directJson.labels.sort()) 143 | } 144 | 145 | def 'Delete repository'() { 146 | setup: 147 | ObjectMapper mapper = new ObjectMapper() 148 | RepositoryDetails repositoryDetails = mapper.readValue(repoJson, RepositoryDetails.class) 149 | bintray.subject(connectionProperties.username).createRepo(repositoryDetails) 150 | 151 | when: 152 | bintray.subject(connectionProperties.username).repository(repositoryDetails.name).delete() 153 | 154 | 155 | then: 156 | !bintray.subject(connectionProperties.username).repository(repositoryDetails.name).exists() 157 | } 158 | 159 | def static void tearDown() { 160 | try { 161 | 162 | } catch (BintrayCallException bce) { 163 | if (bce.getStatusCode() != 404) { 164 | System.err.println("cleanup: " + bce) 165 | } 166 | } catch (Exception e) { 167 | System.err.println("cleanup: " + e) 168 | } 169 | } 170 | 171 | def cleanup() { 172 | deleteRepo(REPO_CREATE_NAME) 173 | deleteRepo(REPO_NAME) 174 | } 175 | } -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/SpecialArtifactUploadSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.details.PackageDetails 4 | import com.jfrog.bintray.client.api.details.VersionDetails 5 | import com.jfrog.bintray.client.impl.handle.BintrayImpl 6 | import spock.lang.Specification 7 | 8 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 9 | 10 | /** 11 | * @author Dan Feldman 12 | */ 13 | class SpecialArtifactUploadSpec extends Specification { 14 | 15 | def DEB_REPO = "deb" 16 | def VAG_REPO = "vag" 17 | def debRepoJson 18 | def vagRepoJson 19 | BintrayImpl downloadServerClient 20 | 21 | def void setup() { 22 | debRepoJson = "{\n" + 23 | " \"name\": \"" + DEB_REPO + "\",\n" + 24 | " \"type\": \"debian\",\n" + 25 | " \"private\": false,\n" + 26 | " \"premium\": false,\n" + 27 | " \"desc\": \"Deb Test Repo\"\n" + 28 | "}" 29 | vagRepoJson = "{\n" + 30 | " \"name\": \"" + VAG_REPO + "\",\n" + 31 | " \"type\": \"vagrant\",\n" + 32 | " \"private\": false,\n" + 33 | " \"premium\": false,\n" + 34 | " \"desc\": \"Vag Test Repo\"\n" + 35 | "}" 36 | createRepoIfNeeded(DEB_REPO, debRepoJson) 37 | createRepoIfNeeded(VAG_REPO, vagRepoJson) 38 | downloadServerClient = createClient(getDownloadUrl()) 39 | } 40 | 41 | def 'Upload Debian'() { 42 | setup: 43 | def DEB_PKG = "deb-test" 44 | PackageDetails debPkg = new PackageDetails(DEB_PKG).description('deb test') 45 | .licenses(['MIT']).vcsUrl("https://github.com/bintray/bintray-client-java.git") 46 | def pkg = bintray.subject(connectionProperties.username).repository(DEB_REPO).createPkg(debPkg) 47 | VersionDetails debVer = new VersionDetails(VERSION).description('versionDesc') 48 | def ver = pkg.createVersion(debVer) 49 | def planckDb = this.class.getResourceAsStream('/planckdb_amd64.deb') 50 | def planckDbPath = "pool/main/p/planckdb_amd64.deb" 51 | def planckDbIndexPath = "distributions/trusty/main/amd64/Packages" 52 | 53 | when: 54 | ver.uploadDebian(planckDbPath, "trusty", "main", "amd64", planckDb) 55 | ver.publish() 56 | sleep(30000) 57 | 58 | then: 59 | downloadServerClient.head("/" + connectionProperties.username + "/" + DEB_REPO + "/" + planckDbPath, null).getStatusLine().getStatusCode() == 200 60 | // downloadServerClient.head("/" + connectionProperties.username + "/" + DEB_REPO + "/" + planckDbIndexPath, null).getStatusLine().getStatusCode() == 200 61 | } 62 | 63 | def 'Upload Vagrant'() { 64 | setup: 65 | def VAG_PKG = "vag-test" 66 | PackageDetails vagPkg = new PackageDetails(VAG_PKG).description('vag test') 67 | .licenses(['MIT']).vcsUrl("https://github.com/bintray/bintray-client-java.git") 68 | def pkg = bintray.subject(connectionProperties.username).repository(VAG_REPO).createPkg(vagPkg) 69 | VersionDetails debVer = new VersionDetails(VERSION).description('versionDesc') 70 | def ver = pkg.createVersion(debVer) 71 | def trustyBox = this.class.getResourceAsStream('/trusty64.box') 72 | def trustyBoxPath = "test/trusty64_1.0.0_virtualbox.box.deb" 73 | 74 | when: 75 | ver.uploadVagrant(trustyBoxPath, "art-provider", trustyBox) 76 | ver.publish() 77 | sleep(5000) 78 | 79 | then: 80 | downloadServerClient.head("/" + connectionProperties.username + "/" + VAG_REPO + "/" + trustyBoxPath, null).getStatusLine().getStatusCode() == 200 81 | } 82 | 83 | def cleanup() { 84 | deleteRepo(DEB_REPO) 85 | deleteRepo(VAG_REPO) 86 | } 87 | } -------------------------------------------------------------------------------- /impl/src/test/groovy/com/jfrog/bintray/client/test/spec/VersionSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.jfrog.bintray.client.test.spec 2 | 3 | import com.jfrog.bintray.client.api.BintrayCallException 4 | import com.jfrog.bintray.client.api.details.Attribute 5 | import com.jfrog.bintray.client.api.details.PackageDetails 6 | import com.jfrog.bintray.client.api.details.VersionDetails 7 | import com.jfrog.bintray.client.api.handle.VersionHandle 8 | import com.jfrog.bintray.client.api.model.Version 9 | import com.jfrog.bintray.client.impl.model.VersionImpl 10 | import groovy.json.JsonSlurper 11 | import org.apache.commons.io.IOUtils 12 | import org.codehaus.jackson.map.ObjectMapper 13 | import org.joda.time.DateTime 14 | import org.joda.time.format.ISODateTimeFormat 15 | import spock.lang.Specification 16 | 17 | import static com.jfrog.bintray.client.api.BintrayClientConstatnts.API_PKGS 18 | import static com.jfrog.bintray.client.test.BintraySpecSuite.* 19 | import static org.apache.http.HttpStatus.SC_NOT_FOUND 20 | 21 | /** 22 | * @author Dan Feldman 23 | */ 24 | class VersionSpec extends Specification { 25 | 26 | def void setup() { 27 | createRepoIfNeeded(REPO_NAME, genericRepoJson) 28 | } 29 | 30 | def 'Version created'() { 31 | setup: 32 | def pkg = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder) 33 | 34 | when: 35 | Version version = pkg.createVersion(versionBuilder).get() 36 | JsonSlurper slurper = new JsonSlurper() 37 | def actual = slurper.parseText(IOUtils.toString(restClient.get("/packages/$connectionProperties.username/$REPO_NAME/$PKG_NAME/versions/$VERSION", null).getEntity().getContent())) 38 | 39 | then: 40 | version.name() == actual.name 41 | version.description() == actual.desc 42 | version.pkg() == actual.package 43 | version.repository() == actual.repo 44 | version.owner() == actual.owner 45 | version.labels() == actual.labels 46 | version.vcsTag() == actual.vcs_tag 47 | version.attributeNames() == actual.attribute_names 48 | version.ordinal() == actual.ordinal.toInteger() 49 | if (actual.created) { 50 | version.created() == ISODateTimeFormat.dateTime().parseDateTime(actual.created as String) 51 | } 52 | if (actual.updated) { 53 | version.updated() == ISODateTimeFormat.dateTime().parseDateTime(actual.updated as String) 54 | } 55 | if (actual.released) { 56 | version.released() == ISODateTimeFormat.dateTime().parseDateTime(actual.released as String) 57 | } 58 | } 59 | 60 | def 'version exists'() { 61 | when: 62 | // Create the version: 63 | bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder) 64 | 65 | then: 66 | // Check that the version exists: 67 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).version(VERSION).exists() 68 | 69 | when: 70 | // Delete the version: 71 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).version(VERSION).delete() 72 | 73 | then: 74 | // Check that the package does not exist: 75 | !bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).version(VERSION).exists() 76 | } 77 | 78 | def 'attributes set on version'() { 79 | setup: 80 | def ver = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgBuilder).createVersion(versionBuilder) 81 | 82 | when: 83 | ver.setAttributes(attributes) 84 | 85 | JsonSlurper slurper = new JsonSlurper() 86 | def actualVersion = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME + "/versions/" + VERSION, null).getEntity().getContent())) 87 | def actualAttributes = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + PKG_NAME + "/versions/" + VERSION + "/attributes", null).getEntity().getContent())) 88 | 89 | then: 90 | ['a', 'b', 'c'] == actualVersion.attribute_names.sort() 91 | and: 92 | expectedVerAttributes.equalsIgnoreCase(actualAttributes.sort().toString()) 93 | 94 | } 95 | 96 | def 'wrong version gives 404'() { 97 | when: 98 | bintray.subject(connectionProperties.username).repository(REPO_NAME).pkg(PKG_NAME).version('3434').get() 99 | then: 100 | BintrayCallException e = thrown() 101 | e.statusCode == SC_NOT_FOUND 102 | } 103 | 104 | def 'Version Creation using VersionDetails'() { 105 | setup: 106 | ObjectMapper mapper = new ObjectMapper() 107 | VersionDetails verDetailsFromJson = mapper.readValue(verJson, VersionDetails.class) 108 | PackageDetails pkgDetailsFromJson = mapper.readValue(pkgJson, PackageDetails.class) 109 | 110 | 111 | List attrs = new ArrayList<>(); 112 | attrs.add(new Attribute("verAtt1", Attribute.Type.string, "verVal1")) 113 | attrs.add(new Attribute("verAtt3", Attribute.Type.number, 1, 8.2, 6)) 114 | attrs.add(new Attribute("verAtt5", Attribute.Type.date, DateTime.parse("2014-01-01T17:36:37+0100"))) 115 | 116 | VersionDetails verDetails = new VersionDetails(tempVerName).description("Version Test").releaseNotesFile("README.md") 117 | .released(DateTime.parse("2014-01-01T17:36:37+0100")).useTagReleaseNotes(false).vcsTag("3.8") 118 | 119 | verDetails.setOrdinal(5) 120 | verDetails.setAttributes(attrs) 121 | verDetails.setLabels(["cool", "awesome", "gorilla"]) 122 | verDetails.setPkg(tempPkgName) 123 | verDetails.setRepo("generic") 124 | verDetails.setOwner(bintray.subject(connectionProperties.username).name()) 125 | 126 | VersionImpl locallyCreated = new VersionImpl(verDetails); 127 | 128 | when: 129 | JsonSlurper slurper = new JsonSlurper() 130 | VersionHandle verHandle = bintray.subject(connectionProperties.username).repository(REPO_NAME).createPkg(pkgDetailsFromJson).createVersion(verDetailsFromJson) 131 | VersionImpl ver = verHandle.get() 132 | def directJson = slurper.parseText(IOUtils.toString(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName + "/versions/" + tempVerName, null).getEntity().getContent())) 133 | List attributes = Attribute.getAttributeListFromJson(restClient.get("/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName + "/versions/" + tempVerName + "/attributes", null).getEntity().getContent()) 134 | 135 | then: 136 | //PackageImpl 137 | locallyCreated.equals(ver) 138 | 139 | //jsons 140 | verDetailsFromJson.getName().equals(directJson.name) 141 | verDetailsFromJson.getDescription().equals(directJson.desc) 142 | verDetailsFromJson.getRepo().equals(directJson.repo) 143 | verDetailsFromJson.getPkg().equals(directJson.package) 144 | verDetailsFromJson.getOwner().equals(directJson.owner) 145 | for (int i = 0; i < verDetailsFromJson.getLabels().size(); i++) { 146 | verDetailsFromJson.getLabels().sort().get(i).equalsIgnoreCase(directJson.labels.sort()[i]) 147 | } 148 | for (int i = 0; i < verDetailsFromJson.getAttributeNames().size(); i++) { 149 | verDetailsFromJson.getAttributeNames().sort().get(i).equalsIgnoreCase(directJson.attribute_names.sort()[i]) 150 | } 151 | 152 | directJson.released != null 153 | verDetailsFromJson.getUseTagReleaseNotes().equals(directJson.github_use_tag_release_notes) 154 | verDetailsFromJson.getVcsTag().equals(directJson.vcs_tag) 155 | 156 | //Attributes 157 | for (Attribute attr : attributes) { 158 | attr.equals(attrs.get(0)) || attr.equals(attrs.get(1)) || attr.equals(attrs.get(2)) 159 | } 160 | 161 | cleanup: 162 | try { 163 | String cleanPkg = "/" + API_PKGS + connectionProperties.username + "/" + REPO_NAME + "/" + tempPkgName 164 | restClient.delete(cleanPkg, null) 165 | } catch (BintrayCallException bce) { 166 | if (bce.getStatusCode() != 404) { 167 | System.err.println("cleanup: " + bce) 168 | } 169 | } catch (Exception e) { 170 | System.err.println("cleanup: " + e) 171 | } 172 | } 173 | 174 | def cleanup() { 175 | deleteRepo(REPO_NAME) 176 | } 177 | } -------------------------------------------------------------------------------- /impl/src/test/resources/planckdb_amd64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bintray/bintray-client-java/93e9aad0f7451399d6a64533ecde9b01bb490572/impl/src/test/resources/planckdb_amd64.deb -------------------------------------------------------------------------------- /impl/src/test/resources/simplelog.properties: -------------------------------------------------------------------------------- 1 | .level=INFO 2 | handlers=java.util.logging.ConsoleHandler 3 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 4 | httpclient.wire.header.level=FINEST 5 | org.apache.commons.httpclient.level=FINEST -------------------------------------------------------------------------------- /impl/src/test/resources/testJar1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bintray/bintray-client-java/93e9aad0f7451399d6a64533ecde9b01bb490572/impl/src/test/resources/testJar1.jar -------------------------------------------------------------------------------- /impl/src/test/resources/testJar2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bintray/bintray-client-java/93e9aad0f7451399d6a64533ecde9b01bb490572/impl/src/test/resources/testJar2.jar -------------------------------------------------------------------------------- /impl/src/test/resources/trusty64.box: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bintray/bintray-client-java/93e9aad0f7451399d6a64533ecde9b01bb490572/impl/src/test/resources/trusty64.box -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | String rootName = 'bintray-client-java' 2 | include 'api', 'impl' 3 | rootProject.name = rootName 4 | 5 | project(":api").name = "$rootName-api" 6 | project(":impl").name = "$rootName-service" --------------------------------------------------------------------------------