org.gradle.model.internal.registry.ModelRegistry Java Examples

The following examples show how to use org.gradle.model.internal.registry.ModelRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentBinariesRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private <R, S extends BinarySpec> void doRegister(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        RuleMethodDataCollector dataCollector = new RuleMethodDataCollector();
        visitAndVerifyMethodSignature(dataCollector, ruleDefinition);

        final Class<S> binaryType = dataCollector.getParameterType(BinarySpec.class);
        final Class<? extends ComponentSpec> componentType = dataCollector.getParameterType(ComponentSpec.class);
        dependencies.add(ComponentModelBasePlugin.class);
        final ModelReference<BinaryContainer> subject = ModelReference.of(ModelPath.path("binaries"), new ModelType<BinaryContainer>() {
        });

        configureMutationRule(modelRegistry, subject, componentType, binaryType, ruleDefinition);
    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #2
Source File: ModelCreationRuleDefinitionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> void register(MethodRuleDefinition<T> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {

        // TODO validate model name
        String modelName = determineModelName(ruleDefinition);

        try {
            ModelPath.validatePath(modelName);
        } catch (Exception e) {
            throw new InvalidModelRuleDeclarationException(String.format("Path of declared model element created by rule %s is invalid.", ruleDefinition.getDescriptor()), e);
        }

        // TODO validate the return type (generics?)
        ModelType<T> returnType = ruleDefinition.getReturnType();
        ModelPath path = ModelPath.path(modelName);
        List<ModelReference<?>> references = ruleDefinition.getReferences();
        ModelRuleDescriptor descriptor = ruleDefinition.getDescriptor();

        Transformer<T, Inputs> transformer = new ModelRuleInvokerBackedTransformer<T>(ruleDefinition.getRuleInvoker(), descriptor, references);
        modelRegistry.create(
                ModelCreators.of(ModelReference.of(path, returnType), transformer)
                        .descriptor(descriptor)
                        .inputs(references)
                        .build()
        );
    }
 
Example #3
Source File: BinaryTasksRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private <R, S extends BinarySpec> void doRegister(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        RuleMethodDataCollector dataCollector = new RuleMethodDataCollector();
        verifyMethodSignature(dataCollector, ruleDefinition);

        Class<S> binaryType =  dataCollector.getParameterType(BinarySpec.class);
        dependencies.add(ComponentModelBasePlugin.class);

        final ModelReference<TaskContainer> tasks = ModelReference.of(ModelPath.path("tasks"), new ModelType<TaskContainer>() {
        });

        modelRegistry.mutate(new BinaryTaskRule<R, S>(tasks, binaryType, ruleDefinition, modelRegistry));

    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #4
Source File: ModelRuleInspector.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> void inspect(Class<T> source, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    validate(source);
    final Method[] methods = source.getDeclaredMethods();

    // sort for determinism
    Arrays.sort(methods, new Comparator<Method>() {
        public int compare(Method o1, Method o2) {
            return o1.toString().compareTo(o2.toString());
        }
    });

    for (Method method : methods) {
        validate(method);
        MethodRuleDefinition<?> ruleDefinition = DefaultMethodRuleDefinition.create(source, method);
        MethodRuleDefinitionHandler handler = getMethodHandler(ruleDefinition);
        if (handler != null) {
            // TODO catch “strange” exceptions thrown here and wrap with some context on the rule being registered
            // If the thrown exception doesn't provide any “model rule” context, it will be more or less impossible for a user
            // to work out what happened because the stack trace won't reveal any info about which rule was being registered.
            // However, a “wrap everything” strategy doesn't quite work because the thrown exception may already have enough context
            // and do a better job of explaining what went wrong than what we can do at this level.
            handler.register(ruleDefinition, modelRegistry, dependencies);
        }
    }
}
 
Example #5
Source File: BinaryTasksRuleDefinitionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private <R, S extends BinarySpec> void doRegister(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        RuleMethodDataCollector dataCollector = new RuleMethodDataCollector();
        verifyMethodSignature(dataCollector, ruleDefinition);

        Class<S> binaryType =  dataCollector.getParameterType(BinarySpec.class);
        dependencies.add(ComponentModelBasePlugin.class);

        final ModelReference<TaskContainer> tasks = ModelReference.of(ModelPath.path("tasks"), new ModelType<TaskContainer>() {
        });

        modelRegistry.mutate(new BinaryTaskRule<R, S>(tasks, binaryType, ruleDefinition, modelRegistry));

    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #6
Source File: ComponentBinariesRuleDefinitionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private <R, S extends BinarySpec> void doRegister(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        RuleMethodDataCollector dataCollector = new RuleMethodDataCollector();
        visitAndVerifyMethodSignature(dataCollector, ruleDefinition);

        final Class<S> binaryType = dataCollector.getParameterType(BinarySpec.class);
        final Class<? extends ComponentSpec> componentType = dataCollector.getParameterType(ComponentSpec.class);
        dependencies.add(ComponentModelBasePlugin.class);
        final ModelReference<BinaryContainer> subject = ModelReference.of(ModelPath.path("binaries"), new ModelType<BinaryContainer>() {
        });

        configureMutationRule(modelRegistry, subject, componentType, binaryType, ruleDefinition);
    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #7
Source File: ModelRuleInspector.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> void inspect(Class<T> source, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    validate(source);
    final Method[] methods = source.getDeclaredMethods();

    // sort for determinism
    Arrays.sort(methods, new Comparator<Method>() {
        public int compare(Method o1, Method o2) {
            return o1.toString().compareTo(o2.toString());
        }
    });

    for (Method method : methods) {
        validate(method);
        MethodRuleDefinition<?> ruleDefinition = DefaultMethodRuleDefinition.create(source, method);
        MethodRuleDefinitionHandler handler = getMethodHandler(ruleDefinition);
        if (handler != null) {
            // TODO catch “strange” exceptions thrown here and wrap with some context on the rule being registered
            // If the thrown exception doesn't provide any “model rule” context, it will be more or less impossible for a user
            // to work out what happened because the stack trace won't reveal any info about which rule was being registered.
            // However, a “wrap everything” strategy doesn't quite work because the thrown exception may already have enough context
            // and do a better job of explaining what went wrong than what we can do at this level.
            handler.register(ruleDefinition, modelRegistry, dependencies);
        }
    }
}
 
Example #8
Source File: ModelCreationRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T> void register(MethodRuleDefinition<T> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {

        // TODO validate model name
        String modelName = determineModelName(ruleDefinition);

        try {
            ModelPath.validatePath(modelName);
        } catch (Exception e) {
            throw new InvalidModelRuleDeclarationException(String.format("Path of declared model element created by rule %s is invalid.", ruleDefinition.getDescriptor()), e);
        }

        // TODO validate the return type (generics?)
        ModelType<T> returnType = ruleDefinition.getReturnType();
        ModelPath path = ModelPath.path(modelName);
        List<ModelReference<?>> references = ruleDefinition.getReferences();
        ModelRuleDescriptor descriptor = ruleDefinition.getDescriptor();

        Transformer<T, Inputs> transformer = new ModelRuleInvokerBackedTransformer<T>(ruleDefinition.getRuleInvoker(), descriptor, references);
        modelRegistry.create(
                ModelCreators.of(ModelReference.of(path, returnType), transformer)
                        .descriptor(descriptor)
                        .inputs(references)
                        .build()
        );
    }
 
Example #9
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public JavaBasePlugin(Instantiator instantiator, JavaToolChain javaToolChain, ITaskFactory taskFactory, ModelRegistry modelRegistry) {
    this.instantiator = instantiator;
    this.javaToolChain = javaToolChain;
    this.taskFactory = taskFactory;
    this.modelRegistry = modelRegistry;
}
 
Example #10
Source File: PluginModelRuleExtractor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(PluginApplication pluginApplication) {
    Class<? extends Plugin> pluginClass = pluginApplication.getPlugin().getClass();
    Set<Class<?>> sources = inspector.getDeclaredSources(pluginClass);
    if (!sources.isEmpty()) {
        PluginAware target = pluginApplication.getTarget();
        if (!(target instanceof ModelRegistryScope)) {
            throw new UnsupportedOperationException(String.format("Cannot apply model rules of plugin '%s' as the target '%s' is not model rule aware", pluginClass.getName(), target));
        }

        ModelRegistry modelRegistry = ((ModelRegistryScope) target).getModelRegistry();
        for (Class<?> source : sources) {
            inspector.inspect(source, modelRegistry, new PluginRuleSourceDependencies(target));
        }
    }
}
 
Example #11
Source File: TransformedModelDslBacking.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
TransformedModelDslBacking(ModelRegistry modelRegistry, Object thisObject, Object owner, Transformer<? extends List<ModelReference<?>>, ? super Closure<?>> inputPathsExtractor,
                           Transformer<SourceLocation, ? super Closure<?>> ruleLocationExtractor) {
    this.modelRegistry = modelRegistry;
    this.thisObject = thisObject;
    this.owner = owner;
    this.inputPathsExtractor = inputPathsExtractor;
    this.ruleLocationExtractor = ruleLocationExtractor;
}
 
Example #12
Source File: AbstractMutationRuleDefinitionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <R> void register(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    List<ModelReference<?>> bindings = ruleDefinition.getReferences();

    ModelReference<?> subject = bindings.get(0);
    List<ModelReference<?>> inputs = bindings.subList(1, bindings.size());
    MethodModelMutator<?> mutator = toMutator(ruleDefinition, subject, inputs);

    if (isFinalize()) {
        modelRegistry.finalize(mutator);
    } else {
        modelRegistry.mutate(mutator);
    }
}
 
Example #13
Source File: ComponentModelRuleDefinitionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <R> void register(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        ModelType<? extends T> type = readType(ruleDefinition);
        ModelType<? extends U> implementation = determineImplementationType(ruleDefinition, type);

        dependencies.add(ComponentModelBasePlugin.class);
        if (implementation != null) {
            ModelMutator<?> mutator = new RegisterTypeRule<T, U>(type, implementation, ruleDefinition.getDescriptor(), registerer);
            modelRegistry.mutate(mutator);
        }
    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #14
Source File: PluginModelRuleExtractor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(PluginApplication pluginApplication) {
    Class<? extends Plugin> pluginClass = pluginApplication.getPlugin().getClass();
    Set<Class<?>> sources = inspector.getDeclaredSources(pluginClass);
    if (!sources.isEmpty()) {
        PluginAware target = pluginApplication.getTarget();
        if (!(target instanceof ModelRegistryScope)) {
            throw new UnsupportedOperationException(String.format("Cannot apply model rules of plugin '%s' as the target '%s' is not model rule aware", pluginClass.getName(), target));
        }

        ModelRegistry modelRegistry = ((ModelRegistryScope) target).getModelRegistry();
        for (Class<?> source : sources) {
            inspector.inspect(source, modelRegistry, new PluginRuleSourceDependencies(target));
        }
    }
}
 
Example #15
Source File: TransformedModelDslBacking.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
TransformedModelDslBacking(ModelRegistry modelRegistry, Object thisObject, Object owner, Transformer<? extends List<ModelReference<?>>, ? super Closure<?>> inputPathsExtractor,
                           Transformer<SourceLocation, ? super Closure<?>> ruleLocationExtractor) {
    this.modelRegistry = modelRegistry;
    this.thisObject = thisObject;
    this.owner = owner;
    this.inputPathsExtractor = inputPathsExtractor;
    this.ruleLocationExtractor = ruleLocationExtractor;
}
 
Example #16
Source File: AbstractMutationRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <R> void register(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    List<ModelReference<?>> bindings = ruleDefinition.getReferences();

    ModelReference<?> subject = bindings.get(0);
    List<ModelReference<?>> inputs = bindings.subList(1, bindings.size());
    MethodModelMutator<?> mutator = toMutator(ruleDefinition, subject, inputs);

    if (isFinalize()) {
        modelRegistry.finalize(mutator);
    } else {
        modelRegistry.mutate(mutator);
    }
}
 
Example #17
Source File: ComponentModelRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <R> void register(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        ModelType<? extends T> type = readType(ruleDefinition);
        ModelType<? extends U> implementation = determineImplementationType(ruleDefinition, type);

        dependencies.add(ComponentModelBasePlugin.class);
        if (implementation != null) {
            ModelMutator<?> mutator = new RegisterTypeRule<T, U>(type, implementation, ruleDefinition.getDescriptor(), registerer);
            modelRegistry.mutate(mutator);
        }
    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example #18
Source File: ComponentModelBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public ComponentModelBasePlugin(Instantiator instantiator, ModelRegistry modelRegistry) {
    this.instantiator = instantiator;
    this.modelRegistry = modelRegistry;
}
 
Example #19
Source File: ProjectScopeServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected ModelRegistry createModelRegistry() {
    return new DefaultModelRegistry();
}
 
Example #20
Source File: ComponentBinariesRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private <S extends BinarySpec, R> void configureMutationRule(ModelRegistry modelRegistry, ModelReference<BinaryContainer> subject, Class<? extends ComponentSpec> componentType, Class<S> binaryType, MethodRuleDefinition<R> ruleDefinition) {
    modelRegistry.mutate(new ComponentBinariesRule<R, S>(subject, componentType, binaryType, ruleDefinition, modelRegistry));
}
 
Example #21
Source File: AbstractProject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public ModelRegistry getModelRegistry() {
    // Decoration takes care of the implementation
    throw new UnsupportedOperationException();
}
 
Example #22
Source File: ComponentReport.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
protected ModelRegistry getModelRegistry() {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: ComponentBinariesRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ComponentBinariesRule(ModelReference<BinaryContainer> subject, final Class<? extends ComponentSpec> componentType, final Class<S> binaryType, MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry) {
    super(subject, componentType, ruleDefinition, ModelReference.of("componentSpecs", ComponentSpecContainer.class));
    this.componentType = componentType;
    this.binaryType = binaryType;
    this.modelRegistry = modelRegistry;
}
 
Example #24
Source File: TransformedModelDslBacking.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public TransformedModelDslBacking(ModelRegistry modelRegistry, Object thisObject, Object owner) {
    this(modelRegistry, thisObject, owner, INPUT_PATHS_EXTRACTOR, RULE_LOCATION_EXTRACTOR);
}
 
Example #25
Source File: NonTransformedModelDslBacking.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private NonTransformedModelDslBacking(AtomicBoolean executingDsl, ModelPath modelPath, ModelRegistry modelRegistry) {
    this.executingDsl = executingDsl;
    this.modelPath = modelPath;
    this.modelRegistry = modelRegistry;
}
 
Example #26
Source File: NonTransformedModelDslBacking.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public NonTransformedModelDslBacking(ModelRegistry modelRegistry) {
    this(new AtomicBoolean(), null, modelRegistry);
}
 
Example #27
Source File: BinaryTasksRuleDefinitionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BinaryTaskRule(ModelReference<TaskContainer> subject, final Class<T> binaryType, MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry) {
    super(subject, binaryType, ruleDefinition, ModelReference.of("binaries", BinaryContainer.class));
    this.binaryType = binaryType;
    this.modelRegistry = modelRegistry;
}
 
Example #28
Source File: LanguageBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public LanguageBasePlugin(Instantiator instantiator, ModelRegistry modelRegistry) {
    this.instantiator = instantiator;
    this.modelRegistry = modelRegistry;
}
 
Example #29
Source File: ComponentModelBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public ComponentModelBasePlugin(Instantiator instantiator, ModelRegistry modelRegistry) {
    this.instantiator = instantiator;
    this.modelRegistry = modelRegistry;
}
 
Example #30
Source File: NonTransformedModelDslBacking.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private NonTransformedModelDslBacking(AtomicBoolean executingDsl, ModelPath modelPath, ModelRegistry modelRegistry) {
    this.executingDsl = executingDsl;
    this.modelPath = modelPath;
    this.modelRegistry = modelRegistry;
}