org.gradle.api.tasks.TaskDependencyMatchers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.tasks;
import org.gradle.api.Buildable;
import org.gradle.api.Task;
import org.hamcrest.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.CoreMatchers.equalTo;
public class TaskDependencyMatchers {
@Factory
public static Matcher dependsOn(final String... tasks) {
return dependsOn(equalTo(new HashSet(Arrays.asList(tasks))));
}
@Factory
public static Matcher dependsOn(Matcher extends Iterable> matcher) {
return dependsOn(matcher, false);
}
@Factory
public static Matcher dependsOnPaths(Matcher extends Iterable> matcher) {
return dependsOn(matcher, true);
}
private static Matcher dependsOn(final Matcher extends Iterable> matcher, final boolean matchOnPaths) {
return new BaseMatcher() {
@Override
public boolean matches(Object o) {
Task task = (Task) o;
Set names = new HashSet();
Set extends Task> depTasks = task.getTaskDependencies().getDependencies(task);
for (Task depTask : depTasks) {
names.add(matchOnPaths ? depTask.getPath() : depTask.getName());
}
boolean matches = matcher.matches(names);
if (!matches) {
StringDescription description = new StringDescription();
matcher.describeTo(description);
System.out.println(String.format("expected %s, got %s.", description.toString(), names));
}
return matches;
}
@Override
public void describeTo(Description description) {
description.appendText("a Task that depends on ").appendDescriptionOf(matcher);
}
};
}
@Factory
public static Matcher builtBy(String... tasks) {
return builtBy(equalTo(new HashSet(Arrays.asList(tasks))));
}
@Factory
public static Matcher builtBy(final Matcher extends Iterable> matcher) {
return new BaseMatcher() {
@Override
public boolean matches(Object o) {
Buildable task = (Buildable) o;
Set names = new HashSet();
Set extends Task> depTasks = task.getBuildDependencies().getDependencies(null);
for (Task depTask : depTasks) {
names.add(depTask.getName());
}
boolean matches = matcher.matches(names);
if (!matches) {
StringDescription description = new StringDescription();
matcher.describeTo(description);
System.out.println(String.format("expected %s, got %s.", description.toString(), names));
}
return matches;
}
@Override
public void describeTo(Description description) {
description.appendText("a Buildable that is built by ").appendDescriptionOf(matcher);
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy