Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build cache issues and improve task configuration #3368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 40 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -521,47 +521,69 @@ subprojects {
}

task generatePackageInfo {
doLast {
def allPathsContainingJavaFiles = [] as Set
String srcMainJava = 'src/main/java'
File outputDir = project.layout.buildDirectory.dir(name).get().asFile
inputs.files(fileTree(srcMainJava).matching() {
include "*/**/*.java"
exclude "*/**/package-info.java"
}).withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir outputDir
outputs.cacheIf { true }

fileTree('src/main/java/').matching() {
include "*/**/*.java"
exclude "*/**/package-info.java"
}.forEach {
allPathsContainingJavaFiles << it.toPath().toFile().getParent();
doLast {
Set<String> allPathsContainingJavaFiles = [] as Set<String>
inputs.files.files.forEach {
allPathsContainingJavaFiles << it.toPath().toFile().parent
}

allPathsContainingJavaFiles.each {
String packageInfoPath = it + "/package-info.java"
File packageInfoFile = new File (packageInfoPath)
if (!packageInfoFile.exists()) {
logger.info("Creating file: " + packageInfoPath)
def packageName = packageInfoFile.getParent().replaceAll("[\\\\ /]", ".").takeAfter("src.main.java.");
String dir = it as String
File packageInfoInputFile = project.file("${dir}/package-info.java")

File packageInfoOutputDir = project.file(dir.replace(project.file(srcMainJava).absolutePath, outputDir.absolutePath))
packageInfoOutputDir.mkdirs()
String packageInfoOutputPath = "${packageInfoOutputDir.absolutePath}/package-info.java"
File packageInfoOutputFile = project.file(packageInfoOutputPath)

if (!packageInfoInputFile.exists()) {
logger.info("Creating file: " + packageInfoOutputPath)
def packageName = packageInfoOutputFile.getParent().replaceAll("[\\\\ /]", ".").takeAfter("${name}.");
String packageInfoContent = applyPackageInfoTemplate(packageName)
packageInfoFile << packageInfoContent
packageInfoOutputFile << packageInfoContent
}
}

def allPackageInfoFiles = [] as Set

fileTree('src/main/java/').matching() {
fileTree(outputDir).matching() {
include "*/**/package-info.java"
}.forEach {
allPackageInfoFiles << it.toPath().toFile();
allPackageInfoFiles << it.toPath().toFile()
}

allPackageInfoFiles.forEach {
File packageInfoFile = it;
if (!allPathsContainingJavaFiles.contains(packageInfoFile.getParent())) {
File packageInfoFile = it as File
if (!allPathsContainingJavaFiles.contains(packageInfoFile.parent)) {
logger.warn("Deleting package info file: " + packageInfoFile)
packageInfoFile.delete();
packageInfoFile.delete()
}
}

}
}

task copyPackageInfo(type: Copy) {
from generatePackageInfo
into 'src/main/java'
}

build.dependsOn(generatePackageInfo)
tasks.named('licenseMain').configure { it.mustRunAfter(generatePackageInfo, copyPackageInfo) }
tasks.named('licenseFormatMain').configure { it.mustRunAfter(generatePackageInfo, copyPackageInfo) }
tasks.named('compileJava').configure { it.mustRunAfter(generatePackageInfo, copyPackageInfo) }
generatePackageInfo.finalizedBy(licenseFormat)
generatePackageInfo.finalizedBy(copyPackageInfo)


jacocoTestReport {
reports {
Expand Down
3 changes: 3 additions & 0 deletions server/sonar-db-dao/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ test {
task dumpSchema(type:JavaExec) {
mainClass = 'org.sonar.db.dump.DumpSQSchema'
classpath = sourceSets.test.runtimeClasspath

outputs.file 'src/schema/schema-sq.ddl'
outputs.doNotCacheIf('Caching has not been enabled for the task.') { true }
}

tasks.check.dependsOn dumpSchema
Expand Down
6 changes: 6 additions & 0 deletions server/sonar-web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ task licenseCheckWeb(type: com.hierynomus.gradle.license.tasks.LicenseCheck) {
source = sources
exclude 'main/js/helpers/standards.json'
if (official) exclude 'main/js/app/components/GlobalFooterBranding.js'
subprojects { subproject ->
mustRunAfter(subproject.copyPackageInfo)
}
}
licenseMain.dependsOn licenseCheckWeb

task licenseFormatWeb(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
source = sources
if (official) exclude 'main/js/app/components/GlobalFooterBranding.js'
subprojects { subproject ->
mustRunAfter(subproject.copyPackageInfo)
}
}
licenseFormat.dependsOn licenseFormatWeb
5 changes: 5 additions & 0 deletions sonar-application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ downloadLicenses {
}

tasks.register('downloadJres') {
inputs.file(layout.projectDirectory.dir('src/main/resources/jres-metadata.json').asFile).withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir(layout.buildDirectory.file('jres'))
outputs.cacheIf { true }

doLast {
def jresMetadata = new JsonSlurper().parse(file(layout.projectDirectory.dir('src/main/resources/jres-metadata.json').asFile))
jresMetadata.each { jre ->
Expand Down Expand Up @@ -363,6 +367,7 @@ task cleanLocalUnzippedDir(dependsOn: zip) {
def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
outputs.upToDateWhen { true }
outputs.cacheIf('Caching has not been enabled for the task.') { false }

doLast {
println("delete directory ${unzippedDir}")
Expand Down