-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add 'sourceSortOrder' to decide how source files are iterated #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'sourceSortOrder' to decide how source files are iterated #719
Conversation
…es' to process source files before directories
Can you help me understand why the existing code which uses I assume that you're using $refs without specifying javaType in your schemas, this isn't recommended as there are a variety of other ways in which your types can be read in a different order and hence generate different names. |
Hi @joelittlejohn Thanks for the fast response. When investigating the issue we were seeing we did a small test using java.lang.File list files and then using On Linux: New On Windows: New Thanks for highlighting around the javaType, we're exploring the possibility of submitting a further feature pull request to enable this to be relative to the target package. |
Is there a reason we cannot just sort these files by their canonical paths? It seems like that would be a much simpler change and should stabilize the sort order, since natural order is clearly defined for strings in Java. |
Hi @ctrimble Thanks for the comment. I think we'd still see inconsistencies between file generation if we're exclusively sorting on the canonical path, we would see files sorted equally with sub directories, as in example above with the Given the scenario where we process the files as: We'll create: Given a subsequent addition of a new schema This time creating: Note the package change. The feature we're proposing will ensure that this scenario is covered, in that the first scenario will be processed as: Creating: And then the second scenario will be processed as: Creating: This goes some way toward helping out with workaround around: |
@Paul-Vincent The sort order here is still going to be unstable. The root cause is that files are visited in a different order on Unix systems and Windows systems, because Windows does not take case into account. https://docs.oracle.com/javase/7/docs/api/java/io/File.html#compareTo(java.io.File) This fix does not address root cause, as you are still going to have an unstable sort order. For instance, the files There are issues with the mapping between source file locations and generated file locations in this project, but that problem is not being directly addressed by this PR. |
Hi @ctrimble, The issue we're trying to resolve with this PR is to resolve the files and directories issue that we're seeing at the moment without the PR. We can add to the PR to do a case insensitive sort within files and directories if you feel it would be use? |
@Paul-Vincent I don't know what Joe wants to do with this, but I would not take this approach to solving the issue. You are encountering an incompatibility between the sort order of files on Windows and Linux, per the PR description. That problem will still exist, in part, after the PR is applied. Subdirectories with mixed case will still be visited in different order. Files in the same directory with mixed case will still be visited in a different order. Based of the examples offered and issues sited, it seems like the issues of inconsistent sort order and generated file location are being conflated. In my opinion, each should be addressed individually, with the former being a bug in the comparator and the latter being a more systemic problem with the overall visit order of the schemas. |
Just in my opinion, the case used within files and directories is within the control of the user so shouldn't be much of a factor, even though it would be nice to be consistent. By ensuring that directories are processed after files it means that we, as clients, can control the generated packages, we have means through the javaName/javaType to ensure the class name is as we expect. The biggest problem we're trying to address here is the package that classes are being generated within, our CI environment using Linux but some of our developers use Windows. |
@ctrimble @joelittlejohn Hi guys, please let me know what we can do to help progress this discussion. We're coming up against some internal milestone dates, and we may need to work around this. Thanks. |
@Paul-Vincent I would feel comfortable merging a PR that was based on sorting files by |
thanks @ctrimble So if we change the comparator to do a case insensitive sort first based on the canonical path, and ensure files are before directories we'll be good? As an example resulting in:
|
Without regard to the type of node (file or directory), but just on the canonical path. The comparison should look something like this:
That will give you the same set of generated files on Linux and Windows. The flag will need to be a configuration option and will let those doing Windows only work keep the current functionality. note: I am not sure what that flag should be called. |
I think this is a good compromise and way forward to do something useful here that solves your problem. Without using javaType in your schemas you'll likely still have occasional surprises when editing your input, however if the result of this PR is at least that output can be made predictable when the same exact project is built on different OSs then that will be a positive change. @ctrimble has identified that the current changes do not solve the problem of OS-specific ordering and I agree that solving this should be the goal of this PR. There seems to be one final question here about how to treat subdirectories. Sorting by canonical path is simple, and solves the problem of OS-specific output, but I don't think it it produces behaviour that is particularly useful or expected. I think dipping in and out of subdirectories and mixing files in the current directory with files in subdirectories as you iterate is a strange thing to do. So I'd be happy with iteration order that uses: case-sensitive-sorted files followed by case-sensitive-sorted directories (or vice-versa). The only question that remains for me is, which makes more sense, directories first or files first? I actually think directories first makes more sense, since I imagine that subdirectories contain shared things that schemas alongside those subdirectories will use. In this case, it's nicer for the naming of those items in subdirectories to be driven by their own filenames and not any $refs to them. Do you think the opposite is true? People generally put shared schemas in the root directory and then have subdirectories with schemas inside that use e.g. I'd actually be happy to call any configuration option we introduce here simply |
Joe, this is your call, but the naming problem with |
@ctrimble Yes, I agree. I only mention issues with The more I think about this, the more I think that whatever strategy we choose here we'll see another issue or PR raised soon with an alternative requirement. I think my preferred solution would be:
We don't need to decide to align with any new sort order in particular because the current behaviour is going to become the default. If anyone wants any other strategy (and that strategy is sensible) then we can add it. I use the word 'source' here rather than 'input' because it fits with the naming convention for the other config arguments. I think it's fair to say that the fact that this option needs to exist at all is proof of bad decisions on my part back when this project started. It's a sticking-plaster for a much deeper problem but I'm happy to see this added as I think people would find it useful and it's fairly easy and simple to implement. |
Thanks for the feedback guys, it's a nice idea to cater for various sorting options. I'll update the pull request aa soon as I can, hopefully this weekend. |
Hi, thanks for the feedback @joelittlejohn and @ctrimble. I've updated the configuration option, removing the previously added Please note that this is a case sensitive sort as per @joelittlejohn last comment. |
Great stuff Paul, and thanks to @ctrimble for valuable input too.
I'm on vacation right now but will look at this as soon as I return (which
is Friday).
…On Tuesday, 18 April 2017, Paul Vincent ***@***.***> wrote:
Hi, thanks for the feedback @joelittlejohn
<https://github.com/joelittlejohn> and @ctrimble
<https://github.com/ctrimble>. I've updated the configuration option,
removing the previously added processSourceFiledBeforeDirectories with
the suggestion of sourceSortOrder configuration option with the options
of OS, SUBDIRS_FIRST or FILES_FIRST.
Please note that this is a case sensitive sort as per @joelittlejohn
<https://github.com/joelittlejohn> last comment.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#719 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAp5MIsNoTTsWc6nD1d9D9z3C4wfcKmjks5rxPhSgaJpZM4M6RWR>
.
|
Based on a quick browse I like the approach you've taken to implement this.
Your changes look thorough and so I expect this can be merged quickly.
One minor comment: could you fix the places where code style is not
consistent with this project?
* Opening braces should be on the same line
* Regular imports should not use wildcards
* Static imports should always use wildcards.
This helps to avoid ping-pong style edits where each author is reorganising
the imports.
…On Tuesday, 18 April 2017, Joe Littlejohn ***@***.***> wrote:
Great stuff Paul, and thanks to @ctrimble for valuable input too.
I'm on vacation right now but will look at this as soon as I return (which
is Friday).
On Tuesday, 18 April 2017, Paul Vincent ***@***.***
***@***.***');>> wrote:
> Hi, thanks for the feedback @joelittlejohn
> <https://github.com/joelittlejohn> and @ctrimble
> <https://github.com/ctrimble>. I've updated the configuration option,
> removing the previously added processSourceFiledBeforeDirectories with
> the suggestion of sourceSortOrder configuration option with the options
> of OS, SUBDIRS_FIRST or FILES_FIRST.
>
> Please note that this is a case sensitive sort as per @joelittlejohn
> <https://github.com/joelittlejohn> last comment.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#719 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAp5MIsNoTTsWc6nD1d9D9z3C4wfcKmjks5rxPhSgaJpZM4M6RWR>
> .
>
|
Great thanks @joelittlejohn. I fully understand about avoiding the ping-pong edits, I've updated the formatting and the imports as requested. |
@Paul-Vincent Just in case you didn't see it, 0.4.34 is released with your changes. Thanks again! |
…es' to process source files before directories.
We have noticed that when running the code generation on Windows and Linux we can inconsistencies of which packages included sub-classes were being created. Given the source files:
src/main/resources/virtualization-capabilities-api/schema/json/includes/MessageProperties.jsd
src/main/resources/virtualization-capabilities-api/schema/json/includes/VirtualMachineQuery.jsd
src/main/resources/virtualization-capabilities-api/schema/json/VMQueryRequestMessage.jsd
On our Linux box it generates:
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/MessageProperties.java
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/Query.java
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/VMQueryRequestMessage.java
And on Windows it generates:
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/includes/MessageProperties.java
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/includes/VirtualMachineQuery.java
target/generated-sources/virtualization-capabilities-api/com/dell/cpsd/vcenter/capabilities/api/VMQueryRequestMessage.java
We're submitting this new configuration option to ensure that within a directory, files are processed first before any sub-directories to ensure consistency between environments. The default
false
maintains the existing behaviour to ensure backward compatibility.We could only provide an integration test for when the option is set to
true
, as in this case we can verify the behaviour, thefalse
configuration option assertions would depend on the underlying OS.