reuse-tool icon indicating copy to clipboard operation
reuse-tool copied to clipboard

Better gradle support

Open nicorikken opened this issue 3 years ago • 5 comments

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:

  1. Add the Python default comment style for gradlew and gradle-wrapper.properties filenames
  2. Maybe update the bat file comment syntax. Perhaps detect the used one to match existing comments.

What do you think about this?

nicorikken avatar Apr 29 '21 12:04 nicorikken

For the 1st suggestion I already created a pull-request.

nicorikken avatar Apr 29 '21 12:04 nicorikken

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

nicorikken avatar Apr 29 '21 13:04 nicorikken

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:

  1. Scan for the use of @echo off and determine whether or not to prepend the command syntax with the @ symbol.
  2. Find the first use of a comment statement (rem, REM, @rem, @REM) and reuse that style for adding the headers.
  3. Treat the gradlew.bat files differently then other batch files and have a dedicated @rem comment syntax for these files.

nicorikken avatar Apr 30 '21 05:04 nicorikken

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:

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.

mxmehl avatar Apr 30 '21 12:04 mxmehl

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

nicorikken avatar May 03 '21 11:05 nicorikken

In an Android project I encountered a gradle.properties file as well. It uses the Python # comment style.

nicorikken avatar Oct 20 '22 13:10 nicorikken