Search in sources :

Example 6 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project gradle by gradle.

the class IdeaPlugin method allImlArtifactsInComposite.

private List<TaskDependency> allImlArtifactsInComposite(ProjectInternal project, IdeaProject ideaProject) {
    List<TaskDependency> dependencies = Lists.newArrayList();
    ProjectComponentIdentifier thisProjectId = projectPathRegistry.getProjectComponentIdentifier(project.getIdentityPath());
    for (IdeArtifactRegistry.Reference<IdeaModuleMetadata> reference : artifactRegistry.getIdeArtifactMetadata(IdeaModuleMetadata.class)) {
        BuildIdentifier otherBuildId = reference.getOwningProject().getBuild();
        if (thisProjectId.getBuild().equals(otherBuildId)) {
            // IDEA Module for project in current build: don't include any module that has been excluded from project
            boolean found = false;
            for (IdeaModule ideaModule : ideaProject.getModules()) {
                if (reference.get().getFile().equals(ideaModule.getOutputFile())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                continue;
            }
        }
        dependencies.add(reference.getBuildDependencies());
    }
    return dependencies;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModuleMetadata(org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata) IdeArtifactRegistry(org.gradle.plugins.ide.internal.IdeArtifactRegistry) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 7 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project gradle by gradle.

the class DefaultTaskDependency method visitDependencies.

@Override
public void visitDependencies(final TaskDependencyResolveContext context) {
    Set<Object> mutableValues = getMutableValues();
    if (mutableValues.isEmpty() && immutableValues.isEmpty()) {
        return;
    }
    final Deque<Object> queue = new ArrayDeque<Object>(mutableValues.size() + immutableValues.size());
    queue.addAll(immutableValues);
    queue.addAll(mutableValues);
    while (!queue.isEmpty()) {
        Object dependency = queue.removeFirst();
        if (dependency instanceof Buildable) {
            context.add(dependency);
        } else if (dependency instanceof Task) {
            context.add(dependency);
        } else if (dependency instanceof TaskDependency) {
            context.add(dependency);
        } else if (dependency instanceof ProviderInternal) {
            // When a Provider is used as a task dependency (rather than as a task input), need to unpack the value
            ProviderInternal<?> provider = (ProviderInternal<?>) dependency;
            ValueSupplier.ValueProducer producer = provider.getProducer();
            if (producer.isKnown()) {
                producer.visitProducerTasks(context);
            } else {
                // The provider does not know how to produce the value, so use the value instead
                queue.addFirst(provider.get());
            }
        } else if (dependency instanceof TaskDependencyContainer) {
            ((TaskDependencyContainer) dependency).visitDependencies(context);
        } else if (dependency instanceof Closure) {
            Closure closure = (Closure) dependency;
            Object closureResult = closure.call(context.getTask());
            if (closureResult != null) {
                queue.addFirst(closureResult);
            }
        } else if (dependency instanceof List) {
            List<?> list = (List) dependency;
            if (list instanceof RandomAccess) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    queue.addFirst(list.get(i));
                }
            } else {
                ListIterator<?> iterator = list.listIterator(list.size());
                while (iterator.hasPrevious()) {
                    Object item = iterator.previous();
                    queue.addFirst(item);
                }
            }
        } else if (dependency instanceof Iterable && !(dependency instanceof Path)) {
            // Path is Iterable, but we don't want to unpack it
            Iterable<?> iterable = Cast.uncheckedNonnullCast(dependency);
            addAllFirst(queue, toArray(iterable, Object.class));
        } else if (dependency instanceof Map) {
            Map<?, ?> map = Cast.uncheckedNonnullCast(dependency);
            addAllFirst(queue, map.values().toArray());
        } else if (dependency instanceof Object[]) {
            Object[] array = (Object[]) dependency;
            addAllFirst(queue, array);
        } else if (dependency instanceof Callable) {
            Callable<?> callable = Cast.uncheckedNonnullCast(dependency);
            Object callableResult = uncheckedCall(Cast.uncheckedNonnullCast(callable));
            if (callableResult != null) {
                queue.addFirst(callableResult);
            }
        } else if (resolver != null && dependency instanceof CharSequence) {
            context.add(resolver.resolveTask(dependency.toString()));
        } else {
            List<String> formats = new ArrayList<String>();
            if (resolver != null) {
                formats.add("A String or CharSequence task name or path");
            }
            formats.add("A Task instance");
            formats.add("A TaskReference instance");
            formats.add("A Buildable instance");
            formats.add("A TaskDependency instance");
            formats.add("A Provider that represents a task output");
            formats.add("A Provider instance that returns any of these types");
            formats.add("A Closure instance that returns any of these types");
            formats.add("A Callable instance that returns any of these types");
            formats.add("An Iterable, Collection, Map or array instance that contains any of these types");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
        }
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Closure(groovy.lang.Closure) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) List(java.util.List) Buildable(org.gradle.api.Buildable) Path(java.nio.file.Path) RandomAccess(java.util.RandomAccess) ArrayDeque(java.util.ArrayDeque) ProviderInternal(org.gradle.api.internal.provider.ProviderInternal) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) Map(java.util.Map)

Example 8 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project gradle by gradle.

the class RunBuildDependenciesTaskBuilder method populate.

private List<TaskDependency> populate(Project project) {
    project.getPluginManager().apply(EclipsePlugin.class);
    EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
    EclipseClasspath eclipseClasspath = eclipseModel.getClasspath();
    EclipseModelBuilder.ClasspathElements elements = EclipseModelBuilder.gatherClasspathElements(projectOpenStatus, eclipseClasspath, false);
    List<TaskDependency> buildDependencies = new ArrayList<>(elements.getBuildDependencies());
    for (Project childProject : project.getChildProjects().values()) {
        buildDependencies.addAll(populate(childProject));
    }
    return buildDependencies;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Project(org.gradle.api.Project) EclipseWorkspaceProject(org.gradle.tooling.model.eclipse.EclipseWorkspaceProject) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) ArrayList(java.util.ArrayList)

Example 9 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project gradle by gradle.

the class RunBuildDependenciesTaskBuilder method buildAll.

@Override
public RunClosedProjectBuildDependencies buildAll(String modelName, EclipseRuntime eclipseRuntime, Project project) {
    this.projectOpenStatus = eclipseRuntime.getWorkspace().getProjects().stream().collect(Collectors.toMap(EclipseWorkspaceProject::getName, EclipseModelBuilder::isProjectOpen, (a, b) -> a | b));
    List<TaskDependency> buildDependencies = populate(project.getRootProject());
    if (!buildDependencies.isEmpty()) {
        Gradle rootGradle = getRootGradle(project.getGradle());
        Project rootProject = rootGradle.getRootProject();
        StartParameter startParameter = rootGradle.getStartParameter();
        List<String> taskPaths = new ArrayList<>(startParameter.getTaskNames());
        String parentTaskName = parentTaskName(rootProject, "eclipseClosedDependencies");
        Task task = rootProject.task(parentTaskName);
        task.dependsOn(buildDependencies.toArray(new Object[0]));
        taskPaths.add(parentTaskName);
        startParameter.setTaskNames(taskPaths);
    }
    return DefaultRunClosedProjectBuildDependencies.INSTANCE;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Project(org.gradle.api.Project) EclipseWorkspaceProject(org.gradle.tooling.model.eclipse.EclipseWorkspaceProject) StartParameter(org.gradle.StartParameter) Task(org.gradle.api.Task) EclipseWorkspaceProject(org.gradle.tooling.model.eclipse.EclipseWorkspaceProject) ArrayList(java.util.ArrayList) Gradle(org.gradle.api.invocation.Gradle)

Example 10 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project gradle by gradle.

the class DefaultSelfResolvingDependencyTest method usesSourceFileCollectionToDetermineBuildDependencies.

@Test
public void usesSourceFileCollectionToDetermineBuildDependencies() {
    final TaskDependency taskDependency = context.mock(TaskDependency.class);
    context.checking(new Expectations() {

        {
            allowing(source).getBuildDependencies();
            will(returnValue(taskDependency));
        }
    });
    assertThat(dependency.getBuildDependencies(), sameInstance(taskDependency));
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Aggregations

TaskDependency (org.gradle.api.tasks.TaskDependency)11 Task (org.gradle.api.Task)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Expectations (org.jmock.Expectations)3 List (java.util.List)2 Set (java.util.Set)2 Buildable (org.gradle.api.Buildable)2 Project (org.gradle.api.Project)2 EclipseWorkspaceProject (org.gradle.tooling.model.eclipse.EclipseWorkspaceProject)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Closure (groovy.lang.Closure)1 Path (java.nio.file.Path)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 RandomAccess (java.util.RandomAccess)1 Callable (java.util.concurrent.Callable)1 Nullable (javax.annotation.Nullable)1