io.quarkus.devtools.codestarts.core.DefaultCodestartProjectDefinition Maven / Gradle / Ivy
package io.quarkus.devtools.codestarts.core;
import static io.quarkus.devtools.codestarts.core.CodestartCatalogs.findLanguageName;
import static io.quarkus.devtools.codestarts.core.CodestartCatalogs.findRequiredCodestart;
import static io.quarkus.devtools.codestarts.core.CodestartData.buildCodestartProjectData;
import static io.quarkus.devtools.codestarts.core.CodestartData.buildDependenciesData;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.quarkus.devtools.codestarts.Codestart;
import io.quarkus.devtools.codestarts.CodestartProjectDefinition;
import io.quarkus.devtools.codestarts.CodestartProjectInput;
import io.quarkus.devtools.codestarts.CodestartType;
import io.quarkus.devtools.codestarts.utils.NestedMaps;
public final class DefaultCodestartProjectDefinition implements CodestartProjectDefinition {
private static final Comparator PROCESSING_ORDER = Comparator.comparingInt(Codestart::getTypeOrder)
.thenComparing(Codestart::getName);
private static final Comparator SHARED_DATA_MERGE_ORDER = PROCESSING_ORDER;
private final String languageName;
private final List codestarts;
private final CodestartProjectInput projectInput;
private DefaultCodestartProjectDefinition(CodestartProjectInput projectInput,
String languageName,
List codestarts) {
this.projectInput = requireNonNull(projectInput, "codestartInput is required");
this.languageName = requireNonNull(languageName, "languageName is required");
this.codestarts = requireNonNull(codestarts, "codestarts is required");
}
public static CodestartProjectDefinition of(CodestartProjectInput projectInput,
Collection codestarts) {
final String languageName = findLanguageName(codestarts);
findRequiredCodestart(codestarts, CodestartType.PROJECT);
final List sorted = codestarts.stream()
.sorted(PROCESSING_ORDER)
.collect(Collectors.toList());
return new DefaultCodestartProjectDefinition(projectInput, languageName, sorted);
}
@Override
public void generate(Path targetDirectory) throws IOException {
CodestartProjectGeneration.generateProject(this, targetDirectory);
}
@Override
public List getCodestarts() {
return codestarts;
}
@Override
public CodestartProjectInput getProjectInput() {
return projectInput;
}
@Override
public Optional getCodestart(CodestartType type) {
return CodestartCatalogs.findCodestart(codestarts, type);
}
@Override
public Codestart getRequiredCodestart(CodestartType type) {
return findRequiredCodestart(codestarts, type);
}
@Override
public String getLanguageName() {
return languageName;
}
@Override
public Map getSharedData() {
final Stream