Skip to content

Commit

Permalink
fix #4515: removing the legacy usage of model.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 16, 2022
1 parent 4eda49b commit ff91f33
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Fix #4136: added support for fieldValidation as a dsl method for POST/PUT/PATCH operations

#### _**Note**_: Breaking changes in the API
* Fix #4515: files located at the root of jars named model.properties, e.g. core.properties, have been removed

### 6.2.0 (2022-10-20)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sun.codemodel.JAnnotationArrayMember;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpressionImpl;
import com.sun.codemodel.JFieldVar;
Expand Down Expand Up @@ -59,7 +58,6 @@ public class KubernetesCoreTypeAnnotator extends Jackson2Annotator {
public static final String OPENSHIFT_PACKAGE = "openshift";
protected final Map<String, JDefinedClass> pendingResources = new HashMap<>();
protected final Map<String, JDefinedClass> pendingLists = new HashMap<>();
protected String moduleName = null;

private final Set<String> handledClasses = new HashSet<>();

Expand Down Expand Up @@ -113,15 +111,13 @@ public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) {
final JDefinedClass resourceClass = pendingResources.remove(resourceName);
if (resourceClass != null) {
annotate(clazz, apiVersion, apiGroup);
addClassesToPropertyFiles(resourceClass);
} else {
pendingLists.put(resourceName, clazz);
}
} else {
final JDefinedClass resourceListClass = pendingLists.remove(resourceName);
if (resourceListClass != null) {
annotate(resourceListClass, apiVersion, apiGroup);
addClassesToPropertyFiles(clazz);
} else {
annotate(clazz, apiVersion, apiGroup);
pendingResources.put(resourceName, clazz);
Expand All @@ -137,10 +133,6 @@ private void annotate(JDefinedClass clazz, String apiVersion, String apiGroup) {

@Override
public void propertyInclusion(JDefinedClass clazz, JsonNode schema) {
if (moduleName == null && schema.has("$module")) {
moduleName = schema.get("$module").textValue();
}

if (schema.has("serializer")) {
annotateSerde(clazz, JsonSerialize.class, schema.get("serializer").asText());
}
Expand Down Expand Up @@ -201,35 +193,6 @@ protected void processBuildable(JDefinedClass clazz) {
.param("builderPackage", "io.fabric8.kubernetes.api.builder");
}

protected void addClassesToPropertyFiles(JDefinedClass clazz) {
if (moduleName == null || moduleName.equals(getPackageCategory(clazz.getPackage().name()))) {
JAnnotationUse annotation = clazz.annotations().stream()
.filter(a -> a.getAnnotationClass().name().equals(TemplateTransformations.class.getSimpleName())).findFirst().get();
JAnnotationArrayMember arrayMember = (JAnnotationArrayMember) annotation.getAnnotationMembers().get(ANNOTATION_VALUE);
arrayMember.annotate(TemplateTransformation.class).param(ANNOTATION_VALUE, "/manifest.vm")
.param("outputPath", (moduleName == null ? "model" : moduleName) + ".properties").param("gather", true);
}
}

private String getPackageCategory(String packageName) {
if (packageName.isEmpty()) {
return null;
}
if (packageName.equals("io.fabric8.kubernetes.api.model")) {
return CORE_PACKAGE;
} else if (packageName.equals("io.fabric8.openshift.api.model")) {
return OPENSHIFT_PACKAGE;
}
// append whatever is after io.fabric8.kubernetes.api.model whether it's
// io.fabric8.kubernetes.api.model.apps or
// io.fabric8.kubernetes.api.model.batch.v1
String[] parts = packageName.split("\\.");
if (parts.length < 6) {
throw new IllegalArgumentException("Invalid package name encountered: " + packageName);
}
return parts[5];
}

private boolean hasInterfaceFields(JsonNode propertiesNode) {
for (Iterator<JsonNode> field = propertiesNode.elements(); field.hasNext();) {
JsonNode propertyNode = field.next();
Expand Down

0 comments on commit ff91f33

Please sign in to comment.