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;
}
Aggregations