Created by: brettwooldridge
This pull request is to address various minor, but annoying, differences between buck generated IntelliJ project files and those generated by IntelliJ itself.
Our team commits buck generated IntelliJ project file artifacts into our repository. However, the simple act of opening the project in IntelliJ results in IntelliJ making various minor (typically whitespace) changes to the project files resulting in spurious diffs with the committed artifacts.
I'll attempt to cover each one by one.
ij-library.st
The ij-library.st
template is responsible for library_XXX.xml
file generation. Opening the project in IntelliJ and closing it again resulted in these differences compared to the buck generated version:
+ <JAVADOC />
+ <SOURCES />
</library>
-</component>
+</component>
\ No newline at end of file
The ij-library.st
template was modified with %else%
conditionals to generate empty XML tags for javadoc and sources when not present. Additionally, the newline at the end of the template was removed.
ij-module-index.st
The ij-module-index.st
template is responsible for modules.xml
file generation. Opening the project in IntelliJ and closing it again resulted in these differences compared to the buck generated version:
- <module fileurl="..." filepath="..." group="modules" />
+ <module fileurl="..." filepath="..." group="modules" />
-
</modules>
The buck generated files contained:
- an additional whitespace character before the
group
attribute - an additional whitespace character before the closing
/>
- an additional newline after the last module entry
IntelliJ strips these and updates the file when the project is opened, which creates a diff for every module in the modules.xml
file (in our case, about 80 modules).
The ij-library.st
template was modified to align the buck generated files to the format maintained by IntelliJ. The removal of whitespace from the template makes it slightly less readable, but after studying the stringtemplate4 syntax I cannot come up with anything more readable.
IjProjectTemplateDataPreparer.java
When buck generates the modules.xml
file it ordered the modules by the natural ordering of the module filepaths. IntelliJ sorts the modules by an ordered depth first traversal of the filesystem represented by the module filepaths.
In other words, this is an example ordering based on a purely alphanumeric sort, as was previously done by buck:
proj/org.company.server.core.jobs.db/proj_org_company_server_core_jobs_db.iml
proj/org.company.server.core.jobs/proj_org_company_server_core_jobs.iml
proj/org.company.server.core/netld_org_company_server_core.iml
And here is the same based on an ordered depth first traversal of the projects, as is done by IntelliJ:
proj/org.company.server.core/netld_org_company_server_core.iml
proj/org.company.server.core.jobs/proj_org_company_server_core_jobs.iml
proj/org.company.server.core.jobs.db/proj_org_company_server_core_jobs_db.iml
You can see that it is basically inverted. In an alphanumeric sort the .
has higher precedence than /
and therefore sorts first in contrast to the file system traversal. This results in IntelliJ updating the module.xml
with a different ordering (but same content) as that generating by buck:
- <module fileurl="..." filepath="$PROJECT_DIR$/proj/org.company.server.core.jobs.db/proj_org_company_server_core_jobs_db.iml" group="modules" />
- <module fileurl="..." filepath="$PROJECT_DIR$/proj/org.company.server.core.jobs/proj_org_company_server_core_jobs.iml" group="modules" />
<module fileurl="..." filepath="$PROJECT_DIR$/proj/org.company.server.core/proj_org_company_server_core.iml" group="modules" />
+ <module fileurl="..." filepath="$PROJECT_DIR$/proj/org.company.server.core.jobs/proj_org_company_server_core_jobs.iml" group="modules" />
+ <module fileurl="..." filepath="$PROJECT_DIR$/proj/org.company.server.core.jobs.db/proj_org_company_server_core_jobs_db.iml" group="modules" />
The change to IjProjectTemplateDataPreparer.java
alters the AbstractModuleIndexEntry
implementation of the Comparable.compareTo()
method to "demote" the path segment separator character for comparison purposes, with the resulting sorted module list matching an ordered depth first file system traversal. Thus, the buck generated modules.xml
file maintains the same order as IntelliJ and spurious diffs are not generated when opening/closing the project in the IDE.