@Override public void prePassivate(ModuleMetaModel module) { module.processingContext.info("Passivating templates"); tags.clear(); this.providers = null; }
@Override public void prePassivate(ModuleMetaModel module) { module.processingContext.info("Passivating templates"); tags.clear(); this.providers = null; }
public void init(ProcessingContext env) throws NullPointerException { this.processingContext = env; // HashMap<P, HashSet<Name>> supportedAnnotationsMap = new HashMap<P, HashSet<Name>>(); LinkedHashMap<String, P> pluginMap = new LinkedHashMap<String, P>(); StringBuilder msg = new StringBuilder("Using plugins:"); for (P plugin : env.loadServices(pluginType)) { msg.append(" ").append(plugin.getName()); pluginMap.put(plugin.getName(), plugin); } env.info(msg); // Collect processed annotations HashSet<Class<? extends java.lang.annotation.Annotation>> supportedAnnotations = new HashSet<Class<? extends java.lang.annotation.Annotation>>(); for (P plugin : pluginMap.values()) { HashSet<Name> pluginSupportedAnnotations = new HashSet<Name>(); for (Class<? extends Annotation> annotationType : plugin.init(env)) { pluginSupportedAnnotations.add(Name.create(annotationType)); supportedAnnotations.add(annotationType); } env.info("Plugin " + plugin.getName() + " supports " + pluginSupportedAnnotations); supportedAnnotationsMap.put(plugin, pluginSupportedAnnotations); } // this.pluginMap = pluginMap; this.supportedAnnotationsMap = supportedAnnotationsMap; this.supportedAnnotations = supportedAnnotations; }
public void init(ProcessingContext env) throws NullPointerException { this.processingContext = env; // HashMap<P, HashSet<Name>> supportedAnnotationsMap = new HashMap<P, HashSet<Name>>(); LinkedHashMap<String, P> pluginMap = new LinkedHashMap<String, P>(); StringBuilder msg = new StringBuilder("Using plugins:"); for (P plugin : env.loadServices(pluginType)) { msg.append(" ").append(plugin.getName()); pluginMap.put(plugin.getName(), plugin); } env.info(msg); // Collect processed annotations HashSet<Class<? extends java.lang.annotation.Annotation>> supportedAnnotations = new HashSet<Class<? extends java.lang.annotation.Annotation>>(); for (P plugin : pluginMap.values()) { HashSet<Name> pluginSupportedAnnotations = new HashSet<Name>(); for (Class<? extends Annotation> annotationType : plugin.init(env)) { pluginSupportedAnnotations.add(Name.create(annotationType)); supportedAnnotations.add(annotationType); } env.info("Plugin " + plugin.getName() + " supports " + pluginSupportedAnnotations); supportedAnnotationsMap.put(plugin, pluginSupportedAnnotations); } // this.pluginMap = pluginMap; this.supportedAnnotationsMap = supportedAnnotationsMap; this.supportedAnnotations = supportedAnnotations; }
env.info("Generated application " + fqn + " as " + applicationFile.toUri());
public String load(String ref) { try { Path.Absolute path = pkg.resolve(ref); FileObject c = processingContext.resolveResourceFromSourcePath(context, path); if (c != null) { try { return c.getCharContent(true).toString(); } catch (IOException e) { processingContext.info("Could not get content of " + path, e); } } } catch (IllegalArgumentException e) { // Log ? } // return null; } }
@Override public void postActivate(ModuleMetaModel applications) { // Load the tag handlers for (TagHandler handler : applications.getProcessingContext().loadServices(TagHandler.class)) { applications.getProcessingContext().info("Loaded tag handler " + handler.getClass().getName() + " as " + handler.getName()); tags.put(handler.getName(), handler); } // Load the template providers Iterable<TemplateProvider> loader = applications.processingContext.loadServices(TemplateProvider.class); Map<String, TemplateProvider> providers = new HashMap<String, TemplateProvider>(); for (TemplateProvider provider : loader) { providers.put(provider.getSourceExtension(), provider); } // this.providers = providers; }
public String load(String ref) { try { Path.Absolute path = pkg.resolve(ref); FileObject c = processingContext.resolveResourceFromSourcePath(context, path); if (c != null) { try { return c.getCharContent(true).toString(); } catch (IOException e) { processingContext.info("Could not get content of " + path, e); } } } catch (IllegalArgumentException e) { // Log ? } // return null; } }
@Override public void postActivate(ModuleMetaModel applications) { // Load the tag handlers for (TagHandler handler : applications.getProcessingContext().loadServices(TagHandler.class)) { applications.getProcessingContext().info("Loaded tag handler " + handler.getClass().getName() + " as " + handler.getName()); tags.put(handler.getName(), handler); } // Load the template providers Iterable<TemplateProvider> loader = applications.processingContext.loadServices(TemplateProvider.class); Map<String, TemplateProvider> providers = new HashMap<String, TemplateProvider>(); for (TemplateProvider provider : loader) { providers.put(provider.getSourceExtension(), provider); } // this.providers = providers; }
@Override public void prePassivate(ApplicationMetaModel application) { application.processingContext.info("Passivating template resolver for " + application.getHandle()); application.getChild(TemplateContainerMetaModel.KEY).prePassivate(); application.getChild(TagContainerMetaModel.KEY).prePassivate(); }
@Override public void postProcessEvents(ApplicationMetaModel application) { application.processingContext.info("Processing templates of " + application.getHandle()); application.getChild(TemplateContainerMetaModel.KEY).postProcessEvents(); application.getChild(TagContainerMetaModel.KEY).postProcessEvents(); }
@Override public void prePassivate(ApplicationMetaModel application) { application.processingContext.info("Passivating template resolver for " + application.getHandle()); application.getChild(TemplateContainerMetaModel.KEY).prePassivate(); application.getChild(TagContainerMetaModel.KEY).prePassivate(); }
@Override public void postProcessEvents(ApplicationMetaModel application) { application.processingContext.info("Processing templates of " + application.getHandle()); application.getChild(TemplateContainerMetaModel.KEY).postProcessEvents(); application.getChild(TagContainerMetaModel.KEY).postProcessEvents(); }
@Override public Timestamped<Resource> resolveResource(Path.Absolute path) { FileObject resource = owner.application.resolveResource(path); if (resource != null) { try { byte[] bytes = Tools.bytes(resource.openInputStream()); long lastModified = resource.getLastModified(); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); } catch (Exception e) { env.info("Could not get resource content " + path.getCanonical(), e); } } return null; }
@Override public void processAnnotationRemoved(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = metaModel.getChild(TemplateContainerMetaModel.KEY); Path removedPath = Path.parse((String)removed.get("value")); Path.Absolute absRemoved = templates.resolvePath(removedPath); metaModel.processingContext.info("Removing template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absRemoved); templates.remove(variableElt); } } }
@Override public Timestamped<Resource> resolveResource(Path.Absolute path) { FileObject resource = owner.application.resolveResource(path); if (resource != null) { try { byte[] bytes = Tools.bytes(resource.openInputStream()); long lastModified = resource.getLastModified(); return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset())); } catch (Exception e) { env.info("Could not get resource content " + path.getCanonical(), e); } } return null; }
@Override public void processAnnotationRemoved(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = metaModel.getChild(TemplateContainerMetaModel.KEY); Path removedPath = Path.parse((String)removed.get("value")); Path.Absolute absRemoved = templates.resolvePath(removedPath); metaModel.processingContext.info("Removing template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absRemoved); templates.remove(variableElt); } } }
@Override public void processAnnotationAdded(ApplicationMetaModel application, AnnotationKey key, AnnotationState added) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = application.getChild(TemplateContainerMetaModel.KEY); Path addedPath = Path.parse((String)added.get("value")); Path.Absolute absAdded = templates.resolvePath(addedPath); application.processingContext.info("Adding template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absAdded); templates.add(variableElt, absAdded); } else { throw MetaModelProcessor.ANNOTATION_UNSUPPORTED.failure(key); } } }
@Override public void processAnnotationAdded(ApplicationMetaModel application, AnnotationKey key, AnnotationState added) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = application.getChild(TemplateContainerMetaModel.KEY); Path addedPath = Path.parse((String)added.get("value")); Path.Absolute absAdded = templates.resolvePath(addedPath); application.processingContext.info("Adding template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absAdded); templates.add(variableElt, absAdded); } else { throw MetaModelProcessor.ANNOTATION_UNSUPPORTED.failure(key); } } }
metaModel.processingContext.info("Emitting application " + application.getHandle() + " config");