use of io.fabric8.crd.generator.utils.Types in project che-server by eclipse-che.
the class KubernetesEnvironmentProvisionerTest method setUp.
@BeforeMethod
public void setUp() {
workspaceConfig = new WorkspaceConfigImpl();
// "openshift" is what we use in the test devfile files and what we need to test the upgrade
// and multiple k8s-based types
Map<String, Set<String>> allowedUpgrades = new HashMap<>();
allowedUpgrades.compute("openshift", (__, ___) -> new HashSet<>()).add(KubernetesEnvironment.TYPE);
Set<String> k8sEnvTypes = new HashSet<>();
k8sEnvTypes.add(KubernetesEnvironment.TYPE);
k8sEnvTypes.add("openshift");
k8sEnvProvisioner = new KubernetesEnvironmentProvisioner(k8sRecipeParser, allowedUpgrades, k8sEnvTypes);
}
use of io.fabric8.crd.generator.utils.Types in project devspaces-images by redhat-developer.
the class KubernetesEnvironmentProvisionerTest method setUp.
@BeforeMethod
public void setUp() {
workspaceConfig = new WorkspaceConfigImpl();
// "openshift" is what we use in the test devfile files and what we need to test the upgrade
// and multiple k8s-based types
Map<String, Set<String>> allowedUpgrades = new HashMap<>();
allowedUpgrades.compute("openshift", (__, ___) -> new HashSet<>()).add(KubernetesEnvironment.TYPE);
Set<String> k8sEnvTypes = new HashSet<>();
k8sEnvTypes.add(KubernetesEnvironment.TYPE);
k8sEnvTypes.add("openshift");
k8sEnvProvisioner = new KubernetesEnvironmentProvisioner(k8sRecipeParser, allowedUpgrades, k8sEnvTypes);
}
use of io.fabric8.crd.generator.utils.Types in project kubernetes-client by fabric8io.
the class AbstractJsonSchema method getSchemaTypeFor.
public static String getSchemaTypeFor(TypeRef typeRef) {
String type = COMMON_MAPPINGS.get(typeRef);
if (type == null && typeRef instanceof ClassRef) {
// Handle complex types
ClassRef classRef = (ClassRef) typeRef;
TypeDef def = Types.typeDefFrom(classRef);
type = def.isEnum() ? STRING_MARKER : "object";
}
return type;
}
use of io.fabric8.crd.generator.utils.Types in project kubernetes-client by fabric8io.
the class CustomResourceAnnotationProcessor method process.
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
final Messager messager = processingEnv.getMessager();
final CRDGenerationInfo allCRDs = generator.withOutput(new FileObjectCRDOutput(processingEnv)).detailedGenerate();
allCRDs.getCRDDetailsPerNameAndVersion().forEach((crdName, versionToInfo) -> {
messager.printMessage(Diagnostic.Kind.NOTE, "Generating CRD " + crdName + ":\n");
versionToInfo.forEach((version, info) -> messager.printMessage(Diagnostic.Kind.NOTE, " - " + version + " -> " + info.getFilePath()));
});
return true;
}
// make sure we create the context before using it
AptContext.create(processingEnv.getElementUtils(), processingEnv.getTypeUtils(), DefinitionRepository.getRepository());
// Collect all annotated types.
for (TypeElement annotation : annotations) {
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
if (element instanceof TypeElement) {
generator.customResources(toCustomResourceInfo((TypeElement) element));
}
}
}
return false;
}
use of io.fabric8.crd.generator.utils.Types in project kubernetes-client by fabric8io.
the class JObject method generateJava.
@Override
public GeneratorResult generateJava() {
CompilationUnit cu = new CompilationUnit();
if (!this.pkg.isEmpty()) {
cu.setPackageDeclaration(this.pkg);
}
ClassOrInterfaceDeclaration clz = cu.addClass(this.className);
clz.addAnnotation(new SingleMemberAnnotationExpr(new Name("com.fasterxml.jackson.annotation.JsonInclude"), new NameExpr("com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL")));
clz.addAnnotation(new SingleMemberAnnotationExpr(new Name("com.fasterxml.jackson.annotation.JsonPropertyOrder"), new NameExpr(getSortedFieldsAsParam(this.fields.keySet()))));
clz.addAnnotation(new SingleMemberAnnotationExpr(new Name("com.fasterxml.jackson.databind.annotation.JsonDeserialize"), new NameExpr("using = com.fasterxml.jackson.databind.JsonDeserializer.None.class")));
if (config.isObjectExtraAnnotations()) {
addExtraAnnotations(clz);
}
clz.addImplementedType("io.fabric8.kubernetes.api.model.KubernetesResource");
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);
GeneratorResult gr = prop.generateJava();
// For now the inner types are only for enums
if (!gr.getInnerClasses().isEmpty()) {
for (GeneratorResult.ClassResult enumCR : gr.getInnerClasses()) {
Optional<EnumDeclaration> ed = enumCR.getCompilationUnit().getEnumByName(enumCR.getName());
if (ed.isPresent()) {
clz.addMember(ed.get());
}
}
}
buffer.addAll(gr.getTopLevelClasses());
String originalFieldName = k;
String fieldName = AbstractJSONSchema2Pojo.sanitizeString(k);
String fieldType = prop.getType();
try {
FieldDeclaration objField = clz.addField(fieldType, fieldName, Modifier.Keyword.PRIVATE);
objField.addAnnotation(new SingleMemberAnnotationExpr(new Name("com.fasterxml.jackson.annotation.JsonProperty"), new StringLiteralExpr(originalFieldName)));
if (isRequired) {
objField.addAnnotation("javax.validation.constraints.NotNull");
}
objField.createGetter();
objField.createSetter();
if (Utils.isNotNullOrEmpty(prop.getDescription())) {
objField.setJavadocComment(prop.getDescription());
objField.addAnnotation(new SingleMemberAnnotationExpr(new Name("com.fasterxml.jackson.annotation.JsonPropertyDescription"), new StringLiteralExpr(prop.getDescription().replace("\"", "\\\""))));
}
} catch (Exception cause) {
throw new JavaGeneratorException("Error generating field " + fieldName + " with type " + prop.getType(), cause);
}
}
if (this.preserveUnknownFields || config.isAlwaysPreserveUnknownFields()) {
ClassOrInterfaceType mapType = new ClassOrInterfaceType().setName(Keywords.JAVA_UTIL_MAP).setTypeArguments(new ClassOrInterfaceType().setName("String"), new ClassOrInterfaceType().setName("Object"));
FieldDeclaration objField = clz.addField(mapType, Keywords.ADDITIONAL_PROPERTIES, Modifier.Keyword.PRIVATE);
objField.setVariables(new NodeList<>(new VariableDeclarator().setName(Keywords.ADDITIONAL_PROPERTIES).setType(mapType).setInitializer("new java.util.HashMap<>()")));
objField.addAnnotation("com.fasterxml.jackson.annotation.JsonIgnore");
objField.createGetter().addAnnotation("com.fasterxml.jackson.annotation.JsonAnyGetter");
objField.createSetter().addAnnotation("com.fasterxml.jackson.annotation.JsonAnySetter");
}
buffer.add(new GeneratorResult.ClassResult(this.className, cu));
return new GeneratorResult(buffer);
}
Aggregations