Skip to content

chore: replace usages of shaded/internal third-party dependency classes #389

@manusa

Description

@manusa

Description

Several files across the codebase import classes from third-party libraries' internal, shaded, or relocated packages. These imports are fragile and can break when the upstream dependency changes its shading/relocation strategy. They should be replaced with standard Java APIs or proper public dependency APIs.

This was originally spotted in PR fabric8io#7426 (io.sundr.deps.org.apache.commons.lang.RandomStringUtils used in tests), but a broader search revealed additional instances.

Affected Files

1. Sundrio shaded Apache Commons (io.sundr.deps.*)

File: kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/HasMetadataTest.java

import io.sundr.deps.org.apache.commons.lang.RandomStringUtils;
  • Usage: Generating random strings for test data
  • Replacement: Use java.util.UUID.randomUUID().toString() or java.util.concurrent.ThreadLocalRandom for random test values

2. Sundrio internal API (io.sundr.builder.internal.*)

File: crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java

import io.sundr.builder.internal.functions.TypeAs;
  • Usage: Unwrapping collection/map/optional types (TypeAs.UNWRAP_ARRAY_OF, TypeAs.UNWRAP_COLLECTION_OF, TypeAs.UNWRAP_MAP_KEY_OF, TypeAs.UNWRAP_MAP_VALUE_OF, TypeAs.UNWRAP_OPTIONAL_OF)
  • Replacement: Check if Sundrio exposes equivalent functionality in its public API (io.sundr.model or io.sundr.model.functions). If not, consider creating local wrapper utilities or requesting public API from Sundrio maintainers. This is the highest priority item since it's in production code (CRD generator).

File: java-generator/core/src/test/java/io/fabric8/java/generator/CompilationTest.java

import io.sundr.builder.internal.processor.BuildableProcessor;
  • Usage: Configuring annotation processor for compilation test (javac().withProcessors(new BuildableProcessor()))
  • Replacement: Use Sundrio's documented/public testing support, or check if the processor can be discovered via standard ServiceLoader/META-INF/services mechanism

3. Pax Exam internal API (org.ops4j.pax.exam.*.internal.*)

File: platforms/karaf/itests/src/test/java/io/fabric8/kubernetes/karaf/itests/TestBase.java

import org.ops4j.pax.exam.karaf.container.internal.JavaVersionUtil;
  • Usage: JavaVersionUtil.getMajorVersion() >= 9 to check Java version
  • Replacement: Use Runtime.version().major() (Java 9+) or parse System.getProperty("java.version")

Out of Scope

The following internal package usages are the project's own internal packages (not third-party shaded classes). They represent a separate API design concern (encapsulation within the project) and are not covered by this issue:

  • io.fabric8.mockwebserver.internal.* — used across ~14 files in junit/kubernetes-server-mock, kubernetes-client-api tests, and kubernetes-tests
  • io.fabric8.zjsonpatch.internal.collections4.ListUtils — used within the zjsonpatch module itself

Checklist

  • Replace RandomStringUtils in HasMetadataTest.java
  • Replace or wrap TypeAs in AbstractJsonSchema.java
  • Replace BuildableProcessor in CompilationTest.java
  • Replace JavaVersionUtil in TestBase.java
  • Verify no regressions (run affected module tests)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions