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

Publish without protobuf-gradle-plugin #51

Merged
merged 1 commit into from
Apr 10, 2022
Merged
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
43 changes: 43 additions & 0 deletions src/test/kotlin/com/parmet/buf/gradle/AbstractPublishTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.parmet.buf.gradle

import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.Test
import java.nio.file.Paths

abstract class AbstractPublishTest : AbstractBufIntegrationTest() {
@Test
fun `publish schema with explicit artifact details`() {
assertImagePublication("bar")
}

@Test
fun `publish schema with inferred artifact details`() {
assertImagePublication("bar-bufbuild")
}

private fun assertImagePublication(artifactId: String) {
assertThat(publishRunner().build().task(":publish")?.outcome).isEqualTo(SUCCESS)

val builtImage = Paths.get(projectDir.path, "build", "bufbuild", "image.json")
val publishedImage = Paths.get(projectDir.path, "build", "repos", "test", "foo", artifactId, "2319", "$artifactId-2319.json")

assertThat(publishedImage.toFile().readText()).isEqualTo(builtImage.toFile().readText())
assertThat(publishedImage.toFile().readText()).contains("BasicMessage")
}
}
28 changes: 2 additions & 26 deletions src/test/kotlin/com/parmet/buf/gradle/PublishTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Andrew Parmet
* Copyright (c) 2022 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,28 +15,4 @@

package com.parmet.buf.gradle

import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.Test
import java.nio.file.Paths

class PublishTest : AbstractBufIntegrationTest() {
@Test
fun `publish schema with explicit artifact details`() {
assertImagePublication("bar")
}

@Test
fun `publish schema with inferred artifact details`() {
assertImagePublication("bar-bufbuild")
}

private fun assertImagePublication(artifactId: String) {
assertThat(publishRunner().build().task(":publish")?.outcome).isEqualTo(SUCCESS)

val builtImage = Paths.get(projectDir.path, "build", "bufbuild", "image.json")
val publishedImage = Paths.get(projectDir.path, "build", "repos", "test", "foo", artifactId, "2319", "$artifactId-2319.json")

assertThat(publishedImage.toFile().readText()).isEqualTo(builtImage.toFile().readText())
}
}
class PublishTest : AbstractPublishTest()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2022 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.parmet.buf.gradle

class PublishWithProtobufGradleTest : AbstractPublishTest()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Andrew Parmet
* Copyright (c) 2022 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,21 +15,10 @@

plugins {
id 'java'
id 'com.google.protobuf' version "$protobufGradleVersion"
id 'com.parmet.buf'
id 'maven-publish'
}

repositories { mavenCentral() }

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
}

compileJava.enabled = false

buf {
publishSchema = true
imageArtifact {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Andrew Parmet
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package parmet.buf.test.v1;

message BasicMessage {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Andrew Parmet
* Copyright (c) 2022 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,21 +15,10 @@

plugins {
id 'java'
id 'com.google.protobuf' version "$protobufGradleVersion"
id 'com.parmet.buf'
id 'maven-publish'
}

repositories { mavenCentral() }

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
}

compileJava.enabled = false

buf {
publishSchema = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Andrew Parmet
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package parmet.buf.test.v1;

message BasicMessage {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'java'
id 'com.google.protobuf' version "$protobufGradleVersion"
id 'com.parmet.buf'
id 'maven-publish'
}

repositories { mavenCentral() }

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
}

compileJava.enabled = false

buf {
publishSchema = true
imageArtifact {
groupId = 'foo'
artifactId = 'bar'
version = '2319'
}
}

publishing {
repositories {
maven { url 'build/repos/test' }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021 Andrew Parmet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'java'
id 'com.google.protobuf' version "$protobufGradleVersion"
id 'com.parmet.buf'
id 'maven-publish'
}

repositories { mavenCentral() }

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
}

compileJava.enabled = false

buf {
publishSchema = true
}

publishing {
repositories {
maven { url 'build/repos/test' }
}

publications {
maven(MavenPublication) {
groupId = 'foo'
artifactId = 'bar'
version = '2319'
from components.java
}
}
}