-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/gradle-8.x
- Loading branch information
Showing
82 changed files
with
5,113 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,130 @@ | ||
package buildsrc.utils | ||
|
||
import java.io.File | ||
import javax.inject.Inject | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.ProjectLayout | ||
import org.gradle.plugins.ide.idea.model.IdeaModule | ||
import org.gradle.api.Task | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.FileSystemOperations | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.ValueSource | ||
import org.gradle.api.provider.ValueSourceParameters | ||
import org.gradle.configurationcache.extensions.serviceOf | ||
import org.gradle.kotlin.dsl.* | ||
import org.gradle.plugins.ide.idea.model.IdeaModel | ||
|
||
|
||
/** exclude generated Gradle code, so it doesn't clog up search results */ | ||
fun IdeaModule.excludeGeneratedGradleDsl(layout: ProjectLayout) { | ||
/** | ||
* Exclude directories containing | ||
* | ||
* - generated Gradle code, | ||
* - IDE files, | ||
* - Gradle config, | ||
* | ||
* so they don't clog up search results. | ||
*/ | ||
fun Project.excludeProjectConfigurationDirs( | ||
idea: IdeaModel | ||
) { | ||
val excludedDirs = providers.of(IdeaExcludedDirectoriesSource::class) { | ||
parameters.projectDir.set(layout.projectDirectory) | ||
}.get() | ||
|
||
idea.module.excludeDirs.addAll(excludedDirs) | ||
} | ||
|
||
val generatedSrcDirs = listOf( | ||
"kotlin-dsl-accessors", | ||
"kotlin-dsl-external-plugin-spec-builders", | ||
"kotlin-dsl-plugins", | ||
) | ||
// Have to use a ValueSource to find the files, otherwise Gradle | ||
// considers _all files_ an input for configuration cache 🙄 | ||
internal abstract class IdeaExcludedDirectoriesSource : | ||
ValueSource<Set<File>, IdeaExcludedDirectoriesSource.Parameters> { | ||
|
||
interface Parameters : ValueSourceParameters { | ||
val projectDir: DirectoryProperty | ||
} | ||
|
||
excludeDirs.addAll( | ||
layout.projectDirectory.asFile.walk() | ||
.filter { it.isDirectory && it.parentFile.name in generatedSrcDirs } | ||
override fun obtain(): Set<File> { | ||
val projectDir = parameters.projectDir.get().asFile | ||
|
||
val doNotWalkDirs = setOf( | ||
".git", | ||
".kotlin", | ||
) | ||
|
||
val generatedSrcDirs = listOf( | ||
"kotlin-dsl-accessors", | ||
"kotlin-dsl-external-plugin-spec-builders", | ||
"kotlin-dsl-plugins", | ||
) | ||
|
||
val generatedDirs = projectDir | ||
.walk() | ||
.onEnter { it.name !in doNotWalkDirs && it.parentFile.name !in generatedSrcDirs } | ||
.filter { it.isDirectory } | ||
.filter { it.parentFile.name in generatedSrcDirs } | ||
.flatMap { file -> | ||
file.walk().maxDepth(1).filter { it.isDirectory }.toList() | ||
} | ||
) | ||
.toSet() | ||
|
||
// exclude .gradle, IDE dirs from nested projects (e.g. example & template projects) | ||
// so IntelliJ project-wide search isn't cluttered with irrelevant files | ||
val projectDirsToExclude = setOf( | ||
".idea", | ||
".gradle", | ||
"build", | ||
"gradle/wrapper", | ||
"ANDROID_SDK", | ||
"examples/versioning-multimodule-example/dokkatoo/previousDocVersions", | ||
"examples/versioning-multimodule-example/dokka/previousDocVersions", | ||
"modules/dokkatoo-plugin-integration-tests/example-project-data", | ||
) | ||
|
||
val excludedProjectDirs = projectDir | ||
.walk() | ||
.onEnter { it.name !in doNotWalkDirs } | ||
// .filter { it.isDirectory } | ||
.filter { dir -> | ||
projectDirsToExclude.any { | ||
dir.invariantSeparatorsPath.endsWith("/$it") | ||
} | ||
} | ||
.toSet() | ||
|
||
// can't use buildSet {} https://github.com/gradle/gradle/issues/28325 | ||
return mutableSetOf<File>().apply { | ||
addAll(generatedDirs) | ||
addAll(excludedProjectDirs) | ||
} | ||
} | ||
} | ||
|
||
|
||
/** Sets a logo for project IDEs */ | ||
fun Project.initIdeProjectLogo( | ||
/** | ||
* Sets a logo for project IDEs. | ||
* | ||
* (Avoid updating the logo during project configuration, | ||
* instead piggyback off a random task that runs on IJ import.) | ||
*/ | ||
fun Task.initIdeProjectLogo( | ||
svgLogoPath: String | ||
) { | ||
val logoSvg = rootProject.layout.projectDirectory.file(svgLogoPath) | ||
val ideaDir = rootProject.layout.projectDirectory.dir(".idea") | ||
|
||
if ( | ||
logoSvg.asFile.exists() | ||
&& ideaDir.asFile.exists() | ||
&& !ideaDir.file("icon.png").asFile.exists() | ||
&& !ideaDir.file("icon.svg").asFile.exists() | ||
) { | ||
copy { | ||
from(logoSvg) { rename { "icon.svg" } } | ||
into(ideaDir) | ||
val fs = project.serviceOf<FileSystemOperations>() | ||
|
||
val logoSvg = project.layout.projectDirectory.file(svgLogoPath) | ||
val ideaDir = project.layout.projectDirectory.dir(".idea") | ||
// don't register task inputs, we don't really care about up-to-date checks | ||
|
||
doLast("initIdeProjectLogo") { | ||
if ( | ||
logoSvg.asFile.exists() | ||
&& ideaDir.asFile.exists() | ||
&& !ideaDir.file("icon.png").asFile.exists() | ||
&& !ideaDir.file("icon.svg").asFile.exists() | ||
) { | ||
fs.copy { | ||
from(logoSvg) { rename { "icon.svg" } } | ||
into(ideaDir) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ples/java-example/dokkatoo/buildSrc/src/main/kotlin/my-java-mongodb-convention.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
val mongodbSourceSet = sourceSets.create("mongodbSupport") { | ||
java { | ||
srcDir("src/mongodb/java") | ||
} | ||
} | ||
|
||
java { | ||
registerFeature("mongodbSupport") { | ||
usingSourceSet(mongodbSourceSet) | ||
} | ||
} |
Oops, something went wrong.