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

Apply conventions to custom-checks project #5308

Merged
merged 1 commit into from
Feb 4, 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
Apply conventions to custom-checks project
  • Loading branch information
anuraaga committed Feb 4, 2022
commit b3fda17b16707c656560a644e1ccb4050a8ddee4
55 changes: 40 additions & 15 deletions custom-checks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
plugins {
`java-library`
id("otel.java-conventions")
}

dependencies {
implementation("com.google.errorprone:error_prone_core:2.10.0")
implementation("com.google.errorprone:error_prone_core")

annotationProcessor("com.google.auto.service:auto-service:1.0.1")
compileOnly("com.google.auto.service:auto-service-annotations:1.0.1")
annotationProcessor("com.google.auto.service:auto-service")
compileOnly("com.google.auto.service:auto-service-annotations")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("com.google.errorprone:error_prone_test_helpers")
}

testImplementation("com.google.errorprone:error_prone_test_helpers:2.11.0")
otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}

// We cannot use "--release" javac option here because that will forbid exporting com.sun.tools package.
// We also can't seem to use the toolchain without the "--release" option. So disable everything.

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
toolchain {
languageVersion.set(null as JavaLanguageVersion?)
}
}

tasks {
test {
useJUnitPlatform()
withType<JavaCompile>().configureEach {
with(options) {
release.set(null as Int?)

compilerArgs.addAll(
listOf(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
)
)
}
}
}

withType<JavaCompile> {
options.compilerArgs.addAll(listOf(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
))
// Our conventions apply this project as a dependency in the errorprone configuration, which would cause
// a circular dependency if trying to compile this project with that still there. So we filter this
// project out.
configurations {
named("errorprone") {
dependencies.removeIf {
it is ProjectDependency && it.dependencyProject == project
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
severity = WARNING)
public class InternalJavadoc extends BugChecker implements BugChecker.ClassTreeMatcher {

private static final long serialVersionUID = 1L;

private static final Pattern INTERNAL_PACKAGE_PATTERN = Pattern.compile("\\binternal\\b");

private static final Pattern EXCLUDE_PACKAGE_PATTERN =
Expand Down Expand Up @@ -60,8 +62,9 @@ private static boolean isInternal(VisitorState state) {
if (packageTree == null) {
return false;
}
String packageName = packageTree.getPackageName().toString();
return INTERNAL_PACKAGE_PATTERN.matcher(packageName).find()
String packageName = state.getSourceForNode(packageTree.getPackageName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return packageName != null
&& INTERNAL_PACKAGE_PATTERN.matcher(packageName).find()
&& !EXCLUDE_PACKAGE_PATTERN.matcher(packageName).find();
}

Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ val DEPENDENCY_SETS = listOf(
DependencySet(
"com.google.errorprone",
"2.10.0",
listOf("error_prone_annotations", "error_prone_core")
listOf("error_prone_annotations", "error_prone_core", "error_prone_test_helpers")
),
DependencySet(
"io.prometheus",
Expand Down