use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.
the class RootOfNestedBuildTree method run.
@Override
public <T> T run(Function<? super BuildTreeLifecycleController, T> action) {
final GradleInternal gradle = getBuildController().getGradle();
ServiceRegistry services = gradle.getServices();
BuildOperationExecutor executor = services.get(BuildOperationExecutor.class);
return executor.call(new CallableBuildOperation<T>() {
@Override
public T call(BuildOperationContext context) {
gradle.addBuildListener(new InternalBuildAdapter() {
@Override
public void settingsEvaluated(Settings settings) {
buildName = settings.getRootProject().getName();
}
});
T result = action.apply(buildTreeLifecycleController);
context.setResult(new RunNestedBuildBuildOperationType.Result() {
});
return result;
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Run nested build").details(new RunNestedBuildBuildOperationType.Details() {
@Override
public String getBuildPath() {
return gradle.getIdentityPath().getPath();
}
});
}
});
}
use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.
the class CleanupStaleOutputsExecuter method cleanupStaleOutputs.
private void cleanupStaleOutputs(TaskExecutionContext context) {
Set<File> filesToDelete = new HashSet<>();
TaskProperties properties = context.getTaskProperties();
for (FilePropertySpec outputFileSpec : properties.getOutputFileProperties()) {
FileCollection files = outputFileSpec.getPropertyFiles();
for (File file : files) {
if (cleanupRegistry.isOutputOwnedByBuild(file) && !outputFilesRepository.isGeneratedByGradle(file) && file.exists()) {
filesToDelete.add(file);
}
}
}
if (!filesToDelete.isEmpty()) {
outputChangeListener.beforeOutputChange(filesToDelete.stream().map(File::getAbsolutePath).collect(Collectors.toList()));
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) throws IOException {
for (File file : filesToDelete) {
if (file.exists()) {
logger.info("Deleting stale output file: {}", file.getAbsolutePath());
deleter.deleteRecursively(file);
}
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName(CLEAN_STALE_OUTPUTS_DISPLAY_NAME).progressDisplayName("Cleaning stale outputs");
}
});
}
}
use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.
the class DefaultTaskContainer method doCreate.
private Task doCreate(Map<String, ?> options, final Action<? super Task> configureAction) {
Map<String, ?> factoryOptions = options;
final boolean replace;
if (options.containsKey(Task.TASK_OVERWRITE)) {
factoryOptions = new HashMap<String, Object>(options);
Object replaceStr = factoryOptions.remove(Task.TASK_OVERWRITE);
replace = "true".equals(replaceStr.toString());
} else {
replace = false;
}
final Map<String, ?> actualArgs = checkTaskArgsAndCreateDefaultValues(factoryOptions);
final String name = actualArgs.get(Task.TASK_NAME).toString();
if (!GUtil.isTrue(name)) {
throw new InvalidUserDataException("The task name must be provided.");
}
final Class<? extends TaskInternal> type = Cast.uncheckedCast(actualArgs.get(Task.TASK_TYPE));
final TaskIdentity<? extends TaskInternal> identity = TaskIdentity.create(name, type, project);
return buildOperationExecutor.call(new CallableBuildOperation<Task>() {
@Override
public BuildOperationDescriptor.Builder description() {
return realizeDescriptor(identity, replace, true);
}
@Override
public Task call(BuildOperationContext context) {
try {
Object[] constructorArgs = getConstructorArgs(actualArgs);
TaskInternal task = createTask(identity, constructorArgs);
statistics.eagerTask(type);
Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
if (dependsOnTasks != null) {
task.dependsOn(dependsOnTasks);
}
Object description = actualArgs.get(Task.TASK_DESCRIPTION);
if (description != null) {
task.setDescription(description.toString());
}
Object group = actualArgs.get(Task.TASK_GROUP);
if (group != null) {
task.setGroup(group.toString());
}
Object action = actualArgs.get(Task.TASK_ACTION);
if (action instanceof Action) {
Action<? super Task> taskAction = Cast.uncheckedCast(action);
task.doFirst(taskAction);
} else if (action != null) {
Closure closure = (Closure) action;
task.doFirst(closure);
}
addTask(task, replace);
configureAction.execute(task);
context.setResult(REALIZE_RESULT);
return task;
} catch (Throwable t) {
throw taskCreationException(name, t);
}
}
});
}
use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.
the class BuildOperationScriptPlugin method apply.
@Override
public void apply(final Object target) {
TextResource resource = getSource().getResource();
if (resource.isContentCached() && resource.getHasEmptyContent()) {
// no operation, if there is no script code provided
decorated.apply(target);
} else {
userCodeApplicationContext.apply(getSource().getShortDisplayName(), userCodeApplicationId -> buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
decorated.apply(target);
context.setResult(OPERATION_RESULT);
}
@Override
public BuildOperationDescriptor.Builder description() {
final ScriptSource source = getSource();
final ResourceLocation resourceLocation = source.getResource().getLocation();
final File file = resourceLocation.getFile();
String name = "Apply " + source.getShortDisplayName();
final String displayName = name + " to " + target;
return BuildOperationDescriptor.displayName(displayName).name(name).details(new OperationDetails(file, resourceLocation, ConfigurationTargetIdentifier.of(target), userCodeApplicationId));
}
}));
}
}
use of org.gradle.internal.operations.BuildOperationContext in project gradle by gradle.
the class NotifyingBuildLoader method load.
@Override
public void load(final SettingsInternal settings, final GradleInternal gradle) {
final String buildPath = gradle.getIdentityPath().toString();
buildOperationExecutor.call(new CallableBuildOperation<Void>() {
@Override
public BuildOperationDescriptor.Builder description() {
// noinspection Convert2Lambda
return BuildOperationDescriptor.displayName("Load projects").progressDisplayName("Loading projects").details(new LoadProjectsBuildOperationType.Details() {
@Override
public String getBuildPath() {
return buildPath;
}
});
}
@Override
public Void call(BuildOperationContext context) {
buildLoader.load(settings, gradle);
context.setResult(createOperationResult(gradle, buildPath));
return null;
}
});
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
gradle.getBuildListenerBroadcaster().projectsLoaded(gradle);
context.setResult(PROJECTS_LOADED_OP_RESULT);
}
@Override
public BuildOperationDescriptor.Builder description() {
// noinspection Convert2Lambda
return BuildOperationDescriptor.displayName(gradle.contextualize("Notify projectsLoaded listeners")).details(new NotifyProjectsLoadedBuildOperationType.Details() {
@Override
public String getBuildPath() {
return buildPath;
}
});
}
});
}
Aggregations