Search in sources :

Example 1 with ArtifactTransform

use of org.gradle.api.artifacts.transform.ArtifactTransform in project gradle by gradle.

the class ArtifactTransformBackedTransformer method apply.

@Override
public List<File> apply(File file, File outputDir) {
    ArtifactTransform artifactTransform = create();
    artifactTransform.setOutputDirectory(outputDir);
    List<File> outputs = artifactTransform.transform(file);
    if (outputs == null) {
        throw new InvalidUserDataException("Transform returned null result.");
    }
    String inputFilePrefix = file.getPath() + File.separator;
    String outputDirPrefix = outputDir.getPath() + File.separator;
    for (File output : outputs) {
        if (!output.exists()) {
            throw new InvalidUserDataException("Transform output file " + output.getPath() + " does not exist.");
        }
        if (output.equals(file) || output.equals(outputDir)) {
            continue;
        }
        if (output.getPath().startsWith(outputDirPrefix)) {
            continue;
        }
        if (output.getPath().startsWith(inputFilePrefix)) {
            continue;
        }
        throw new InvalidUserDataException("Transform output file " + output.getPath() + " is not a child of the transform's input file or output directory.");
    }
    return outputs;
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArtifactTransform(org.gradle.api.artifacts.transform.ArtifactTransform) File(java.io.File)

Aggregations

File (java.io.File)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 ArtifactTransform (org.gradle.api.artifacts.transform.ArtifactTransform)1