Skip to content

Commit

Permalink
added collectors to init scripts. Also publishing all artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Nov 27, 2024
1 parent f8329b2 commit 29f364a
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
run: echo "VERSION_NAME=$(cat gradle.properties | grep "^version=" | awk -F'=' '{print $2}')" >> $GITHUB_ENV

- name: Publish Snapshot
run: ./gradlew :invert-report:publish :invert-models:publish :invert-gradle-plugin:publish --no-configuration-cache --stacktrace
run: ./gradlew publish --no-configuration-cache --stacktrace
if: success() && endsWith(env.VERSION_NAME, '-SNAPSHOT')
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import javax.inject.Singleton
@Singleton
@MergeComponent(AppScope::class)
interface AppComponent {
// TODO make this app better
fun networking(): NetworkGraph
}
11 changes: 9 additions & 2 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ plugins {
}

invert {

ownershipCollector(com.squareup.invert.owners.GitHubCodeOwnersInvertOwnershipCollector)
addStatCollector(
com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector(
Expand All @@ -38,13 +37,21 @@ invert {
)
)
addStatCollector(
com.squareup.invert.collectors.contains.LineContainsStatCollector(
com.squareup.invert.collectors.contains.InvertContainsStatCollector(
statKey = "wildcard-imports",
statDescription = "Wildcard Imports",
linePredicate = { it.contains("import") && it.contains("*") },
filePredicate = { it.extension == "kt" || it.extension == "kts" },
)
)
addStatCollector(
com.squareup.invert.collectors.contains.InvertContainsStatCollector(
statKey = "todos",
statDescription = "TODOs",
linePredicate = { it.contains("TODO") },
filePredicate = { true },
)
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.squareup.invert.models.StatDataType
import com.squareup.invert.models.StatMetadata
import java.io.File

open class LineContainsStatCollector(
open class InvertContainsStatCollector(
private val statKey: String,
private val statDescription: String,
private val linePredicate: (String) -> Boolean,
Expand Down Expand Up @@ -58,6 +58,6 @@ open class LineContainsStatCollector(
}

override fun getName(): String {
return this::class.java.name
return this::class.java.name + "-" + statKey
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.io.File
open class LinesOfCodeStatCollector(
name: String,
private val fileExtensions: List<String>,
keySuffix: String = fileExtensions.joinToString(","),
keySuffix: String = fileExtensions.joinToString("_"),
private val sourcesDirectory: (InvertProjectData) -> File = {
it.projectSrcDir
},
Expand Down
4 changes: 4 additions & 0 deletions invert-owners-github/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ plugins {
alias(libs.plugins.dokka)
}

java {
withSourcesJar()
}

dependencies {
implementation(project(":invert-gradle-plugin"))

Expand Down
109 changes: 69 additions & 40 deletions invert.init.script.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,55 +1,84 @@
import com.squareup.invert.InvertGradlePlugin
import com.squareup.invert.InvertExtension
import com.squareup.invert.InvertGradlePlugin

initscript {
repositories {
mavenCentral()
gradlePluginPortal()
// SNAPSHOT Versions
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}
dependencies {
val invertVersion = "+"
classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion")
repositories {
mavenCentral()
gradlePluginPortal()
// SNAPSHOT Versions
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}
dependencies {
val invertVersion = "+"
classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion")
}
}

apply<InvertInitScriptPlugin>()

class InvertInitScriptPlugin : Plugin<Gradle> {

override fun apply(gradle: Gradle) {
gradle.settingsEvaluated {
gradle.rootProject {
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
// SNAPSHOT Versions
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}

dependencies {
val invertVersion = "0.0.4-dev-SNAPSHOT"
classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion")
}
}
override fun apply(gradle: Gradle) {
gradle.settingsEvaluated {
gradle.rootProject {
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
// SNAPSHOT Versions
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}

gradle.rootProject {
afterEvaluate {
plugins.apply(com.squareup.invert.InvertGradlePlugin::class.java)
this.extensions.getByType(com.squareup.invert.InvertExtension::class.java).apply {
// ownershipCollector(...)
// addStatCollector(...)
}
}
}
dependencies {
val invertVersion = "0.0.4-dev-SNAPSHOT"
classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion")
classpath("com.squareup.invert:invert-collectors:$invertVersion")
classpath("com.squareup.invert:invert-owners-github:$invertVersion")
}
}
}

gradle.rootProject {
afterEvaluate {
plugins.apply(com.squareup.invert.InvertGradlePlugin::class.java)
this.extensions.getByType(com.squareup.invert.InvertExtension::class.java).apply {
ownershipCollector(com.squareup.invert.owners.GitHubCodeOwnersInvertOwnershipCollector)
addStatCollector(
com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector(
name = "Kotlin",
fileExtensions = listOf("kt", "kts"),
)
)
addStatCollector(
com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector(
name = "Java",
fileExtensions = listOf("java"),
)
)
addStatCollector(
com.squareup.invert.collectors.contains.InvertContainsStatCollector(
statKey = "wildcard-imports",
statDescription = "Wildcard Imports",
linePredicate = { it.contains("import") && it.contains("*") },
filePredicate = { it.extension == "kt" || it.extension == "kts" },
)
)
addStatCollector(
com.squareup.invert.collectors.contains.InvertContainsStatCollector(
statKey = "todos",
statDescription = "TODOs",
linePredicate = { it.contains("TODO") },
filePredicate = { true },
)
)
}
}
}
}
}
}
Loading

0 comments on commit 29f364a

Please sign in to comment.