Search in sources :

Example 1 with TaskDependency

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

the class DefaultConfigurableFileCollectionTest method taskDependenciesContainsUnionOfDependenciesOfNestedFileCollectionsPlusOwnDependencies.

@Test
public void taskDependenciesContainsUnionOfDependenciesOfNestedFileCollectionsPlusOwnDependencies() {
    final FileCollectionInternal fileCollectionMock = context.mock(FileCollectionInternal.class);
    collection.from(fileCollectionMock);
    collection.from("f");
    collection.builtBy("b");
    final Task taskA = context.mock(Task.class, "a");
    final Task taskB = context.mock(Task.class, "b");
    context.checking(new Expectations() {

        {
            allowing(resolverMock).resolve("f");
            will(returnValue(new File("f")));
            TaskDependency dependency = context.mock(TaskDependency.class);
            allowing(fileCollectionMock).getBuildDependencies();
            will(returnValue(dependency));
            allowing(dependency).getDependencies(null);
            will(returnValue(toSet(taskA)));
            allowing(taskResolverStub).resolveTask("b");
            will(returnValue(taskB));
        }
    });
    assertThat(collection.getBuildDependencies().getDependencies(null), equalTo((Set) toSet(taskA, taskB)));
}
Also used : Expectations(org.jmock.Expectations) TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Set(java.util.Set) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) File(java.io.File) Test(org.junit.Test)

Example 2 with TaskDependency

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

the class TaskReportTaskTest method task.

private Task task(final String name, final String taskGroup, final Task... dependencies) {
    final Task task = context.mock(Task.class);
    context.checking(new Expectations() {

        {
            allowing(task).getName();
            will(returnValue(name));
            allowing(task).getPath();
            will(returnValue(':' + name));
            allowing(task).getProject();
            will(returnValue(project));
            allowing(project).relativeProjectPath(':' + name);
            will(returnValue(name));
            allowing(task).getGroup();
            will(returnValue(taskGroup));
            allowing(task).compareTo(with(Matchers.notNullValue(Task.class)));
            will(new Action() {

                public Object invoke(Invocation invocation) throws Throwable {
                    Task other = (Task) invocation.getParameter(0);
                    return name.compareTo(other.getName());
                }

                public void describeTo(Description description) {
                    description.appendText("compare to");
                }
            });
            TaskDependency dependency = context.mock(TaskDependency.class);
            allowing(task).getTaskDependencies();
            will(returnValue(dependency));
            allowing(dependency).getDependencies(task);
            will(returnValue(toSet(dependencies)));
        }
    });
    return task;
}
Also used : Expectations(org.jmock.Expectations) TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation)

Example 3 with TaskDependency

use of org.gradle.api.tasks.TaskDependency in project spring-boot by spring-projects.

the class RepackagePluginFeatures method addRepackageTask.

private void addRepackageTask(Project project) {
    RepackageTask task = project.getTasks().create(REPACKAGE_TASK_NAME, RepackageTask.class);
    task.setDescription("Repackage existing JAR and WAR " + "archives so that they can be executed from the command " + "line using 'java -jar'");
    task.setGroup(BasePlugin.BUILD_GROUP);
    Configuration runtimeConfiguration = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME);
    TaskDependency runtimeProjectDependencyJarTasks = runtimeConfiguration.getTaskDependencyFromProjectDependency(true, JavaPlugin.JAR_TASK_NAME);
    task.dependsOn(project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION).getAllArtifacts().getBuildDependencies(), runtimeProjectDependencyJarTasks);
    registerOutput(project, task);
    ensureTaskRunsOnAssembly(project, task);
    ensureMainClassHasBeenFound(project, task);
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Configuration(org.gradle.api.artifacts.Configuration)

Example 4 with TaskDependency

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

the class AbstractTask method dependsOnTaskDidWork.

@Override
public boolean dependsOnTaskDidWork() {
    DeprecationLogger.nagUserOfDiscontinuedMethod("Task.dependsOnTaskDidWork()", "Instead, check the value of \"didWork()\" for each task, or declare the task inputs and outputs and let Gradle decide what needs to be run.");
    TaskDependency dependency = getTaskDependencies();
    for (Task depTask : dependency.getDependencies(this)) {
        if (depTask.getDidWork()) {
            return true;
        }
    }
    return false;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) DefaultTaskDependency(org.gradle.api.internal.tasks.DefaultTaskDependency) Task(org.gradle.api.Task)

Example 5 with TaskDependency

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

the class ArtifactTransformingVisitor method visitArtifact.

@Override
public void visitArtifact(String variantName, AttributeContainer variantAttributes, ResolvableArtifact artifact) {
    TransformArtifactOperation operation = artifactResults.get(artifact);
    if (operation.getFailure() != null) {
        visitor.visitFailure(operation.getFailure());
        return;
    }
    ResolvedArtifact sourceArtifact = artifact.toPublicView();
    List<File> transformedFiles = operation.getResult();
    TaskDependency buildDependencies = ((Buildable) artifact).getBuildDependencies();
    for (File output : transformedFiles) {
        IvyArtifactName artifactName = DefaultIvyArtifactName.forFile(output, sourceArtifact.getClassifier());
        ComponentArtifactIdentifier newId = new ComponentFileArtifactIdentifier(sourceArtifact.getId().getComponentIdentifier(), artifactName);
        DefaultResolvedArtifact resolvedArtifact = new DefaultResolvedArtifact(sourceArtifact.getModuleVersion().getId(), artifactName, newId, buildDependencies, output);
        visitor.visitArtifact(variantName, target, resolvedArtifact);
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) ComponentFileArtifactIdentifier(org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File) Buildable(org.gradle.api.Buildable)

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