Java Code Examples for org.gradle.api.project#getRootProject()
The following examples show how to use
org.gradle.api.project#getRootProject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GradleDependencyResolutionHelper.java From thorntail with Apache License 2.0 | 6 votes |
/** * Get data (identified by the given key) that has been cached on the given Gradle project reference. * * @param project the Gradle project reference. * @param key the key used for caching the data. * @param supplier the function that needs to be executed in the event of a cache-miss. * @param <T> the type of the data stored on the project. * @return data that has been cached on the given Gradle project reference. */ @SuppressWarnings("unchecked") private static <T> T getCachedReference(Project project, String key, Supplier<T> supplier) { if (project == null) { throw new IllegalArgumentException("Gradle project reference cannot be null."); } Project rootProject = project.getRootProject(); ExtraPropertiesExtension ext = rootProject.getExtensions().getExtraProperties(); T value; if (ext.has(key)) { value = (T) ext.get(key); } else { value = supplier.get(); ext.set(key, value); } return value; }
Example 2
Source File: ProjectFinderByTaskPath.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectInternal findProject(String projectPath, ProjectInternal startFrom) { if (projectPath.equals(Project.PATH_SEPARATOR)) { return startFrom.getRootProject(); } Project current = startFrom; if (projectPath.startsWith(Project.PATH_SEPARATOR)) { current = current.getRootProject(); projectPath = projectPath.substring(1); } for (String pattern : projectPath.split(Project.PATH_SEPARATOR)) { Map<String, Project> children = current.getChildProjects(); NameMatcher matcher = new NameMatcher(); Project child = matcher.find(pattern, children); if (child != null) { current = child; continue; } throw new ProjectLookupException(matcher.formatErrorMessage("project", current)); } return (ProjectInternal) current; }
Example 3
Source File: ProjectFinderByTaskPath.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectInternal findProject(String projectPath, ProjectInternal startFrom) { if (projectPath.equals(Project.PATH_SEPARATOR)) { return startFrom.getRootProject(); } Project current = startFrom; if (projectPath.startsWith(Project.PATH_SEPARATOR)) { current = current.getRootProject(); projectPath = projectPath.substring(1); } for (String pattern : projectPath.split(Project.PATH_SEPARATOR)) { Map<String, Project> children = current.getChildProjects(); NameMatcher matcher = new NameMatcher(); Project child = matcher.find(pattern, children); if (child != null) { current = child; continue; } throw new ProjectLookupException(matcher.formatErrorMessage("project", current)); } return (ProjectInternal) current; }
Example 4
Source File: ProjectFinderByTaskPath.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectInternal findProject(String projectPath, ProjectInternal startFrom) { if (projectPath.equals(Project.PATH_SEPARATOR)) { return startFrom.getRootProject(); } Project current = startFrom; if (projectPath.startsWith(Project.PATH_SEPARATOR)) { current = current.getRootProject(); projectPath = projectPath.substring(1); } for (String pattern : projectPath.split(Project.PATH_SEPARATOR)) { Map<String, Project> children = current.getChildProjects(); NameMatcher matcher = new NameMatcher(); Project child = matcher.find(pattern, children); if (child != null) { current = child; continue; } throw new ProjectLookupException(matcher.formatErrorMessage("project", current)); } return (ProjectInternal) current; }
Example 5
Source File: ProjectReportTask.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected void generate(Project project) throws IOException { BuildClientMetaData metaData = getServices().get(BuildClientMetaData.class); StyledTextOutput textOutput = getRenderer().getTextOutput(); render(project, new GraphRenderer(textOutput), true, textOutput); if (project.getChildProjects().isEmpty()) { textOutput.withStyle(Info).text("No sub-projects"); textOutput.println(); } textOutput.println(); textOutput.text("To see a list of the tasks of a project, run "); metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s", ImplicitTasksConfigurer.TASKS_TASK)); textOutput.println(); textOutput.text("For example, try running "); Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0); metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath( ImplicitTasksConfigurer.TASKS_TASK)); textOutput.println(); if (project != project.getRootProject()) { textOutput.println(); textOutput.text("To see a list of all the projects in this build, run "); metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath( ImplicitTasksConfigurer.PROJECTS_TASK)); textOutput.println(); } }
Example 6
Source File: ProjectReportTask.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected void generate(Project project) throws IOException { BuildClientMetaData metaData = getClientMetaData(); StyledTextOutput textOutput = getRenderer().getTextOutput(); render(project, new GraphRenderer(textOutput), true, textOutput); if (project.getChildProjects().isEmpty()) { textOutput.withStyle(Info).text("No sub-projects"); textOutput.println(); } textOutput.println(); textOutput.text("To see a list of the tasks of a project, run "); metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s", ProjectInternal.TASKS_TASK)); textOutput.println(); textOutput.text("For example, try running "); Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0); metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath( ProjectInternal.TASKS_TASK)); textOutput.println(); if (project != project.getRootProject()) { textOutput.println(); textOutput.text("To see a list of all the projects in this build, run "); metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath( ProjectInternal.PROJECTS_TASK)); textOutput.println(); } }
Example 7
Source File: LazyConfiguration.java From shipkit with MIT License | 5 votes |
/** * Gets singleton configurer from the root project */ @ExposedForTesting static LazyConfiguration getConfigurer(Project project) { Project rootProject = project.getRootProject(); //single configurer for the entire build, hooked up to the root project, for simplicity and speed //we don't want too many listeners that introduce blocking callbacks to Gradle internals LazyConfiguration configurer = rootProject.getExtensions().findByType(LazyConfiguration.class); if (configurer == null) { configurer = new LazyConfiguration(); rootProject.getExtensions().add(LazyConfiguration.class.getName(), configurer); rootProject.getGradle().addListener(configurer.listener); } return configurer; }
Example 8
Source File: ProjectReportTask.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected void generate(Project project) throws IOException { BuildClientMetaData metaData = getClientMetaData(); StyledTextOutput textOutput = getRenderer().getTextOutput(); render(project, new GraphRenderer(textOutput), true, textOutput); if (project.getChildProjects().isEmpty()) { textOutput.withStyle(Info).text("No sub-projects"); textOutput.println(); } textOutput.println(); textOutput.text("To see a list of the tasks of a project, run "); metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s", ProjectInternal.TASKS_TASK)); textOutput.println(); textOutput.text("For example, try running "); Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0); metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath( ProjectInternal.TASKS_TASK)); textOutput.println(); if (project != project.getRootProject()) { textOutput.println(); textOutput.text("To see a list of all the projects in this build, run "); metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath( ProjectInternal.PROJECTS_TASK)); textOutput.println(); } }
Example 9
Source File: EclipseModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public DefaultEclipseProject buildAll(String modelName, Project project) { boolean includeTasks = modelName.equals("org.gradle.tooling.model.eclipse.EclipseProject"); tasksFactory = new TasksFactory(includeTasks); projectDependenciesOnly = modelName.equals("org.gradle.tooling.model.eclipse.HierarchicalEclipseProject"); currentProject = project; Project root = project.getRootProject(); rootGradleProject = gradleProjectBuilder.buildAll(project); tasksFactory.collectTasks(root); applyEclipsePlugin(root); buildHierarchy(root); populate(root); return result; }
Example 10
Source File: ProjectReportTask.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected void generate(Project project) throws IOException { BuildClientMetaData metaData = getServices().get(BuildClientMetaData.class); StyledTextOutput textOutput = getRenderer().getTextOutput(); render(project, new GraphRenderer(textOutput), true, textOutput); if (project.getChildProjects().isEmpty()) { textOutput.withStyle(Info).text("No sub-projects"); textOutput.println(); } textOutput.println(); textOutput.text("To see a list of the tasks of a project, run "); metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s", ImplicitTasksConfigurer.TASKS_TASK)); textOutput.println(); textOutput.text("For example, try running "); Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0); metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath( ImplicitTasksConfigurer.TASKS_TASK)); textOutput.println(); if (project != project.getRootProject()) { textOutput.println(); textOutput.text("To see a list of all the projects in this build, run "); metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath( ImplicitTasksConfigurer.PROJECTS_TASK)); textOutput.println(); } }
Example 11
Source File: EclipseModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public DefaultEclipseProject buildAll(String modelName, Project project) { boolean includeTasks = modelName.equals("org.gradle.tooling.model.eclipse.EclipseProject"); tasksFactory = new TasksFactory(includeTasks); projectDependenciesOnly = modelName.equals("org.gradle.tooling.model.eclipse.HierarchicalEclipseProject"); currentProject = project; Project root = project.getRootProject(); rootGradleProject = gradleProjectBuilder.buildAll(project); tasksFactory.collectTasks(root); applyEclipsePlugin(root); buildHierarchy(root); populate(root); return result; }
Example 12
Source File: EclipseModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public DefaultEclipseProject buildAll(String modelName, Project project) { boolean includeTasks = modelName.equals("org.gradle.tooling.model.eclipse.EclipseProject"); tasksFactory = new TasksFactory(includeTasks); projectDependenciesOnly = modelName.equals("org.gradle.tooling.model.eclipse.HierarchicalEclipseProject"); currentProject = project; Project root = project.getRootProject(); rootGradleProject = gradleProjectBuilder.buildAll(project); tasksFactory.collectTasks(root); applyEclipsePlugin(root); buildHierarchy(root); populate(root); return result; }
Example 13
Source File: TextReportRenderer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
protected String createHeader(Project project) { String header; if (project.getRootProject() == project) { header = "Root project"; } else { header = String.format("Project %s", project.getPath()); } if (GUtil.isTrue(project.getDescription())) { header = header + " - " + project.getDescription(); } return header; }
Example 14
Source File: IdeaModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public DefaultIdeaProject buildAll(String modelName, Project project) { Project root = project.getRootProject(); applyIdeaPlugin(root); DefaultGradleProject<?> rootGradleProject = gradleProjectBuilder.buildAll(project); return build(root, rootGradleProject); }
Example 15
Source File: IdeaModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public DefaultIdeaProject buildAll(String modelName, Project project) { Project root = project.getRootProject(); applyIdeaPlugin(root); DefaultGradleProject<?> rootGradleProject = gradleProjectBuilder.buildAll(project); return build(root, rootGradleProject); }
Example 16
Source File: GithubBasePlugin.java From gradle-plugins with MIT License | 4 votes |
@Override public void apply(Project project) { this.project = project; if (project != project.getRootProject()) { project.getLogger().warn("This plugin should only be applied to the root project"); } githubExtension = project.getExtensions().create("github", GithubExtension.class); githubExtension.getSlug().convention(project.provider(() -> GitUtils.findSlug(project))); githubExtension.getTravis().convention(project.provider(this::isTravis)); githubExtension.getTag().convention(project.provider(() -> GitUtils.getTag(project))); OkHttpPlugin okHttpPlugin = project.getPlugins().apply(OkHttpPlugin.class); githubClient = new GithubClient(githubExtension, okHttpPlugin.getOkHttpClient()); }
Example 17
Source File: IdeaModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public DefaultIdeaProject buildAll(String modelName, Project project) { Project root = project.getRootProject(); applyIdeaPlugin(root); DefaultGradleProject<?> rootGradleProject = gradleProjectBuilder.buildAll(project); return build(root, rootGradleProject); }
Example 18
Source File: GithubBasePlugin.java From gradle-plugins with MIT License | 4 votes |
@Override public void apply(Project project) { this.project = project; if (project != project.getRootProject()) { project.getLogger().warn("This plugin should only be applied to the root project"); } githubExtension = project.getExtensions().create("github", GithubExtension.class); githubExtension.getSlug().convention(project.provider(() -> GitUtils.findSlug(project))); githubExtension.getTravis().convention(project.provider(this::isTravis)); githubExtension.getTag().convention(project.provider(() -> GitUtils.getTag(project))); OkHttpPlugin okHttpPlugin = project.getPlugins().apply(OkHttpPlugin.class); githubClient = new GithubClient(githubExtension, okHttpPlugin.getOkHttpClient()); }
Example 19
Source File: OkHttpCachePlugin.java From gradle-plugins with MIT License | 3 votes |
@Override public void apply(Project project) { if (project != project.getRootProject()) { throw new IllegalStateException(); } ProjectCacheDir projectCacheDir = ((ProjectInternal) project).getServices().get(ProjectCacheDir.class); cache = new Cache(new File(projectCacheDir.getDir(), getClass().getName()), 50 * 1024 * 1024); }
Example 20
Source File: OkHttpCachePlugin.java From gradle-plugins with MIT License | 3 votes |
@Override public void apply(Project project) { if (project != project.getRootProject()) { throw new IllegalStateException(); } ProjectCacheDir projectCacheDir = ((ProjectInternal) project).getServices().get(ProjectCacheDir.class); cache = new Cache(new File(projectCacheDir.getDir(), getClass().getName()), 50 * 1024 * 1024); }