/** * Creates the project. * * @return The project */ public Project build() { if (projectDir == null) { try { projectDir = GFileUtils.canonicalise(File.createTempFile("gradle", "projectDir")); projectDir.delete(); projectDir.mkdir(); projectDir.deleteOnExit(); } catch (IOException e) { throw new UncheckedIOException(e); } } final File homeDir = new File(projectDir, "gradleHome"); StartParameter startParameter = new StartParameter(); startParameter.setGradleUserHomeDir(new File(projectDir, "userHome")); ServiceRegistryFactory topLevelRegistry = new TestTopLevelBuildServiceRegistry(startParameter, homeDir); GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry); DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor( null, "test", projectDir, new DefaultProjectDescriptorRegistry()); ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle); gradle.setRootProject(project); gradle.setDefaultProject(project); return project; }
private void attachDefaultProject(ProjectDescriptor defaultProject, GradleInternal gradle) { gradle.setDefaultProject( gradle.getRootProject().getProjectRegistry().getProject(defaultProject.getPath())); }