@@ -61,8 +61,8 @@ private record ContributingQuestion(String question, String help) {}
6161    private  final  Map <String , ContributingQuestion > questions  = new  HashMap <>();
6262
6363    private  void  initializeWorkingDirectories (){
64-         testsDirectory  = getProject ().file (CoordinateUtils .replace ("tests/src/$group$/$artifact$/$version$" , coordinates )).toPath ( );
65-         metadataDirectory  = getProject ().file (CoordinateUtils .replace ("metadata/$group$/$artifact$/$version$" , coordinates )).toPath ( );
64+         testsDirectory  = Path . of ( getProject ().file (CoordinateUtils .replace ("tests/src/$group$/$artifact$/$version$" , coordinates )).getAbsolutePath () );
65+         metadataDirectory  = Path . of ( getProject ().file (CoordinateUtils .replace ("metadata/$group$/$artifact$/$version$" , coordinates )).getAbsolutePath () );
6666        gradlew  = Path .of (getProject ().file ("gradlew" ).getAbsolutePath ());
6767    }
6868
@@ -84,7 +84,7 @@ void run() throws IOException {
8484        coordinates  = getCoordinates ();
8585        InteractiveTaskUtils .closeSection ();
8686
87-         Path  coordinatesMetadataRoot  = getProject ().file (CoordinateUtils .replace ("metadata/$group$/$artifact$" , coordinates )).toPath ( );
87+         Path  coordinatesMetadataRoot  = Path . of ( getProject ().file (CoordinateUtils .replace ("metadata/$group$/$artifact$" , coordinates )).getAbsolutePath () );
8888        boolean  isExistingLibrary  = Files .exists (coordinatesMetadataRoot );
8989
9090        Path  testsLocation  = getTestsLocation ();
@@ -170,9 +170,9 @@ private void checkPackages(Path testsPath) throws ContributingException {
170170
171171        for  (Path  file  : javaFiles ) {
172172            try  {
173-                 Optional <String > packageLine  = Files .readAllLines (file ).stream ().filter (line  -> line .contains ("package " )).findFirst ();
173+                 Optional <String > packageLine  = Files .readAllLines (file ).stream ().filter (line  -> line .trim (). startsWith ("package " )).findFirst ();
174174                if  (packageLine .isEmpty ()) {
175-                     throw  new  ContributingException ("Java file: "  + file  + " does not contain declared package" );
175+                     throw  new  ContributingException ("Java file: "  + file  + " does not contain declared package. " );
176176                }
177177
178178                String  declaredPackage  = packageLine .get ().split (" " )[1 ].replace (";" , "" );
@@ -211,10 +211,15 @@ private Path getResourcesLocation(){
211211    private  List <String > getDockerImages () {
212212        ContributingQuestion  question  = questions .get ("docker" );
213213        return  InteractiveTaskUtils .askRecurringQuestions (question .question (), question .help (), 0 , answer  -> {
214-             if  (answer .split (":" ).length  != 2 ) {
214+             String [] imageNameParts  = answer .split (":" );
215+             if  (imageNameParts .length  != 2 ) {
215216                throw  new  ContributingException ("Docker image name not provided in the correct format. Type help for explanation." );
216217            }
217218
219+             if  (imageNameParts [1 ].equalsIgnoreCase ("latest" )) {
220+                 throw  new  ContributingException ("Docker image tag cannot be latest." );
221+             }
222+ 
218223            return  answer ;
219224        });
220225    }
@@ -235,13 +240,10 @@ private List<Coordinates> getAdditionalDependencies() {
235240        });
236241    }
237242
238-     private  void  createStubs (boolean  shouldUpdate ){
243+     private  void  createStubs (boolean  shouldUpdate )  {
239244        InteractiveTaskUtils .printUserInfo ("Generating stubs for: "  + coordinates  );
240-         if  (shouldUpdate ) {
241-             invokeCommand (gradlew  + " scaffold --coordinates "  + coordinates  + " --skipTests --update " , "Cannot generate stubs for: "  + coordinates );
242-         } else  {
243-             invokeCommand (gradlew  + " scaffold --coordinates "  + coordinates  + " --skipTests" , "Cannot generate stubs for: "  + coordinates );
244-         }
245+         String  opt  = shouldUpdate  ? "--update"  : "" ;
246+         invokeCommand (gradlew  + " scaffold --coordinates "  + coordinates  + " --skipTests "  + opt , "Cannot generate stubs for: "  + coordinates );
245247    }
246248
247249    private  void  updateAllowedPackages (List <String > allowedPackages , boolean  libraryAlreadyExists ) throws  IOException  {
@@ -253,6 +255,7 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean library
253255        for  (int  i  = 0 ; i  < entries .size (); i ++) {
254256            if  (entries .get (i ).module ().equals (coordinates .group () + ":"  + coordinates .artifact ())) {
255257                replaceEntryIndex  = i ;
258+                 break ;
256259            }
257260        }
258261
@@ -270,11 +273,8 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean library
270273            entries .add (new  MetadataIndexEntry (replacedEntry .directory (), replacedEntry .module (), replacedEntry .requires (), new  ArrayList <>(extendedAllowedPackages )));
271274        }
272275
273-         List <MetadataIndexEntry > sortedEntries  = entries .stream ()
274-                 .sorted (Comparator .comparing (MetadataIndexEntry ::module ))
275-                 .toList ();
276- 
277-         objectMapper .writeValue (metadataIndex , sortedEntries );
276+         entries .sort (Comparator .comparing (MetadataIndexEntry ::module ));
277+         objectMapper .writeValue (metadataIndex , entries );
278278    }
279279
280280    private  void  addTests (Path  originalTestsLocation ){
@@ -338,14 +338,14 @@ private void addUserCodeFilterFile(List<String> packages) throws IOException {
338338    }
339339
340340    private  void  addAdditionalDependencies (List <Coordinates > dependencies ) throws  IOException  {
341-         if  (dependencies  ==  null ) {
341+         if  (dependencies . isEmpty () ) {
342342            return ;
343343        }
344344
345345        Path  buildFilePath  = testsDirectory .resolve (BUILD_FILE );
346346        InteractiveTaskUtils .printUserInfo ("Adding following dependencies to "  + BUILD_FILE  + " file: "  + dependencies );
347347
348-         if  (!Files .exists ( buildFilePath ) || ! Files . isRegularFile (buildFilePath )) {
348+         if  (!Files .isRegularFile (buildFilePath )) {
349349            throw  new  RuntimeException ("Cannot add additional dependencies to "  + buildFilePath  + ". Please check if a "  + BUILD_FILE  + " exists on that location." );
350350        }
351351
@@ -369,7 +369,7 @@ private void addAgentConfigBlock() throws IOException {
369369        Path  buildFilePath  = testsDirectory .resolve (BUILD_FILE );
370370        InteractiveTaskUtils .printUserInfo ("Configuring agent block in: "  + BUILD_FILE );
371371
372-         if  (!Files .exists ( buildFilePath ) || ! Files . isRegularFile (buildFilePath )) {
372+         if  (!Files .isRegularFile (buildFilePath )) {
373373            throw  new  RuntimeException ("Cannot add agent block to "  + buildFilePath  + ". Please check if a "  + BUILD_FILE  + " exists on that location." );
374374        }
375375
@@ -446,7 +446,7 @@ private void invokeCommand(String executable, List<String> args, String errorMes
446446    }
447447
448448    private  void  ensureFileBelongsToProject (Path  file ) {
449-         if  (!file .startsWith (getProject ().getProjectDir ().getAbsolutePath ())) {
449+         if  (!file .isAbsolute () || ! file . startsWith (getProject ().getProjectDir ().getAbsolutePath ())) {
450450            throw  new  RuntimeException ("The following file doesn't belong to the metadata repository: "  + file );
451451        }
452452    }
0 commit comments