Skip to content

Commit

Permalink
Merge branch 'main' into feat-ip-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
rodaine authored Oct 31, 2023
2 parents 64ed2f1 + e150db6 commit f2c624d
Show file tree
Hide file tree
Showing 80 changed files with 16,419 additions and 14,892 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
java-version: '17'
cache: 'gradle'
- name: Test conformance
run: make conformance
run: make conformance
53 changes: 6 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ SHELL := bash
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2023
LICENSE_IGNORE := --ignore src/main/java/build/buf/validate/ --ignore conformance/src/main/java/build/buf/validate/conformance/
JAVA_VERSION = 20
JAVAC = javac
JAVA = java
GO ?= go
ARGS ?= --strict_message
JAVA_COMPILE_OPTIONS = --enable-preview --release $(JAVA_VERSION)
JAVA_OPTIONS = --enable-preview
PROTOVALIDATE_VERSION ?= v0.4.2
JAVA_MAIN_CLASS = build.buf.protovalidate
JAVA_SOURCES = $(wildcard src/main/java/**/**/**/*.java, src/main/java/**/**/*.java)
JAVA_CLASSES = $(patsubst src/main/java/%.java, target/classes/%.class, $(JAVA_SOURCES))

.PHONY: all
all: lint generate build docs conformance ## Run all tests and lint (default)
Expand All @@ -39,30 +25,19 @@ checkgenerate: generate ## Checks if `make generate` produces a diff.

.PHONY: clean
clean: ## Delete intermediate build artifacts
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf
./gradlew clean

.PHONY: conformance
conformance: build $(BIN)/protovalidate-conformance ## Execute conformance tests.
./gradlew conformance:jar
$(BIN)/protovalidate-conformance $(ARGS) ./conformance/conformance.sh

.PHONY: generate-license
generate-license: $(BIN)/license-header ## Generates license headers for all source files.
$(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "$(COPYRIGHT_YEARS)" $(LICENSE_IGNORE)
conformance: ## Execute conformance tests.
./gradlew conformance:conformance

.PHONY: help
help: ## Describe useful make targets
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'

.PHONY: generate
generate: $(BIN)/buf generate-license ## Regenerate code and license headers
$(BIN)/buf export buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION) --output src/main/resources
$(BIN)/buf generate --template buf.gen.yaml src/main/resources
$(BIN)/buf generate --template conformance/buf.gen.yaml -o conformance/ buf.build/bufbuild/protovalidate-testing:$(PROTOVALIDATE_VERSION)
generate: ## Regenerate code and license headers
./gradlew generate

.PHONY: lint
lint: ## Lint code
Expand All @@ -84,19 +59,3 @@ releaselocal: ## Release artifacts to local maven repository.
.PHONY: test
test: ## Run all tests.
./gradlew test

$(BIN):
@mkdir -p $(BIN)

$(BIN)/buf: $(BIN) Makefile
GOBIN=$(abspath $(@D)) $(GO) install \
github.com/bufbuild/buf/cmd/buf@latest

$(BIN)/license-header: $(BIN) Makefile
GOBIN=$(abspath $(@D)) $(GO) install \
github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest

$(BIN)/protovalidate-conformance: $(BIN) Makefile
GOBIN=$(abspath $(BIN)) $(GO) install \
github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(PROTOVALIDATE_VERSION)

2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version: v1
managed:
enabled: false
plugins:
- plugin: buf.build/protocolbuffers/java:v24.3
- plugin: buf.build/protocolbuffers/java:v24.4
out: src/main/java
174 changes: 155 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.SonatypeHost
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SonatypeHost
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.errorprone

plugins {
`version-catalog`

`java-library`
alias(libs.plugins.errorprone)
alias(libs.plugins.git)
alias(libs.plugins.maven)
}

Expand All @@ -18,12 +17,133 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

// The releaseVersion property is set on official releases in the release.yml workflow.
// If not specified, we attempt to calculate a snapshot version based on the last tagged release.
// So if the local build's last tag was v0.1.9, this will set snapshotVersion to 0.1.10-SNAPSHOT.
// If this fails for any reason, we'll fall back to using 0.0.0-SNAPSHOT version.
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
val details = versionDetails()
var snapshotVersion = "0.0.0-SNAPSHOT"
val matchResult = """^v(\d+)\.(\d+)\.(\d+)$""".toRegex().matchEntire(details.lastTag)
if (matchResult != null) {
val (major, minor, patch) = matchResult.destructured
snapshotVersion = "$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
}
val releaseVersion = project.findProperty("releaseVersion") as String? ?: snapshotVersion

val bufCLIFile = project.layout.buildDirectory.file("gobin/buf").get().asFile
val bufCLIPath: String = bufCLIFile.absolutePath
val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file("gobin/license-header").get().asFile
val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath

tasks.register<Exec>("installBuf") {
description = "Installs the Buf CLI."
environment("GOBIN", bufCLIFile.parentFile.absolutePath)
outputs.file(bufCLIFile)
commandLine("go", "install", "github.com/bufbuild/buf/cmd/buf@latest")
}

tasks.register<Exec>("installLicenseHeader") {
description = "Installs the Buf license-header CLI."
environment("GOBIN", bufLicenseHeaderCLIFile.parentFile.absolutePath)
outputs.file(bufLicenseHeaderCLIFile)
commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest")
}

tasks.register<Exec>("licenseHeader") {
dependsOn("installLicenseHeader")
description = "Runs the Buf license-header CLI."
commandLine(
bufLicenseHeaderCLIPath,
"--license-type",
"apache",
"--copyright-holder",
"Buf Technologies, Inc.",
"--year-range",
project.findProperty("license-header.years")!!.toString(),
"--ignore",
"src/main/java/build/buf/validate/",
"--ignore",
"conformance/src/main/java/build/buf/validate/conformance/",
)
}

tasks.register<Exec>("generateTestSourcesImports") {
dependsOn("installBuf")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(
bufCLIPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.imports.yaml",
"src/test/resources/proto",
"--include-imports",
)
}

tasks.register<Exec>("generateTestSourcesNoImports") {
dependsOn("installBuf")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(bufCLIPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto")
}

tasks.register("generateTestSources") {
dependsOn("generateTestSourcesImports", "generateTestSourcesNoImports")
description = "Generates code with buf generate for unit tests"
}

tasks.register<Exec>("exportProtovalidateModule") {
dependsOn("installBuf")
description = "Exports the bufbuild/protovalidate module sources to src/main/resources."
commandLine(
bufCLIPath,
"export",
"buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}",
"--output",
"src/main/resources",
)
}

tasks.register<Exec>("generateSources") {
dependsOn("installBuf")
description = "Generates sources for the bufbuild/protovalidate module sources to src/main/java."
commandLine(bufCLIPath, "generate", "--template", "buf.gen.yaml", "src/main/resources")
}

tasks.register<Exec>("generateConformance") {
dependsOn("installBuf")
description = "Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java."
commandLine(
bufCLIPath,
"generate",
"--template",
"conformance/buf.gen.yaml",
"-o",
"conformance/",
"buf.build/bufbuild/protovalidate-testing:${project.findProperty("protovalidate.version")}",
)
}

tasks.register("generate") {
description = "Generates sources with buf generate and buf export."
dependsOn(
"generateTestSources",
"exportProtovalidateModule",
"generateSources",
"generateConformance",
"licenseHeader",
)
}

tasks.withType<JavaCompile> {
if (JavaVersion.current().isJava9Compatible) doFirst {
options.compilerArgs = mutableListOf("--release", "8")
dependsOn("generateTestSources")
if (JavaVersion.current().isJava9Compatible) {
doFirst {
options.compilerArgs = mutableListOf("--release", "8")
}
}
// Disable errorprone on generated code
options.errorprone.excludedPaths.set(".*/src/main/java/build/buf/validate/.*")
options.errorprone.excludedPaths.set("(.*/src/main/java/build/buf/validate/.*|.*/build/generated/.*)")
if (!name.lowercase().contains("test")) {
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
Expand All @@ -49,14 +169,27 @@ buildscript {
}
}

sourceSets {
test {
java {
srcDir(layout.buildDirectory.dir("generated/test-sources/bufgen"))
}
}
}

apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
java {
targetExclude("src/main/java/build/buf/validate/**/*.java")
targetExclude("src/main/java/build/buf/validate/**/*.java", "build/generated/test-sources/bufgen/**/*.java")
}
kotlinGradle {
ktlint()
target("**/*.kts")
}
}

allprojects {
version = releaseVersion
repositories {
mavenCentral()
maven {
Expand All @@ -75,6 +208,13 @@ allprojects {
trimTrailingWhitespace()
}
}
tasks.withType<Jar>().configureEach {
if (name == "jar") {
manifest {
attributes("Implementation-Version" to releaseVersion)
}
}
}
}

mavenPublishing {
Expand All @@ -83,31 +223,28 @@ mavenPublishing {
if (isAutoReleased) {
signAllPublications()
}
val releaseVersion = project.findProperty("releaseVersion") as String? ?: System.getenv("VERSION")
coordinates("build.buf", "protovalidate", releaseVersion ?: "0.0.0-SNAPSHOT")
coordinates("build.buf", "protovalidate", releaseVersion)
pomFromGradleProperties()
configure(JavaLibrary(
configure(
JavaLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an emprt jar
// - `JavadocJar.Empty()` publish an empty jar
// - `JavadocJar.Javadoc()` to publish standard javadocs
javadocJar = JavadocJar.Javadoc(),
// whether to publish a sources jar
sourcesJar = true,
)
),
)
pom {
name.set("connect-library") // This is overwritten in subprojects.
name.set("protovalidate-java")
group = "build.buf"
val releaseVersion = project.findProperty("releaseVersion") as String?
// Default to snapshot versioning for local publishing.
version = releaseVersion ?: "0.0.0-SNAPSHOT"
description.set("Protocol Buffer Validation")
url.set("https://github.com/bufbuild/protovalidate-java")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
Expand All @@ -123,7 +260,6 @@ mavenPublishing {
developerConnection.set("scm:git:ssh://[email protected]/bufbuild/protovalidate-java.git")
}
}

}

dependencies {
Expand Down
Loading

0 comments on commit f2c624d

Please sign in to comment.