use of io.micronaut.starter.application.ApplicationType 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");
}
}
}
use of io.micronaut.starter.application.ApplicationType in project micronaut-starter by micronaut-projects.
the class AbstractAzureFunction method apply.
@Override
public void apply(GeneratorContext generatorContext) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ApplicationType type = generatorContext.getApplicationType();
generatorContext.addTemplate("host.json", new URLTemplate("host.json", classLoader.getResource("functions/azure/host.json")));
generatorContext.addTemplate("local.settings.json", new URLTemplate("local.settings.json", classLoader.getResource("functions/azure/local.settings.json")));
BuildTool buildTool = generatorContext.getBuildTool();
Project project = generatorContext.getProject();
if (buildTool == BuildTool.MAVEN) {
BuildProperties props = generatorContext.getBuildProperties();
props.put("functionAppName", project.getName());
props.put("functionAppRegion", "westus");
props.put("functionResourceGroup", "java-functions-group");
props.put("stagingDirectory", "${project.build.directory}/azure-functions/${functionAppName}");
}
addFunctionTemplate(generatorContext, project);
applyFunction(generatorContext, type);
}
Aggregations