Skip to content

Commit

Permalink
Merge pull request #8440 from gradle/bamboo/reproducible-properties
Browse files Browse the repository at this point in the history
Make `ReproduciblePropertiesWriter` entry order independent
  • Loading branch information
bamboo committed Feb 9, 2019
2 parents 8fe8f40 + 9e2bce0 commit d8484e9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 55 deletions.
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Expand Up @@ -190,7 +190,6 @@ fun Project.applyGroovyProjectConventions() {
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
jvmArgs("--illegal-access=deny")
}

}

val compileGroovy by tasks.existing(GroovyCompile::class)
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/subprojects/build/build.gradle.kts
@@ -1,8 +1,9 @@
dependencies {
api("com.google.guava:guava:26.0-jre")
api("org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2")
implementation("org.asciidoctor:asciidoctorj:1.5.8.1")

implementation(project(":buildPlatform"))
implementation("org.asciidoctor:asciidoctorj:1.5.8.1")
implementation("commons-lang:commons-lang:2.6")
implementation("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
implementation("com.github.javaparser:javaparser-core")
Expand Down
Expand Up @@ -13,38 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.build

import com.google.common.base.Charsets
import org.gradle.internal.util.PropertiesUtils

class ReproduciblePropertiesWriter {

/**
* Writes {@link Map} of data as {@link Properties} to a file, but without including the timestamp comment.
*
* See {@link PropertiesUtils#store(java.util.Properties, java.io.File)}.
*/
static void store(Map<String, ?> data, File file, String comment = null) {
def properties = new Properties()
data.each { key, value ->
properties.put(key, value == null ? null : value.toString())
}
store(properties, file, comment)
store(propertiesFrom(data), file, comment)
}

/**
* Writes {@link Properties} to a file, but without including the timestamp comment.
*
* See {@link PropertiesUtils#store(java.util.Properties, java.io.File)}.
*/
static void store(Properties properties, File file, String comment = null) {
def sw = new StringWriter()
properties.store(sw, null)
String systemLineSeparator = System.lineSeparator()
String lineSeparator = "\n" // Use LF to have the same result on Windows and on Linux
def content = sw.toString().split(systemLineSeparator).findAll { !it.startsWith("#") }.join(lineSeparator)
file.parentFile.mkdirs()
file.withWriter("8859_1") { BufferedWriter bw ->
if (comment) {
bw.write("# ${comment}")
bw.write(lineSeparator)
PropertiesUtils.store(properties, file, comment, Charsets.ISO_8859_1, "\n")
}

private static Properties propertiesFrom(Map<String, ?> data) {
new Properties().with {
data.forEach { key, value ->
put(key, value ?: value.toString())
}
bw.write(content)
it
}
}
}

This file was deleted.

Expand Up @@ -71,7 +71,7 @@ class WrapperGenerationIntegrationTest extends AbstractIntegrationSpec {
executer.inDirectory(file("second")).withTasks("wrapper").run()

then: "the checksum should be constant (unless there are code changes)"
sha256(file("first/gradle/wrapper/gradle-wrapper.jar")).asHexString() == "372ef28e56755b074af00b3d1e615efc695ae881fedce8eb398c583d534bdf4"
sha256(file("first/gradle/wrapper/gradle-wrapper.jar")).asHexString() == "7b9a14d31f0cfbc1a5587e0d77d8a0a9baa8f1db4382d64406d53a7a6a5e5e01"

and:
file("first/gradle/wrapper/gradle-wrapper.jar").md5Hash == file("second/gradle/wrapper/gradle-wrapper.jar").md5Hash
Expand Down

0 comments on commit d8484e9

Please sign in to comment.