Skip to content

Commit e945517

Browse files
committed
Gradle: use a different line conversion procedure to avoid Git glitches
1 parent 33ae100 commit e945517

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

build.gradle

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ tasks.register('checkLegacyJava') {
114114
classes.finalizedBy checkLegacyJava
115115

116116
tasks.register('lineEndingConversion', CRLFConvert) {
117+
description 'Convert top-level files to Windows line endings'
118+
file "$rootDir/RELEASE_NOTES.md"
119+
}
120+
121+
tasks.register('lineEndingConvCopy', CRLFConvertCopy) {
117122
description 'Convert LICENSE and NOTICE to Windows line endings'
118-
file "$rootDir/LICENSE.txt"
119-
file "$rootDir/NOTICE.txt"
123+
from "$rootDir/LICENSE.txt"
124+
from "$rootDir/NOTICE.txt"
120125
}
121126

122127
tasks.register('cleanBuildSrc') {
@@ -146,15 +151,17 @@ tasks.withType(AbstractArchiveTask).configureEach {
146151
preserveFileTimestamps = false
147152
reproducibleFileOrder = true
148153
// Copy license file
149-
dependsOn lineEndingConversion
150-
from ('LICENSE.txt') {
154+
dependsOn lineEndingConvCopy
155+
from ("$buildDir/tmp/crlf/LICENSE.txt") {
151156
into 'META-INF'
152157
}
153-
from ('NOTICE.txt') {
158+
from ("$buildDir/tmp/crlf/NOTICE.txt") {
154159
into 'META-INF'
155160
}
156161
}
157162

163+
build.dependsOn lineEndingConversion
164+
158165
publishing {
159166
repositories {
160167
maven {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* -*- Mode: groovy; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2+
* This file is dual licensed under the BSD-3-Clause and the MPL.
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7+
8+
import org.gradle.api.DefaultTask
9+
import org.gradle.api.tasks.TaskAction
10+
11+
/**
12+
* Converts line endings to CRLF (Windows), copy to build/tmp/crlf
13+
* <p>
14+
* Usage:
15+
* </p>
16+
* <code>
17+
* tasks.register('lineEndingConvCopy', CRLFConvertCopy) {
18+
* from "path/to/file1.txt"
19+
* from "path/to/fileN.txt"
20+
* }
21+
* </code>
22+
*/
23+
class CRLFConvertCopy extends DefaultTask {
24+
25+
private static final String CRLF = "\r\n"
26+
private static final String LF = "\n"
27+
28+
private files = []
29+
30+
@TaskAction
31+
def action() {
32+
def tmpDir = new File(project.buildDir, 'tmp');
33+
def destDir = new File(tmpDir, 'crlf');
34+
if (!destDir.exists()) {
35+
destDir.mkdirs();
36+
}
37+
files.each { path ->
38+
def file = new File(path)
39+
if (file.exists()) {
40+
String content = file.text
41+
String newContent = content.replaceAll(/\r\n/, LF)
42+
newContent = newContent.replaceAll(/\n|\r/, CRLF)
43+
def dest = new File(destDir, file.name);
44+
dest.write(newContent, 'utf-8')
45+
} else {
46+
logger.warn('File ' + path + ' does not exist.')
47+
}
48+
}
49+
}
50+
51+
def from(String path) {
52+
this.files << path
53+
}
54+
}

0 commit comments

Comments
 (0)