use of org.gradle.api.Transformer in project gradle by gradle.
the class CompositeBuildDependencySubstitutions method getReplacementFor.
private ProjectComponentIdentifier getReplacementFor(ModuleComponentSelector selector) {
ModuleIdentifier candidateId = moduleIdentifierFactory.module(selector.getGroup(), selector.getModule());
Collection<ProjectComponentIdentifier> providingProjects = replacementMap.get(candidateId);
if (providingProjects.isEmpty()) {
LOGGER.info("Found no composite build substitute for module '" + candidateId + "'.");
return null;
}
if (providingProjects.size() == 1) {
ProjectComponentIdentifier match = providingProjects.iterator().next();
LOGGER.info("Found project '" + match + "' as substitute for module '" + candidateId + "'.");
return match;
}
SortedSet<String> sortedProjects = Sets.newTreeSet(CollectionUtils.collect(providingProjects, new Transformer<String, ProjectComponentIdentifier>() {
@Override
public String transform(ProjectComponentIdentifier projectComponentIdentifier) {
return projectComponentIdentifier.getDisplayName();
}
}));
String failureMessage = String.format("Module version '%s' is not unique in composite: can be provided by %s.", selector.getDisplayName(), sortedProjects);
throw new ModuleVersionResolveException(selector, failureMessage);
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class ArgWriter method argsFileGenerator.
/**
* Returns an args transformer that replaces the provided args with a generated args file containing the args. Uses platform text encoding.
*/
public static Transformer<List<String>, List<String>> argsFileGenerator(final File argsFile, final Transformer<ArgWriter, PrintWriter> argWriterFactory) {
return new Transformer<List<String>, List<String>>() {
@Override
public List<String> transform(List<String> args) {
if (args.isEmpty()) {
return args;
}
argsFile.getParentFile().mkdirs();
try {
PrintWriter writer = new PrintWriter(argsFile);
try {
ArgWriter argWriter = argWriterFactory.transform(writer);
argWriter.args(args);
} finally {
writer.close();
}
} catch (IOException e) {
throw new UncheckedIOException(String.format("Could not write options file '%s'.", argsFile.getAbsolutePath()), e);
}
return Collections.singletonList("@" + argsFile.getAbsolutePath());
}
};
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class HtmlDependencyReporter method render.
@Override
public void render(final Set<Project> projects, File outputDirectory) {
this.outputDirectory = outputDirectory;
HtmlReportRenderer renderer = new HtmlReportRenderer();
renderer.render(projects, new ReportRenderer<Set<Project>, HtmlReportBuilder>() {
@Override
public void render(Set<Project> model, HtmlReportBuilder builder) {
Transformer<String, Project> htmlPageScheme = projectNamingScheme("html");
Transformer<String, Project> jsScheme = projectNamingScheme("js");
ProjectPageRenderer projectPageRenderer = new ProjectPageRenderer(jsScheme);
builder.renderRawHtmlPage("index.html", projects, new ProjectsPageRenderer(htmlPageScheme));
for (Project project : projects) {
String jsFileName = jsScheme.transform(project);
generateJsFile(project, jsFileName);
String htmlFileName = htmlPageScheme.transform(project);
builder.renderRawHtmlPage(htmlFileName, project, projectPageRenderer);
}
}
}, outputDirectory);
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class VariantAttributeMatchingCache method findProducersFor.
private void findProducersFor(AttributeContainerInternal actual, AttributeContainerInternal requested, ConsumerVariantMatchResult result) {
// Prefer direct transformation over indirect transformation
List<VariantTransformRegistry.Registration> candidates = new ArrayList<VariantTransformRegistry.Registration>();
for (VariantTransformRegistry.Registration transform : variantTransforms.getTransforms()) {
if (matchAttributes(transform.getTo(), requested, false)) {
if (matchAttributes(actual, transform.getFrom(), true)) {
ImmutableAttributes variantAttributes = attributesFactory.concat(actual.asImmutable(), transform.getTo().asImmutable());
result.matched(variantAttributes, transform.getArtifactTransform(), 1);
}
candidates.add(transform);
}
}
if (result.hasMatches()) {
return;
}
for (final VariantTransformRegistry.Registration candidate : candidates) {
ConsumerVariantMatchResult inputVariants = new ConsumerVariantMatchResult();
collectConsumerVariants(actual, candidate.getFrom(), inputVariants);
if (!inputVariants.hasMatches()) {
continue;
}
for (final ConsumerVariantMatchResult.ConsumerVariant inputVariant : inputVariants.getMatches()) {
ImmutableAttributes variantAttributes = attributesFactory.concat(inputVariant.attributes.asImmutable(), candidate.getTo().asImmutable());
Transformer<List<File>, File> transformer = new Transformer<List<File>, File>() {
@Override
public List<File> transform(File file) {
List<File> result = new ArrayList<File>();
for (File intermediate : inputVariant.transformer.transform(file)) {
result.addAll(candidate.getArtifactTransform().transform(intermediate));
}
return result;
}
};
result.matched(variantAttributes, transformer, inputVariant.depth + 1);
}
}
}
Aggregations