public DomainObjectSet<NativeLibraryBinary> getBinaries(NativeLibraryRequirement requirement) { ModelRegistry projectModel = projectModelResolver.resolveProjectModel(requirement.getProjectPath()); NamedDomainObjectSet<PrebuiltLibraries> repositories = projectModel.realize("repositories", Repositories.class).withType(PrebuiltLibraries.class); if (repositories.isEmpty()) { return null; } PrebuiltLibrary prebuiltLibrary = getPrebuiltLibrary(repositories, requirement.getLibraryName()); return prebuiltLibrary != null ? prebuiltLibrary.getBinaries() : null; }
/** Invoked by transformed DSL creation rules */ public <T> void create(String modelPathString, Class<T> type, Closure<?> closure) { SourceLocation sourceLocation = ruleLocationExtractor.transform(closure); ModelPath modelPath = ModelPath.path(modelPathString); ModelRuleDescriptor descriptor = toDescriptor(sourceLocation, modelPath); try { NodeInitializerRegistry nodeInitializerRegistry = modelRegistry.realize( DefaultNodeInitializerRegistry.DEFAULT_REFERENCE.getPath(), DefaultNodeInitializerRegistry.DEFAULT_REFERENCE.getType()); NodeInitializer nodeInitializer = nodeInitializerRegistry.getNodeInitializer(ModelType.of(type)); modelRegistry.create( ModelCreators.of(modelPath, nodeInitializer).descriptor(descriptor).build()); } catch (ModelTypeInitializationException e) { throw new InvalidModelRuleDeclarationException(descriptor, e); } registerAction(modelPath, type, descriptor, ModelActionRole.Initialize, closure); }
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 applyJUnitTestSuiteRules() { modelRegistry .getRoot() .applyTo(allDescendants(withType(JUnitTestSuiteSpec.class)), JUnitTestSuiteRules.class); }