22
22
import java .io .IOException ;
23
23
import java .io .Writer ;
24
24
import java .nio .file .Path ;
25
- import java .util .AbstractList ;
25
+ import java .util .AbstractSequentialList ;
26
26
import java .util .ArrayList ;
27
27
import java .util .Collection ;
28
28
import java .util .Collections ;
29
29
import java .util .HashMap ;
30
30
import java .util .LinkedHashMap ;
31
31
import java .util .LinkedHashSet ;
32
32
import java .util .List ;
33
+ import java .util .ListIterator ;
33
34
import java .util .Map ;
34
35
import java .util .Objects ;
35
36
import java .util .Properties ;
@@ -738,56 +739,42 @@ public Build getBuild() {
738
739
*/
739
740
@ Deprecated (since = "4.0.0" )
740
741
public List <Resource > getResources () {
741
- return new AbstractList <>() {
742
- @ Override
743
- public Resource get (int index ) {
744
- return toResource (getEnabledSourceRoots (ProjectScope .MAIN , Language .RESOURCES )
745
- .toList ()
746
- .get (index ));
747
- }
748
-
749
- @ Override
750
- public int size () {
751
- return (int ) getEnabledSourceRoots (ProjectScope .MAIN , Language .RESOURCES )
752
- .count ();
753
- }
754
-
755
- @ Override
756
- public boolean add (Resource resource ) {
757
- addResource (resource );
758
- return true ;
759
- }
760
- };
742
+ return getResources (ProjectScope .MAIN );
761
743
}
762
744
763
745
/**
764
746
* @deprecated Replaced by {@code getEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES)}.
765
747
*/
766
748
@ Deprecated (since = "4.0.0" )
767
749
public List <Resource > getTestResources () {
768
- return new AbstractList <>() {
750
+ return getResources (ProjectScope .TEST );
751
+ }
752
+
753
+ private List <Resource > getResources (final ProjectScope scope ) {
754
+ return new AbstractSequentialList <>() {
769
755
@ Override
770
- public Resource get (int index ) {
771
- return toResource (getEnabledSourceRoots (ProjectScope .TEST , Language .RESOURCES )
756
+ public ListIterator <Resource > listIterator (int index ) {
757
+ return getEnabledSourceRoots (scope , Language .RESOURCES )
758
+ .map (MavenProject ::toResource )
772
759
.toList ()
773
- .get (index ) );
760
+ .listIterator (index );
774
761
}
775
762
776
763
@ Override
777
764
public int size () {
778
- return ( int ) getEnabledSourceRoots ( ProjectScope . TEST , Language . RESOURCES )
779
- . count ();
765
+ return Math . toIntExact (
766
+ getEnabledSourceRoots ( scope , Language . RESOURCES ). count () );
780
767
}
781
768
782
769
@ Override
783
770
public boolean add (Resource resource ) {
784
- addTestResource (resource );
771
+ addResource (resource );
785
772
return true ;
786
773
}
787
774
};
788
775
}
789
776
790
- private Resource toResource (SourceRoot sourceRoot ) {
777
+ private static Resource toResource (SourceRoot sourceRoot ) {
791
778
return new Resource (org .apache .maven .api .model .Resource .newBuilder ()
792
779
.directory (sourceRoot .directory ().toString ())
793
780
.includes (sourceRoot .includes ().stream ().map (Object ::toString ).toList ())
@@ -796,20 +783,24 @@ private Resource toResource(SourceRoot sourceRoot) {
796
783
.build ());
797
784
}
798
785
786
+ private void addResource (ProjectScope scope , Resource resource ) {
787
+ addSourceRoot (new DefaultSourceRoot (getBaseDirectory (), scope , resource .getDelegate ()));
788
+ }
789
+
799
790
/**
800
791
* @deprecated {@link Resource} is replaced by {@link SourceRoot}.
801
792
*/
802
793
@ Deprecated (since = "4.0.0" )
803
794
public void addResource (Resource resource ) {
804
- addSourceRoot ( new DefaultSourceRoot ( getBaseDirectory (), ProjectScope .MAIN , resource . getDelegate ()) );
795
+ addResource ( ProjectScope .MAIN , resource );
805
796
}
806
797
807
798
/**
808
799
* @deprecated {@link Resource} is replaced by {@link SourceRoot}.
809
800
*/
810
801
@ Deprecated (since = "4.0.0" )
811
802
public void addTestResource (Resource testResource ) {
812
- addSourceRoot ( new DefaultSourceRoot ( getBaseDirectory (), ProjectScope .TEST , testResource . getDelegate ()) );
803
+ addResource ( ProjectScope .TEST , testResource );
813
804
}
814
805
815
806
public void setLicenses (List <License > licenses ) {
0 commit comments