-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
369 generate pojos for annoation processor from cip57 plutusblueprints (
#376) * #369 added json models and tests for validation * #369 added parsing of CIP57 Blueprints. Currenlty implemented datatypes: List, Constr, bytes, integer, String, boolean ToDo: Map, tuple, unit * #369 add Mapdatatype * #369 added scriptaddress method and alternatives will be set in converter according to used type * #369 fixed test deployment * #369 had to add resources to sourceSets to enable the filer to find the files used in the tests * #369 still excluding guava * #369 added AnyPlutusData datatype. This field is identified through missing datatype description it can be anything. The correctness will be checked by the smartcontract itself. So it can't be distinguished within the blueprint. * chore: #369 Fixed typo * chore: #369 Remove test classes * Fix: Fix camecase class name, package refactoring and target package folder --------- Co-authored-by: Satya <satran004@gmail.com>
- Loading branch information
Showing
44 changed files
with
1,780 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...an/cardano/client/plutus/annotation/processor/blueprint/BlueprintAnnotationProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.bloxbean.cardano.client.plutus.annotation.processor.blueprint; | ||
|
||
import com.bloxbean.cardano.client.plutus.annotation.Blueprint; | ||
import com.bloxbean.cardano.client.plutus.blueprint.PlutusBlueprintLoader; | ||
import com.bloxbean.cardano.client.plutus.blueprint.model.*; | ||
import com.google.auto.service.AutoService; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.annotation.processing.*; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.tools.Diagnostic; | ||
import javax.tools.FileObject; | ||
import javax.tools.StandardLocation; | ||
import java.io.File; | ||
import java.util.*; | ||
|
||
@AutoService(Processor.class) | ||
@Slf4j | ||
public class BlueprintAnnotationProcessor extends AbstractProcessor { | ||
|
||
private Messager messager; | ||
private List<TypeElement> typeElements = new ArrayList<>(); | ||
private ValidatorProcessor validatorProcessor; | ||
|
||
@Override | ||
public synchronized void init(ProcessingEnvironment processingEnv) { | ||
super.init(processingEnv); | ||
messager = processingEnv.getMessager(); | ||
} | ||
|
||
@Override | ||
public Set<String> getSupportedAnnotationTypes() { | ||
Set<String> annotataions = new LinkedHashSet<String>(); | ||
annotataions.add(Blueprint.class.getCanonicalName()); | ||
return annotataions; | ||
} | ||
|
||
@Override | ||
public SourceVersion getSupportedSourceVersion() { | ||
return SourceVersion.latestSupported(); | ||
} | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
log.debug("Processing Blueprint annotation"); | ||
|
||
typeElements = getTypeElementsWithAnnotations(annotations, roundEnv); | ||
|
||
for(TypeElement typeElement : typeElements) { | ||
Blueprint annotation = typeElement.getAnnotation(Blueprint.class); | ||
if (annotation == null) { | ||
log.error("Blueprint annotation not found for class {}", typeElement.getSimpleName()); | ||
return false; | ||
} else { | ||
validatorProcessor = new ValidatorProcessor(annotation, processingEnv); | ||
} | ||
File blueprintFile = getFileFromAnnotation(annotation); | ||
if (blueprintFile == null || !blueprintFile.exists()) { | ||
log.error("Blueprint file {} not found", annotation.fileInResources()); | ||
return false; | ||
} | ||
PlutusContractBlueprint plutusContractBlueprint; | ||
try { | ||
plutusContractBlueprint = PlutusBlueprintLoader.loadBlueprint(blueprintFile); | ||
} catch (Exception e) { | ||
log.error("Error processing blueprint file {}", blueprintFile.getAbsolutePath(), e); | ||
return false; | ||
} | ||
for (Validator validator : plutusContractBlueprint.getValidators()) { | ||
validatorProcessor.processValidator(validator); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private List<TypeElement> getTypeElementsWithAnnotations(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
List<TypeElement> elementsList = new ArrayList<>(); | ||
for (TypeElement annotation : annotations) { | ||
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation); | ||
for (Element element : elements) { | ||
if (element instanceof TypeElement) { | ||
TypeElement typeElement = (TypeElement) element; | ||
elementsList.add(typeElement); | ||
|
||
} | ||
} | ||
} | ||
return elementsList; | ||
} | ||
|
||
private File getFileFromAnnotation(Blueprint annotation) { | ||
File blueprintFile = null; | ||
if(!annotation.file().isEmpty()) | ||
blueprintFile = new File(annotation.file()); | ||
if(!annotation.fileInResources().isEmpty()) | ||
blueprintFile = getFileFromRessourcers(annotation.fileInResources()); | ||
if(blueprintFile == null || !blueprintFile.exists()) { | ||
log.error("Blueprint file {} not found", annotation.file()); | ||
return null; | ||
} | ||
return blueprintFile; | ||
} | ||
|
||
public File getFileFromRessourcers(String s) { | ||
try { | ||
FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_PATH, "", s); | ||
return new File(resource.toUri()); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
private void error(Element e, String msg, Object... args) { | ||
messager.printMessage( | ||
Diagnostic.Kind.ERROR, | ||
String.format(msg, args), | ||
e); | ||
} | ||
} |
Oops, something went wrong.