Search in sources :

Example 16 with GradleInternal

use of org.gradle.api.internal.GradleInternal in project gradle by gradle.

the class DefaultGradleLauncherFactory method doNewInstance.

private DefaultGradleLauncher doNewInstance(BuildDefinition buildDefinition, @Nullable GradleLauncher parent, BuildCancellationToken cancellationToken, BuildRequestMetaData requestMetaData, BuildEventConsumer buildEventConsumer, final BuildTreeScopeServices buildTreeScopeServices, List<?> servicesToStop) {
    BuildScopeServices serviceRegistry = new BuildScopeServices(buildTreeScopeServices);
    serviceRegistry.add(BuildDefinition.class, buildDefinition);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    serviceRegistry.add(BuildEventConsumer.class, buildEventConsumer);
    serviceRegistry.add(BuildCancellationToken.class, cancellationToken);
    serviceRegistry.add(BuildIdentity.class, new DefaultBuildIdentity(buildDefinition, parent == null));
    NestedBuildFactoryImpl nestedBuildFactory = new NestedBuildFactoryImpl(buildTreeScopeServices);
    serviceRegistry.add(NestedBuildFactory.class, nestedBuildFactory);
    StartParameter startParameter = buildDefinition.getStartParameter();
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggerProvider loggerProvider = (parent == null) ? buildProgressLogger : LoggerProvider.NO_OP;
    listenerManager.useLogger(new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class), loggerProvider));
    if (parent == null) {
        BuildStartedTime buildStartedTime = serviceRegistry.get(BuildStartedTime.class);
        Clock clock = serviceRegistry.get(Clock.class);
        listenerManager.useLogger(new BuildLogger(Logging.getLogger(BuildLogger.class), serviceRegistry.get(StyledTextOutputFactory.class), startParameter, requestMetaData, buildStartedTime, clock));
    }
    listenerManager.addListener(serviceRegistry.get(TaskExecutionStatisticsEventAdapter.class));
    listenerManager.addListener(new TaskExecutionStatisticsReporter(serviceRegistry.get(StyledTextOutputFactory.class)));
    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
        listenerManager.addListener(new ReportGeneratingProfileListener(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    ShowStacktrace showStacktrace = startParameter.getShowStacktrace();
    switch(showStacktrace) {
        case ALWAYS:
        case ALWAYS_FULL:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(true);
            break;
        default:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(false);
    }
    DeprecationLogger.init(usageLocationReporter, startParameter.getWarningMode());
    SettingsLoaderFactory settingsLoaderFactory = serviceRegistry.get(SettingsLoaderFactory.class);
    SettingsLoader settingsLoader = parent != null ? settingsLoaderFactory.forNestedBuild() : settingsLoaderFactory.forTopLevelBuild();
    GradleInternal parentBuild = parent == null ? null : parent.getGradle();
    GradleInternal gradle = serviceRegistry.get(Instantiator.class).newInstance(DefaultGradle.class, parentBuild, startParameter, serviceRegistry.get(ServiceRegistryFactory.class));
    DefaultGradleLauncher gradleLauncher = new DefaultGradleLauncher(gradle, serviceRegistry.get(InitScriptHandler.class), settingsLoader, serviceRegistry.get(BuildLoader.class), serviceRegistry.get(BuildConfigurer.class), serviceRegistry.get(ExceptionAnalyser.class), gradle.getBuildListenerBroadcaster(), listenerManager.getBroadcaster(ModelConfigurationListener.class), listenerManager.getBroadcaster(BuildCompletionListener.class), serviceRegistry.get(BuildOperationExecutor.class), gradle.getServices().get(BuildConfigurationActionExecuter.class), gradle.getServices().get(BuildExecuter.class), serviceRegistry, servicesToStop);
    nestedBuildFactory.setParent(gradleLauncher);
    return gradleLauncher;
}
Also used : ExceptionAnalyser(org.gradle.api.internal.ExceptionAnalyser) TaskExecutionStatisticsReporter(org.gradle.internal.buildevents.TaskExecutionStatisticsReporter) Instantiator(org.gradle.internal.reflect.Instantiator) Clock(org.gradle.internal.time.Clock) GradleInternal(org.gradle.api.internal.GradleInternal) ReportGeneratingProfileListener(org.gradle.profile.ReportGeneratingProfileListener) BuildExecuter(org.gradle.execution.BuildExecuter) LoggerProvider(org.gradle.internal.progress.LoggerProvider) ScriptUsageLocationReporter(org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter) BuildConfigurer(org.gradle.configuration.BuildConfigurer) StartParameter(org.gradle.StartParameter) BuildConfigurationActionExecuter(org.gradle.execution.BuildConfigurationActionExecuter) ProfileEventAdapter(org.gradle.profile.ProfileEventAdapter) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) TaskExecutionStatisticsEventAdapter(org.gradle.api.internal.tasks.execution.statistics.TaskExecutionStatisticsEventAdapter) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) TaskExecutionLogger(org.gradle.internal.buildevents.TaskExecutionLogger) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) BuildLogger(org.gradle.internal.buildevents.BuildLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 17 with GradleInternal

use of org.gradle.api.internal.GradleInternal in project gradle by gradle.

the class DefaultSettingsLoaderFactory method defaultSettingsLoader.

private SettingsLoader defaultSettingsLoader() {
    final DefaultSettingsLoader delegate = new DefaultSettingsLoader(settingsFinder, settingsProcessor, buildSourceBuilder);
    return new SettingsLoader() {

        @Override
        public SettingsInternal findAndLoadSettings(GradleInternal gradle) {
            SettingsInternal settings = delegate.findAndLoadSettings(gradle);
            gradle.setSettings(settings);
            return settings;
        }
    };
}
Also used : SettingsInternal(org.gradle.api.internal.SettingsInternal) GradleInternal(org.gradle.api.internal.GradleInternal) CompositeBuildSettingsLoader(org.gradle.internal.composite.CompositeBuildSettingsLoader)

Example 18 with GradleInternal

use of org.gradle.api.internal.GradleInternal in project gradle by gradle.

the class BuildSourceBuilder method buildGradleLauncher.

private GradleLauncher buildGradleLauncher(BuildDefinition buildDefinition) {
    // TODO: Migrate buildSrc builds to be more similar to other "included" builds.
    GradleLauncher gradleLauncher = nestedBuildFactory.nestedInstance(buildDefinition);
    StartParameter startParameter = buildDefinition.getStartParameter();
    GradleInternal build = gradleLauncher.getGradle();
    if (build.getParent().findIdentityPath() == null) {
        // When nested inside a nested build, we need to synthesize a path for this build, as the root project is not yet known for the parent build
        // Use the directory structure to do this. This means that the buildSrc build and its containing build may end up with different paths
        Path path = build.getParent().getParent().getIdentityPath().child(startParameter.getCurrentDir().getParentFile().getName()).child(startParameter.getCurrentDir().getName());
        build.setIdentityPath(path);
    }
    return gradleLauncher;
}
Also used : Path(org.gradle.util.Path) ClassPath(org.gradle.internal.classpath.ClassPath) GradleLauncher(org.gradle.initialization.GradleLauncher) StartParameter(org.gradle.StartParameter) GradleInternal(org.gradle.api.internal.GradleInternal)

Example 19 with GradleInternal

use of org.gradle.api.internal.GradleInternal in project gradle by gradle.

the class BuildSrcUpdateFactory method build.

private Collection<File> build() {
    BuildSrcBuildListenerFactory.Listener listener = listenerFactory.create();
    GradleInternal gradle = buildController.getGradle();
    gradle.addListener(listener);
    buildController.run();
    return listener.getRuntimeClasspath();
}
Also used : GradleInternal(org.gradle.api.internal.GradleInternal)

Example 20 with GradleInternal

use of org.gradle.api.internal.GradleInternal in project gradle by gradle.

the class ProjectBuilderImpl method createProject.

public Project createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
    File projectDir = prepareProjectDir(inputProjectDir);
    final File homeDir = new File(projectDir, "gradleHome");
    StartParameter startParameter = new StartParameterInternal();
    File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
    startParameter.setGradleUserHomeDir(userHomeDir);
    NativeServices.initialize(userHomeDir);
    BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
    CrossBuildSessionScopeServices crossBuildSessionScopeServices = new CrossBuildSessionScopeServices(getGlobalServices(), startParameter);
    ServiceRegistry userHomeServices = getUserHomeServices(userHomeDir);
    BuildSessionScopeServices buildSessionScopeServices = new BuildSessionScopeServices(userHomeServices, crossBuildSessionScopeServices, startParameter, buildRequestMetaData, ClassPath.EMPTY);
    BuildTreeScopeServices buildTreeScopeServices = new BuildTreeScopeServices(buildSessionScopeServices);
    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(buildTreeScopeServices, homeDir);
    GradleInternal gradle = CLASS_GENERATOR.newInstance(DefaultGradle.class, null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));
    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(), topLevelRegistry.get(FileResolver.class));
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, rootProjectScope, baseScope);
    gradle.setRootProject(project);
    gradle.setDefaultProject(project);
    // Take a root worker lease, it won't ever be released as ProjectBuilder has no lifecycle
    ResourceLockCoordinationService coordinationService = topLevelRegistry.get(ResourceLockCoordinationService.class);
    WorkerLeaseService workerLeaseService = topLevelRegistry.get(WorkerLeaseService.class);
    coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(workerLeaseService.getWorkerLease()));
    return project;
}
Also used : DefaultProjectDescriptorRegistry(org.gradle.initialization.DefaultProjectDescriptorRegistry) StartParameter(org.gradle.StartParameter) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuildTreeScopeServices(org.gradle.internal.service.scopes.BuildTreeScopeServices) BuildSessionScopeServices(org.gradle.internal.service.scopes.BuildSessionScopeServices) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) GradleInternal(org.gradle.api.internal.GradleInternal) IProjectFactory(org.gradle.api.internal.project.IProjectFactory) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) CrossBuildSessionScopeServices(org.gradle.internal.service.scopes.CrossBuildSessionScopeServices) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) FileResolver(org.gradle.api.internal.file.FileResolver) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) File(java.io.File)

Aggregations

GradleInternal (org.gradle.api.internal.GradleInternal)21 StartParameter (org.gradle.StartParameter)4 ServiceRegistryFactory (org.gradle.internal.service.scopes.ServiceRegistryFactory)3 Task (org.gradle.api.Task)2 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)2 BuildConfigurer (org.gradle.configuration.BuildConfigurer)2 BuildConfigurationActionExecuter (org.gradle.execution.BuildConfigurationActionExecuter)2 BuildExecuter (org.gradle.execution.BuildExecuter)2 GradleLauncher (org.gradle.initialization.GradleLauncher)2 BuildLogger (org.gradle.internal.buildevents.BuildLogger)2 TaskExecutionLogger (org.gradle.internal.buildevents.TaskExecutionLogger)2 ListenerManager (org.gradle.internal.event.ListenerManager)2 ScriptUsageLocationReporter (org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter)2 BuildOperationExecutor (org.gradle.internal.operations.BuildOperationExecutor)2 LoggerProvider (org.gradle.internal.progress.LoggerProvider)2 Instantiator (org.gradle.internal.reflect.Instantiator)2 BuildScopeServices (org.gradle.internal.service.scopes.BuildScopeServices)2 ProfileEventAdapter (org.gradle.profile.ProfileEventAdapter)2