reuse-tool
reuse-tool copied to clipboard
Better gradle support
I have encountered multiple project that include gradle build files. The reuse-tool support can be added and improved.
gradlew
Located in the root of the project is the gradlew
file. It is basically a shell script, so using the Python comment style (#
) would be good.
gradlew.bat
Also located in the root of the project it is a bat file. As it has an extension, this is currently recognized by reuse-tool, although it uses a different comment syntax. The gradlew.bat
file uses @rem
prefixes by default, and currently reuse-tool introduces REM
prefixes. I dislike the mismatch in commenting syntax, but I'm not sure if this has any practical consequences.
gradle-wrapper.properties
Nested in gradle/wrapper/gradle-wrapper.properties
is some configuration. I found the comment syntax to be the Python style (#
).
Proposal
With my current knowledge, I think the best steps would be for reuse-tool to:
- Add the Python default comment style for
gradlew
andgradle-wrapper.properties
filenames - Maybe update the
bat
file comment syntax. Perhaps detect the used one to match existing comments.
What do you think about this?
For the 1st suggestion I already created a pull-request.
I tried changing the gradlew.bat
header syntax from REM
to @rem
and retrigger the --add-header
command. It doesn't recognizes the header with the @rem
syntax and just adds a new set of entries. This results in something like:
REM SPDX-FileCopyrightText: 2020-2021 CopyrightHolder
REM
REM SPDX-License-Identifier: Apache-2.0
@rem SPDX-FileCopyrightText: 2020-2021 CopyrightHolder
@rem
@rem SPDX-License-Identifier: Apache-2.0
It seems capitalization is not an issue here (REM
vs rem
) but most tutorials I have found are using capitals. Regarding the @
sign, this apparently is a way to prevent printing the line when executing the file. It is typically found for an echo
command like @echo
to prevent first writing the command with the message and then again printing it. This post explains it clear and simple.
Of course one could prevent printing all statements from a file using @echo off
, but not all files we encounter might have that.
Some ideas that come to my mind to improve the situation:
- Scan for the use of
@echo off
and determine whether or not to prepend the command syntax with the@
symbol. - Find the first use of a comment statement (
rem
,REM
,@rem
,@REM
) and reuse that style for adding the headers. - Treat the
gradlew.bat
files differently then other batch files and have a dedicated@rem
comment syntax for these files.
I tried changing the
gradlew.bat
header syntax fromREM
to@rem
and retrigger the--add-header
command. It doesn't recognizes the header with the@rem
syntax and just adds a new set of entries. This results in something like:
Ah, that's nasty, and probably the first step to approach this. Did you try to add @rem
as a new comment style to the tool? I am not fully certain but perhaps that makes REUSE understand the existing lines and does not add to them.
On the other hand, it's also like that REUSE expects REM
because it detects the file names as a bat file.
Programmatically from your options I would prefer 3, but only if we are somewhat certain that this odd comment style only happens with these. If not, 2 would be my next favourite choice, but that of course adds some complexity.
It seems that the gradlew.bat
file has been using the lower case variant since the beginning: https://github.com/gradle/gradle/blob/f966f1f61ada1e34075787709d6608ef91592d8b/gradlew.bat
But if I do a GitHub code search, I can find multiple cases where capitalized comments were found: https://github.com/search?q=language%3Abatch+REM+filename%3Agradlew.bat&type=Code
But in any case, the comments were prefixed with a @
sign.
Maybe we can change the generic batch file comment style to include the @
sign? Most entries that pop up in a GitHub code search that use REM
instead of @REM
, start with an echo off
to prevent printing license information: https://github.com/search?q=language%3Abatch+REM+copyright&type=Code
In an Android project I encountered a gradle.properties
file as well. It uses the Python #
comment style.