Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions buildSrc/src/main/groovy/com.google.api-ads.release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ abstract class UpdateVersionTask extends DefaultTask {
if (!newVersion.matches(VERSION_REGEX)) {
throw new GradleException("Invalid format for -PnewVersion. Expecting: ${VERSION_REGEX}")
}
def toSet = new Properties()
propertiesFile.withInputStream { toSet.load(it) }
toSet.version = newVersion
propertiesFile.withOutputStream { toSet.store(it, "See LICENSE for license terms") }
// Rewrites only the version line. Properties.store() would reorder keys
// (in a JDK-dependent order) and add a timestamp comment, creating noisy
// diffs in release PRs. Matches the canonical `version=` form because
// the Kokoro release script reads it with `sed 's/^version=//'`.
def lines = propertiesFile.readLines()
def versionIndex = lines.findIndexOf { it.startsWith('version=') }
if (versionIndex < 0) {
throw new GradleException("No version property found in ${propertiesFile}")
}
lines[versionIndex] = "version=${newVersion}"
propertiesFile.text = lines.join('\n') + '\n'
}
}

Expand Down
47 changes: 47 additions & 0 deletions google-ads/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
*/


import groovy.json.JsonOutput
import groovy.json.JsonSlurper

import java.util.regex.Pattern
import java.util.stream.Collectors

import static nl.javadude.gradle.plugins.license.DownloadLicensesExtension.license
Expand Down Expand Up @@ -168,6 +170,12 @@ Googlers, there is a company policy for this available internally.""")
}
}

// Entry patterns for the com.github.hierynomus.license-report 0.16.1 output
// format. Each entry begins with the dependency name, so sorting the entry text
// orders entries by dependency name (matching the JSON sort in copyLicenses).
final Pattern XML_LICENSE_ENTRY = ~/(?s) <dependency name='[^']*'>.*?<\/dependency>\R/
final Pattern HTML_LICENSE_ENTRY = ~/(?s) <tr>\s*<td class='dependencies'>.*?<\/tr>\R/

task copyLicenses(type: Copy) {
description = "Copies licenses from build directory to third_party"
dependsOn 'verifyLicenses'
Expand Down Expand Up @@ -196,7 +204,46 @@ task copyLicenses(type: Copy) {
"Failed to locate files to copy from. Expected: 3 but was: "
+ inputs.sourceFiles.toList())
}

// The license-report plugin emits dependencies in a nondeterministic
// order. Sorts each report by dependency name so that diffs of
// third_party only show actual dependency changes.
def thirdPartyDir = tasks.generateThirdPartyDirectory.thirdPartyDir
sortLicenseReportEntries(new File(thirdPartyDir, 'LICENSES.xml'), XML_LICENSE_ENTRY)
sortLicenseReportEntries(new File(thirdPartyDir, 'LICENSES.html'), HTML_LICENSE_ENTRY)
def jsonFile = new File(thirdPartyDir, 'LICENSES.json')
def json = new JsonSlurper().parse(jsonFile)
json.dependencies = json.dependencies.sort(false) { it.name }
jsonFile.text = JsonOutput.toJson(json)
}
}

/**
* Sorts the contiguous entries matching entryPattern in a license report file,
* leaving the text before the first entry and after the last entry untouched.
* Fails if the entries aren't contiguous, so that an unexpected change in the
* report format can't silently corrupt the report.
*/
def sortLicenseReportEntries(File file, Pattern entryPattern) {
String text = file.text
def matcher = entryPattern.matcher(text)
List<String> entries = []
int start = -1
int end = -1
while (matcher.find()) {
if (start < 0) {
start = matcher.start()
} else if (matcher.start() != end) {
throw new GradleException(
"Unexpected content between license entries in ${file}")
}
end = matcher.end()
entries << matcher.group()
}
if (entries.isEmpty()) {
throw new GradleException("No license entries found in ${file}")
}
file.text = text.substring(0, start) + entries.sort().join('') + text.substring(end)
}

task copyThirdPartySources(type: Copy) {
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#See LICENSE for license terms
#Thu Oct 29 16:19:14 EDT 2026
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.console=rich
Expand Down
Loading
Loading