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