blob: f3ee1f07b88b4489558354126b33e3603549b141 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.bnd.service;
2
3import java.io.*;
Stuart McCulloch2929e2d2012-08-07 10:57:21 +00004import java.net.*;
Stuart McCullochf3173222012-06-07 21:57:32 +00005import java.util.*;
6
Stuart McCullochcd1ddd72012-07-19 13:11:20 +00007import aQute.bnd.version.*;
Stuart McCullochf3173222012-06-07 21:57:32 +00008
Stuart McCulloch2a0afd62012-09-06 18:28:06 +00009/**
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 McCullochf3173222012-06-07 21:57:32 +000015public interface RepositoryPlugin {
Stuart McCullochf3173222012-06-07 21:57:32 +000016 /**
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000017 * Options used to steer the put operation
18 */
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000019 class PutOptions {
20 public String BUNDLE = "application/vnd.osgi.bundle";
21 public String LIB = "application/vnd.aQute.lib";
22
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000023 /**
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000024 * The <b>SHA1</b> digest of the artifact to put into the repository.
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000025 * When specified the digest of the <b>fetched</b> artifact will be
26 * calculated and verified against this digest, <b>before</b> putting
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000027 * the artifact into the repository. </p> An exception is thrown if the
28 * specified digest and the calculated digest do not match.
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000029 */
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000030 public byte[] digest = null;
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000031
32 /**
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000033 * 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 McCulloch2929e2d2012-08-07 10:57:21 +000036 */
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000037 public String type;
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000038 }
39
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000040 PutOptions DEFAULTOPTIONS = new PutOptions();
41
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000042 /**
43 * Results returned by the put operation
44 */
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000045 class PutResult {
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000046 /**
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000047 * A (potentially public) uri to the revision as it was put in the
48 * repository.<br/>
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000049 * <br/>
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000050 * 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 McCulloch2929e2d2012-08-07 10:57:21 +000052 */
53 public URI artifact = null;
54
55 /**
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000056 * The <b>SHA1</b> digest of the artifact as it was put into the
57 * repository.<br/>
58 * <br/>
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000059 * 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 McCulloch2929e2d2012-08-07 10:57:21 +000061 */
62 public byte[] digest = null;
63 }
64
65 /**
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000066 * 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 McCullochf3173222012-06-07 21:57:32 +000072 *
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000073 * @param stream
74 * The input stream with the artifact
75 * @param options
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000076 * The put options. See {@link RepositoryPlugin.PutOptions}, can
77 * be {@code null}, which will then take the default options like
78 * new PutOptions().
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000079 * @return The result of the put, never null. See
80 * {@link RepositoryPlugin.PutResult}
Stuart McCullochf3173222012-06-07 21:57:32 +000081 * @throws Exception
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000082 * 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 McCullochf3173222012-06-07 21:57:32 +000089 */
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000090 PutResult put(InputStream stream, PutOptions options) throws Exception;
Stuart McCullochf3173222012-06-07 21:57:32 +000091
92 /**
Stuart McCulloch2a0afd62012-09-06 18:28:06 +000093 * 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 McCullochf3173222012-06-07 21:57:32 +0000175 * Return a list of bsns that are present in the repository.
176 *
Stuart McCulloch2a0afd62012-09-06 18:28:06 +0000177 * @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 McCullochf3173222012-06-07 21:57:32 +0000183 * @throws Exception
184 */
Stuart McCulloch2a0afd62012-09-06 18:28:06 +0000185 List<String> list(String pattern) throws Exception;
Stuart McCullochf3173222012-06-07 21:57:32 +0000186
187 /**
188 * Return a list of versions.
189 *
190 * @throws Exception
191 */
192
Stuart McCulloch2a0afd62012-09-06 18:28:06 +0000193 SortedSet<Version> versions(String bsn) throws Exception;
Stuart McCullochf3173222012-06-07 21:57:32 +0000194
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}