git-commit-id / git-commit-id-maven-plugin

Maven plugin which includes build-time git repository information into an POJO / *.properties). Make your apps tell you which version exactly they were built from! Priceless in large distributed deployments... :-)

Home Page:http://www.kto.so

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chinene commit message support better

timbersea opened this issue · comments

the Chinese commit message in the git.properties will be transform as unicode such as \u4F18\u5316 ,it's diffcult to read for human

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties>
my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7
git.commit.message.short=\u611F\u53F9\u53F7 😓

commented

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7 git.commit.message.short=\u611F\u53F9\u53F7 😓

you can use <format>json</format> to resolve this

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7 git.commit.message.short=\u611F\u53F9\u53F7 😓

you can use <format>json</format> to resolve this

I don't think this solve the problem.

Below is method dumpProperties inside class PropertyManager from git-commit-id/git-commit-id-plugin-core, which is used by PropertiesFileGenerator's method maybeGeneratePropertiesFile, which is eventually called inside class GitCommitIdMojo.

public static void dumpProperties(OutputStream outputStream, OrderedProperties sortedLocalProperties) throws IOException {
        Writer outputWriter = new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1);

        try {
            outputWriter.write("#Generated by Git-Commit-Id-Plugin");
            outputWriter.write(System.getProperty("line.separator"));
            Iterator var3 = sortedLocalProperties.entrySet().iterator();

            while(var3.hasNext()) {
                Map.Entry<String, String> e = (Map.Entry)var3.next();
                String key = saveConvert((String)e.getKey(), true, true);
                String val = saveConvert((String)e.getValue(), false, true);
                outputWriter.write(key + "=" + val);
                outputWriter.write(System.getProperty("line.separator"));
            }
        } catch (Throwable var8) {
            try {
                outputWriter.close();
            } catch (Throwable var7) {
                var8.addSuppressed(var7);
            }

            throw var8;
        }

        outputWriter.close();
    }

function saveConvert has it's third parameter as escapeUnicode, this is why now Chinese inside git.properties are transformed to unicode.

Maybe we have to modify git-commit-id/git-commit-id-plugin-core to accept a new parameter to control whether escapeUnicode or not ?

Will do a pull request after git-commit-id/git-commit-id-plugin-core have 6.0.0 version out.

We can then control escape unicode or not by last parameter, which is a boolean, of method maybeGeneratePropertiesFile .
public void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, File base, String propertiesFilename, Charset sourceCharset, boolean escapeUnicode) throws GitCommitIdExecutionException

Pull request to github.com/git-commit-id/git-commit-id-plugin-core in order to control whether escapeUnicode or not by a new parameter.