Skip to content

Commit

Permalink
Fixed format violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Javatar81 committed Aug 30, 2024
1 parent 1d6ad14 commit d78072a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
*/
package io.fabric8.java.generator;

import io.fabric8.java.generator.exceptions.JavaGeneratorException;
import io.fabric8.java.generator.nodes.AbstractJSONSchema2Pojo;
import io.fabric8.java.generator.nodes.GeneratorResult;
import io.fabric8.java.generator.nodes.JCRObject;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion;
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -25,20 +34,11 @@
import java.util.Optional;
import java.util.stream.Collectors;

import io.fabric8.java.generator.exceptions.JavaGeneratorException;
import io.fabric8.java.generator.nodes.AbstractJSONSchema2Pojo;
import io.fabric8.java.generator.nodes.GeneratorResult;
import io.fabric8.java.generator.nodes.JCRObject;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion;
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps;

public class CRGeneratorRunner {

private final Config config;
private static final List<String> STD_PROPS = Arrays.asList("metadata", "spec", "status", "apiVersion", "kind");

public CRGeneratorRunner(Config config) {
this.config = config;
}
Expand All @@ -54,14 +54,14 @@ public List<WritableCRCompilationUnit> generate(CustomResourceDefinition crd, St
String version = crdv.getName();

String pkgNotOverridden = Optional.ofNullable(basePackageName)
.map(p -> p + "." + version)
.orElse(version);
.map(p -> p + "." + version)
.orElse(version);

String pkg;
if (config.getPackageOverrides().containsKey(pkgNotOverridden)) {
pkg = config.getPackageOverrides().get(pkgNotOverridden);
pkg = config.getPackageOverrides().get(pkgNotOverridden);
} else {
pkg = pkgNotOverridden;
pkg = pkgNotOverridden;
}

AbstractJSONSchema2Pojo specGenerator = null;
Expand All @@ -79,16 +79,17 @@ public List<WritableCRCompilationUnit> generate(CustomResourceDefinition crd, St
crName + "Status", status, pkg, config);
}

boolean preserveUnknownFields = Boolean.TRUE.equals(crdv.getSchema().getOpenAPIV3Schema().getXKubernetesPreserveUnknownFields());

boolean preserveUnknownFields = Boolean.TRUE
.equals(crdv.getSchema().getOpenAPIV3Schema().getXKubernetesPreserveUnknownFields());

Map<String, JSONSchemaProps> topLevelProps = crdv.getSchema().getOpenAPIV3Schema().getProperties().entrySet().stream()
.filter(e -> !STD_PROPS.contains(e.getKey()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
.filter(e -> !STD_PROPS.contains(e.getKey()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));

List<String> requiredTopLevelProps = crdv.getSchema().getOpenAPIV3Schema().getRequired().stream()
.filter(prop -> !STD_PROPS.contains(prop))
.collect(Collectors.toList());
.filter(prop -> !STD_PROPS.contains(prop))
.collect(Collectors.toList());

AbstractJSONSchema2Pojo crGenerator = new JCRObject(
pkg,
crName,
Expand Down Expand Up @@ -116,7 +117,7 @@ public List<WritableCRCompilationUnit> generate(CustomResourceDefinition crd, St

return writableCUs;
}

private List<GeneratorResult.ClassResult> validateAndAggregate(
AbstractJSONSchema2Pojo... generators) {
return Arrays.stream(generators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
*/
package io.fabric8.java.generator.nodes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.PackageDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
Expand All @@ -28,10 +23,14 @@
import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr;
import com.github.javaparser.ast.expr.StringLiteralExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;

import io.fabric8.java.generator.Config;
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class JCRObject extends JObject implements JObjectExtraAnnotations {

private final String group;
Expand Down Expand Up @@ -67,7 +66,7 @@ public JCRObject(
String plural,
Config config) {

super(pkg, type, toplevelProps, required, preserveUnknownFields, config, description, false, null);
super(pkg, type, toplevelProps, required, preserveUnknownFields, config, description, false, null);

this.group = group;
this.version = version;
Expand Down Expand Up @@ -123,7 +122,7 @@ public GeneratorResult generateJava() {
new Name("io.fabric8.kubernetes.model.annotation.Plural"),
new StringLiteralExpr(plural)));
}

ClassOrInterfaceType jlVoid = new ClassOrInterfaceType().setName("java.lang.Void");

ClassOrInterfaceType spec = (withSpec)
Expand All @@ -150,10 +149,10 @@ public GeneratorResult generateJava() {
if (config.isObjectExtraAnnotations()) {
addExtraAnnotations(clz);
}

List<GeneratorResult.ClassResult> buffer = generateJavaFields(clz);
List<GeneratorResult.ClassResult> results = new ArrayList<>();

List<GeneratorResult.ClassResult> results = new ArrayList<>();
results.add(new GeneratorResult.ClassResult(className, cu));
results.addAll(buffer);
return new GeneratorResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ public GeneratorResult generateJava() {
return new GeneratorResult(buffer);
}

protected List<GeneratorResult.ClassResult> generateJavaFields(ClassOrInterfaceDeclaration clz) {
List<GeneratorResult.ClassResult> buffer = new ArrayList<>(this.fields.size() + 1);
List<String> sortedKeys = this.fields.keySet().stream().sorted().collect(Collectors.toList());
protected List<GeneratorResult.ClassResult> generateJavaFields(ClassOrInterfaceDeclaration clz) {
List<GeneratorResult.ClassResult> buffer = new ArrayList<>(this.fields.size() + 1);

List<String> sortedKeys = this.fields.keySet().stream().sorted().collect(Collectors.toList());
for (String k : sortedKeys) {
AbstractJSONSchema2Pojo prop = this.fields.get(k);
boolean isRequired = this.required.contains(k);
Expand Down Expand Up @@ -351,7 +351,7 @@ protected List<GeneratorResult.ClassResult> generateJavaFields(ClassOrInterfaceD
.setBody(new BlockStmt().addStatement(new NameExpr("this." + Keywords.ADDITIONAL_PROPERTIES + ".put(key, value)")));
}
return buffer;
}
}

/**
* This method is responsible for creating an expression that will initialize the default value if primitive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down

0 comments on commit d78072a

Please sign in to comment.