Search in sources :

Example 1 with Cached

use of com.devonfw.cobigen.api.annotation.Cached in project cobigen by devonfw.

the class InputResolverImpl method resolveContainerElements.

@Cached
@Override
public List<Object> resolveContainerElements(Object input, Trigger trigger) {
    List<Object> inputObjects = new ArrayList<>();
    if (this.inputInterpreter.combinesMultipleInputs(input)) {
        TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType());
        InputReader inputReader = triggerInterpreter.getInputReader();
        // check whether the inputs should be retrieved recursively
        boolean retrieveInputsRecursively = false;
        for (ContainerMatcher containerMatcher : trigger.getContainerMatchers()) {
            MatcherTo matcherTo = new MatcherTo(containerMatcher.getType(), containerMatcher.getValue(), input);
            if (triggerInterpreter.getMatcher().matches(matcherTo)) {
                if (!retrieveInputsRecursively) {
                    retrieveInputsRecursively = containerMatcher.isRetrieveObjectsRecursively();
                } else {
                    break;
                }
            }
        }
        if (retrieveInputsRecursively) {
            inputObjects = inputReader.getInputObjectsRecursively(input, trigger.getInputCharset());
        } else {
            inputObjects = inputReader.getInputObjects(input, trigger.getInputCharset());
        }
        // Remove non matching inputs
        Iterator<Object> it = inputObjects.iterator();
        while (it.hasNext()) {
            Object next = it.next();
            if (!this.matcherEvaluator.matches(next, trigger.getMatcher(), triggerInterpreter)) {
                it.remove();
            }
        }
    } else {
        inputObjects.add(input);
    }
    return inputObjects;
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) InputReader(com.devonfw.cobigen.api.extension.InputReader) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 2 with Cached

use of com.devonfw.cobigen.api.annotation.Cached in project cobigen by devonfw.

the class ConfigurationInterpreterImpl method getMatchingIncrements.

@Cached
@Override
public List<IncrementTo> getMatchingIncrements(Object matcherInput) throws InvalidConfigurationException {
    LOG.debug("Matching increments requested.");
    List<IncrementTo> increments = Lists.newLinkedList();
    List<String> matchingTriggerIds = getMatchingTriggerIds(matcherInput);
    for (TemplatesConfiguration templatesConfiguration : getMatchingTemplatesConfigurations(matcherInput)) {
        increments.addAll(convertIncrements(templatesConfiguration.getAllGenerationPackages(), templatesConfiguration.getTrigger(), matchingTriggerIds));
    }
    LOG.debug("{} matching increments found.", increments.size());
    return increments;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) TemplatesConfiguration(com.devonfw.cobigen.impl.config.TemplatesConfiguration) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 3 with Cached

use of com.devonfw.cobigen.api.annotation.Cached in project cobigen by devonfw.

the class ConfigurationInterpreterImpl method getMatchingTriggerIds.

@Cached
@Override
public List<String> getMatchingTriggerIds(Object matcherInput) {
    LOG.debug("Matching trigger IDs requested.");
    List<String> matchingTriggerIds = Lists.newLinkedList();
    for (Trigger trigger : this.triggerMatchingEvaluator.getMatchingTriggers(matcherInput)) {
        matchingTriggerIds.add(trigger.getId());
    }
    LOG.debug("{} matching trigger IDs found.", matchingTriggerIds.size());
    return matchingTriggerIds;
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 4 with Cached

use of com.devonfw.cobigen.api.annotation.Cached in project cobigen by devonfw.

the class ConfigurationInterpreterImpl method getMatchingTemplates.

@Cached
@Override
public List<TemplateTo> getMatchingTemplates(Object matcherInput) throws InvalidConfigurationException {
    LOG.debug("Matching templates requested.");
    List<TemplateTo> templates = Lists.newLinkedList();
    for (TemplatesConfiguration templatesConfiguration : getMatchingTemplatesConfigurations(matcherInput)) {
        for (Template template : templatesConfiguration.getAllTemplates()) {
            templates.add(new TemplateTo(template.getName(), template.getMergeStrategy(), templatesConfiguration.getTrigger().getId()));
        }
    }
    LOG.debug("{} matching templates found.", templates.size());
    return templates;
}
Also used : TemplateTo(com.devonfw.cobigen.api.to.TemplateTo) TemplatesConfiguration(com.devonfw.cobigen.impl.config.TemplatesConfiguration) Template(com.devonfw.cobigen.impl.config.entity.Template) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 5 with Cached

use of com.devonfw.cobigen.api.annotation.Cached in project cobigen by devonfw.

the class InputInterpreterImpl method resolveContainers.

@Cached
@Override
public List<Object> resolveContainers(Object input) {
    List<Trigger> matchingTriggers = this.configurationInterpreter.getMatchingTriggers(input);
    List<Object> inputs = new ArrayList<>();
    for (Trigger t : matchingTriggers) {
        inputs.addAll(this.inputResolver.resolveContainerElements(input, t));
    }
    return inputs;
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ArrayList(java.util.ArrayList) Cached(com.devonfw.cobigen.api.annotation.Cached)

Aggregations

Cached (com.devonfw.cobigen.api.annotation.Cached)7 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)3 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)3 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)2 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)2 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)2 ArrayList (java.util.ArrayList)2 InputReader (com.devonfw.cobigen.api.extension.InputReader)1 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)1 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)1 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)1 Template (com.devonfw.cobigen.impl.config.entity.Template)1 List (java.util.List)1