|
15 | 15 | import javax.ws.rs.core.Response;
|
16 | 16 | import javax.ws.rs.core.Response.Status;
|
17 | 17 |
|
| 18 | +import org.gitlab4j.api.models.ArtifactsFile; |
18 | 19 | import org.gitlab4j.api.models.Job;
|
19 | 20 |
|
20 | 21 | /**
|
@@ -261,6 +262,60 @@ public InputStream downloadArtifactsFile(Object projectIdOrPath, Integer jobId)
|
261 | 262 | return (response.readEntity(InputStream.class));
|
262 | 263 | }
|
263 | 264 |
|
| 265 | + /** |
| 266 | + * Download a single artifact file from within the job's artifacts archive. |
| 267 | + * |
| 268 | + * Only a single file is going to be extracted from the archive and streamed to a client. |
| 269 | + * |
| 270 | + * GET /projects/:id/jobs/:job_id/artifacts/*artifact_path |
| 271 | + * |
| 272 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 273 | + * @param jobId the unique job identifier |
| 274 | + * @param artifactsFile an ArtifactsFile instance for the artifact to download |
| 275 | + * @param directory the File instance of the directory to save the file to, if null will use "java.io.tmpdir" |
| 276 | + * @return a File instance pointing to the download of the specified artifacts file |
| 277 | + * @throws GitLabApiException if any exception occurs |
| 278 | + */ |
| 279 | + public File downloadArtifactsFile(Object projectIdOrPath, Integer jobId, ArtifactsFile artifactsFile, File directory) throws GitLabApiException { |
| 280 | + |
| 281 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), |
| 282 | + "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", artifactsFile.getFilename()); |
| 283 | + try { |
| 284 | + |
| 285 | + if (directory == null) |
| 286 | + directory = new File(System.getProperty("java.io.tmpdir")); |
| 287 | + |
| 288 | + String filename = artifactsFile.getFilename(); |
| 289 | + File file = new File(directory, filename); |
| 290 | + |
| 291 | + InputStream in = response.readEntity(InputStream.class); |
| 292 | + Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 293 | + return (file); |
| 294 | + |
| 295 | + } catch (IOException ioe) { |
| 296 | + throw new GitLabApiException(ioe); |
| 297 | + } |
| 298 | + } |
| 299 | + |
| 300 | + /** |
| 301 | + * Download a single artifact file from within the job's artifacts archive. |
| 302 | + * |
| 303 | + * Only a single file is going to be extracted from the archive and streamed to a client. |
| 304 | + * |
| 305 | + * GET /projects/:id/jobs/:job_id/artifacts/*artifact_path |
| 306 | + * |
| 307 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 308 | + * @param jobId the unique job identifier |
| 309 | + * @param artifactsFile an ArtifactsFile instance for the artifact to download |
| 310 | + * @return an InputStream to read the specified artifacts file from |
| 311 | + * @throws GitLabApiException if any exception occurs |
| 312 | + */ |
| 313 | + public InputStream downloadArtifactsFile(Object projectIdOrPath, Integer jobId, ArtifactsFile artifactsFile) throws GitLabApiException { |
| 314 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), |
| 315 | + "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", artifactsFile.getFilename()); |
| 316 | + return (response.readEntity(InputStream.class)); |
| 317 | + } |
| 318 | + |
264 | 319 | /**
|
265 | 320 | * Download a single artifact file from within the job's artifacts archive.
|
266 | 321 | *
|
|
0 commit comments