@@ -443,14 +443,35 @@ public InputStream getRawBlobContent(Object projectIdOrPath, String sha) throws
443
443
* @return an input stream that can be used to save as a file
444
444
* or to read the content of the archive
445
445
* @throws GitLabApiException if any exception occurs
446
+ * @deprecated Use {@link #getRepositoryArchiveByPathAndSha(Object, String, String)}
446
447
*/
448
+ @ Deprecated
447
449
public InputStream getRepositoryArchive (Object projectIdOrPath , String sha ) throws GitLabApiException {
448
450
Form formData = new GitLabApiForm ().withParam ("sha" , sha );
449
451
Response response = getWithAccepts (Response .Status .OK , formData .asMap (), MediaType .WILDCARD ,
450
452
"projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "archive" );
451
453
return (response .readEntity (InputStream .class ));
452
454
}
453
455
456
+ /**
457
+ * Get an archive of the complete repository by SHA (optional).
458
+ *
459
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
460
+ *
461
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
462
+ * @param path The subpath of the repository to download
463
+ * @param sha the SHA of the archive to get
464
+ * @return an input stream that can be used to save as a file
465
+ * or to read the content of the archive
466
+ * @throws GitLabApiException if any exception occurs
467
+ */
468
+ public InputStream getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha ) throws GitLabApiException {
469
+ Form formData = new GitLabApiForm ().withParam ("sha" , sha ).withParam ("path" , path );
470
+ Response response = getWithAccepts (Response .Status .OK , formData .asMap (), MediaType .WILDCARD ,
471
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "archive" );
472
+ return (response .readEntity (InputStream .class ));
473
+ }
474
+
454
475
/**
455
476
* Get an archive of the complete repository by SHA (optional).
456
477
*
@@ -461,12 +482,31 @@ public InputStream getRepositoryArchive(Object projectIdOrPath, String sha) thro
461
482
* @param format The archive format, defaults to "tar.gz" if null
462
483
* @return an input stream that can be used to save as a file or to read the content of the archive
463
484
* @throws GitLabApiException if format is not a valid archive format or any exception occurs
485
+ * @deprecated Use {@link #getRepositoryArchiveByPathAndSha(Object, String, String, String)}
464
486
*/
487
+ @ Deprecated
465
488
public InputStream getRepositoryArchive (Object projectIdOrPath , String sha , String format ) throws GitLabApiException {
466
489
ArchiveFormat archiveFormat = ArchiveFormat .forValue (format );
467
490
return (getRepositoryArchive (projectIdOrPath , sha , archiveFormat ));
468
491
}
469
492
493
+ /**
494
+ * Get an archive of the complete repository by SHA (optional).
495
+ *
496
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
497
+ *
498
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
499
+ * @param path The subpath of the repository to download
500
+ * @param sha the SHA of the archive to get
501
+ * @param format The archive format, defaults to "tar.gz" if null
502
+ * @return an input stream that can be used to save as a file or to read the content of the archive
503
+ * @throws GitLabApiException if format is not a valid archive format or any exception occurs
504
+ */
505
+ public InputStream getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha , String format ) throws GitLabApiException {
506
+ ArchiveFormat archiveFormat = ArchiveFormat .forValue (format );
507
+ return (getRepositoryArchiveByPathAndSha (projectIdOrPath , path , sha , archiveFormat ));
508
+ }
509
+
470
510
/**
471
511
* Get an archive of the complete repository by SHA (optional).
472
512
*
@@ -477,7 +517,9 @@ public InputStream getRepositoryArchive(Object projectIdOrPath, String sha, Stri
477
517
* @param format The archive format, defaults to TAR_GZ if null
478
518
* @return an input stream that can be used to save as a file or to read the content of the archive
479
519
* @throws GitLabApiException if any exception occurs
520
+ * @deprecated User {@link #getRepositoryArchiveByPathAndSha(Object, String, String, ArchiveFormat)}
480
521
*/
522
+ @ Deprecated
481
523
public InputStream getRepositoryArchive (Object projectIdOrPath , String sha , ArchiveFormat format ) throws GitLabApiException {
482
524
483
525
if (format == null ) {
@@ -497,6 +539,37 @@ public InputStream getRepositoryArchive(Object projectIdOrPath, String sha, Arch
497
539
return (response .readEntity (InputStream .class ));
498
540
}
499
541
542
+ /**
543
+ * Get an archive of the complete repository by SHA (optional).
544
+ *
545
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
546
+ *
547
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
548
+ * @param path The subpath of the repository to download
549
+ * @param sha the SHA of the archive to get
550
+ * @param format The archive format, defaults to TAR_GZ if null
551
+ * @return an input stream that can be used to save as a file or to read the content of the archive
552
+ * @throws GitLabApiException if any exception occurs
553
+ */
554
+ public InputStream getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha , ArchiveFormat format ) throws GitLabApiException {
555
+
556
+ if (format == null ) {
557
+ format = ArchiveFormat .TAR_GZ ;
558
+ }
559
+
560
+ /*
561
+ * Gitlab-ce has a bug when you try to download file archives with format by using "&format=zip(or tar... etc.)",
562
+ * there is a solution to request .../archive.:format instead of .../archive?format=:format.
563
+ *
564
+ * Issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/45992
565
+ * https://gitlab.com/gitlab-com/support-forum/issues/3067
566
+ */
567
+ Form formData = new GitLabApiForm ().withParam ("path" , path ).withParam ("sha" , sha );
568
+ Response response = getWithAccepts (Response .Status .OK , formData .asMap (), MediaType .WILDCARD ,
569
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "archive" + "." + format .toString ());
570
+ return (response .readEntity (InputStream .class ));
571
+ }
572
+
500
573
/**
501
574
* Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
502
575
* If the archive already exists in the directory it will be overwritten.
@@ -508,7 +581,9 @@ public InputStream getRepositoryArchive(Object projectIdOrPath, String sha, Arch
508
581
* @param directory the File instance of the directory to save the archive to, if null will use "java.io.tmpdir"
509
582
* @return a File instance pointing to the downloaded instance
510
583
* @throws GitLabApiException if any exception occurs
584
+ * @deprecated Use {@link #getRepositoryArchiveByPathAndSha(Object, String, String, File)}
511
585
*/
586
+ @ Deprecated
512
587
public File getRepositoryArchive (Object projectIdOrPath , String sha , File directory ) throws GitLabApiException {
513
588
514
589
Form formData = new GitLabApiForm ().withParam ("sha" , sha );
@@ -532,6 +607,42 @@ public File getRepositoryArchive(Object projectIdOrPath, String sha, File direct
532
607
}
533
608
}
534
609
610
+ /**
611
+ * Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
612
+ * If the archive already exists in the directory it will be overwritten.
613
+ *
614
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
615
+ *
616
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
617
+ * @param path The subpath of the repository to download
618
+ * @param sha the SHA of the archive to get
619
+ * @param directory the File instance of the directory to save the archive to, if null will use "java.io.tmpdir"
620
+ * @return a File instance pointing to the downloaded instance
621
+ * @throws GitLabApiException if any exception occurs
622
+ */
623
+ public File getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha , File directory ) throws GitLabApiException {
624
+
625
+ Form formData = new GitLabApiForm ().withParam ("path" , path ).withParam ("sha" , sha );
626
+ Response response = getWithAccepts (Response .Status .OK , formData .asMap (), MediaType .WILDCARD ,
627
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "archive" );
628
+
629
+ try {
630
+
631
+ if (directory == null )
632
+ directory = new File (System .getProperty ("java.io.tmpdir" ));
633
+
634
+ String filename = FileUtils .getFilenameFromContentDisposition (response );
635
+ File file = new File (directory , filename );
636
+
637
+ InputStream in = response .readEntity (InputStream .class );
638
+ Files .copy (in , file .toPath (), StandardCopyOption .REPLACE_EXISTING );
639
+ return (file );
640
+
641
+ } catch (IOException ioe ) {
642
+ throw new GitLabApiException (ioe );
643
+ }
644
+ }
645
+
535
646
/**
536
647
* Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
537
648
* If the archive already exists in the directory it will be overwritten.
@@ -544,12 +655,33 @@ public File getRepositoryArchive(Object projectIdOrPath, String sha, File direct
544
655
* @param format The archive format, defaults to "tar.gz" if null
545
656
* @return a File instance pointing to the downloaded instance
546
657
* @throws GitLabApiException if format is not a valid archive format or any exception occurs
658
+ * @deprecated Use {@link #getRepositoryArchiveByPathAndSha(Object, String, String, File, String)}
547
659
*/
660
+ @ Deprecated
548
661
public File getRepositoryArchive (Object projectIdOrPath , String sha , File directory , String format ) throws GitLabApiException {
549
662
ArchiveFormat archiveFormat = ArchiveFormat .forValue (format );
550
663
return (getRepositoryArchive (projectIdOrPath , sha , directory , archiveFormat ));
551
664
}
552
665
666
+ /**
667
+ * Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
668
+ * If the archive already exists in the directory it will be overwritten.
669
+ *
670
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
671
+ *
672
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
673
+ * @param path The subpath of the repository to download
674
+ * @param sha the SHA of the archive to get
675
+ * @param directory the File instance of the directory to save the archive to, if null will use "java.io.tmpdir"
676
+ * @param format The archive format, defaults to "tar.gz" if null
677
+ * @return a File instance pointing to the downloaded instance
678
+ * @throws GitLabApiException if format is not a valid archive format or any exception occurs
679
+ */
680
+ public File getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha , File directory , String format ) throws GitLabApiException {
681
+ ArchiveFormat archiveFormat = ArchiveFormat .forValue (format );
682
+ return (getRepositoryArchiveByPathAndSha (projectIdOrPath , path , sha , directory , archiveFormat ));
683
+ }
684
+
553
685
/**
554
686
* Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
555
687
* If the archive already exists in the directory it will be overwritten.
@@ -562,7 +694,9 @@ public File getRepositoryArchive(Object projectIdOrPath, String sha, File direct
562
694
* @param format The archive format, defaults to TAR_GZ if null
563
695
* @return a File instance pointing to the downloaded instance
564
696
* @throws GitLabApiException if any exception occurs
697
+ * @deprecated Use {@link #getRepositoryArchiveByPathAndSha(Object, String, String, File, ArchiveFormat)}
565
698
*/
699
+ @ Deprecated
566
700
public File getRepositoryArchive (Object projectIdOrPath , String sha , File directory , ArchiveFormat format ) throws GitLabApiException {
567
701
568
702
if (format == null ) {
@@ -597,6 +731,54 @@ public File getRepositoryArchive(Object projectIdOrPath, String sha, File direct
597
731
}
598
732
}
599
733
734
+ /**
735
+ * Get an archive of the complete repository by SHA (optional) and saves to the specified directory.
736
+ * If the archive already exists in the directory it will be overwritten.
737
+ *
738
+ * <pre><code>GitLab Endpoint: GET /projects/:id/repository/archive</code></pre>
739
+ *
740
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
741
+ * @param path The subpath of the repository to download
742
+ * @param sha the SHA of the archive to get
743
+ * @param directory the File instance of the directory to save the archive to, if null will use "java.io.tmpdir"
744
+ * @param format The archive format, defaults to TAR_GZ if null
745
+ * @return a File instance pointing to the downloaded instance
746
+ * @throws GitLabApiException if any exception occurs
747
+ */
748
+ public File getRepositoryArchiveByPathAndSha (Object projectIdOrPath , String path , String sha , File directory , ArchiveFormat format ) throws GitLabApiException {
749
+
750
+ if (format == null ) {
751
+ format = ArchiveFormat .TAR_GZ ;
752
+ }
753
+
754
+ /*
755
+ * Gitlab-ce has a bug when you try to download file archives with format by using "&format=zip(or tar... etc.)",
756
+ * there is a solution to request .../archive.:format instead of .../archive?format=:format.
757
+ *
758
+ * Issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/45992
759
+ * https://gitlab.com/gitlab-com/support-forum/issues/3067
760
+ */
761
+ Form formData = new GitLabApiForm ().withParam ("path" , path ).withParam ("sha" , sha );
762
+ Response response = getWithAccepts (Response .Status .OK , formData .asMap (), MediaType .WILDCARD ,
763
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "archive" + "." + format .toString ());
764
+
765
+ try {
766
+
767
+ if (directory == null )
768
+ directory = new File (System .getProperty ("java.io.tmpdir" ));
769
+
770
+ String filename = FileUtils .getFilenameFromContentDisposition (response );
771
+ File file = new File (directory , filename );
772
+
773
+ InputStream in = response .readEntity (InputStream .class );
774
+ Files .copy (in , file .toPath (), StandardCopyOption .REPLACE_EXISTING );
775
+ return (file );
776
+
777
+ } catch (IOException ioe ) {
778
+ throw new GitLabApiException (ioe );
779
+ }
780
+ }
781
+
600
782
/**
601
783
* Compare branches, tags or commits. This can be accessed without authentication
602
784
* if the repository is publicly accessible.
0 commit comments