-
Notifications
You must be signed in to change notification settings - Fork 242
chore: remove the JavaPoet dependency #3556
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,21 @@ | |
| */ | ||
| package io.javaoperatorsdk.operator.config.runtime; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
|
|
||
| import javax.tools.StandardLocation; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.google.testing.compile.Compilation; | ||
| import com.google.testing.compile.CompilationSubject; | ||
| import com.google.testing.compile.Compiler; | ||
| import com.google.testing.compile.JavaFileObjects; | ||
|
|
||
| import static io.javaoperatorsdk.operator.config.runtime.RuntimeControllerMetadata.RECONCILERS_RESOURCE_PATH; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: sed -n '20,35p' operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java
python3 - <<'PY'
from pathlib import Path
path = Path("operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java")
for number, line in enumerate(path.read_text().splitlines(), 1):
if number in range(20, 35):
print(f"{number}: {len(line)} chars: {line}")
PY
rg -n "RECONCILERS_RESOURCE_PATH|RuntimeControllerMetadata" operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.javaRepository: operator-framework/java-operator-sdk Length of output: 1713 Keep the static import within the 100-character limit. This import is 109 characters. Run Spotless with Google Java Format. If it remains too long, import 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class ControllerConfigurationAnnotationProcessorTest { | ||
|
|
||
| @Test | ||
|
|
@@ -33,6 +41,9 @@ public void generateCorrectDoneableClassIfInterfaceIsSecond() { | |
| JavaFileObjects.forResource( | ||
| "compile-fixtures/ReconcilerImplemented2Interfaces.java")); | ||
| CompilationSubject.assertThat(compilation).succeeded(); | ||
| assertMapping( | ||
| compilation, | ||
| "io.ReconcilerImplemented2Interfaces,io.ReconcilerImplemented2Interfaces.MyCustomResource"); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -45,6 +56,9 @@ public void generateCorrectDoneableClassIfThereIsAbstractBaseController() { | |
| JavaFileObjects.forResource( | ||
| "compile-fixtures/ReconcilerImplementedIntermediateAbstractClass.java")); | ||
| CompilationSubject.assertThat(compilation).succeeded(); | ||
| assertMapping( | ||
| compilation, | ||
| "io.ReconcilerImplementedIntermediateAbstractClass,io.AbstractReconciler.MyCustomResource"); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -57,5 +71,74 @@ public void generateDoneableClassWithMultilevelHierarchy() { | |
| JavaFileObjects.forResource("compile-fixtures/MultilevelAbstractReconciler.java"), | ||
| JavaFileObjects.forResource("compile-fixtures/MultilevelReconciler.java")); | ||
| CompilationSubject.assertThat(compilation).succeeded(); | ||
| assertMapping(compilation, "io.MultilevelReconciler,io.MultilevelReconciler.MyCustomResource"); | ||
| } | ||
|
|
||
| /** | ||
| * When the reconciled resource is itself generic, the resolved type is a parameterized {@code | ||
| * DeclaredType}. Only its erasure may be written to the mapping resource: {@link | ||
| * ClassMappingProvider} loads the recorded name with {@code ClassUtils.getClass(String)}, which | ||
| * cannot parse type arguments. | ||
| */ | ||
| @Test | ||
| public void writesErasureOfGenericResourceType() { | ||
| Compilation compilation = | ||
| Compiler.javac() | ||
| .withProcessors(new ControllerConfigurationAnnotationProcessor()) | ||
| .compile( | ||
| JavaFileObjects.forResource("compile-fixtures/GenericResourceReconciler.java")); | ||
| CompilationSubject.assertThat(compilation).succeeded(); | ||
| assertMapping( | ||
| compilation, | ||
| "io.GenericResourceReconciler,io.GenericResourceReconciler.MyGenericCustomResource"); | ||
| assertLoadableMapping(compilation); | ||
| } | ||
|
|
||
| /** | ||
| * Checks that the generated mapping resource contains the expected {@code | ||
| * reconciler,resource-class} line, using the same fully qualified, dot separated names that | ||
| * {@link ClassMappingProvider} expects to be able to load at runtime. | ||
| */ | ||
| private static void assertMapping(Compilation compilation, String expectedMapping) { | ||
| CompilationSubject.assertThat(compilation) | ||
| .generatedFile(StandardLocation.CLASS_OUTPUT, RECONCILERS_RESOURCE_PATH) | ||
| .contentsAsUtf8String() | ||
| .contains(expectedMapping); | ||
|
Comment on lines
+102
to
+106
|
||
| } | ||
|
|
||
| /** | ||
| * Checks that every recorded name in the generated mapping resource is a plain binary-ish class | ||
| * name, i.e. one that {@code ClassUtils.getClass(String)} can actually resolve, rather than a | ||
| * generic type signature such as {@code io.Foo<java.lang.String>}. | ||
| */ | ||
| private static void assertLoadableMapping(Compilation compilation) { | ||
| final var contents = | ||
| compilation | ||
| .generatedFile(StandardLocation.CLASS_OUTPUT, RECONCILERS_RESOURCE_PATH) | ||
| .map( | ||
| file -> { | ||
| try { | ||
| return file.getCharContent(true).toString(); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| }) | ||
| .orElseThrow(() -> new AssertionError("no mapping resource was generated")); | ||
| contents | ||
| .lines() | ||
| .filter(line -> !line.isBlank()) | ||
| .forEach( | ||
| line -> { | ||
| final var names = line.split(","); | ||
| assertThat(names).as("mapping line '%s'", line).hasSize(2); | ||
| for (String name : names) { | ||
| assertThat(name) | ||
| .as("recorded class name '%s' must be loadable at runtime", name) | ||
| .doesNotContain("<") | ||
| .doesNotContain(">") | ||
| .doesNotContain(" ") | ||
| .matches("[\\p{L}_$][\\p{L}\\p{N}_$]*(\\.[\\p{L}_$][\\p{L}\\p{N}_$]*)*"); | ||
|
Comment on lines
+135
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file="$(git ls-files | grep -F 'operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java' | head -n 1)"
printf '%s\n' "FILE=$file"
wc -l "$file"
sed -n '1,220p' "$file"
printf '\n-- ClassMappingProvider references --\n'
rg -n -C 4 'ClassMappingProvider|assertLoadableMapping|assertMapping|loadClass|Class\.forName' operator-framework/src operator-framework/pom.xml pom.xml 2>/dev/null || trueRepository: operator-framework/java-operator-sdk Length of output: 21788 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '-- ClassMappingProvider --'
cat -n operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/ClassMappingProvider.java
printf '%s\n' '-- Compile-testing dependency declarations and API usage --'
rg -n -C 3 'compile-testing|com.google.testing.compile|Compilation\.|classLoader|ClassLoader' \
operator-framework/pom.xml pom.xml operator-framework/src test 2>/dev/null || true
printf '%s\n' '-- Relevant fixture declarations --'
for f in $(git ls-files 'operator-framework/src/test/resources/compile-fixtures/*.java' \
| grep -E '(GenericResourceReconciler|MultilevelReconciler|AbstractReconciler|ReconcilerImplemented)'); do
echo "### $f"
sed -n '1,180p' "$f"
doneRepository: operator-framework/java-operator-sdk Length of output: 16543 🌐 Web query:
💡 Result: In Google Compile-Testing 0.23.0, the Compilation class does not expose a ClassLoader or a method to retrieve a "compiledClass" directly [1]. Instead, the Compilation class is designed to represent the outcome of a compilation process, providing access to the compilation status (success/failure), diagnostics (errors/warnings), source files, and generated files [1]. To interact with the classpath during compilation tests—such as ensuring specific libraries or classes are available to the compiler—you use methods on the Compiler class rather than the Compilation result [2][3][4]. Key methods include: - withClasspath(Iterable): Allows you to explicitly provide a list of files or JARs as the classpath [3]. - withClasspathFrom(ClassLoader): Allows you to derive the compilation classpath from an existing ClassLoader (e.g., this.getClass.getClassLoader), which is useful for making classes available to the test compilation that are already on your test runtime classpath [3][4]. The Compilation class itself focuses on verification of the output, typically used in conjunction with Truth assertions (e.g., assertThat(compilation).succeeded) to validate that the compilation behaved as expected [1][3]. If you need to load and inspect classes generated by the compilation, that typically falls outside the primary scope of the Compile-Testing library's assertions, which are centered on verifying compiler behavior and diagnostics [5][1]. Citations:
Resolve each mapping name with the runtime loading path.
🤖 Prompt for AI Agents |
||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * 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 io; | ||
|
|
||
| import io.fabric8.kubernetes.client.CustomResource; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Reconciler; | ||
| import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
|
|
||
| /** | ||
| * The reconciled resource is itself a generic type, so the resolved resource type is a | ||
| * parameterized {@code DeclaredType}. Only its erasure can be written to the mapping resource, | ||
| * because that is the only form {@code ClassMappingProvider} is able to load at runtime. | ||
| */ | ||
| @ControllerConfiguration | ||
| public class GenericResourceReconciler implements | ||
| Reconciler<GenericResourceReconciler.MyGenericCustomResource<String>> { | ||
|
|
||
| public static class MyGenericCustomResource<S> extends CustomResource<S, Void> { | ||
| } | ||
|
|
||
| @Override | ||
| public UpdateControl<MyGenericCustomResource<String>> reconcile( | ||
| MyGenericCustomResource<String> customResource, | ||
| Context<MyGenericCustomResource<String>> context) { | ||
| return UpdateControl.noUpdate(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the added comments for short logic.
Both comments document short, direct operations. Keep comments only for very long or complex logic.
operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessor.java#L104-L104: remove the explanatory comment above the type conversion.operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java#L73-L77: remove the Javadoc forassertMapping.As per coding guidelines: do not add comments except for very long or complex logic.
📍 Affects 2 files
operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessor.java#L104-L104(this comment)operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/ControllerConfigurationAnnotationProcessorTest.java#L73-L77🤖 Prompt for AI Agents
Source: Coding guidelines