Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.devonfw.cobigen.cli.commands;
import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.text.similarity.JaccardDistance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.exception.InputReaderException;
import com.devonfw.cobigen.api.to.GenerableArtifact;
import com.devonfw.cobigen.api.to.GenerationReportTo;
import com.devonfw.cobigen.api.to.IncrementTo;
import com.devonfw.cobigen.api.to.TemplateTo;
import com.devonfw.cobigen.api.util.MavenUtil;
import com.devonfw.cobigen.api.util.Tuple;
import com.devonfw.cobigen.cli.CobiGenCLI;
import com.devonfw.cobigen.cli.constants.MessagesConstants;
import com.devonfw.cobigen.cli.utils.CobiGenUtils;
import com.devonfw.cobigen.cli.utils.ParsingUtils;
import com.devonfw.cobigen.cli.utils.ValidationUtils;
import com.google.googlejavaformat.java.FormatterException;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
/**
* This class handles the generation command
*/
@Command(description = MessagesConstants.GENERATE_DESCRIPTION, name = "generate", aliases = { "g" },
mixinStandardHelpOptions = true)
public class GenerateCommand extends CommandCommons {
/**
* Selection threshold when user tries to find closest increments and templates
*/
final double SELECTION_THRESHOLD = 0.1;
/**
* User input file
*/
@Parameters(index = "0", arity = "1..*", split = ",", description = MessagesConstants.INPUT_FILE_DESCRIPTION)
List inputFiles = null;
/**
* User output project
*/
@Option(names = { "--out", "-o" }, arity = "0..1", description = MessagesConstants.OUTPUT_ROOT_PATH_DESCRIPTION)
File outputRootPath = null;
/**
* This option provides the use of multiple available increments
*/
@Option(names = { "--increments", "-i" }, split = ",",
description = MessagesConstants.INCREMENTS_OPTION_DESCRIPTION)
List increments = null;
/**
* This option provide specified list of template
*/
@Option(names = { "--templates", "-t" }, split = ",", description = MessagesConstants.TEMPLATES_OPTION_DESCRIPTION)
List templates = null;
/**
* Logger to output useful information to the user
*/
private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class);
/**
* Used for getting users input
*/
private static final Scanner inputReader = new Scanner(System.in);
/**
* Constructor needed for Picocli
*/
public GenerateCommand() {
super();
}
@Override
public Integer doAction() throws Exception {
if (!areArgumentsValid()) {
return 1;
}
LOG.debug("Input files and output root path confirmed to be valid.");
CobiGen cg = CobiGenUtils.initializeCobiGen(templatesProject);
if (increments == null && templates != null) {
Tuple, List> inputsAndArtifacts = preprocess(cg, TemplateTo.class);
for (int i = 0; i < inputsAndArtifacts.getA().size(); i++) {
generate(inputFiles.get(i).toPath(), inputsAndArtifacts.getA().get(i),
MavenUtil.getProjectRoot(inputFiles.get(i).toPath(), false), inputsAndArtifacts.getB(), cg,
TemplateTo.class);
}
} else {
Tuple, List> inputsAndArtifacts = preprocess(cg, IncrementTo.class);
for (int i = 0; i < inputsAndArtifacts.getA().size(); i++) {
generate(inputFiles.get(i).toPath(), inputsAndArtifacts.getA().get(i),
MavenUtil.getProjectRoot(inputFiles.get(i).toPath(), false), inputsAndArtifacts.getB(), cg,
IncrementTo.class);
}
}
return 0;
}
/**
* For each input file it is going to get its matching templates or increments and then performs an
* intersection between all of them, so that the user gets only the templates or increments that will work
* @param
* type of generable artifacts to be pre-processed
*
* @param cg
* CobiGen initialized instance
* @param c
* class type, specifies whether Templates or Increments should be preprocessed
* @return List of templates that the user will be able to use
*
*/
@SuppressWarnings("unchecked")
private Tuple, List> preprocess(CobiGen cg, Class c) {
boolean isIncrements = c.getSimpleName().equals(IncrementTo.class.getSimpleName());
boolean firstIteration = true;
List finalTos = new ArrayList<>();
List