Search in sources :

Example 11 with Instantiator

use of org.gradle.internal.reflect.Instantiator in project gradle by gradle.

the class DefaultWorkerServer method execute.

@Override
public DefaultWorkResult execute(SimpleActionExecutionSpec<?> spec) {
    try {
        Class<? extends WorkAction<?>> implementationClass = Cast.uncheckedCast(spec.getImplementationClass());
        // Exceptions to services available for injection
        Spec<Class<?>> whiteListPolicy;
        if (spec.isInternalServicesRequired()) {
            whiteListPolicy = element -> true;
        } else {
            whiteListPolicy = element -> false;
        }
        ServiceLookup instantiationServices = isolationScheme.servicesForImplementation(spec.getParameters(), internalServices, additionalWhitelistedServices, whiteListPolicy);
        Instantiator instantiator = instantiatorFactory.inject(instantiationServices);
        WorkAction<?> execution;
        if (ProvidesWorkResult.class.isAssignableFrom(implementationClass)) {
            execution = instantiator.newInstance(implementationClass, spec.getParameters(), instantiator);
        } else {
            execution = instantiator.newInstance(implementationClass);
        }
        execution.execute();
        if (execution instanceof ProvidesWorkResult) {
            return ((ProvidesWorkResult) execution).getWorkResult();
        } else {
            return DefaultWorkResult.SUCCESS;
        }
    } catch (Throwable t) {
        return new DefaultWorkResult(true, t);
    }
}
Also used : ServiceLookup(org.gradle.internal.service.ServiceLookup) Instantiator(org.gradle.internal.reflect.Instantiator)

Example 12 with Instantiator

use of org.gradle.internal.reflect.Instantiator in project gradle by gradle.

the class ResolveIvyFactory method create.

public ComponentResolvers create(String resolveContextName, ResolutionStrategyInternal resolutionStrategy, Collection<? extends ResolutionAwareRepository> repositories, ComponentMetadataProcessorFactory metadataProcessor, AttributeContainer consumerAttributes, AttributesSchema attributesSchema, ImmutableAttributesFactory attributesFactory, ComponentMetadataSupplierRuleExecutor componentMetadataSupplierRuleExecutor) {
    if (repositories.isEmpty()) {
        return new NoRepositoriesResolver();
    }
    CachePolicy cachePolicy = resolutionStrategy.getCachePolicy();
    startParameterResolutionOverride.applyToCachePolicy(cachePolicy);
    UserResolverChain moduleResolver = new UserResolverChain(versionComparator, resolutionStrategy.getComponentSelection(), versionParser, consumerAttributes, attributesSchema, attributesFactory, metadataProcessor, componentMetadataSupplierRuleExecutor, cachePolicy, calculatedValueContainerFactory);
    ParentModuleLookupResolver parentModuleResolver = new ParentModuleLookupResolver(versionComparator, moduleIdentifierFactory, versionParser, consumerAttributes, attributesSchema, attributesFactory, metadataProcessor, componentMetadataSupplierRuleExecutor, cachePolicy, calculatedValueContainerFactory);
    for (ResolutionAwareRepository repository : repositories) {
        ConfiguredModuleComponentRepository baseRepository = repository.createResolver();
        baseRepository.setComponentResolvers(parentModuleResolver);
        Instantiator instantiator = baseRepository.getComponentMetadataInstantiator();
        MetadataResolutionContext metadataResolutionContext = new DefaultMetadataResolutionContext(cachePolicy, instantiator);
        ComponentMetadataProcessor componentMetadataProcessor = metadataProcessor.createComponentMetadataProcessor(metadataResolutionContext);
        ModuleComponentRepository moduleComponentRepository = baseRepository;
        if (baseRepository.isLocal()) {
            moduleComponentRepository = new CachingModuleComponentRepository(moduleComponentRepository, cacheProvider.getInMemoryOnlyCaches(), cachePolicy, timeProvider, componentMetadataProcessor, ChangingValueDependencyResolutionListener.NO_OP);
            moduleComponentRepository = new LocalModuleComponentRepository(moduleComponentRepository);
        } else {
            moduleComponentRepository = startParameterResolutionOverride.overrideModuleVersionRepository(moduleComponentRepository);
            moduleComponentRepository = new CachingModuleComponentRepository(moduleComponentRepository, cacheProvider.getPersistentCaches(), cachePolicy, timeProvider, componentMetadataProcessor, listener);
        }
        moduleComponentRepository = cacheProvider.getResolvedArtifactCaches().provideResolvedArtifactCache(moduleComponentRepository, resolutionStrategy.isDependencyVerificationEnabled());
        if (baseRepository.isDynamicResolveMode()) {
            moduleComponentRepository = new IvyDynamicResolveModuleComponentRepository(moduleComponentRepository);
        }
        moduleComponentRepository = new ErrorHandlingModuleComponentRepository(moduleComponentRepository, repositoryBlacklister);
        moduleComponentRepository = filterRepository(repository, moduleComponentRepository, resolveContextName, consumerAttributes);
        moduleComponentRepository = dependencyVerificationOverride.overrideDependencyVerification(moduleComponentRepository, resolveContextName, resolutionStrategy);
        moduleResolver.add(moduleComponentRepository);
        parentModuleResolver.add(moduleComponentRepository);
    }
    return moduleResolver;
}
Also used : ResolutionAwareRepository(org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository) MetadataResolutionContext(org.gradle.api.internal.artifacts.MetadataResolutionContext) Instantiator(org.gradle.internal.reflect.Instantiator) ComponentMetadataProcessor(org.gradle.api.internal.artifacts.ComponentMetadataProcessor) CachePolicy(org.gradle.api.internal.artifacts.configurations.dynamicversion.CachePolicy)

Example 13 with Instantiator

use of org.gradle.internal.reflect.Instantiator in project gradle by gradle.

the class DefaultFlatDirArtifactRepository method createRealResolver.

private IvyResolver createRealResolver() {
    Set<File> dirs = getDirs();
    if (dirs.isEmpty()) {
        throw new InvalidUserDataException("You must specify at least one directory for a flat directory repository.");
    }
    RepositoryTransport transport = transportFactory.createFileTransport(getName());
    Instantiator injector = createInjectorForMetadataSuppliers(transport, instantiatorFactory, null, null);
    IvyResolver resolver = new IvyResolver(getName(), transport, locallyAvailableResourceFinder, false, artifactFileStore, null, null, createMetadataSources(), IvyMetadataArtifactProvider.INSTANCE, injector, checksumService);
    for (File root : dirs) {
        resolver.addArtifactLocation(root.toURI(), "/[artifact]-[revision](-[classifier]).[ext]");
        resolver.addArtifactLocation(root.toURI(), "/[artifact](-[classifier]).[ext]");
    }
    return resolver;
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) IvyResolver(org.gradle.api.internal.artifacts.repositories.resolver.IvyResolver) Instantiator(org.gradle.internal.reflect.Instantiator) RepositoryTransport(org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransport) File(java.io.File)

Example 14 with Instantiator

use of org.gradle.internal.reflect.Instantiator in project gradle by gradle.

the class DefaultFileOperations method createSimple.

public static DefaultFileOperations createSimple(FileResolver fileResolver, FileCollectionFactory fileTreeFactory, ServiceRegistry services) {
    Instantiator instantiator = services.get(Instantiator.class);
    ObjectFactory objectFactory = services.get(ObjectFactory.class);
    FileSystem fileSystem = services.get(FileSystem.class);
    DirectoryFileTreeFactory directoryFileTreeFactory = services.get(DirectoryFileTreeFactory.class);
    StreamHasher streamHasher = services.get(StreamHasher.class);
    FileHasher fileHasher = services.get(FileHasher.class);
    ApiTextResourceAdapter.Factory textResourceAdapterFactory = services.get(ApiTextResourceAdapter.Factory.class);
    Factory<PatternSet> patternSetFactory = services.getFactory(PatternSet.class);
    Deleter deleter = services.get(Deleter.class);
    DocumentationRegistry documentationRegistry = services.get(DocumentationRegistry.class);
    ProviderFactory providers = services.get(ProviderFactory.class);
    DefaultResourceHandler.Factory resourceHandlerFactory = DefaultResourceHandler.Factory.from(fileResolver, fileSystem, null, textResourceAdapterFactory);
    return new DefaultFileOperations(fileResolver, null, instantiator, directoryFileTreeFactory, streamHasher, fileHasher, resourceHandlerFactory, fileTreeFactory, objectFactory, fileSystem, patternSetFactory, deleter, documentationRegistry, providers);
}
Also used : Deleter(org.gradle.internal.file.Deleter) Instantiator(org.gradle.internal.reflect.Instantiator) StreamHasher(org.gradle.internal.hash.StreamHasher) FileHasher(org.gradle.internal.hash.FileHasher) ObjectFactory(org.gradle.api.model.ObjectFactory) DirectoryFileTreeFactory(org.gradle.api.internal.file.collections.DirectoryFileTreeFactory) DefaultResourceHandler(org.gradle.api.internal.resources.DefaultResourceHandler) FileSystem(org.gradle.internal.nativeintegration.filesystem.FileSystem) ProviderFactory(org.gradle.api.provider.ProviderFactory) DocumentationRegistry(org.gradle.api.internal.DocumentationRegistry) ApiTextResourceAdapter(org.gradle.api.internal.resources.ApiTextResourceAdapter) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 15 with Instantiator

use of org.gradle.internal.reflect.Instantiator in project gradle by gradle.

the class DefaultDomainObjectCollectionFactory method newPolymorphicDomainObjectContainer.

@Override
public <T> ExtensiblePolymorphicDomainObjectContainer<T> newPolymorphicDomainObjectContainer(Class<T> elementType) {
    Instantiator instantiator = instantiatorFactory.decorateLenient();
    Instantiator elementInstantiator = instantiatorFactory.decorateLenient(servicesToInject);
    return Cast.uncheckedCast(instantiator.newInstance(DefaultPolymorphicDomainObjectContainer.class, elementType, instantiator, elementInstantiator, collectionCallbackActionDecorator));
}
Also used : DefaultPolymorphicDomainObjectContainer(org.gradle.api.internal.DefaultPolymorphicDomainObjectContainer) Instantiator(org.gradle.internal.reflect.Instantiator)

Aggregations

Instantiator (org.gradle.internal.reflect.Instantiator)17 FileResolver (org.gradle.api.internal.file.FileResolver)4 RepositoryTransport (org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransport)3 FileSystem (org.gradle.internal.nativeintegration.filesystem.FileSystem)3 File (java.io.File)2 ComponentMetadataListerDetails (org.gradle.api.artifacts.ComponentMetadataListerDetails)2 ComponentMetadataSupplierDetails (org.gradle.api.artifacts.ComponentMetadataSupplierDetails)2 MavenMetadataLoader (org.gradle.api.internal.artifacts.repositories.maven.MavenMetadataLoader)2 IvyResolver (org.gradle.api.internal.artifacts.repositories.resolver.IvyResolver)2 MavenResolver (org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver)2 CopyActionExecuter (org.gradle.api.internal.file.copy.CopyActionExecuter)2 ProviderFactory (org.gradle.api.provider.ProviderFactory)2 URI (java.net.URI)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 DefaultPolymorphicDomainObjectContainer (org.gradle.api.internal.DefaultPolymorphicDomainObjectContainer)1 DocumentationRegistry (org.gradle.api.internal.DocumentationRegistry)1 DynamicPropertyNamer (org.gradle.api.internal.DynamicPropertyNamer)1 FactoryNamedDomainObjectContainer (org.gradle.api.internal.FactoryNamedDomainObjectContainer)1 ReflectiveNamedDomainObjectFactory (org.gradle.api.internal.ReflectiveNamedDomainObjectFactory)1 ComponentMetadataProcessor (org.gradle.api.internal.artifacts.ComponentMetadataProcessor)1