@@ -61,8 +61,8 @@ private record ContributingQuestion(String question, String help) {}
61
61
private final Map <String , ContributingQuestion > questions = new HashMap <>();
62
62
63
63
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 () );
66
66
gradlew = Path .of (getProject ().file ("gradlew" ).getAbsolutePath ());
67
67
}
68
68
@@ -84,7 +84,7 @@ void run() throws IOException {
84
84
coordinates = getCoordinates ();
85
85
InteractiveTaskUtils .closeSection ();
86
86
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 () );
88
88
boolean isExistingLibrary = Files .exists (coordinatesMetadataRoot );
89
89
90
90
Path testsLocation = getTestsLocation ();
@@ -170,9 +170,9 @@ private void checkPackages(Path testsPath) throws ContributingException {
170
170
171
171
for (Path file : javaFiles ) {
172
172
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 ();
174
174
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. " );
176
176
}
177
177
178
178
String declaredPackage = packageLine .get ().split (" " )[1 ].replace (";" , "" );
@@ -211,10 +211,15 @@ private Path getResourcesLocation(){
211
211
private List <String > getDockerImages () {
212
212
ContributingQuestion question = questions .get ("docker" );
213
213
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 ) {
215
216
throw new ContributingException ("Docker image name not provided in the correct format. Type help for explanation." );
216
217
}
217
218
219
+ if (imageNameParts [1 ].equalsIgnoreCase ("latest" )) {
220
+ throw new ContributingException ("Docker image tag cannot be latest." );
221
+ }
222
+
218
223
return answer ;
219
224
});
220
225
}
@@ -235,13 +240,10 @@ private List<Coordinates> getAdditionalDependencies() {
235
240
});
236
241
}
237
242
238
- private void createStubs (boolean shouldUpdate ){
243
+ private void createStubs (boolean shouldUpdate ) {
239
244
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 );
245
247
}
246
248
247
249
private void updateAllowedPackages (List <String > allowedPackages , boolean libraryAlreadyExists ) throws IOException {
@@ -253,6 +255,7 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean library
253
255
for (int i = 0 ; i < entries .size (); i ++) {
254
256
if (entries .get (i ).module ().equals (coordinates .group () + ":" + coordinates .artifact ())) {
255
257
replaceEntryIndex = i ;
258
+ break ;
256
259
}
257
260
}
258
261
@@ -270,11 +273,8 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean library
270
273
entries .add (new MetadataIndexEntry (replacedEntry .directory (), replacedEntry .module (), replacedEntry .requires (), new ArrayList <>(extendedAllowedPackages )));
271
274
}
272
275
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 );
278
278
}
279
279
280
280
private void addTests (Path originalTestsLocation ){
@@ -338,14 +338,14 @@ private void addUserCodeFilterFile(List<String> packages) throws IOException {
338
338
}
339
339
340
340
private void addAdditionalDependencies (List <Coordinates > dependencies ) throws IOException {
341
- if (dependencies == null ) {
341
+ if (dependencies . isEmpty () ) {
342
342
return ;
343
343
}
344
344
345
345
Path buildFilePath = testsDirectory .resolve (BUILD_FILE );
346
346
InteractiveTaskUtils .printUserInfo ("Adding following dependencies to " + BUILD_FILE + " file: " + dependencies );
347
347
348
- if (!Files .exists ( buildFilePath ) || ! Files . isRegularFile (buildFilePath )) {
348
+ if (!Files .isRegularFile (buildFilePath )) {
349
349
throw new RuntimeException ("Cannot add additional dependencies to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
350
350
}
351
351
@@ -369,7 +369,7 @@ private void addAgentConfigBlock() throws IOException {
369
369
Path buildFilePath = testsDirectory .resolve (BUILD_FILE );
370
370
InteractiveTaskUtils .printUserInfo ("Configuring agent block in: " + BUILD_FILE );
371
371
372
- if (!Files .exists ( buildFilePath ) || ! Files . isRegularFile (buildFilePath )) {
372
+ if (!Files .isRegularFile (buildFilePath )) {
373
373
throw new RuntimeException ("Cannot add agent block to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
374
374
}
375
375
@@ -446,7 +446,7 @@ private void invokeCommand(String executable, List<String> args, String errorMes
446
446
}
447
447
448
448
private void ensureFileBelongsToProject (Path file ) {
449
- if (!file .startsWith (getProject ().getProjectDir ().getAbsolutePath ())) {
449
+ if (!file .isAbsolute () || ! file . startsWith (getProject ().getProjectDir ().getAbsolutePath ())) {
450
450
throw new RuntimeException ("The following file doesn't belong to the metadata repository: " + file );
451
451
}
452
452
}
0 commit comments