Search in sources :

Example 6 with Options

use of io.micronaut.starter.options.Options in project micronaut-starter by micronaut-projects.

the class FeatureDiffer method produceDiff.

/**
 * Produces a Diff for the given arguments.
 * @param projectGenerator The project generator
 * @param generatorContext The generator context
 * @param consoleOutput The console output
 * @throws Exception If something does wrong
 */
public void produceDiff(ProjectGenerator projectGenerator, GeneratorContext generatorContext, ConsoleOutput consoleOutput) throws Exception {
    MapOutputHandler outputHandler = new MapOutputHandler();
    Project project = generatorContext.getProject();
    ApplicationType applicationType = generatorContext.getApplicationType();
    projectGenerator.generate(applicationType, project, new Options(generatorContext.getLanguage(), generatorContext.getTestFramework(), generatorContext.getBuildTool(), generatorContext.getJdkVersion()), generatorContext.getOperatingSystem(), Collections.emptyList(), outputHandler, ConsoleOutput.NOOP);
    Map<String, String> oldProject = outputHandler.getProject();
    outputHandler = new MapOutputHandler();
    projectGenerator.generate(applicationType, project, outputHandler, generatorContext);
    Map<String, String> newProject = outputHandler.getProject();
    for (Map.Entry<String, String> entry : newProject.entrySet()) {
        String oldFile = oldProject.remove(entry.getKey());
        if (entry.getValue() == null) {
            continue;
        }
        List<String> oldFileLines = oldFile == null ? Collections.emptyList() : toLines(oldFile);
        String newFile = entry.getValue();
        List<String> newFileLines = toLines(newFile);
        Patch<String> diff = DiffUtils.diff(oldFileLines, newFileLines);
        List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(entry.getKey(), entry.getKey(), oldFileLines, diff, 3);
        if (!unifiedDiff.isEmpty()) {
            for (String delta : unifiedDiff) {
                if (delta.startsWith("+")) {
                    consoleOutput.green(delta);
                } else if (delta.startsWith("-")) {
                    consoleOutput.red(delta);
                } else {
                    consoleOutput.out(delta);
                }
            }
            consoleOutput.out("\n");
        }
    }
    for (Map.Entry<String, String> entry : oldProject.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        List<String> oldFileLines = toLines(entry.getValue());
        Patch<String> diff = DiffUtils.diff(oldFileLines, Collections.emptyList());
        List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(entry.getKey(), entry.getKey(), oldFileLines, diff, 3);
        if (!unifiedDiff.isEmpty()) {
            for (String delta : unifiedDiff) {
                if (delta.startsWith("+")) {
                    consoleOutput.green(delta);
                } else if (delta.startsWith("-")) {
                    consoleOutput.red(delta);
                } else {
                    consoleOutput.out(delta);
                }
            }
            consoleOutput.out("\n");
        }
    }
}
Also used : Project(io.micronaut.starter.application.Project) ApplicationType(io.micronaut.starter.application.ApplicationType) Options(io.micronaut.starter.options.Options) MapOutputHandler(io.micronaut.starter.io.MapOutputHandler) Map(java.util.Map)

Aggregations

Options (io.micronaut.starter.options.Options)6 Project (io.micronaut.starter.application.Project)4 ApplicationType (io.micronaut.starter.application.ApplicationType)3 HttpStatusException (io.micronaut.http.exceptions.HttpStatusException)2 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)2 ConsoleOutput (io.micronaut.starter.io.ConsoleOutput)2 MapOutputHandler (io.micronaut.starter.io.MapOutputHandler)2 Language (io.micronaut.starter.options.Language)2 IOException (java.io.IOException)2 java.util (java.util)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 BeanContext (io.micronaut.context.BeanContext)1 Introspected (io.micronaut.core.annotation.Introspected)1 BeanIntrospection (io.micronaut.core.beans.BeanIntrospection)1 Get (io.micronaut.http.annotation.Get)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 ApplicationGeneratingEvent (io.micronaut.starter.api.event.ApplicationGeneratingEvent)1 ProjectGenerator (io.micronaut.starter.application.generator.ProjectGenerator)1 io.micronaut.starter.feature (io.micronaut.starter.feature)1 AvailableFeatures (io.micronaut.starter.feature.AvailableFeatures)1