org.gradle.model.internal.core.ModelReference Java Examples
The following examples show how to use
org.gradle.model.internal.core.ModelReference.
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: AbstractAnnotationDrivenMethodComponentRuleDefinitionHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
protected <R, S> void visitDependency(RuleMethodDataCollector dataCollector, MethodRuleDefinition<R> ruleDefinition, ModelType<S> expectedDependency) { // TODO:DAZ Use ModelType.toString instead of getSimpleName() List<ModelReference<?>> references = ruleDefinition.getReferences(); ModelType<? extends S> dependency = null; for (ModelReference<?> reference : references) { ModelType<? extends S> newDependency = expectedDependency.asSubclass(reference.getType()); if (newDependency != null) { if (dependency != null) { throw new InvalidComponentModelException(String.format("%s method must have one parameter extending %s. Found multiple parameter extending %s.", annotationType.getSimpleName(), expectedDependency.getConcreteClass().getSimpleName(), expectedDependency.getConcreteClass().getSimpleName())); } dependency = newDependency; } } if (dependency == null) { throw new InvalidComponentModelException(String.format("%s method must have one parameter extending %s. Found no parameter extending %s.", annotationType.getSimpleName(), expectedDependency.getConcreteClass().getSimpleName(), expectedDependency.getConcreteClass().getSimpleName())); } dataCollector.put(expectedDependency.getConcreteClass(), dependency.getConcreteClass()); }
Example #2
Source File: BinaryTasksRuleDefinitionHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 #3
Source File: AbstractAnnotationDrivenMethodComponentRuleDefinitionHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
protected <R, S> void visitDependency(RuleMethodDataCollector dataCollector, MethodRuleDefinition<R> ruleDefinition, ModelType<S> expectedDependency) { // TODO:DAZ Use ModelType.toString instead of getSimpleName() List<ModelReference<?>> references = ruleDefinition.getReferences(); ModelType<? extends S> dependency = null; for (ModelReference<?> reference : references) { ModelType<? extends S> newDependency = expectedDependency.asSubclass(reference.getType()); if (newDependency != null) { if (dependency != null) { throw new InvalidComponentModelException(String.format("%s method must have one parameter extending %s. Found multiple parameter extending %s.", annotationType.getSimpleName(), expectedDependency.getConcreteClass().getSimpleName(), expectedDependency.getConcreteClass().getSimpleName())); } dependency = newDependency; } } if (dependency == null) { throw new InvalidComponentModelException(String.format("%s method must have one parameter extending %s. Found no parameter extending %s.", annotationType.getSimpleName(), expectedDependency.getConcreteClass().getSimpleName(), expectedDependency.getConcreteClass().getSimpleName())); } dataCollector.put(expectedDependency.getConcreteClass(), dependency.getConcreteClass()); }
Example #4
Source File: ComponentModelBasePlugin.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void apply(final ProjectInternal project) { project.getPlugins().apply(LanguageBasePlugin.class); LanguageRegistry languageRegistry = project.getExtensions().create("languages", DefaultLanguageRegistry.class); ProjectSourceSet sources = project.getExtensions().getByType(ProjectSourceSet.class); DefaultComponentSpecContainer components = project.getExtensions().create("componentSpecs", DefaultComponentSpecContainer.class, instantiator); modelRegistry.create( ModelCreators.of(ModelReference.of("componentSpecs", DefaultComponentSpecContainer.class), components) .simpleDescriptor("Project.<init>.componentSpecs()") .withProjection(new PolymorphicDomainObjectContainerModelProjection<DefaultComponentSpecContainer, ComponentSpec>(components, ComponentSpec.class)) .build() ); // TODO:DAZ Convert to model rules createLanguageSourceSets(sources, components, languageRegistry, project.getFileResolver()); }
Example #5
Source File: ComponentBinariesRuleDefinitionHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 #6
Source File: NonTransformedModelDslBacking.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void registerConfigurationAction(final Closure<?> action) { modelRegistry.mutate(new ModelMutator<Object>() { public ModelReference<Object> getSubject() { return ModelReference.untyped(modelPath); } public void mutate(Object object, Inputs inputs) { new ClosureBackedAction<Object>(action).execute(object); } public ModelRuleDescriptor getDescriptor() { return new SimpleModelRuleDescriptor("model." + modelPath); } public List<ModelReference<?>> getInputs() { return Collections.emptyList(); } }); }
Example #7
Source File: UnboundRulesProcessor.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private UnboundRuleInput.Builder toInputBuilder(ModelBinding<?> binding, ModelReference<?> reference) { UnboundRuleInput.Builder builder = UnboundRuleInput.type(reference.getType()); ModelPath path; if (binding != null) { builder.bound(); path = binding.getPath(); } else { path = reference.getPath(); if (path != null) { builder.suggestions(CollectionUtils.stringize(suggestionsProvider.transform(path))); } } if (path != null) { builder.path(path); } builder.description(reference.getDescription()); return builder; }
Example #8
Source File: UnboundRulesProcessor.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private UnboundRuleInput.Builder toInputBuilder(ModelBinding<?> binding, ModelReference<?> reference) { UnboundRuleInput.Builder builder = UnboundRuleInput.type(reference.getType()); ModelPath path; if (binding != null) { builder.bound(); path = binding.getPath(); } else { path = reference.getPath(); if (path != null) { builder.suggestions(CollectionUtils.stringize(suggestionsProvider.transform(path))); } } if (path != null) { builder.path(path); } builder.description(reference.getDescription()); return builder; }
Example #9
Source File: NonTransformedModelDslBacking.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void registerConfigurationAction(final Closure<?> action) { modelRegistry.mutate(new ModelMutator<Object>() { public ModelReference<Object> getSubject() { return ModelReference.untyped(modelPath); } public void mutate(Object object, Inputs inputs) { new ClosureBackedAction<Object>(action).execute(object); } public ModelRuleDescriptor getDescriptor() { return new SimpleModelRuleDescriptor("model." + modelPath); } public List<ModelReference<?>> getInputs() { return Collections.emptyList(); } }); }
Example #10
Source File: JavaBasePlugin.java From javaide with GNU General Public License v3.0 | 6 votes |
public void apply(ProjectInternal project) { project.getPluginManager().apply(BasePlugin.class); project.getPluginManager().apply(ReportingBasePlugin.class); project.getPluginManager().apply(LanguageBasePlugin.class); project.getPluginManager().apply(BinaryBasePlugin.class); JavaPluginConvention javaConvention = new JavaPluginConvention(project, instantiator); project.getConvention().getPlugins().put("java", javaConvention); configureCompileDefaults(project, javaConvention); BridgedBinaries binaries = configureSourceSetDefaults(javaConvention); modelRegistry.register(ModelRegistrations.bridgedInstance(ModelReference.of("bridgedBinaries", BridgedBinaries.class), binaries) .descriptor("JavaBasePlugin.apply()") .hidden(true) .build()); configureJavaDoc(project, javaConvention); configureTest(project, javaConvention); configureBuildNeeded(project); configureBuildDependents(project); }
Example #11
Source File: ComponentBinariesRuleDefinitionHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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 #12
Source File: BinaryTasksRuleDefinitionHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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 #13
Source File: ComponentModelBasePlugin.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void apply(final ProjectInternal project) { project.getPlugins().apply(LanguageBasePlugin.class); LanguageRegistry languageRegistry = project.getExtensions().create("languages", DefaultLanguageRegistry.class); ProjectSourceSet sources = project.getExtensions().getByType(ProjectSourceSet.class); DefaultComponentSpecContainer components = project.getExtensions().create("componentSpecs", DefaultComponentSpecContainer.class, instantiator); modelRegistry.create( ModelCreators.of(ModelReference.of("componentSpecs", DefaultComponentSpecContainer.class), components) .simpleDescriptor("Project.<init>.componentSpecs()") .withProjection(new PolymorphicDomainObjectContainerModelProjection<DefaultComponentSpecContainer, ComponentSpec>(components, ComponentSpec.class)) .build() ); // TODO:DAZ Convert to model rules createLanguageSourceSets(sources, components, languageRegistry, project.getFileResolver()); }
Example #14
Source File: TransformedModelDslBacking.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public List<ModelReference<?>> transform(Closure<?> closure) { RuleMetadata ruleMetadata = getRuleMetadata(closure); String[] paths = ruleMetadata.inputPaths(); List<ModelReference<?>> references = Lists.newArrayListWithCapacity(paths.length); for (int i = 0; i < paths.length; i++) { String description = String.format("@ line %d", ruleMetadata.inputLineNumbers()[i]); references.add(ModelReference.untyped(ModelPath.path(paths[i]), description)); } return references; }
Example #15
Source File: LanguageBasePlugin.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void apply(final Project target) { target.getPlugins().apply(LifecycleBasePlugin.class); target.getExtensions().create("sources", DefaultProjectSourceSet.class, instantiator); DefaultBinaryContainer binaries = target.getExtensions().create("binaries", DefaultBinaryContainer.class, instantiator); modelRegistry.create( ModelCreators.of(ModelReference.of("binaries", BinaryContainer.class), binaries) .simpleDescriptor("Project.<init>.binaries()") .withProjection(new PolymorphicDomainObjectContainerModelProjection<DefaultBinaryContainer, BinarySpec>(binaries, BinarySpec.class)) .build() ); }
Example #16
Source File: DefaultMethodRuleDefinition.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private ModelReference<?> reference(Type type, Annotation[] annotations, int i) { Path pathAnnotation = (Path) findFirst(annotations, new Spec<Annotation>() { public boolean isSatisfiedBy(Annotation element) { return element.annotationType().equals(Path.class); } }); String path = pathAnnotation == null ? null : pathAnnotation.value(); ModelType<?> cast = ModelType.of(type); return ModelReference.of(path == null ? null : ModelPath.path(path), cast, String.format("parameter %s", i + 1)); }
Example #17
Source File: RuleBinder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public RuleBinder(@Nullable ModelReference<T> subjectReference, List<ModelReference<?>> inputReferences, ModelRuleDescriptor descriptor, Action<? super RuleBinder<T>> onBind) { this.subjectReference = subjectReference; this.inputReferences = inputReferences; this.descriptor = descriptor; this.onBind = onBind; this.inputBindings = inputReferences.isEmpty() ? Collections.<ModelBinding<?>>emptyList() : Arrays.asList(new ModelBinding<?>[inputReferences.size()]); // fix size maybeFire(); }
Example #18
Source File: RuleBinder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public RuleBinder(@Nullable ModelReference<T> subjectReference, List<ModelReference<?>> inputReferences, ModelRuleDescriptor descriptor, Action<? super RuleBinder<T>> onBind) { this.subjectReference = subjectReference; this.inputReferences = inputReferences; this.descriptor = descriptor; this.onBind = onBind; this.inputBindings = inputReferences.isEmpty() ? Collections.<ModelBinding<?>>emptyList() : Arrays.asList(new ModelBinding<?>[inputReferences.size()]); // fix size maybeFire(); }
Example #19
Source File: DefaultMethodRuleDefinition.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private ModelReference<?> reference(Type type, Annotation[] annotations, int i) { Path pathAnnotation = (Path) findFirst(annotations, new Spec<Annotation>() { public boolean isSatisfiedBy(Annotation element) { return element.annotationType().equals(Path.class); } }); String path = pathAnnotation == null ? null : pathAnnotation.value(); ModelType<?> cast = ModelType.of(type); return ModelReference.of(path == null ? null : ModelPath.path(path), cast, String.format("parameter %s", i + 1)); }
Example #20
Source File: TransformedModelDslBacking.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 #21
Source File: TransformedModelDslBacking.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void configure(String modelPathString, Closure<?> configuration) { List<ModelReference<?>> references = inputPathsExtractor.transform(configuration); SourceLocation sourceLocation = ruleLocationExtractor.transform(configuration); ModelPath modelPath = ModelPath.path(modelPathString); Closure<?> reownered = configuration.rehydrate(null, owner, thisObject); modelRegistry.mutate(new ClosureBackedModelMutator(reownered, references, modelPath, sourceLocation)); }
Example #22
Source File: TransformedModelDslBacking.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public List<ModelReference<?>> transform(Closure<?> closure) { RuleMetadata ruleMetadata = getRuleMetadata(closure); String[] paths = ruleMetadata.inputPaths(); List<ModelReference<?>> references = Lists.newArrayListWithCapacity(paths.length); for (int i = 0; i < paths.length; i++) { String description = String.format("@ line %d", ruleMetadata.inputLineNumbers()[i]); references.add(ModelReference.untyped(ModelPath.path(paths[i]), description)); } return references; }
Example #23
Source File: TransformedModelDslBacking.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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 #24
Source File: TransformedModelDslBacking.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void configure(String modelPathString, Closure<?> configuration) { List<ModelReference<?>> references = inputPathsExtractor.transform(configuration); SourceLocation sourceLocation = ruleLocationExtractor.transform(configuration); ModelPath modelPath = ModelPath.path(modelPathString); Closure<?> reownered = configuration.rehydrate(null, owner, thisObject); modelRegistry.mutate(new ClosureBackedModelMutator(reownered, references, modelPath, sourceLocation)); }
Example #25
Source File: DefaultMethodRuleDefinition.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public List<ModelReference<?>> getReferences() { Type[] types = method.getGenericParameterTypes(); ImmutableList.Builder<ModelReference<?>> inputBindingBuilder = ImmutableList.builder(); for (int i = 0; i < types.length; i++) { Type paramType = types[i]; Annotation[] paramAnnotations = method.getParameterAnnotations()[i]; inputBindingBuilder.add(reference(paramType, paramAnnotations, i)); } return inputBindingBuilder.build(); }
Example #26
Source File: ComponentModelRuleDefinitionHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
protected RegisterTypeRule(ModelType<? extends T> type, ModelType<? extends U> implementation, ModelRuleDescriptor descriptor, Action<? super RegistrationContext<T, U>> registerAction) { this.type = type; this.implementation = implementation; this.descriptor = descriptor; this.registerAction = registerAction; subject = ModelReference.of("extensions", ExtensionContainer.class); inputs = ImmutableList.<ModelReference<?>>of(ModelReference.of(ProjectIdentifier.class)); }
Example #27
Source File: AbstractMutationRuleDefinitionHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 #28
Source File: ComponentModelRuleDefinitionHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
protected RegisterTypeRule(ModelType<? extends T> type, ModelType<? extends U> implementation, ModelRuleDescriptor descriptor, Action<? super RegistrationContext<T, U>> registerAction) { this.type = type; this.implementation = implementation; this.descriptor = descriptor; this.registerAction = registerAction; subject = ModelReference.of("extensions", ExtensionContainer.class); inputs = ImmutableList.<ModelReference<?>>of(ModelReference.of(ProjectIdentifier.class)); }
Example #29
Source File: LanguageBasePlugin.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void apply(final Project target) { target.getPlugins().apply(LifecycleBasePlugin.class); target.getExtensions().create("sources", DefaultProjectSourceSet.class, instantiator); DefaultBinaryContainer binaries = target.getExtensions().create("binaries", DefaultBinaryContainer.class, instantiator); modelRegistry.create( ModelCreators.of(ModelReference.of("binaries", BinaryContainer.class), binaries) .simpleDescriptor("Project.<init>.binaries()") .withProjection(new PolymorphicDomainObjectContainerModelProjection<DefaultBinaryContainer, BinarySpec>(binaries, BinarySpec.class)) .build() ); }
Example #30
Source File: AbstractMutationRuleDefinitionHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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); } }