Skip to content

Commit

Permalink
Make GenerateProviderManifest configuration cache compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Oct 19, 2023
1 parent 5d14bca commit ac4509e
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal;

import org.elasticsearch.gradle.util.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import java.io.File;
import java.util.stream.Collectors;

abstract class GenerateProviderManifest extends DefaultTask {

@Classpath
@InputFiles
abstract public ConfigurableFileCollection getProviderImplClasspath();

@OutputFile
abstract public Provider<File> getManifestFile();

@TaskAction
void generateManifest() {
File manifestFile = getManifestFile().get();
manifestFile.getParentFile().mkdirs();
FileUtils.write(manifestFile, generateManifestContent(), "UTF-8");
}

private String generateManifestContent() {
return getProviderImplClasspath().getFiles().stream().map(File::getName).sorted().collect(Collectors.joining("\n"));
}
}

0 comments on commit ac4509e

Please sign in to comment.