private ModelReference<?> mapSubject(ModelReference<?> subject, ModelPath targetPath) { if (subject.getPath() == null) { return subject.inScope(targetPath); } else { return subject.withPath(targetPath.descendant(subject.getPath())); } }
private void mapInputs(List<ModelReference<?>> inputs, ModelPath targetPath) { for (int i = 0; i < inputs.size(); i++) { ModelReference<?> input = inputs.get(i); if (input.getPath() != null) { inputs.set(i, input.withPath(targetPath.descendant(input.getPath()))); } else { inputs.set(i, input.inScope(ModelPath.ROOT)); } } }
public RegistrationAction( ModelType<? extends ComponentSpec> publicType, ModelType<? extends BaseComponentSpec> implementationType, Set<Class<?>> internalViews, ModelRuleDescriptor descriptor) { super( ModelReference.of(ComponentSpecFactory.class), descriptor, ModelReference.of("serviceRegistry", ServiceRegistry.class), ModelReference.of("projectIdentifier", ProjectIdentifier.class), ModelReference.of("sources", ProjectSourceSet.class)); this.publicType = publicType; this.implementationType = implementationType; this.internalViews = internalViews; }
@Override public List<ModelReference<?>> getInputs() { return ImmutableList.<ModelReference<?>>builder() .add(ModelReference.of(ITaskFactory.class)) .addAll(super.getInputs()) .build(); }
private <R, S extends BinarySpec> ExtractedModelRule createRegistration( MethodRuleDefinition<R, ?> ruleDefinition) { try { RuleMethodDataCollector dataCollector = new RuleMethodDataCollector(); verifyMethodSignature(dataCollector, ruleDefinition); final Class<S> binaryType = dataCollector.getParameterType(BinarySpec.class); final BinaryTaskRule<R, S> binaryTaskRule = new BinaryTaskRule<R, S>(binaryType, ruleDefinition); return new ExtractedModelAction( ModelActionRole.Defaults, ImmutableList.of(ComponentModelBasePlugin.class), DirectNodeNoInputsModelAction.of( ModelReference.of("binaries"), new SimpleModelRuleDescriptor("binaries*.create()"), new Action<MutableModelNode>() { @Override public void execute(MutableModelNode modelNode) { modelNode.applyToAllLinks(ModelActionRole.Finalize, binaryTaskRule); } })); } catch (InvalidModelException e) { throw invalidModelRule(ruleDefinition, e); } }
@Override public Multimap<ModelActionRole, ModelAction> getActions( ModelReference<?> subject, ModelRuleDescriptor descriptor) { return ImmutableSetMultimap.<ModelActionRole, ModelAction>builder() .put( ModelActionRole.Discover, DirectNodeInputUsingModelAction.of( subject, descriptor, Arrays.<ModelReference<?>>asList( ModelReference.of(ManagedProxyFactory.class), ModelReference.of(TypeConverter.class)), new BiAction<MutableModelNode, List<ModelView<?>>>() { @Override public void execute(MutableModelNode modelNode, List<ModelView<?>> modelViews) { ManagedProxyFactory proxyFactory = getInstance(modelViews.get(0), ManagedProxyFactory.class); TypeConverter typeConverter = getInstance(modelViews, 1, TypeConverter.class); for (StructSchema<?> viewSchema : bindings.getAllViewSchemas()) { addProjection(modelNode, viewSchema, proxyFactory, typeConverter); } } })) .put( ModelActionRole.Create, DirectNodeInputUsingModelAction.of( subject, descriptor, Arrays.<ModelReference<?>>asList( ModelReference.of(ModelSchemaStore.class), ModelReference.of(NodeInitializerRegistry.class)), new BiAction<MutableModelNode, List<ModelView<?>>>() { @Override public void execute(MutableModelNode modelNode, List<ModelView<?>> modelViews) { ModelSchemaStore schemaStore = getInstance(modelViews, 0, ModelSchemaStore.class); NodeInitializerRegistry nodeInitializerRegistry = getInstance(modelViews, 1, NodeInitializerRegistry.class); addPropertyLinks(modelNode, schemaStore, nodeInitializerRegistry); initializePrivateData(modelNode); } })) .build(); }
@Override protected List<ModelReference<?>> withImplicitInputs(List<? extends ModelReference<?>> inputs) { List<ModelReference<?>> allInputs = new ArrayList<ModelReference<?>>(inputs.size() + implicitInputs.size()); allInputs.addAll(inputs); for (ModelProperty<?> property : implicitInputs) { ManagedInstance value = (ManagedInstance) values.get(property.getName()); allInputs.add(ModelReference.of(value.getBackingNode().getPath())); } return allInputs; }
private <T> void registerAction( final ModelPath modelPath, final Class<T> viewType, final ModelRuleDescriptor descriptor, final ModelActionRole role, final Closure<?> closure) { final ModelReference<T> reference = ModelReference.of(modelPath, viewType); modelRegistry.configure( ModelActionRole.DefineRules, DirectNodeNoInputsModelAction.of( reference, descriptor, new Action<MutableModelNode>() { @Override public void execute(MutableModelNode mutableModelNode) { InputReferences inputs = inputPathsExtractor.transform(closure); List<String> absolutePaths = inputs.getAbsolutePaths(); List<Integer> absolutePathLineNumbers = inputs.getAbsolutePathLineNumbers(); final List<PotentialInput> potentialInputs = Lists.newArrayListWithCapacity(absolutePaths.size()); List<ModelReference<?>> actualInputs = Lists.newArrayListWithCapacity(potentialInputs.size()); for (int i = 0; i < absolutePaths.size(); i++) { String description = String.format("@ line %d", absolutePathLineNumbers.get(i)); String path = absolutePaths.get(i); potentialInputs.add(PotentialInput.absoluteInput(path, actualInputs.size())); actualInputs.add(ModelReference.untyped(ModelPath.path(path), description)); } mutableModelNode.applyToSelf( role, InputUsingModelAction.of( reference, descriptor, actualInputs, new BiAction<T, List<ModelView<?>>>() { @Override public void execute(final T t, List<ModelView<?>> modelViews) { ((TransformedClosure) closure) .applyRuleInputs(new PotentialInputs(modelViews, potentialInputs)); ClosureBackedAction.execute( t, closure.rehydrate( null, closure.getThisObject(), closure.getThisObject())); } })); } })); }
private void validateRuleMethod( MethodRuleDefinition<?, ?> ruleDefinition, Method ruleMethod, ValidationProblemCollector problems) { if (Modifier.isPrivate(ruleMethod.getModifiers())) { problems.add(ruleMethod, "A rule method cannot be private"); } if (Modifier.isAbstract(ruleMethod.getModifiers())) { problems.add(ruleMethod, "A rule method cannot be abstract"); } if (ruleMethod.getTypeParameters().length > 0) { problems.add(ruleMethod, "Cannot have type variables (i.e. cannot be a generic method)"); } // TODO validations on method: synthetic, bridge methods, varargs, abstract, native ModelType<?> returnType = ModelType.returnType(ruleMethod); if (returnType.isRawClassOfParameterizedType()) { problems.add( ruleMethod, "Raw type " + returnType + " used for return type (all type parameters must be specified of parameterized type)"); } for (int i = 0; i < ruleDefinition.getReferences().size(); i++) { ModelReference<?> reference = ruleDefinition.getReferences().get(i); if (reference.getType().isRawClassOfParameterizedType()) { problems.add( ruleMethod, "Raw type " + reference.getType() + " used for parameter " + (i + 1) + " (all type parameters must be specified of parameterized type)"); } if (reference.getPath() != null) { try { ModelPath.validatePath(reference.getPath().toString()); } catch (Exception e) { problems.add( ruleDefinition, "The declared model element path '" + reference.getPath() + "' used for parameter " + (i + 1) + " is not a valid path", e); } } } }
@TaskAction public void report() { Project project = getProject(); StyledTextOutput textOutput = getTextOutputFactory().create(ComponentReport.class); ComponentReportRenderer renderer = new ComponentReportRenderer(getFileResolver()); renderer.setOutput(textOutput); renderer.startProject(project); Collection<ProjectComponent> components = new ArrayList<ProjectComponent>(); ProjectComponentContainer projectComponents = project.getExtensions().findByType(ProjectComponentContainer.class); if (projectComponents != null) { components.addAll(projectComponents); } try { TestSuiteContainer testSuites = getModelRegistry().get(ModelReference.of("testSuites", TestSuiteContainer.class)); components.addAll(testSuites); } catch (IllegalStateException e) { // TODO - need a better contract here // Ignore for now } renderer.renderComponents(components); ProjectSourceSet sourceSets = project.getExtensions().findByType(ProjectSourceSet.class); if (sourceSets != null) { renderer.renderSourceSets(sourceSets); } BinaryContainer binaries = project.getExtensions().findByType(BinaryContainer.class); if (binaries != null) { renderer.renderBinaries(binaries); } renderer.completeProject(project); renderer.complete(); }
@Override public List<? extends ModelReference<?>> getInputs() { return Collections.singletonList(ModelReference.of(NodeInitializerRegistry.class)); }
public BinaryTaskRule(Class<T> binaryType, MethodRuleDefinition<R, ?> ruleDefinition) { super(ModelReference.of(binaryType), binaryType, ruleDefinition); }