-
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.
* minor fixes - use new doc site in Maven POM - update project logo to avoid doing work during configuration - update IDEA exclusions dirs via a value source (otherwise Gradle will then add all files as CC input, for no reason - replace enum `entries` with `values` (awaiting Gradle bumping the minimum Kotlin version to 1.9...) * tidy up docs for examples * add build service to prevent parallel Maven Publishing * wrap test report hack with region * cool background animation for homepage banner * useClasspathSnapshot=false
- Loading branch information
Showing
11 changed files
with
172 additions
and
82 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
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