@Defaults public static void addToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final OperatingSystem operatingSystem = serviceRegistry.get(OperatingSystem.class); final BuildOperationProcessor buildOperationProcessor = serviceRegistry.get(BuildOperationProcessor.class); final VisualStudioLocator visualStudioLocator = serviceRegistry.get(VisualStudioLocator.class); final UcrtLocator ucrtLocator = serviceRegistry.get(UcrtLocator.class); final WindowsSdkLocator windowsSdkLocator = serviceRegistry.get(WindowsSdkLocator.class); toolChainRegistry.registerFactory(VisualCpp.class, new NamedDomainObjectFactory<VisualCpp>() { public VisualCpp create(String name) { return instantiator.newInstance(VisualCppToolChain.class, name, buildOperationProcessor, operatingSystem, fileResolver, execActionFactory, visualStudioLocator, windowsSdkLocator, ucrtLocator, instantiator); } }); toolChainRegistry.registerDefaultToolChain(VisualCppToolChain.DEFAULT_NAME, VisualCpp.class); }
@Defaults public static void addToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final BuildOperationProcessor buildOperationProcessor = serviceRegistry.get(BuildOperationProcessor.class); final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class); toolChainRegistry.registerFactory(Gcc.class, new NamedDomainObjectFactory<Gcc>() { public Gcc create(String name) { return instantiator.newInstance(GccToolChain.class, instantiator, name, buildOperationProcessor, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory); } }); toolChainRegistry.registerDefaultToolChain(GccToolChain.DEFAULT_NAME, Gcc.class); }
@Mutate public static void addGccToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final OperatingSystem operatingSystem = serviceRegistry.get(OperatingSystem.class); final VisualStudioLocator visualStudioLocator = serviceRegistry.get(VisualStudioLocator.class); final WindowsSdkLocator windowsSdkLocator = serviceRegistry.get(WindowsSdkLocator.class); toolChainRegistry.registerFactory(VisualCpp.class, new NamedDomainObjectFactory<VisualCpp>() { public VisualCpp create(String name) { return instantiator.newInstance(VisualCppToolChain.class, name, operatingSystem, fileResolver, execActionFactory, visualStudioLocator, windowsSdkLocator, instantiator); } }); toolChainRegistry.registerDefaultToolChain(VisualCppToolChain.DEFAULT_NAME, VisualCpp.class); }
@Override public NamedDomainObjectContainer<ConfigurationVariant> getVariants() { if (variants == null) { // Create variants container only as required variants = new FactoryNamedDomainObjectContainer<ConfigurationVariant>(ConfigurationVariant.class, instantiator, new NamedDomainObjectFactory<ConfigurationVariant>() { @Override public ConfigurationVariant create(String name) { return instantiator.newInstance(DefaultVariant.class, name, parentAttributes, artifactNotationParser, fileCollectionFactory); } }); } return variants; }
@Defaults public static void addToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final BuildOperationProcessor buildOperationProcessor = serviceRegistry.get(BuildOperationProcessor.class); final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class); toolChainRegistry.registerFactory(Clang.class, new NamedDomainObjectFactory<Clang>() { public Clang create(String name) { return instantiator.newInstance(ClangToolChain.class, name, buildOperationProcessor, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory, instantiator); } }); toolChainRegistry.registerDefaultToolChain(ClangToolChain.DEFAULT_NAME, Clang.class); }
@Defaults public void registerFactoryForCustomNativePlatforms(PlatformContainer platforms, final Instantiator instantiator) { NamedDomainObjectFactory<NativePlatform> nativePlatformFactory = new NamedDomainObjectFactory<NativePlatform>() { public NativePlatform create(String name) { return instantiator.newInstance(DefaultNativePlatform.class, name); } }; platforms.registerFactory(NativePlatform.class, nativePlatformFactory); platforms.registerFactory(Platform.class, nativePlatformFactory); }
private DefaultRepositories(final Instantiator instantiator, final SourceDirectorySetFactory sourceDirectorySetFactory, final Action<PrebuiltLibrary> binaryFactory) { super(ArtifactRepository.class, instantiator, new ArtifactRepositoryNamer()); registerFactory(PrebuiltLibraries.class, new NamedDomainObjectFactory<PrebuiltLibraries>() { public PrebuiltLibraries create(String name) { return instantiator.newInstance(DefaultPrebuiltLibraries.class, name, instantiator, sourceDirectorySetFactory, binaryFactory); } }); }
public <S extends T> S create(String name, Class<S> type) { @SuppressWarnings("unchecked") NamedDomainObjectFactory<S> factory = (NamedDomainObjectFactory<S>) factories.get(type); if (factory == null) { throw new InvalidUserDataException( String.format("Cannot create a %s because this type is not known to %s. Known types are: %s", type.getSimpleName(), displayName, getSupportedTypeNames()), new NoFactoryRegisteredForTypeException()); } return factory.create(name); }
@Override public <U extends T> void registerFactory(Class<U> type, NamedDomainObjectFactory<? extends U> factory) { if (!baseType.isAssignableFrom(type)) { String message = String.format("Cannot register a factory for type %s because it is not a subtype of container element type %s.", type.getSimpleName(), baseType.getSimpleName()); throw new IllegalArgumentException(message); } if(factories.containsKey(type)){ throw new GradleException(String.format("Cannot register a factory for type %s because a factory for this type is already registered.", type.getSimpleName())); } factories.put(type, factory); }
@Override protected void applyOnce(Project project) { project.getExtensions().add(NAME, project.container(EquinoxLaunchSetupTask.class, new NamedDomainObjectFactory<EquinoxLaunchSetupTask>() { @Override public EquinoxLaunchSetupTask create(String name) { EquinoxLaunchSetupTask setupTask = project.getTasks().create(name, EquinoxLaunchSetupTask.class); setupTask.setInstallDir(new File(project.getBuildDir(), name)); return setupTask; } })); }
private <T extends ComponentSpec, I extends BaseComponentSpec> void doRegister(final ModelType<T> type, final ModelType<I> implementation, final ProjectSourceSet projectSourceSet, ComponentSpecContainer componentSpecs, final ProjectIdentifier projectIdentifier) { componentSpecs.registerFactory(type.getConcreteClass(), new NamedDomainObjectFactory<T>() { public T create(String name) { FunctionalSourceSet componentSourceSet = projectSourceSet.maybeCreate(name); ComponentSpecIdentifier id = new DefaultComponentSpecIdentifier(projectIdentifier.getPath(), name); // safe because we implicitly know that U extends V, but can't express this in the type system @SuppressWarnings("unchecked") T created = (T) BaseComponentSpec.create(implementation.getConcreteClass(), id, componentSourceSet, instantiator); return created; } }); }
private <T extends BinarySpec, U extends BaseBinarySpec> void doRegister(BinaryContainer binaries, ModelType<T> type, final ModelType<U> implementation) { binaries.registerFactory(type.getConcreteClass(), new NamedDomainObjectFactory<T>() { public T create(String name) { BinaryNamingScheme binaryNamingScheme = new DefaultBinaryNamingSchemeBuilder() .withComponentName(name) .build(); // safe because we implicitly know that U extends V, but can't express this in the type system @SuppressWarnings("unchecked") T created = (T) BaseBinarySpec.create(implementation.getConcreteClass(), binaryNamingScheme, instantiator); return created; } }); }
@Mutate public static void addToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class); toolChainRegistry.registerFactory(Clang.class, new NamedDomainObjectFactory<Clang>() { public Clang create(String name) { return instantiator.newInstance(ClangToolChain.class, name, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory, instantiator); } }); toolChainRegistry.registerDefaultToolChain(ClangToolChain.DEFAULT_NAME, Clang.class); }
@Mutate public static void addGccToolChain(NativeToolChainRegistryInternal toolChainRegistry, ServiceRegistry serviceRegistry) { final FileResolver fileResolver = serviceRegistry.get(FileResolver.class); final ExecActionFactory execActionFactory = serviceRegistry.get(ExecActionFactory.class); final Instantiator instantiator = serviceRegistry.get(Instantiator.class); final CompilerMetaDataProviderFactory metaDataProviderFactory = serviceRegistry.get(CompilerMetaDataProviderFactory.class); toolChainRegistry.registerFactory(Gcc.class, new NamedDomainObjectFactory<Gcc>() { public Gcc create(String name) { return instantiator.newInstance(GccToolChain.class, instantiator, name, OperatingSystem.current(), fileResolver, execActionFactory, metaDataProviderFactory); } }); toolChainRegistry.registerDefaultToolChain(GccToolChain.DEFAULT_NAME, Gcc.class); }
private DefaultRepositories(final Instantiator instantiator, final FileResolver fileResolver, final Action<PrebuiltLibrary> binaryFactory) { super(ArtifactRepository.class, instantiator, new ArtifactRepositoryNamer()); registerFactory(PrebuiltLibraries.class, new NamedDomainObjectFactory<PrebuiltLibraries>() { public PrebuiltLibraries create(String name) { return instantiator.newInstance(DefaultPrebuiltLibraries.class, name, instantiator, fileResolver, binaryFactory); } }); }
public <T> NamedDomainObjectContainer<T> container(Class<T> type, NamedDomainObjectFactory<T> factory) { Instantiator instantiator = getServices().get(Instantiator.class); return instantiator.newInstance(FactoryNamedDomainObjectContainer.class, type, instantiator, new DynamicPropertyNamer(), factory); }
<U extends T> void copyFactory(DefaultPolymorphicNamedEntityInstantiator<T> source, Class<U> type) { NamedDomainObjectFactory<U> factory = uncheckedCast(source.factories.get(type)); registerFactory(type, factory); }
@Override public <U extends T> void registerFactory(Class<U> type, NamedDomainObjectFactory<? extends U> factory) { checkCanRegister(type); super.registerFactory(type, factory); }
/** * <p>Creates a container that instantiates using the given factory.<p> * * @param type The concrete type of element in the container (must implement {@link Named}) * @param instantiator The instantiator to use to create any other collections based on this one * @param factory The factory responsible for creating new instances on demand */ public FactoryNamedDomainObjectContainer(Class<T> type, Instantiator instantiator, NamedDomainObjectFactory<T> factory) { this(type, instantiator, Named.Namer.forType(type), factory); }
/** * <p>Creates a container that instantiates using the given factory.<p> * * @param type The concrete type of element in the container * @param instantiator The instantiator to use to create any other collections based on this one * @param namer The naming strategy to use * @param factory The factory responsible for creating new instances on demand */ public FactoryNamedDomainObjectContainer(Class<T> type, Instantiator instantiator, Namer<? super T> namer, NamedDomainObjectFactory<T> factory) { super(type, instantiator, namer); this.factory = factory; }
<U extends T> void registerFactory(Class<U> type, NamedDomainObjectFactory<? extends U> factory);