Search in sources :

Example 6 with Transformer

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);
}
Also used : Transformer(org.gradle.api.Transformer) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 7 with Transformer

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());
        }
    };
}
Also used : Transformer(org.gradle.api.Transformer) List(java.util.List) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) PrintWriter(java.io.PrintWriter)

Example 8 with Transformer

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);
}
Also used : Project(org.gradle.api.Project) Set(java.util.Set) HtmlReportBuilder(org.gradle.reporting.HtmlReportBuilder) Transformer(org.gradle.api.Transformer) HtmlReportRenderer(org.gradle.reporting.HtmlReportRenderer)

Example 9 with Transformer

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);
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Transformer(org.gradle.api.Transformer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) VariantTransformRegistry(org.gradle.api.internal.artifacts.VariantTransformRegistry)

Aggregations

Transformer (org.gradle.api.Transformer)9 File (java.io.File)4 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Project (org.gradle.api.Project)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 Set (java.util.Set)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Task (org.gradle.api.Task)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 FileCollection (org.gradle.api.file.FileCollection)1 VariantTransformRegistry (org.gradle.api.internal.artifacts.VariantTransformRegistry)1 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)1 TestSelectionMatcher (org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher)1 FileWatcherEvent (org.gradle.internal.filewatch.FileWatcherEvent)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1