Search in sources :

Example 1 with ServiceLookup

use of org.gradle.internal.service.ServiceLookup in project gradle by gradle.

the class DefaultTransformer method newTransformAction.

private TransformAction<?> newTransformAction(Provider<FileSystemLocation> inputArtifactProvider, ArtifactTransformDependencies artifactTransformDependencies, @Nullable InputChanges inputChanges) {
    TransformParameters parameters = isolatedParameters.get().getIsolatedParameterObject().isolate();
    ServiceLookup services = new IsolationScheme<>(TransformAction.class, TransformParameters.class, TransformParameters.None.class).servicesForImplementation(parameters, internalServices);
    services = new TransformServiceLookup(inputArtifactProvider, requiresDependencies ? artifactTransformDependencies : null, inputChanges, services);
    return instanceFactory.newInstance(services);
}
Also used : ServiceLookup(org.gradle.internal.service.ServiceLookup) TransformAction(org.gradle.api.artifacts.transform.TransformAction) TransformParameters(org.gradle.api.artifacts.transform.TransformParameters)

Example 2 with ServiceLookup

use of org.gradle.internal.service.ServiceLookup 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 3 with ServiceLookup

use of org.gradle.internal.service.ServiceLookup in project gradle by gradle.

the class BuildServiceProvider method instantiate.

private Try<T> instantiate() {
    // TODO - extract some shared infrastructure to take care of instantiation (eg which services are visible, strict vs lenient, decorated or not?)
    // TODO - should hold the project lock to do the isolation. Should work the same way as artifact transforms (a work node does the isolation, etc)
    P isolatedParameters = isolatableFactory.isolate(parameters).isolate();
    // TODO - reuse this in other places
    ServiceLookup instantiationServices = instantiationServicesFor(isolatedParameters);
    try {
        return Try.successful(instantiate(instantiationServices));
    } catch (Exception e) {
        return Try.failure(instantiationException(e));
    }
}
Also used : ServiceLookup(org.gradle.internal.service.ServiceLookup)

Aggregations

ServiceLookup (org.gradle.internal.service.ServiceLookup)3 TransformAction (org.gradle.api.artifacts.transform.TransformAction)1 TransformParameters (org.gradle.api.artifacts.transform.TransformParameters)1 Instantiator (org.gradle.internal.reflect.Instantiator)1