Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.service; |
| 2 | |
| 3 | import java.io.*; |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 4 | import java.net.*; |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 5 | import java.util.*; |
| 6 | |
Stuart McCulloch | cd1ddd7 | 2012-07-19 13:11:20 +0000 | [diff] [blame] | 7 | import aQute.bnd.version.*; |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 8 | |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 9 | /** |
| 10 | * A Repository Plugin abstract a bnd repository. This interface allows bnd to |
| 11 | * find programs from their bsn and revisions from their bsn-version |
| 12 | * combination. It is also possible to put revisions in a repository if the |
| 13 | * repository is not read only. |
| 14 | */ |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 15 | public interface RepositoryPlugin { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 16 | /** |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 17 | * Options used to steer the put operation |
| 18 | */ |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 19 | class PutOptions { |
| 20 | public String BUNDLE = "application/vnd.osgi.bundle"; |
| 21 | public String LIB = "application/vnd.aQute.lib"; |
| 22 | |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 23 | /** |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 24 | * The <b>SHA1</b> digest of the artifact to put into the repository. |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 25 | * When specified the digest of the <b>fetched</b> artifact will be |
| 26 | * calculated and verified against this digest, <b>before</b> putting |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 27 | * the artifact into the repository. </p> An exception is thrown if the |
| 28 | * specified digest and the calculated digest do not match. |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 29 | */ |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 30 | public byte[] digest = null; |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 33 | * Specify the mime type of the importing stream. This can be either |
| 34 | * {@link #BUNDLE} or {@link #LIB}. If left open, it is up to the |
| 35 | * repository to guess the content type. |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 36 | */ |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 37 | public String type; |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 40 | PutOptions DEFAULTOPTIONS = new PutOptions(); |
| 41 | |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 42 | /** |
| 43 | * Results returned by the put operation |
| 44 | */ |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 45 | class PutResult { |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 46 | /** |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 47 | * A (potentially public) uri to the revision as it was put in the |
| 48 | * repository.<br/> |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 49 | * <br/> |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 50 | * This can be a URI to the given artifact (when it was put into the |
| 51 | * repository). This does not have to be a File URI! |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 52 | */ |
| 53 | public URI artifact = null; |
| 54 | |
| 55 | /** |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 56 | * The <b>SHA1</b> digest of the artifact as it was put into the |
| 57 | * repository.<br/> |
| 58 | * <br/> |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 59 | * This can be null and it can differ from the input digest if the |
| 60 | * repository rewrote the stream for optimization reason. If the |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 61 | */ |
| 62 | public byte[] digest = null; |
| 63 | } |
| 64 | |
| 65 | /** |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 66 | * Put an artifact (from the InputStream) into the repository.<br/> |
| 67 | * <br/> |
| 68 | * There is NO guarantee that the artifact on the input stream has not been |
| 69 | * modified after it's been put in the repository since that is dependent on |
| 70 | * the implementation of the repository (see |
| 71 | * {@link RepositoryPlugin.PutOptions#allowArtifactChange}). |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 72 | * |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 73 | * @param stream |
| 74 | * The input stream with the artifact |
| 75 | * @param options |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 76 | * The put options. See {@link RepositoryPlugin.PutOptions}, can |
| 77 | * be {@code null}, which will then take the default options like |
| 78 | * new PutOptions(). |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 79 | * @return The result of the put, never null. See |
| 80 | * {@link RepositoryPlugin.PutResult} |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 81 | * @throws Exception |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 82 | * When the repository root directory doesn't exist, when the |
| 83 | * repository is read-only, when the specified checksum doesn't |
| 84 | * match the checksum of the fetched artifact (see |
| 85 | * {@link RepositoryPlugin.PutOptions#digest}), when the |
| 86 | * implementation wants to modify the artifact but isn't allowed |
| 87 | * (see {@link RepositoryPlugin.PutOptions#allowArtifactChange} |
| 88 | * ), or when another error has occurred. |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 89 | */ |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 90 | PutResult put(InputStream stream, PutOptions options) throws Exception; |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 91 | |
| 92 | /** |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 93 | * The caller can specify any number of DownloadListener objects that are |
| 94 | * called back when a download is finished (potentially before the get |
| 95 | * method has returned). |
| 96 | */ |
| 97 | |
| 98 | interface DownloadListener { |
| 99 | /** |
| 100 | * Called when the file is successfully downloaded from a remote |
| 101 | * repository. |
| 102 | * |
| 103 | * @param file |
| 104 | * The file that was downloaded |
| 105 | * @throws Exception |
| 106 | * , are logged and ignored |
| 107 | */ |
| 108 | void success(File file) throws Exception; |
| 109 | |
| 110 | /** |
| 111 | * Called when the file could not be downloaded from a remote |
| 112 | * repository. |
| 113 | * |
| 114 | * @param file |
| 115 | * The file that was intended to be downloaded. |
| 116 | * @throws Exception |
| 117 | * , are logged and ignored |
| 118 | */ |
| 119 | void failure(File file, String reason) throws Exception; |
| 120 | |
| 121 | /** |
| 122 | * Can be called back regularly before success/failure but never after. |
| 123 | * Indicates how far the download has progressed in percents. Since |
| 124 | * downloads can be restarted, it is possible that the percentage |
| 125 | * decreases. |
| 126 | * |
| 127 | * @param file |
| 128 | * The file that was intended to be downloaded |
| 129 | * @param percentage |
| 130 | * Percentage of file downloaded (can go down) |
| 131 | * @return true if the download should continue, fails if it should be |
| 132 | * canceled (and fail) |
| 133 | * @throws Exception |
| 134 | * , are logged and ignored |
| 135 | */ |
| 136 | boolean progress(File file, int percentage) throws Exception; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Return a URL to a matching version of the given bundle. |
| 141 | * <p/> |
| 142 | * If download listeners are specified then the returned file is not |
| 143 | * guaranteed to exist before a download listener is notified of success or |
| 144 | * failure. The callback can happen before the method has returned. If the |
| 145 | * returned file is null then download listeners are not called back. |
| 146 | * <p/> |
| 147 | * The intention of the Download Listeners is to allow a caller to obtain |
| 148 | * references to files that do not yet exist but are to be downloaded. If |
| 149 | * the downloads were done synchronously in the call, then no overlap of |
| 150 | * downloads could take place. |
| 151 | * |
| 152 | * @param bsn |
| 153 | * Bundle-SymbolicName of the searched bundle |
| 154 | * @param version |
| 155 | * Version requested |
| 156 | * @param listeners |
| 157 | * Zero or more download listener that will be notified of the |
| 158 | * outcome. |
| 159 | * @return A file to the revision or null if not found |
| 160 | * @throws Exception |
| 161 | * when anything goes wrong, in this case no listeners will be |
| 162 | * called back. |
| 163 | */ |
| 164 | File get(String bsn, Version version, Map<String,String> properties, DownloadListener... listeners) |
| 165 | throws Exception; |
| 166 | |
| 167 | /** |
| 168 | * Answer if this repository can be used to store files. |
| 169 | * |
| 170 | * @return true if writable |
| 171 | */ |
| 172 | boolean canWrite(); |
| 173 | |
| 174 | /** |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 175 | * Return a list of bsns that are present in the repository. |
| 176 | * |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 177 | * @param pattern |
| 178 | * A <ahref="https://en.wikipedia.org/wiki/Glob_%28programming%29">glob pattern</a> |
| 179 | * to be matched against bsns present in the repository, or {@code null}. |
| 180 | * @return A list of bsns that match the pattern parameter or all if pattern |
| 181 | * is null; repositories that do not support browsing or querying |
| 182 | * should return an empty list. |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 183 | * @throws Exception |
| 184 | */ |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 185 | List<String> list(String pattern) throws Exception; |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Return a list of versions. |
| 189 | * |
| 190 | * @throws Exception |
| 191 | */ |
| 192 | |
Stuart McCulloch | 2a0afd6 | 2012-09-06 18:28:06 +0000 | [diff] [blame^] | 193 | SortedSet<Version> versions(String bsn) throws Exception; |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * @return The name of the repository |
| 197 | */ |
| 198 | String getName(); |
| 199 | |
| 200 | /** |
| 201 | * Return a location identifier of this repository |
| 202 | */ |
| 203 | |
| 204 | String getLocation(); |
| 205 | } |