[bug] Fix FILES sort and path provider issue (#7729)

The FILES metadata is supplementary, but was logging a warning while
generating Ada client that FILES couldn't be written. An exception was
being thrown because Path was being reported as two different "types of
Path". One would be reported as mac file, while the other was reported
as a unix file. The fix here is to disconnect path details from the
underlying file system provider by creating a new Path based on the
file's absolute path. This change also fixes sorting so it works
alphabetically in ascending order.
This commit is contained in:
Jim Schubert
2020-10-16 00:34:34 -04:00
committed by GitHub
parent e1e38c8783
commit 41851b45e1
20 changed files with 48 additions and 36 deletions

View File

@@ -1433,6 +1433,11 @@ public class DefaultGenerator implements Generator {
}
}
private Path absPath(File input) {
// intentionally creates a new absolute path instance, disconnected from underlying FileSystem provider of File
return java.nio.file.Paths.get(input.getAbsolutePath());
}
/**
* Generates a file at .openapi-generator/FILES to track the files created by the user's latest run.
* This is ideal for CI and regeneration of code without stale/unused files from older generations.
@@ -1443,7 +1448,7 @@ public class DefaultGenerator implements Generator {
if (generateMetadata) {
try {
StringBuilder sb = new StringBuilder();
File outDir = new File(this.config.getOutputDir());
Path outDir = absPath(new File(this.config.getOutputDir()));
List<File> filesToSort = new ArrayList<>();
@@ -1452,7 +1457,7 @@ public class DefaultGenerator implements Generator {
// We have seen NPE on CI for getPath() returning null, so guard against this (to be fixed in 5.0 template management refactor)
//noinspection ConstantConditions
if (f != null && f.getPath() != null) {
filesToSort.add(f);
filesToSort.add(outDir.relativize(absPath(f)).normalize().toFile());
}
});
@@ -1461,13 +1466,12 @@ public class DefaultGenerator implements Generator {
String relativeMeta = METADATA_DIR + "/VERSION";
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
filesToSort.forEach(f -> {
String tmp = outDir.toPath().relativize(f.toPath()).normalize().toString();
// some Java implementations don't honor .relativize documentation fully.
// When outDir is /a/b and the input is /a/b/c/d, the result should be c/d.
// Some implementations make the output ./c/d which seems to mix the logic
// as documented for symlinks. So we need to trim any / or ./ from the start,
// as nobody should be generating into system root and our expectation is no ./
String relativePath = removeStart(removeStart(tmp, "." + File.separator), File.separator);
String relativePath = removeStart(removeStart(f.toString(), "." + File.separator), File.separator);
if (File.separator.equals("\\")) {
// ensure that windows outputs same FILES format
relativePath = relativePath.replace(File.separator, "/");

View File

@@ -0,0 +1,8 @@
config.gpr
src/client/samples-petstore-clients.adb
src/client/samples-petstore-clients.ads
src/model/samples-petstore-models.adb
src/model/samples-petstore-models.ads
src/samples-petstore-client.adb
src/samples-petstore.ads
src/samples.ads

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -11,9 +11,9 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
variables.ts

View File

@@ -11,11 +11,11 @@ git_push.sh
index.ts
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
ng-package.json
package.json
tsconfig.json

View File

@@ -7,8 +7,8 @@ api/userApi.ts
git_push.sh
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts

View File

@@ -7,10 +7,10 @@ api/userApi.ts
git_push.sh
model/apiResponse.ts
model/category.ts
model/models.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
package.json
tsconfig.json

View File

@@ -1,3 +1,7 @@
.coveralls.yml
.gitignore
.php_cs.dist
.travis.yml
Api/ApiServer.php
Api/PetApiInterface.php
Api/StoreApiInterface.php
@@ -6,27 +10,14 @@ Controller/Controller.php
Controller/PetController.php
Controller/StoreController.php
Controller/UserController.php
DependencyInjection/Compiler/OpenAPIServerApiPass.php
DependencyInjection/OpenAPIServerExtension.php
Model/ApiResponse.php
Model/Category.php
Model/Order.php
Model/Pet.php
Model/Tag.php
Model/User.php
Service/JmsSerializer.php
Service/SerializerInterface.php
Service/StrictJsonDeserializationVisitor.php
Service/SymfonyValidator.php
Service/TypeMismatchException.php
Service/ValidatorInterface.php
Tests/AppKernel.php
Tests/Controller/ControllerTest.php
Tests/test_config.yml
.coveralls.yml
.gitignore
.php_cs.dist
.travis.yml
DependencyInjection/Compiler/OpenAPIServerApiPass.php
DependencyInjection/OpenAPIServerExtension.php
OpenAPIServerBundle.php
README.md
Resources/config/routing.yml
@@ -40,6 +31,15 @@ Resources/docs/Model/Order.md
Resources/docs/Model/Pet.md
Resources/docs/Model/Tag.md
Resources/docs/Model/User.md
Service/JmsSerializer.php
Service/SerializerInterface.php
Service/StrictJsonDeserializationVisitor.php
Service/SymfonyValidator.php
Service/TypeMismatchException.php
Service/ValidatorInterface.php
Tests/AppKernel.php
Tests/Controller/ControllerTest.php
Tests/test_config.yml
autoload.php
composer.json
git_push.sh