Skip to content

Commit

Permalink
update terminology and update deprecated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet committed Jan 29, 2021
1 parent 3a18f37 commit bbceef9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ apply(plugin = "com.parmet.buf")
```

When applied the plugin creates two useful tasks:
- `bufCheckLint` lints protobuf code
- `bufCheckBreaking` checks protobuf against a previous version for
- `bufLint` lints protobuf code
- `bufBreaking` checks protobuf against a previous version for
backwards-incompatible changes.

### Configuration
Expand Down Expand Up @@ -103,14 +103,14 @@ publishing {
}
```

#### `bufCheckLint`
#### `bufLint`

`bufCheckLint` is configured solely through `buf.yaml` and follows Buf's
`bufLint` is configured solely through `buf.yaml` and follows Buf's
standard CLI behavior.

#### `bufCheckBreaking`
#### `bufBreaking`

`bufCheckBreaking` is more complicated since it requires a previous version of
`bufBreaking` is more complicated since it requires a previous version of
the protobuf schema to validate the current version. Buf's built-in Git
integration isn't quite enough since it requires a buildable protobuf source set
and the `protobuf-gradle-plugin`'s merge step typically targets the project
Expand Down Expand Up @@ -146,7 +146,7 @@ The plugin will run Buf checking the project's current schema against
version `0.1.0`:

```
> Task :bufCheckBreaking FAILED
> Task :bufBreaking FAILED
src/main/proto/parmet/service/test/test.proto:9:1:Previously present field "1" with name "test_content" on message "TestMessage" was deleted.
```

Expand Down
43 changes: 21 additions & 22 deletions src/main/kotlin/com/parmet/buf/gradle/BufPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class BufPlugin : Plugin<Project> {
}

private fun Project.configureCheckLint(ext: BufExtension) {
tasks.register<Exec>(BUF_CHECK_LINT_TASK_NAME) {
tasks.register<Exec>(BUF_LINT_TASK_NAME) {
group = JavaBasePlugin.CHECK_TASK_NAME
bufTask(ext, "check", "lint")
bufTask(ext, "lint")
}

afterEvaluate {
tasks.named(BUF_CHECK_LINT_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
tasks.named(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(BUF_CHECK_LINT_TASK_NAME)
tasks.named(BUF_LINT_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
tasks.named(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(BUF_LINT_TASK_NAME)
}
}

Expand All @@ -53,7 +53,7 @@ class BufPlugin : Plugin<Project> {
private fun Project.configureImageBuild(ext: BufExtension): AtomicReference<ArtifactDetails> {
val bufBuildImage = "$BUF_BUILD_DIR/image.json"

tasks.register<Exec>(BUF_IMAGE_BUILD_TASK_NAME) {
tasks.register<Exec>(BUF_IMAGE_TASK_NAME) {
doFirst {
file("$buildDir/$BUF_BUILD_DIR").mkdirs()
}
Expand All @@ -66,7 +66,7 @@ class BufPlugin : Plugin<Project> {
}

afterEvaluate {
tasks.named(BUF_IMAGE_BUILD_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
tasks.named(BUF_IMAGE_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
}

val box = AtomicReference<ArtifactDetails>()
Expand All @@ -93,7 +93,7 @@ class BufPlugin : Plugin<Project> {
this.version = version

artifact(file("$buildDir/$bufBuildImage")) {
builtBy(tasks.named(BUF_IMAGE_BUILD_TASK_NAME))
builtBy(tasks.named(BUF_IMAGE_TASK_NAME))
}
}
}
Expand All @@ -111,49 +111,48 @@ class BufPlugin : Plugin<Project> {
) {
val bufbuildBreaking = "$BUF_BUILD_DIR/breaking"

configurations.create(BUF_CHECK_BREAKING_CONFIGURATION_NAME)
configurations.create(BUF_BREAKING_CONFIGURATION_NAME)
dependencies {
afterEvaluate {
if (ext.previousVersion != null) {
add(BUF_CHECK_BREAKING_CONFIGURATION_NAME, "$artifactDetails:${ext.previousVersion}")
add(BUF_BREAKING_CONFIGURATION_NAME, "$artifactDetails:${ext.previousVersion}")
}
}
}

tasks.register<Copy>(BUF_CHECK_BREAKING_EXTRACT_TASK_NAME) {
tasks.register<Copy>(BUF_BREAKING_EXTRACT_TASK_NAME) {
enabled = ext.previousVersion != null
from(configurations.getByName(BUF_CHECK_BREAKING_CONFIGURATION_NAME).files)
from(configurations.getByName(BUF_BREAKING_CONFIGURATION_NAME).files)
into(file("$buildDir/$bufbuildBreaking"))
}

tasks.register<Exec>(BUF_CHECK_BREAKING_TASK_NAME) {
tasks.register<Exec>(BUF_BREAKING_TASK_NAME) {
group = JavaBasePlugin.CHECK_TASK_NAME
enabled = ext.previousVersion != null
bufTask(
ext,
"check",
"breaking",
"--against-input",
"--against",
"$relativeBuildDir/$bufbuildBreaking/${artifactDetails.get().artifactId}-${ext.previousVersion}.json"
)
}

afterEvaluate {
tasks.named(BUF_CHECK_BREAKING_TASK_NAME).dependsOn(BUF_CHECK_BREAKING_EXTRACT_TASK_NAME)
tasks.named(BUF_CHECK_BREAKING_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
tasks.named(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(BUF_CHECK_BREAKING_TASK_NAME)
tasks.named(BUF_BREAKING_TASK_NAME).dependsOn(BUF_BREAKING_EXTRACT_TASK_NAME)
tasks.named(BUF_BREAKING_TASK_NAME).dependsOn(EXTRACT_INCLUDE_PROTO_TASK_NAME)
tasks.named(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(BUF_BREAKING_TASK_NAME)
}
}

companion object {
private const val EXTRACT_INCLUDE_PROTO_TASK_NAME = "extractIncludeProto"

const val BUF_IMAGE_BUILD_TASK_NAME = "bufImageBuild"
const val BUF_CHECK_BREAKING_EXTRACT_TASK_NAME = "bufCheckBreakingExtract"
const val BUF_CHECK_BREAKING_TASK_NAME = "bufCheckBreaking"
const val BUF_CHECK_LINT_TASK_NAME = "bufCheckLint"
const val BUF_IMAGE_TASK_NAME = "bufImage"
const val BUF_BREAKING_EXTRACT_TASK_NAME = "bufBreakingExtract"
const val BUF_BREAKING_TASK_NAME = "bufBreaking"
const val BUF_LINT_TASK_NAME = "bufLint"

const val BUF_CHECK_BREAKING_CONFIGURATION_NAME = "bufCheckBreaking"
const val BUF_BREAKING_CONFIGURATION_NAME = "bufBreaking"
const val BUF_CONFIGURATION_NAME = "buf"
const val BUF_IMAGE_PUBLICATION_NAME = "bufbuild"
const val BUF_BUILD_DIR = "bufbuild"
Expand Down

0 comments on commit bbceef9

Please sign in to comment.