1919package org .apache .maven .impl ;
2020
2121import java .nio .file .Path ;
22+ import java .util .List ;
2223import java .util .Optional ;
2324
2425import org .apache .maven .api .Language ;
2526import org .apache .maven .api .ProjectScope ;
2627import org .apache .maven .api .Session ;
28+ import org .apache .maven .api .model .Resource ;
2729import org .apache .maven .api .model .Source ;
28- import org .apache .maven .model .Resource ;
2930import org .junit .jupiter .api .BeforeEach ;
3031import org .junit .jupiter .api .Test ;
3132import org .junit .jupiter .api .extension .ExtendWith ;
@@ -125,9 +126,10 @@ void testModuleTestDirectory() {
125126 @ Test
126127 void testExtractsTargetPathFromResource () {
127128 // Test the Resource constructor that was broken in the regression
128- Resource resource = new Resource ();
129- resource .setDirectory ("src/test/resources" );
130- resource .setTargetPath ("test-output" );
129+ Resource resource = Resource .newBuilder ()
130+ .directory ("src/test/resources" )
131+ .targetPath ("test-output" )
132+ .build ();
131133
132134 DefaultSourceRoot sourceRoot = new DefaultSourceRoot (Path .of ("myproject" ), ProjectScope .TEST , resource );
133135
@@ -143,8 +145,8 @@ void testExtractsTargetPathFromResource() {
143145 @ Test
144146 void testHandlesNullTargetPathFromResource () {
145147 // Test null targetPath handling
146- Resource resource = new Resource ();
147- resource . setDirectory ( "src/test/resources" );
148+ Resource resource =
149+ Resource . newBuilder (). directory ( "src/test/resources" ). build ( );
148150 // targetPath is null by default
149151
150152 DefaultSourceRoot sourceRoot = new DefaultSourceRoot (Path .of ("myproject" ), ProjectScope .TEST , resource );
@@ -157,9 +159,10 @@ void testHandlesNullTargetPathFromResource() {
157159 @ Test
158160 void testHandlesEmptyTargetPathFromResource () {
159161 // Test empty string targetPath
160- Resource resource = new Resource ();
161- resource .setDirectory ("src/test/resources" );
162- resource .setTargetPath ("" );
162+ Resource resource = Resource .newBuilder ()
163+ .directory ("src/test/resources" )
164+ .targetPath ("" )
165+ .build ();
163166
164167 DefaultSourceRoot sourceRoot = new DefaultSourceRoot (Path .of ("myproject" ), ProjectScope .TEST , resource );
165168
@@ -171,9 +174,10 @@ void testHandlesEmptyTargetPathFromResource() {
171174 @ Test
172175 void testHandlesPropertyPlaceholderInTargetPath () {
173176 // Test property placeholder preservation
174- Resource resource = new Resource ();
175- resource .setDirectory ("src/main/resources" );
176- resource .setTargetPath ("${project.build.directory}/custom" );
177+ Resource resource = Resource .newBuilder ()
178+ .directory ("src/test/resources" )
179+ .targetPath ("${project.build.directory}/custom" )
180+ .build ();
177181
178182 DefaultSourceRoot sourceRoot = new DefaultSourceRoot (Path .of ("myproject" ), ProjectScope .MAIN , resource );
179183
@@ -186,7 +190,7 @@ void testHandlesPropertyPlaceholderInTargetPath() {
186190 @ Test
187191 void testResourceConstructorRequiresNonNullDirectory () {
188192 // Test that null directory throws exception
189- Resource resource = new Resource ();
193+ Resource resource = Resource . newBuilder (). build ();
190194 // directory is null by default
191195
192196 assertThrows (
@@ -199,12 +203,13 @@ void testResourceConstructorRequiresNonNullDirectory() {
199203 @ Test
200204 void testResourceConstructorPreservesOtherProperties () {
201205 // Test that other Resource properties are correctly preserved
202- Resource resource = new Resource ();
203- resource .setDirectory ("src/test/resources" );
204- resource .setTargetPath ("test-classes" );
205- resource .setFiltering ("true" );
206- resource .addInclude ("*.properties" );
207- resource .addExclude ("*.tmp" );
206+ Resource resource = Resource .newBuilder ()
207+ .directory ("src/test/resources" )
208+ .targetPath ("test-classes" )
209+ .filtering ("true" )
210+ .includes (List .of ("*.properties" ))
211+ .excludes (List .of ("*.tmp" ))
212+ .build ();
208213
209214 DefaultSourceRoot sourceRoot = new DefaultSourceRoot (Path .of ("myproject" ), ProjectScope .TEST , resource );
210215
0 commit comments