Java tutorial
/** * Copyright 2015-present beyond constraint. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.beyondconstraint.bounty.plugin; import com.beyondconstraint.bounty.CodeGen; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import java.util.List; /** * @goal generate * @phase process-sources * @author Samuel Kirton <a href="mailto:sam@beyondconstraint.com" /> */ public class GeneratorMojo extends AbstractMojo { /** * @parameter name="source" */ private String source; /** * @parameter name="brokerSchema" */ private String brokerSchema; /** * @parameter name="templateDir" */ private List<String> templateDir; /** * @parameter name="outputDir" */ private String outputDir; /** * @parameter name="formatter" default-value="yaml" */ private String formatter; /** * @parameter name="language" default-value="english" */ private String language; public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("source: " + source); getLog().info("brokerSchema:" + brokerSchema); logTemplateDir(templateDir); getLog().info("outputDir: " + outputDir); getLog().info("formatter: " + formatter); getLog().info("language: " + language); try { CodeGen.getBuilder().source(source).schema(brokerSchema).outputDir(outputDir).formatter(formatter) .language(language).addTemplateDirs(templateDir).generateCode(); } catch (Throwable e) { getLog().error(""); getLog().error("plugin stack trace:"); getLog().error("-----------"); getLog().error(" ", e); getLog().error("-----------"); throw new MojoExecutionException(e.getMessage()); } } private void logTemplateDir(List<String> templateDir) { getLog().info("templateDir:"); if (templateDir != null) templateDir.stream().forEach(getLog()::info); } }