Skip to content

Commit

Permalink
[release-later] Remove deprecated code usages
Browse files Browse the repository at this point in the history
  • Loading branch information
remal committed Dec 22, 2024
1 parent 9778b87 commit 5c169f5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle/github-submit-dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ allprojects {
pluginManager.withPlugin('java') {
project.apply plugin: 'reporting-base'

Task githubSubmitDependencies = tasks.create('githubSubmitDependencies') { Task task ->
TaskProvider githubSubmitDependencies = tasks.register('githubSubmitDependencies') { Task task ->
task.group = 'documentation'

SetProperty<DependencyToSubmit> lazyDependenciesToSubmitSet = project.objects.setProperty(DependencyToSubmit.class).with { it.finalizeValueOnRead(); it }
Expand Down
94 changes: 50 additions & 44 deletions gradle/publish-maven-push-back.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import static java.util.stream.Collectors.toList

import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser
import org.gradle.internal.resource.transport.http.HttpErrorStatusCodeException
Expand All @@ -13,61 +15,65 @@ tasks.register('pushBackPublishedVersions') { Task task ->
task.group = 'documentation'
task.outputs.upToDateWhen { false }

doLast {
Collection<String> versionFilePaths = new LinkedHashSet<>()
ListProperty<MavenPublication> allMavenPublications = objects.listProperty(MavenPublication).value(provider {
project.allprojects.stream()
.filter { it.pluginManager.hasPlugin('maven-publish') }
.flatMap { it.publishing.publications.withType(MavenPublication).stream() }
.map { MavenPublication.cast(it) }
.forEach { MavenPublication publication ->
String versionFilePath = "$publishedVersionsDirRelativePath/${publication.groupId}/${publication.artifactId}.version"
if (!versionFilePaths.add(versionFilePath)) {
return
}
.collect(toList())
}).with { it.finalizeValueOnRead(); it }

int maxAttempts = 3
for (int attempt = 1; attempt <= maxAttempts; ++attempt) {
Map getResponse = project.sendGitHubRestApiRequest(
"contents/${URLDecoder.decode(versionFilePath, 'UTF-8')}",
)
doLast {
Collection<String> versionFilePaths = new LinkedHashSet<>()
allMavenPublications.get().forEach { MavenPublication publication ->
String versionFilePath = "$publishedVersionsDirRelativePath/${publication.groupId}/${publication.artifactId}.version"
if (!versionFilePaths.add(versionFilePath)) {
return
}

String prevContent = getResponse?.content?.with {
new String(Base64.decoder.decode(it.trim()), "UTF-8").trim()
}
String curContent = publication.version
if (prevContent != null && !curContent.isEmpty()) {
VersionParser parser = new VersionParser()
def prevVer = parser.transform(prevContent)
def curVer = parser.transform(curContent)
Comparator comparator = new DefaultVersionComparator().asVersionComparator()
int comparisonResult = comparator.compare(prevVer, curVer)
if (comparisonResult == 0) {
logger.quiet("Version {} has been already reported to {}", curContent, versionFilePath)
return
} else if (comparisonResult > 0) {
logger.quiet("Version {} is less than what was already reported to {}: {}", curContent, versionFilePath, prevContent)
return
}
int maxAttempts = 3
for (int attempt = 1; attempt <= maxAttempts; ++attempt) {
Map getResponse = sendGitHubRestApiRequest(
"contents/${URLDecoder.decode(versionFilePath, 'UTF-8')}",
)

String prevContent = getResponse?.content?.with {
new String(Base64.decoder.decode(it.trim()), "UTF-8").trim()
}
String curContent = publication.version
if (prevContent != null && !curContent.isEmpty()) {
VersionParser parser = new VersionParser()
def prevVer = parser.transform(prevContent)
def curVer = parser.transform(curContent)
Comparator comparator = new DefaultVersionComparator().asVersionComparator()
int comparisonResult = comparator.compare(prevVer, curVer)
if (comparisonResult == 0) {
logger.quiet("Version {} has been already reported to {}", curContent, versionFilePath)
return
} else if (comparisonResult > 0) {
logger.quiet("Version {} is less than what was already reported to {}: {}", curContent, versionFilePath, prevContent)
return
}
}

try {
logger.quiet("Reporting version {} to {}", curContent, versionFilePath)
project.sendGitHubRestApiRequest(
"contents/${URLDecoder.decode(versionFilePath, 'UTF-8')}",
'PUT',
[
message: "[no-changelog] Update $versionFilePath",
content: Base64.encoder.encodeToString(curContent.getBytes('UTF-8')),
sha: getResponse?.sha
],
)
try {
logger.quiet("Reporting version {} to {}", curContent, versionFilePath)
sendGitHubRestApiRequest(
"contents/${URLDecoder.decode(versionFilePath, 'UTF-8')}",
'PUT',
[
message: "[no-changelog] Update $versionFilePath",
content: Base64.encoder.encodeToString(curContent.getBytes('UTF-8')),
sha: getResponse?.sha
],
)

} catch (HttpErrorStatusCodeException e) {
if (e.statusCode != 409 || attempt >= maxAttempts) {
throw e
}
} catch (HttpErrorStatusCodeException e) {
if (e.statusCode != 409 || attempt >= maxAttempts) {
throw e
}
}
}
}
}
}
7 changes: 4 additions & 3 deletions gradle/publish-maven-to-build-dir.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ if (project.isBuildSrcProject) {

allprojects {
pluginManager.withPlugin('maven-publish') {
TaskContainer tasks = project.tasks
tasks.register('publishToBuildDir') { Task task ->
task.group = 'publishing'

Closure<GenerateMavenPom> getGeneratePomFileTask = { MavenPublication publication ->
project.tasks.named(
tasks.named(
"generatePomFileFor${publication.name.capitalize()}Publication",
GenerateMavenPom
).get()
Expand All @@ -21,7 +22,7 @@ allprojects {
task.inputs.files(project.provider { publications.collect { getGeneratePomFileTask(it).destination }.flatten() }).optional().withPropertyName('pomFiles')
task.inputs.files(project.provider { publications.collect { it.artifacts.collect { it.file } }.flatten() }).optional().withPropertyName('artifactFiles')

File outputDir = project.file("${project.buildDir}/.m2")
File outputDir = project.layout.buildDirectory.dir(".m2").get().asFile
task.outputs.dir(outputDir).withPropertyName('outputDir')
task.ext.outputDir = outputDir

Expand All @@ -33,7 +34,7 @@ allprojects {

task.doLast {
publications.forEach { publication ->
File artifactDir = project.file("${outputDir}/${publication.groupId.replace('.', '/')}/${publication.artifactId}")
File artifactDir = new File(outputDir, "${publication.groupId.replace('.', '/')}/${publication.artifactId}")
File versionDir = new File(artifactDir, publication.version)

File pomFile = getGeneratePomFileTask(publication).destination
Expand Down
1 change: 0 additions & 1 deletion gradle/sonarlint.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ allprojects {
rules {
disable(
// see https://rules.sonarsource.com/

'java:S110', // Inheritance tree of classes should not be too deep
'java:S112', // Generic exceptions should never be thrown
'java:S125', // Sections of code should not be commented out
Expand Down

0 comments on commit 5c169f5

Please sign in to comment.