Search in sources :

Example 41 with ProjectInternal

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

the class JavaPlugin method apply.

@Override
public void apply(final Project project) {
    if (project.getPluginManager().hasPlugin("java-platform")) {
        throw new IllegalStateException("The \"java\" or \"java-library\" plugin cannot be applied together with the \"java-platform\" plugin. " + "A project is either a platform or a library but cannot be both at the same time.");
    }
    final ProjectInternal projectInternal = (ProjectInternal) project;
    project.getPluginManager().apply(JavaBasePlugin.class);
    project.getPluginManager().apply("org.gradle.jvm-test-suite");
    JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
    projectInternal.getServices().get(ComponentRegistry.class).setMainComponent(new BuildableJavaComponentImpl(project, javaExtension));
    BuildOutputCleanupRegistry buildOutputCleanupRegistry = projectInternal.getServices().get(BuildOutputCleanupRegistry.class);
    SourceSet mainSourceSet = javaExtension.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);
    configureSourceSets(project, javaExtension, buildOutputCleanupRegistry, mainSourceSet);
    configureConfigurations(project, javaExtension, mainSourceSet);
    configureJavadocTask(project, javaExtension);
    configureArchivesAndComponent(project, javaExtension);
    configureBuild(project);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) BuildOutputCleanupRegistry(org.gradle.internal.execution.BuildOutputCleanupRegistry) ComponentRegistry(org.gradle.api.internal.component.ComponentRegistry) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 42 with ProjectInternal

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

the class JavaBasePlugin method apply.

@Override
public void apply(final Project project) {
    ProjectInternal projectInternal = (ProjectInternal) project;
    project.getPluginManager().apply(BasePlugin.class);
    project.getPluginManager().apply(JvmEcosystemPlugin.class);
    project.getPluginManager().apply(ReportingBasePlugin.class);
    DefaultJavaPluginExtension javaPluginExtension = addExtensions(projectInternal);
    configureSourceSetDefaults(project, javaPluginExtension);
    configureCompileDefaults(project, javaPluginExtension);
    configureJavaDoc(project, javaPluginExtension);
    configureTest(project, javaPluginExtension);
    configureBuildNeeded(project);
    configureBuildDependents(project);
}
Also used : ProjectInternal(org.gradle.api.internal.project.ProjectInternal) DefaultJavaPluginExtension(org.gradle.api.plugins.internal.DefaultJavaPluginExtension)

Example 43 with ProjectInternal

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

the class DefaultProjectModelResolver method resolveProjectModel.

@Override
public ModelRegistry resolveProjectModel(String path) {
    ProjectInternal projectInternal = delegate.getProject(path);
    if (projectInternal == null) {
        throw new UnknownProjectException("Project with path '" + path + "' not found.");
    }
    // TODO This is a brain-dead way to ensure that the reference project's model is ready to access
    return projectInternal.getOwner().fromMutableState(project -> {
        project.prepareForRuleBasedPlugins();
        project.evaluate();
        project.getTasks().discoverTasks();
        return project.getModelRegistry();
    });
}
Also used : ProjectInternal(org.gradle.api.internal.project.ProjectInternal) UnknownProjectException(org.gradle.api.UnknownProjectException)

Example 44 with ProjectInternal

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

the class ProjectBuilderImpl method createChildProject.

public Project createChildProject(String name, Project parent, File projectDir) {
    ProjectInternal parentProject = (ProjectInternal) parent;
    ProjectDescriptorRegistry descriptorRegistry = parentProject.getServices().get(ProjectDescriptorRegistry.class);
    DefaultProjectDescriptor parentDescriptor = descriptorRegistry.getProject(parentProject.getPath());
    projectDir = (projectDir != null) ? projectDir.getAbsoluteFile() : new File(parentProject.getProjectDir(), name);
    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(parentDescriptor, name, projectDir, descriptorRegistry, parentProject.getServices().get(FileResolver.class));
    descriptorRegistry.addProject(projectDescriptor);
    ProjectState projectState = parentProject.getServices().get(ProjectStateRegistry.class).registerProject(parentProject.getServices().get(BuildState.class), projectDescriptor);
    projectState.createMutableModel(parentProject.getClassLoaderScope().createChild("project-" + name), parentProject.getBaseClassLoaderScope());
    ProjectInternal project = projectState.getMutableModel();
    // Lock the project, these won't ever be released as ProjectBuilder has no lifecycle
    ResourceLockCoordinationService coordinationService = project.getServices().get(ResourceLockCoordinationService.class);
    coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(project.getOwner().getAccessLock()));
    return project;
}
Also used : ProjectDescriptorRegistry(org.gradle.initialization.ProjectDescriptorRegistry) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ProjectState(org.gradle.api.internal.project.ProjectState) ProjectStateRegistry(org.gradle.api.internal.project.ProjectStateRegistry) FileResolver(org.gradle.api.internal.file.FileResolver) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) File(java.io.File) BuildState(org.gradle.internal.build.BuildState) AbstractBuildState(org.gradle.internal.build.AbstractBuildState) RootBuildState(org.gradle.internal.build.RootBuildState)

Example 45 with ProjectInternal

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

the class ProjectBuilderImpl method createProject.

public ProjectInternal createProject(String name, File inputProjectDir, File gradleUserHomeDir) {
    final File projectDir = prepareProjectDir(inputProjectDir);
    File userHomeDir = gradleUserHomeDir == null ? new File(projectDir, "userHome") : FileUtils.canonicalize(gradleUserHomeDir);
    StartParameterInternal startParameter = new StartParameterInternal();
    startParameter.setGradleUserHomeDir(userHomeDir);
    NativeServices.initializeOnDaemon(userHomeDir);
    final ServiceRegistry globalServices = getGlobalServices();
    BuildRequestMetaData buildRequestMetaData = new DefaultBuildRequestMetaData(Time.currentTimeMillis());
    CrossBuildSessionState crossBuildSessionState = new CrossBuildSessionState(globalServices, startParameter);
    GradleUserHomeScopeServiceRegistry userHomeServices = userHomeServicesOf(globalServices);
    BuildSessionState buildSessionState = new BuildSessionState(userHomeServices, crossBuildSessionState, startParameter, buildRequestMetaData, ClassPath.EMPTY, new DefaultBuildCancellationToken(), buildRequestMetaData.getClient(), new NoOpBuildEventConsumer());
    BuildTreeModelControllerServices.Supplier modelServices = buildSessionState.getServices().get(BuildTreeModelControllerServices.class).servicesForBuildTree(new RunTasksRequirements(startParameter));
    BuildTreeState buildTreeState = new BuildTreeState(buildSessionState.getServices(), modelServices);
    TestRootBuild build = new TestRootBuild(projectDir, startParameter, buildTreeState);
    BuildScopeServices buildServices = build.getBuildServices();
    buildServices.get(BuildStateRegistry.class).attachRootBuild(build);
    // Take a root worker lease; this won't ever be released as ProjectBuilder has no lifecycle
    ResourceLockCoordinationService coordinationService = buildServices.get(ResourceLockCoordinationService.class);
    WorkerLeaseService workerLeaseService = buildServices.get(WorkerLeaseService.class);
    WorkerLeaseRegistry.WorkerLeaseCompletion workerLease = workerLeaseService.maybeStartWorker();
    GradleInternal gradle = build.getMutableModel();
    gradle.setIncludedBuilds(Collections.emptyList());
    ProjectDescriptorRegistry projectDescriptorRegistry = buildServices.get(ProjectDescriptorRegistry.class);
    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, projectDescriptorRegistry, buildServices.get(FileResolver.class));
    projectDescriptorRegistry.addProject(projectDescriptor);
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild("root-project");
    ProjectStateRegistry projectStateRegistry = buildServices.get(ProjectStateRegistry.class);
    ProjectState projectState = projectStateRegistry.registerProject(build, projectDescriptor);
    projectState.createMutableModel(rootProjectScope, baseScope);
    ProjectInternal project = projectState.getMutableModel();
    gradle.setRootProject(project);
    gradle.setDefaultProject(project);
    // Lock root project; this won't ever be released as ProjectBuilder has no lifecycle
    coordinationService.withStateLock(DefaultResourceLockCoordinationService.lock(project.getOwner().getAccessLock()));
    project.getExtensions().getExtraProperties().set("ProjectBuilder.stoppable", stoppable((Stoppable) workerLeaseService::runAsIsolatedTask, (Stoppable) workerLease::leaseFinish, buildServices, buildTreeState, buildSessionState, crossBuildSessionState));
    return project;
}
Also used : BuildRequestMetaData(org.gradle.initialization.BuildRequestMetaData) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) WorkerLeaseRegistry(org.gradle.internal.work.WorkerLeaseRegistry) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) GradleInternal(org.gradle.api.internal.GradleInternal) BuildTreeModelControllerServices(org.gradle.internal.buildtree.BuildTreeModelControllerServices) RunTasksRequirements(org.gradle.internal.buildtree.RunTasksRequirements) ResourceLockCoordinationService(org.gradle.internal.resources.ResourceLockCoordinationService) DefaultResourceLockCoordinationService(org.gradle.internal.resources.DefaultResourceLockCoordinationService) FileResolver(org.gradle.api.internal.file.FileResolver) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildStateRegistry(org.gradle.internal.build.BuildStateRegistry) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) DefaultBuildRequestMetaData(org.gradle.initialization.DefaultBuildRequestMetaData) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildSessionState(org.gradle.internal.session.BuildSessionState) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) Stoppable(org.gradle.internal.concurrent.Stoppable) BuildTreeState(org.gradle.internal.buildtree.BuildTreeState) DefaultProjectDescriptor(org.gradle.initialization.DefaultProjectDescriptor) NoOpBuildEventConsumer(org.gradle.initialization.NoOpBuildEventConsumer) ProjectDescriptorRegistry(org.gradle.initialization.ProjectDescriptorRegistry) DefaultBuildCancellationToken(org.gradle.initialization.DefaultBuildCancellationToken) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ProjectState(org.gradle.api.internal.project.ProjectState) GradleUserHomeScopeServiceRegistry(org.gradle.internal.service.scopes.GradleUserHomeScopeServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) ProjectStateRegistry(org.gradle.api.internal.project.ProjectStateRegistry) File(java.io.File)

Aggregations

ProjectInternal (org.gradle.api.internal.project.ProjectInternal)58 File (java.io.File)13 Project (org.gradle.api.Project)11 Task (org.gradle.api.Task)6 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)6 Inject (javax.inject.Inject)5 Plugin (org.gradle.api.Plugin)5 ProjectStateRegistry (org.gradle.api.internal.project.ProjectStateRegistry)5 Map (java.util.Map)4 Configuration (org.gradle.api.artifacts.Configuration)4 FileResolver (org.gradle.api.internal.file.FileResolver)4 Lists (com.google.common.collect.Lists)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Callable (java.util.concurrent.Callable)3 Collectors (java.util.stream.Collectors)3 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)3