All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.devtools.codestarts.core.CodestartData Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.devtools.codestarts.core;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.quarkus.devtools.codestarts.Codestart;
import io.quarkus.devtools.codestarts.CodestartType;
import io.quarkus.devtools.codestarts.core.CodestartSpec.CodestartDep;
import io.quarkus.devtools.codestarts.utils.NestedMaps;

public final class CodestartData {

    public static final String INPUT_BASE_CODESTART_KEY_PREFIX = "input.base-codestart.";
    public static final String INPUT_BASE_CODESTARTS_KEY = "input.base-codestarts";
    public static final String INPUT_EXTRA_CODESTARTS_KEY = "input.extra-codestarts";

    private CodestartData() {
    }

    public static Optional getInputCodestartForType(final Map data, final CodestartType type) {
        return NestedMaps.getValue(data, INPUT_BASE_CODESTART_KEY_PREFIX + type.toString().toLowerCase());
    }

    public static Optional getBuildtool(final Map data) {
        return getInputCodestartForType(data, CodestartType.BUILDTOOL);
    }

    public static Map buildCodestartData(final Codestart codestart, final String languageName,
            final Map data) {
        final Optional> value = NestedMaps.getValue(data, codestart.getName());
        Map withLocalCodestartData = NestedMaps.deepMerge(data, codestart.getLocalData(languageName));
        if (!value.isPresent()) {
            return withLocalCodestartData;
        }
        return NestedMaps.deepMerge(withLocalCodestartData, value.get());
    }

    public static Map buildCodestartProjectData(Collection baseCodestarts,
            Collection extraCodestarts) {
        final HashMap data = new HashMap<>();
        baseCodestarts.forEach((c) -> data.put(INPUT_BASE_CODESTART_KEY_PREFIX + c.getSpec().getType().toString().toLowerCase(),
                c.getName()));
        data.put(INPUT_BASE_CODESTARTS_KEY,
                baseCodestarts.stream().map(Codestart::getName).collect(Collectors.toList()));
        data.put(INPUT_EXTRA_CODESTARTS_KEY,
                extraCodestarts.stream().map(Codestart::getName).collect(Collectors.toList()));
        return NestedMaps.unflatten(data);
    }

    public static Map buildDependenciesData(Stream codestartsStream, String languageName,
            Collection extensions, Collection platforms) {
        final Map> depsData = new HashMap<>();
        final Set boms = new LinkedHashSet<>();
        final Set dependencies = new LinkedHashSet<>();
        final Set testDependencies = new LinkedHashSet<>();
        platforms.stream()
                .map(CodestartDep::new)
                .forEach(boms::add);
        extensions.stream()
                .map(CodestartDep::new)
                .forEach(dependencies::add);
        codestartsStream
                .flatMap(s -> Stream.of(s.getBaseLanguageSpec(), s.getLanguageSpec(languageName)))
                .forEach(d -> {
                    dependencies.addAll(d.getDependencies());
                    testDependencies.addAll(d.getTestDependencies());
                });
        depsData.put("dependencies", dependencies);
        depsData.put("boms", boms);
        depsData.put("test-dependencies", testDependencies);
        return Collections.unmodifiableMap(depsData);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy