Java Code Examples for org.gradle.api.Task#getProject()

The following examples show how to use org.gradle.api.Task#getProject() . 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: TaskDetailsFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TaskDetails create(final Task task) {
    final String path;
    Project project = task.getProject();
    if (projects.contains(project)) {
        path = this.project.relativeProjectPath(task.getPath());
    } else {
        path = task.getPath();
    }
    return new TaskDetails() {
        public Path getPath() {
            return Path.path(path);
        }

        public String getDescription() {
            return task.getDescription();
        }

        public Set<TaskDetails> getDependencies() {
            return Collections.emptySet();
        }

        public Set<TaskDetails> getChildren() {
            return Collections.emptySet();
        }
    };
}
 
Example 2
Source File: CpdPlugin.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
private void logWarningIfCheckTaskOnTaskGraph(Project project, TaskExecutionGraph graph) {
    if (logger.isWarnEnabled()) {
        Optional<Task> lastCheckTask = graph.getAllTasks().stream().sorted(reverseOrder())
                .filter(t -> t.getName().endsWith(LifecycleBasePlugin.CHECK_TASK_NAME)).findFirst();
        if (lastCheckTask.isPresent()) { // it is possible to just execute a task before "check", e.g. "compileJava"
            Task task = lastCheckTask.get();
            String message = "\n" +
                    "WARNING: Due to the absence of '" + LifecycleBasePlugin.class.getSimpleName() +
                    "' on " + project + " the task ':" + TASK_NAME_CPD_CHECK +
                    "' could not be added to task graph. Therefore CPD will not be executed. To prevent this, manually add a task dependency of ':" +
                    TASK_NAME_CPD_CHECK + "' to a '" + LifecycleBasePlugin.CHECK_TASK_NAME +
                    "' task of a subproject.\n" +
                    "1) Directly to " + task.getProject() + ":\n" +
                    "    " + task.getName() + ".dependsOn(':" + TASK_NAME_CPD_CHECK + "')\n" +
                    "2) Indirectly, e.g. via " + project + ":\n" +
                    "    project('" + task.getProject().getPath() + "') {\n" +
                    "        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject\n" +
                    "            " + task.getName() + ".dependsOn(" + TASK_NAME_CPD_CHECK + ")\n" +
                    "        }\n" +
                    "    }\n";
            logger.warn(message);
        }
    }
}
 
Example 3
Source File: TaskDetailsFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TaskDetails create(final Task task) {
    final String path;
    Project project = task.getProject();
    if (projects.contains(project)) {
        path = this.project.relativeProjectPath(task.getPath());
    } else {
        path = task.getPath();
    }
    return new TaskDetails() {
        public Path getPath() {
            return Path.path(path);
        }

        public String getDescription() {
            return task.getDescription();
        }

        public Set<TaskDetails> getDependencies() {
            return Collections.emptySet();
        }

        public Set<TaskDetails> getChildren() {
            return Collections.emptySet();
        }
    };
}
 
Example 4
Source File: TaskDetailsFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TaskDetails create(final Task task) {
    final String path;
    Project project = task.getProject();
    if (projects.contains(project)) {
        path = this.project.relativeProjectPath(task.getPath());
    } else {
        path = task.getPath();
    }
    return new TaskDetails() {
        public Path getPath() {
            return Path.path(path);
        }

        public String getDescription() {
            return task.getDescription();
        }

        public Set<TaskDetails> getDependencies() {
            return Collections.emptySet();
        }

        public Set<TaskDetails> getChildren() {
            return Collections.emptySet();
        }
    };
}
 
Example 5
Source File: ProfileEventAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterExecute(Task task, TaskState state) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    TaskExecution taskExecution = projectProfile.getTaskProfile(task.getPath());
    taskExecution.setFinish(now);
    taskExecution.completed(state);
}
 
Example 6
Source File: TaskSelector.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isSatisfiedBy(Task element) {
    if (!element.getName().equals(taskName)) {
        return true;
    }
    for (Project current = element.getProject(); current != null; current = current.getParent()) {
        if (current.equals(targetProject)) {
            return false;
        }
    }
    return true;
}
 
Example 7
Source File: GradleBuildMetricsCollector.java    From gradle-metrics-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void afterExecute(Task task, TaskState state) {
    initializeBuildMetrics();
    long now = clock.getCurrentTime();
    Project project = task.getProject();
    ProjectMetrics projectMetrics = buildMetrics.getProjectProfile(project.getPath());
    TaskExecution taskExecution = projectMetrics.getTaskProfile(task.getPath());
    taskExecution.setFinish(now);
    taskExecution.completed(state);
}
 
Example 8
Source File: ProfileEventAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterExecute(Task task, TaskState state) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    TaskExecution taskExecution = projectProfile.getTaskProfile(task.getPath());
    taskExecution.setFinish(now);
    taskExecution.completed(state);
}
 
Example 9
Source File: TaskSelector.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isSatisfiedBy(Task element) {
    if (!element.getName().equals(taskName)) {
        return true;
    }
    for (Project current = element.getProject(); current != null; current = current.getParent()) {
        if (current.equals(targetProject)) {
            return false;
        }
    }
    return true;
}
 
Example 10
Source File: GitPlugin.java    From shipkit with MIT License 5 votes vote down vote up
public static void registerChangesForCommitIfApplied(final List<File> changedFiles,
                                                     final String changeDescription, final Task changingTask) {
    final Project project = changingTask.getProject();
    project.getPlugins().withType(GitPlugin.class, new Action<GitPlugin>() {
        @Override
        public void execute(GitPlugin gitPushPlugin) {
            GitCommitTask gitCommitTask = (GitCommitTask) project.getTasks().findByName(GitPlugin.GIT_COMMIT_TASK);
            gitCommitTask.addChange(changedFiles, changeDescription, changingTask);
        }
    });
}
 
Example 11
Source File: ProfileEventAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void afterExecute(Task task, TaskState state) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    TaskExecution taskExecution = projectProfile.getTaskProfile(task.getPath());
    taskExecution.setFinish(now);
    taskExecution.completed(state);
}
 
Example 12
Source File: ProfileEventAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void beforeExecute(Task task) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    projectProfile.getTaskProfile(task.getPath()).setStart(now);
}
 
Example 13
Source File: ProfileEventAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void beforeExecute(Task task) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    projectProfile.getTaskProfile(task.getPath()).setStart(now);
}
 
Example 14
Source File: ProfileEventAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void beforeExecute(Task task) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    projectProfile.getTaskProfile(task.getPath()).setStart(now);
}
 
Example 15
Source File: ProfileEventAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void beforeExecute(Task task) {
    long now = timeProvider.getCurrentTime();
    Project project = task.getProject();
    ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
    projectProfile.getTaskProfile(task.getPath()).setStart(now);
}
 
Example 16
Source File: DependencyManager.java    From javaide with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Adds a dependency on tasks with the specified name in other projects.  The other projects
 * are determined from project lib dependencies using the specified configuration name.
 * These may be projects this project depends on or projects that depend on this project
 * based on the useDependOn argument.
 *
 * @param task                 Task to add dependencies to
 * @param useDependedOn        if true, add tasks from projects this project depends on, otherwise
 *                             use projects that depend on this one.
 * @param otherProjectTaskName name of task in other projects
 * @param configurationName    name of configuration to use to find the other projects
 */
private static void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn,
                                                    String otherProjectTaskName,
                                                    String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(
            configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(
            useDependedOn, otherProjectTaskName));
}
 
Example 17
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Adds a dependency on tasks with the specified name in other projects.  The other projects are determined from
 * project lib dependencies using the specified configuration name. These may be projects this project depends on or
 * projects that depend on this project based on the useDependOn argument.
 *
 * @param task Task to add dependencies to
 * @param useDependedOn if true, add tasks from projects this project depends on, otherwise use projects that depend
 * on this one.
 * @param otherProjectTaskName name of task in other projects
 * @param configurationName name of configuration to use to find the other projects
 */
private void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName,
                                             String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
}
 
Example 18
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Adds a dependency on tasks with the specified name in other projects.  The other projects are determined from
 * project lib dependencies using the specified configuration name. These may be projects this project depends on or
 * projects that depend on this project based on the useDependOn argument.
 *
 * @param task Task to add dependencies to
 * @param useDependedOn if true, add tasks from projects this project depends on, otherwise use projects that depend
 * on this one.
 * @param otherProjectTaskName name of task in other projects
 * @param configurationName name of configuration to use to find the other projects
 */
private void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName,
                                             String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
}
 
Example 19
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Adds a dependency on tasks with the specified name in other projects.  The other projects are determined from
 * project lib dependencies using the specified configuration name. These may be projects this project depends on or
 * projects that depend on this project based on the useDependOn argument.
 *
 * @param task Task to add dependencies to
 * @param useDependedOn if true, add tasks from projects this project depends on, otherwise use projects that depend
 * on this one.
 * @param otherProjectTaskName name of task in other projects
 * @param configurationName name of configuration to use to find the other projects
 */
private void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName,
                                             String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
}
 
Example 20
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Adds a dependency on tasks with the specified name in other projects.  The other projects are determined from
 * project lib dependencies using the specified configuration name. These may be projects this project depends on or
 * projects that depend on this project based on the useDependOn argument.
 *
 * @param task Task to add dependencies to
 * @param useDependedOn if true, add tasks from projects this project depends on, otherwise use projects that depend
 * on this one.
 * @param otherProjectTaskName name of task in other projects
 * @param configurationName name of configuration to use to find the other projects
 */
private void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName,
                                             String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
}