├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── CNAME ├── README.md ├── _config.yml ├── etc └── spring-scaffold.png ├── generator-core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── generator │ │ │ └── core │ │ │ ├── EngineContract.java │ │ │ ├── Generator.java │ │ │ ├── GeneratorContract.java │ │ │ ├── GeneratorExecutor.java │ │ │ ├── GeneratorOptions.java │ │ │ ├── TemplateEngine.java │ │ │ └── exceptions │ │ │ └── TemplateEngineException.java │ └── resources │ │ └── templates │ │ └── test-template.txt │ └── test │ ├── java │ └── br │ │ └── com │ │ └── generator │ │ └── core │ │ ├── GeneratorExecutorTest.java │ │ └── TemplateEngineTest.java │ └── resources │ └── templates │ └── test-template.txt ├── mvnw ├── mvnw.cmd ├── pom.xml ├── sample ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ ├── DemoApplication.java │ │ │ ├── controller │ │ │ ├── ProductController.java │ │ │ └── UserController.java │ │ │ ├── model │ │ │ └── User.java │ │ │ ├── repository │ │ │ └── UserRepository.java │ │ │ └── service │ │ │ └── UserService.java │ └── resources │ │ ├── application.properties │ │ ├── scaffold.info │ │ └── templates │ │ ├── layout.html │ │ ├── product │ │ └── index.html │ │ └── user │ │ ├── form.html │ │ ├── index.html │ │ └── show.html │ └── test │ └── java │ └── com │ └── example │ └── DemoApplicationTests.java ├── spring-boot-generate ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── generate │ │ │ ├── Generator.java │ │ │ ├── GeneratorBoundary.java │ │ │ ├── Layers.java │ │ │ ├── config │ │ │ └── jms_aws_sqs │ │ │ │ └── MessageListenerGenerator.java │ │ │ ├── helpers │ │ │ ├── FileHelper.java │ │ │ ├── ModelGenerateHelper.java │ │ │ └── ScaffoldInfoHelper.java │ │ │ ├── resources │ │ │ └── GeneratorProperties.java │ │ │ ├── setup │ │ │ └── SetupGenerator.java │ │ │ ├── source │ │ │ ├── controller │ │ │ │ ├── ControllerCleanGenerator.java │ │ │ │ └── ControllerGenerator.java │ │ │ ├── model │ │ │ │ └── ModelGenerator.java │ │ │ ├── repository │ │ │ │ ├── RepositoryCleanGenerator.java │ │ │ │ └── RepositoryGenerator.java │ │ │ └── service │ │ │ │ ├── ServiceCleanGenerator.java │ │ │ │ └── ServiceGenerator.java │ │ │ ├── thymeleaf │ │ │ ├── AbstractThymeleafGenerate.java │ │ │ ├── ThymeleafCleanGenerator.java │ │ │ └── ThymeleafGenerator.java │ │ │ └── validators │ │ │ ├── GenerateValidator.java │ │ │ └── TypeValidator.java │ └── resources │ │ ├── scaffold.info │ │ └── templates │ │ ├── config │ │ └── jms_aws_sqs │ │ │ └── template-message-listener.txt │ │ ├── java │ │ ├── controller │ │ │ ├── template-clean-controller.txt │ │ │ └── template-controller.txt │ │ ├── model │ │ │ └── template-model.txt │ │ ├── repository │ │ │ ├── template-clean-repository.txt │ │ │ └── template-repository.txt │ │ └── service │ │ │ ├── template-clean-service.txt │ │ │ └── template-service.txt │ │ ├── resources │ │ └── template-application.properties.txt │ │ ├── template-clean-index.html │ │ ├── template-form.html │ │ ├── template-index.html │ │ ├── template-layout.html │ │ └── template-show.html │ └── test │ ├── java │ └── br │ │ └── com │ │ └── generate │ │ ├── test │ │ ├── ControllerGenerateTest.java │ │ ├── RepositoryCleanGeneratorBoundaryTest.java │ │ ├── RepositoryGenerateTest.java │ │ └── ServiceGenerateTest.java │ │ └── utils │ │ ├── FileGeneratorTestUtils.java │ │ └── LoadTemplateHelper.java │ └── resources │ └── templates │ └── java │ ├── controller │ ├── UserController.txt │ └── UserControllerTest.txt │ ├── repository │ ├── UserCleanRepository.txt │ └── UserRepository.txt │ └── service │ └── UserService.txt ├── spring-scaffold-cli ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── command │ │ │ ├── ScaffoldFactoryCommands.java │ │ │ ├── controller │ │ │ ├── ControllerCommand.java │ │ │ └── ControllerHandler.java │ │ │ ├── model │ │ │ ├── ModelCommand.java │ │ │ └── ModelHandler.java │ │ │ ├── repository │ │ │ ├── RepositoryCommand.java │ │ │ └── RepositoryHandler.java │ │ │ ├── scaffold │ │ │ ├── ScaffoldCommand.java │ │ │ └── ScaffoldHandler.java │ │ │ ├── service │ │ │ ├── ServiceCommand.java │ │ │ └── ServiceHandler.java │ │ │ ├── setup │ │ │ ├── SetupScaffoldCommand.java │ │ │ └── SetupScaffoldHandler.java │ │ │ └── template │ │ │ ├── TemplateCommand.java │ │ │ └── TemplateHandler.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── org.springframework.boot.cli.command.CommandFactory │ │ ├── scaffold.info │ │ └── templates │ │ ├── config │ │ └── jms_aws_sqs │ │ │ └── template-message-listener.txt │ │ ├── java │ │ ├── controller │ │ │ ├── template-clean-controller.txt │ │ │ └── template-controller.txt │ │ ├── model │ │ │ └── template-model.txt │ │ ├── repository │ │ │ ├── template-clean-repository.txt │ │ │ └── template-repository.txt │ │ └── service │ │ │ ├── template-clean-service.txt │ │ │ └── template-service.txt │ │ ├── resources │ │ └── template-application.properties.txt │ │ ├── template-clean-index.html │ │ ├── template-form.html │ │ ├── template-index.html │ │ ├── template-layout.html │ │ └── template-show.html │ └── test │ ├── java │ └── br │ │ └── com │ │ └── command │ │ ├── model │ │ └── ModelHandlerTest.java │ │ └── template │ │ └── TemplateHandlerTest.java │ └── resources │ └── templates │ ├── fake-application.properties │ └── template-fake-pom.xml └── templates ├── pom.xml └── src ├── main ├── java │ └── br │ │ └── com │ │ └── templates │ │ ├── ComposeTemplate.java │ │ ├── config │ │ ├── jms_aws_sqs │ │ │ ├── EntryPointMessageGenerator.java │ │ │ ├── MessageListenerGenerator.java │ │ │ ├── ProducerMessageGenerator.java │ │ │ ├── SQSDependencyGenerator.java │ │ │ └── SQSPropertiesGenerator.java │ │ └── openj9 │ │ │ ├── OpenJ9DockerfileGenerator.java │ │ │ └── OpenJ9MavenPluginGenerator.java │ │ └── entity │ │ ├── EntityCache.java │ │ ├── EntityExecutor.java │ │ ├── EntityGenerator.java │ │ ├── EntityValidator.java │ │ └── LombokDependencyGenerator.java └── resources │ ├── templates.entity │ └── entity-template.txt │ └── templates │ └── config │ ├── openj9 │ └── dockerfile-template.txt │ ├── template-entrypoint-listener.txt │ ├── template-message-listener.txt │ └── template-producer-message.txt └── test ├── java └── br │ └── com │ └── templates │ ├── config │ ├── jms_aws_sqs │ │ ├── EntryPointMessageGeneratorTest.java │ │ ├── MessageListenerGeneratorTest.java │ │ ├── ProducerMessageGeneratorTest.java │ │ └── SQSDependencyGeneratorTest.java │ └── openj9 │ │ ├── OpenJ9DockerfileGeneratorTest.java │ │ └── OpenJ9MavenPluginGeneratorTest.java │ ├── entity │ ├── EntityCacheTest.java │ └── EntityExecutorTest.java │ └── helper │ └── LoadTemplateTester.java └── resources └── templates └── config ├── fake-application.properties ├── openj9 ├── dockerfile-template-test.txt └── template-pom-test.xml ├── template-entrypoint-listener-test.txt ├── template-message-listener-test.txt ├── template-pom-test.xml ├── template-pom.xml └── template-producer-message-test.txt /.gitignore: -------------------------------------------------------------------------------- 1 | spring-boot-generate/target/ 2 | spring-boot-generate/*.iml 3 | spring-scaffold-cli/target/ 4 | spring-scaffold-cli/*.iml 5 | generator-core/target/ 6 | generator-core/*.iml 7 | templates/target/ 8 | templates/*.iml 9 | 10 | *.iml 11 | .idea/ 12 | 13 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netodevel/cli-spring-boot-scaffold/780ad4c90efae4d27e4faf1884ebfd5fe6541944/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | spring.scaffold.cli -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /etc/spring-scaffold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netodevel/cli-spring-boot-scaffold/780ad4c90efae4d27e4faf1884ebfd5fe6541944/etc/spring-scaffold.png -------------------------------------------------------------------------------- /generator-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-cli 7 | br.com.netodevel 8 | 1.1.0.BUILD-SNAPSHOT 9 | 10 | 4.0.0 11 | generator-core 12 | 1.0.0-BUILD-SNAPSHOT 13 | 14 | 15 | 16 | junit 17 | junit 18 | 19 | 20 | org.apache.commons 21 | commons-io 22 | 1.3.2 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/EngineContract.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import java.util.Map; 4 | 5 | public interface EngineContract { 6 | 7 | String replaceValues(String contentTemplate, Map keyValues); 8 | } 9 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/Generator.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | public abstract class Generator implements GeneratorContract { 7 | 8 | private GeneratorExecutor generator; 9 | private GeneratorOptions generatorOptions; 10 | 11 | public Generator() { 12 | generator = new GeneratorExecutor(new TemplateEngine()); 13 | } 14 | 15 | public File generate(GeneratorOptions generatorOptions) throws IOException { 16 | this.generatorOptions = generatorOptions; 17 | return generator.generate(generatorOptions); 18 | } 19 | 20 | public File addDependency(GeneratorOptions generatorOptions) throws IOException { 21 | return generator.addDependecies(generatorOptions); 22 | } 23 | 24 | public File addMavenPlugin(GeneratorOptions generatorOptions) throws IOException { 25 | return generator.addMavenPlugin(generatorOptions); 26 | } 27 | 28 | public File addProperties(GeneratorOptions generatorOptions) throws IOException { 29 | return generator.addProperties(generatorOptions); 30 | } 31 | 32 | public void output(String pathPackage, String filename) { 33 | System.out.println("created ".concat(pathPackage.concat(filename))); 34 | } 35 | 36 | public GeneratorOptions getGeneratorOptions() { 37 | return generatorOptions; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/GeneratorContract.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | public interface GeneratorContract { 7 | 8 | File runGenerate() throws IOException; 9 | } 10 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/GeneratorExecutor.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.apache.commons.io.IOUtils; 5 | 6 | import java.io.*; 7 | 8 | public class GeneratorExecutor { 9 | 10 | private EngineContract templateEngine; 11 | 12 | public GeneratorExecutor(EngineContract templateEngine) { 13 | this.templateEngine = templateEngine; 14 | } 15 | 16 | public File generate(GeneratorOptions options) throws IOException { 17 | String contentTemplate = loadTemplate(options.getTemplatePath()); 18 | String contentReplaced = templateEngine.replaceValues(contentTemplate, options.getKeyValue()); 19 | File fileGenerated = new File(options.getDestination().concat("/").concat(options.getName())); 20 | 21 | if (fileGenerated.exists()) 22 | System.out.println("INFO ".concat(options.getDestination().concat("/").concat(options.getName())).concat(" already exists")); 23 | if (!fileGenerated.exists()) { 24 | FileUtils.writeStringToFile(fileGenerated, contentReplaced); 25 | System.out.println("CREATED ".concat(options.getDestination().concat("/").concat(options.getName()))); 26 | } 27 | 28 | return fileGenerated; 29 | } 30 | 31 | public File addDependecies(GeneratorOptions options) throws IOException { 32 | String contentTemplate = loadPom(options.getTemplatePath()); 33 | 34 | Boolean alreadyDeps = false; 35 | if (options.getDependencies() != null) { 36 | for (int i = 0; i < options.getDependencies().size(); i++) { 37 | if (contentTemplate.contains(options.getDependencies().get(i))) { 38 | System.out.println("[INFO] ".concat(options.getDependencies().get(i)).concat(" already added.")); 39 | alreadyDeps = true; 40 | } 41 | } 42 | } 43 | if (alreadyDeps) return null; 44 | 45 | String contentReplaced = templateEngine.replaceValues(contentTemplate, options.getKeyValue()); 46 | 47 | File fileGenerated = new File(options.getDestination()); 48 | FileUtils.writeStringToFile(fileGenerated, contentReplaced); 49 | 50 | System.out.println("Add dependencies in ".concat(options.getName())); 51 | return fileGenerated; 52 | } 53 | 54 | public File addMavenPlugin(GeneratorOptions options) throws IOException { 55 | String contentTemplate = loadPom(options.getTemplatePath()); 56 | String contentReplaced = templateEngine.replaceValues(contentTemplate, options.getKeyValue()); 57 | String addPluginValues = templateEngine.replaceValues(contentReplaced, options.getPluginValues()); 58 | 59 | File fileGenerated = new File(options.getDestination()); 60 | FileUtils.writeStringToFile(fileGenerated, addPluginValues); 61 | 62 | System.out.println("Add maven plugin in ".concat(options.getName())); 63 | return fileGenerated; 64 | } 65 | 66 | public File addProperties(GeneratorOptions options) throws IOException { 67 | File loadFiled = new File(options.getTemplatePath()); 68 | 69 | FileWriter fileWritter = new FileWriter(loadFiled, true); 70 | BufferedWriter bufferWritter = new BufferedWriter(fileWritter); 71 | bufferWritter.write(options.getProperties()); 72 | bufferWritter.close(); 73 | fileWritter.close(); 74 | 75 | System.out.println("Add properties in ".concat(options.getName())); 76 | System.out.println("\t".concat(options.getProperties())); 77 | 78 | return loadFiled; 79 | } 80 | 81 | public String loadTemplate(String templatePath) throws IOException { 82 | InputStream in = getClass().getResourceAsStream(templatePath); 83 | return IOUtils.toString(in, "UTF-8"); 84 | } 85 | 86 | public String loadPom(String pomPath) throws IOException { 87 | File file = new File(pomPath); 88 | InputStream in = new FileInputStream(file); 89 | return IOUtils.toString(in, "UTF-8"); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/GeneratorOptions.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class GeneratorOptions { 7 | 8 | private String destination; 9 | private String templatePath; 10 | private String name; 11 | private String properties; 12 | private Map pluginValues; 13 | private Map keyValue; 14 | private List dependencies; 15 | 16 | public String getDestination() { 17 | return destination; 18 | } 19 | 20 | public void setDestination(String destination) { 21 | this.destination = destination; 22 | } 23 | 24 | public String getTemplatePath() { 25 | return templatePath; 26 | } 27 | 28 | public void setTemplatePath(String templatePath) { 29 | this.templatePath = templatePath; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public Map getKeyValue() { 41 | return keyValue; 42 | } 43 | 44 | public void setKeyValue(Map keyValue) { 45 | this.keyValue = keyValue; 46 | } 47 | 48 | public String getProperties() { 49 | return properties; 50 | } 51 | 52 | public void setProperties(String properties) { 53 | this.properties = properties; 54 | } 55 | 56 | public Map getPluginValues() { 57 | return pluginValues; 58 | } 59 | 60 | public void setPluginValues(Map pluginValues) { 61 | this.pluginValues = pluginValues; 62 | } 63 | 64 | public List getDependencies() { 65 | return dependencies; 66 | } 67 | 68 | public void setDependencies(List dependencies) { 69 | this.dependencies = dependencies; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/TemplateEngine.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import br.com.generator.core.exceptions.TemplateEngineException; 4 | 5 | import java.util.Iterator; 6 | import java.util.Map; 7 | 8 | public class TemplateEngine implements EngineContract { 9 | 10 | public String replaceValues(String contentTemplate, Map keyValues) { 11 | if (contentTemplate == null) throw new TemplateEngineException("contentTemplate can not be null"); 12 | if (keyValues == null) return contentTemplate; 13 | Iterator it = keyValues.entrySet().iterator(); 14 | 15 | while (it.hasNext()) { 16 | Map.Entry pair = (Map.Entry) it.next(); 17 | if (contentTemplate.contains(pair.getKey())) 18 | contentTemplate = contentTemplate.replace(pair.getKey(), pair.getValue()); 19 | } 20 | 21 | return contentTemplate; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /generator-core/src/main/java/br/com/generator/core/exceptions/TemplateEngineException.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core.exceptions; 2 | 3 | public class TemplateEngineException extends RuntimeException { 4 | 5 | public TemplateEngineException(String msg) { 6 | super(msg); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /generator-core/src/main/resources/templates/test-template.txt: -------------------------------------------------------------------------------- 1 | ${key} -------------------------------------------------------------------------------- /generator-core/src/test/java/br/com/generator/core/GeneratorExecutorTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.junit.Before; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.TemporaryFolder; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | public class GeneratorExecutorTest { 17 | 18 | @Rule 19 | public TemporaryFolder temporaryFolder = new TemporaryFolder(); 20 | 21 | private File temporaryPath; 22 | 23 | @Before 24 | public void setUp() throws IOException { 25 | temporaryPath = temporaryFolder.newFolder("templates-test"); 26 | } 27 | 28 | @Test 29 | public void shouldReturnFileGenerator() throws IOException { 30 | GeneratorExecutor generatorExecutor = new GeneratorExecutor(new TemplateEngine()); 31 | String templateFile = "/templates/test-template.txt"; 32 | 33 | HashMap keyValue = new HashMap(); 34 | keyValue.put("${key}", "custom value"); 35 | 36 | GeneratorOptions generatorOptions = new GeneratorOptions(); 37 | generatorOptions.setTemplatePath(templateFile); 38 | generatorOptions.setDestination(temporaryPath.getAbsolutePath()); 39 | generatorOptions.setKeyValue(keyValue); 40 | generatorOptions.setName("my-file.txt"); 41 | 42 | File file = generatorExecutor.generate(generatorOptions); 43 | assertTrue(file.exists()); 44 | } 45 | 46 | @Test 47 | public void shouldReturnCustomValue() throws IOException { 48 | GeneratorExecutor generatorExecutor = new GeneratorExecutor(new TemplateEngine()); 49 | String templateFile = "/templates/test-template.txt"; 50 | 51 | HashMap keyValue = new HashMap(); 52 | keyValue.put("${key}", "custom value"); 53 | 54 | GeneratorOptions generatorOptions = new GeneratorOptions(); 55 | generatorOptions.setTemplatePath(templateFile); 56 | generatorOptions.setDestination(temporaryPath.getAbsolutePath()); 57 | generatorOptions.setKeyValue(keyValue); 58 | generatorOptions.setName("my-file.txt"); 59 | 60 | File file = generatorExecutor.generate(generatorOptions); 61 | String content = FileUtils.readFileToString(file); 62 | 63 | assertEquals("custom value", content); 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /generator-core/src/test/java/br/com/generator/core/TemplateEngineTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generator.core; 2 | 3 | import br.com.generator.core.exceptions.TemplateEngineException; 4 | import org.junit.Test; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class TemplateEngineTest { 12 | 13 | @Test 14 | public void shouldReturnHelloWorld() { 15 | String contentTemplate = "${key}"; 16 | Map keyValues = new HashMap(); 17 | keyValues.put("${key}", "Hello World"); 18 | 19 | TemplateEngine templateEngine = new TemplateEngine(); 20 | String expectedValue = templateEngine.replaceValues(contentTemplate, keyValues); 21 | 22 | assertEquals("Hello World", expectedValue); 23 | } 24 | 25 | @Test(expected = TemplateEngineException.class) 26 | public void givenContentNull_shouldInvokeException() { 27 | TemplateEngine templateEngine = new TemplateEngine(); 28 | templateEngine.replaceValues(null, null); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /generator-core/src/test/resources/templates/test-template.txt: -------------------------------------------------------------------------------- 1 | ${key} -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %* 125 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 126 | if ERRORLEVEL 1 goto error 127 | goto end 128 | 129 | :error 130 | set ERROR_CODE=1 131 | 132 | :end 133 | @endlocal & set ERROR_CODE=%ERROR_CODE% 134 | 135 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 136 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 137 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 138 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 139 | :skipRcPost 140 | 141 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 142 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 143 | 144 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 145 | 146 | exit /B %ERROR_CODE% 147 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | br.com.netodevel 5 | spring-boot-cli 6 | 1.1.0.BUILD-SNAPSHOT 7 | 8 | pom 9 | cli-spring-boot-scaffold 10 | Generate templates for rapid development 11 | https://projects.spring.io/spring-cloud/ 12 | 13 | 14 | spring-scaffold-cli 15 | spring-boot-generate 16 | generator-core 17 | templates 18 | 19 | 20 | 21 | 22 | spring 23 | 24 | 25 | spring-snapshots 26 | Spring Snapshots 27 | https://repo.spring.io/libs-snapshot-local 28 | 29 | true 30 | 31 | 32 | false 33 | 34 | 35 | 36 | spring-milestones 37 | Spring Milestones 38 | https://repo.spring.io/libs-milestone-local 39 | 40 | false 41 | 42 | 43 | 44 | spring-releases 45 | Spring Releases 46 | https://repo.spring.io/release 47 | 48 | false 49 | 50 | 51 | 52 | 53 | 54 | spring-snapshots 55 | Spring Snapshots 56 | https://repo.spring.io/libs-snapshot-local 57 | 58 | true 59 | 60 | 61 | 62 | spring-milestones 63 | Spring Milestones 64 | https://repo.spring.io/libs-milestone-local 65 | 66 | false 67 | 68 | 69 | 70 | spring-releases 71 | Spring Releases 72 | https://repo.spring.io/libs-release-local 73 | 74 | false 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-parent 86 | 1.4.2.RELEASE 87 | pom 88 | import 89 | 90 | 91 | org.springframework.boot 92 | spring-boot-dependencies 93 | 1.4.2.RELEASE 94 | pom 95 | import 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /sample/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netodevel/cli-spring-boot-scaffold/780ad4c90efae4d27e4faf1884ebfd5fe6541944/sample/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /sample/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip 2 | -------------------------------------------------------------------------------- /sample/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% -------------------------------------------------------------------------------- /sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | my-project 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-thymeleaf 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /sample/src/main/java/com/example/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sample/src/main/java/com/example/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | import org.springframework.stereotype.Controller; 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | @RequestMapping("/product") 8 | public class ProductController { 9 | 10 | @GetMapping 11 | public String index() { 12 | return "product/index"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sample/src/main/java/com/example/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.Valid; 6 | 7 | import org.hibernate.service.spi.ServiceException; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.validation.BindingResult; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.ModelAttribute; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 20 | import com.example.model.User; 21 | import com.example.service.UserService; 22 | 23 | @Controller 24 | @RequestMapping("/users") 25 | public class UserController { 26 | 27 | private static final String MSG_SUCESS_INSERT = "User inserted successfully."; 28 | private static final String MSG_SUCESS_UPDATE = "User successfully changed."; 29 | private static final String MSG_SUCESS_DELETE = "Deleted User successfully."; 30 | private static final String MSG_ERROR = "Error."; 31 | 32 | @Autowired 33 | private UserService userService; 34 | 35 | @GetMapping 36 | public String index(Model model) { 37 | List all = userService.findAll(); 38 | model.addAttribute("listUser", all); 39 | return "user/index"; 40 | } 41 | 42 | @GetMapping("/{id}") 43 | public String show(Model model, @PathVariable("id") Integer id) { 44 | if (id != null) { 45 | User user = userService.findOne(id); 46 | model.addAttribute("user", user); 47 | } 48 | return "user/show"; 49 | } 50 | 51 | @GetMapping(value = "/new") 52 | public String create(Model model, @ModelAttribute User entity) { 53 | model.addAttribute("user", entity); 54 | return "user/form"; 55 | } 56 | 57 | @PostMapping 58 | public String create(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 59 | User user = null; 60 | try { 61 | user = userService.save(entity); 62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT); 63 | } catch (Exception e) { 64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 65 | e.printStackTrace(); 66 | } 67 | return "redirect:/users/" + user.getId(); 68 | } 69 | 70 | @GetMapping("/{id}/edit") 71 | public String update(Model model, @PathVariable("id") Integer id) { 72 | try { 73 | if (id != null) { 74 | User entity = userService.findOne(id); 75 | model.addAttribute("user", entity); 76 | } 77 | } catch (Exception e) { 78 | throw new ServiceException(e.getMessage()); 79 | } 80 | return "user/form"; 81 | } 82 | 83 | @PutMapping 84 | public String update(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 85 | User user = null; 86 | try { 87 | user = userService.save(entity); 88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE); 89 | } catch (Exception e) { 90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 91 | e.printStackTrace(); 92 | } 93 | return "redirect:/users/" + user.getId(); 94 | } 95 | 96 | @DeleteMapping("/{id}") 97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) { 98 | try { 99 | if (id != null) { 100 | User entity = userService.findOne(id); 101 | userService.delete(entity); 102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE); 103 | } 104 | } catch (Exception e) { 105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 106 | throw new ServiceException(e.getMessage()); 107 | } 108 | return "redirect:/users/index"; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sample/src/main/java/com/example/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.model; 2 | import javax.persistence.Entity; 3 | import javax.persistence.GenerationType; 4 | import javax.persistence.Table; 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import java.io.Serializable; 9 | import java.lang.String; 10 | import java.lang.String; 11 | 12 | 13 | @Entity 14 | @Table(name = "users") 15 | public class User implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Id @GeneratedValue(strategy = GenerationType.AUTO) 20 | private Integer id; 21 | 22 | @Column(name = "name") 23 | private String name; 24 | 25 | @Column(name = "email") 26 | private String email; 27 | 28 | public void setName(String name) {this.name = name;} 29 | public String getName() {return name;} 30 | public void setEmail(String email) {this.email = email;} 31 | public String getEmail() {return email;} 32 | 33 | public Integer getId() { 34 | return id; 35 | } 36 | 37 | public void setId(Integer id) { 38 | this.id = id; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/example/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.repository; 2 | import org.springframework.stereotype.Repository; 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import com.example.model.User; 5 | 6 | @Repository 7 | public interface UserRepository extends JpaRepository { 8 | 9 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/example/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Service; 6 | import com.example.model.User; 7 | import com.example.repository.UserRepository; 8 | import org.springframework.transaction.annotation.Transactional; 9 | import java.util.List; 10 | 11 | @Service 12 | @Transactional(readOnly = true) 13 | public class UserService { 14 | 15 | @Autowired 16 | private UserRepository userRepository; 17 | 18 | public List findAll() { 19 | return userRepository.findAll(); 20 | } 21 | 22 | public User findOne(Integer id) { 23 | return userRepository.findOne(id); 24 | } 25 | 26 | @Transactional(readOnly = false) 27 | public User save(User entity) { 28 | return userRepository.save(entity); 29 | } 30 | 31 | @Transactional(readOnly = false) 32 | public void delete(User entity) { 33 | userRepository.delete(entity); 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) 2 | spring.datasource.url = jdbc:mysql://localhost/mydb 3 | spring.datasource.username=root 4 | spring.datasource.password=root 5 | 6 | spring.datasource.tomcat.test-on-borrow=true 7 | spring.datasource.tomcat.validation-query=SELECT 1 8 | spring.datasource.sql-script-encoding=UTF-8 9 | 10 | # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration) 11 | spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy 12 | spring.jpa.openInView=true 13 | spring.jpa.show-sql=false 14 | spring.jpa.hibernate.ddl-auto=create-drop 15 | -------------------------------------------------------------------------------- /sample/src/main/resources/scaffold.info: -------------------------------------------------------------------------------- 1 | package:com.example 2 | dataBaseName:mydb 3 | username:root 4 | password:root 5 | -------------------------------------------------------------------------------- /sample/src/main/resources/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | Template Layout 10 | 11 | 12 | 13 | 14 | 15 | 16 | 35 | 36 |
37 | 38 | 39 | 40 |
41 |

Page content goes here

42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /sample/src/main/resources/templates/product/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Product

15 |
16 |
17 | 18 | -------------------------------------------------------------------------------- /sample/src/main/resources/templates/user/form.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | New User 12 | 13 | 14 |
15 |

New User

16 |

Edit User

17 |
18 |
20 | 21 | 22 |
23 | 24 | 25 |
26 |
27 | 28 | 29 |
30 | 31 | 32 | Back 33 |
34 |
35 | 36 | -------------------------------------------------------------------------------- /sample/src/main/resources/templates/user/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

List User

15 |
16 | New User

17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 37 |
NameEmailAction
31 | Show 32 | Edit 33 | Destroy 34 |
38 |
39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/resources/templates/user/show.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | Show User 12 | 13 | 14 |
15 |

Show User

16 |
17 |
18 | 19 | 20 |
21 |
22 | 23 | 24 |
25 | 26 | Edit this record
27 | Delete this record
28 | Back to list Alunos
29 |
30 | 31 | -------------------------------------------------------------------------------- /sample/src/test/java/com/example/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-generate/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | br.com 5 | spring-boot-generate 6 | 1.1.0.BUILD-SNAPSHOT 7 | 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.3.RELEASE 18 | 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 26 | 27 | 28 | org.apache.commons 29 | commons-io 30 | 1.3.2 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | 42 | 43 | 44 | postgresql 45 | postgresql 46 | 9.1-901-1.jdbc4 47 | 48 | 49 | 50 | commons-lang 51 | commons-lang 52 | 2.3 53 | 54 | 55 | org.scala-lang 56 | scala-library 57 | 2.11.0 58 | 59 | 60 | br.com.netodevel 61 | generator-core 62 | 1.0.0-BUILD-SNAPSHOT 63 | compile 64 | 65 | 66 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/Generator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate; 2 | 3 | import br.com.generate.helpers.ScaffoldInfoHelper; 4 | import org.apache.commons.io.FileUtils; 5 | import org.apache.commons.io.IOUtils; 6 | import org.springframework.util.StringUtils; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | 12 | 13 | public abstract class Generator extends ScaffoldInfoHelper implements GeneratorBoundary { 14 | 15 | public String readTemplateFile(String fileNameTemplate) throws IOException { 16 | InputStream in = getClass().getResourceAsStream("/templates/java/" + getLayer() + "/" + fileNameTemplate); 17 | String theString = IOUtils.toString(in, "UTF-8"); 18 | return theString; 19 | } 20 | 21 | public String readConfigTemplate(String pathTemplate) throws IOException { 22 | InputStream in = getClass().getResourceAsStream("/templates/config/".concat(pathTemplate)); 23 | String theString = IOUtils.toString(in, "UTF-8"); 24 | return theString; 25 | } 26 | 27 | public void outPutFile(String javaStrings, String fileOutPutName) throws IOException { 28 | String nameFileOutPut; 29 | if (getLayer().equals(Layers.MODEL) || getLayer().equals("consumer")) { 30 | nameFileOutPut = getPathPackage() + getLayer() + "/" + fileOutPutName + ".java"; 31 | } else { 32 | nameFileOutPut = getPathPackage() + getLayer() + "/" + fileOutPutName + StringUtils.capitalize(getLayer()) + ".java"; 33 | } 34 | File newJavaFile = new File(nameFileOutPut); 35 | FileUtils.writeStringToFile(newJavaFile, javaStrings); 36 | outputCreate(fileOutPutName, getLayer()); 37 | } 38 | 39 | public void outputCreate(String fileOutPutName, String layer) { 40 | String layerConcat = ""; 41 | if (!layer.equals(Layers.MODEL) && !layer.equals("consumer")) { 42 | layerConcat = StringUtils.capitalize(getLayer()); 43 | } 44 | System.out.println("create " + getPathPackage() + getLayer() + "/" + fileOutPutName + layerConcat + ".java"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/GeneratorBoundary.java: -------------------------------------------------------------------------------- 1 | package br.com.generate; 2 | 3 | import java.io.IOException; 4 | 5 | public interface GeneratorBoundary { 6 | 7 | boolean generate(String nameClass, String parameters, String fileNameTemplate) throws IOException; 8 | 9 | String getLayer(); 10 | } 11 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/Layers.java: -------------------------------------------------------------------------------- 1 | package br.com.generate; 2 | 3 | public final class Layers { 4 | 5 | public static final String CONTROLLER = "controller"; 6 | public static final String MODEL = "model"; 7 | public static final String REPOSITORY = "repository"; 8 | public static final String SERVICE = "service"; 9 | } 10 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/config/jms_aws_sqs/MessageListenerGenerator.java: -------------------------------------------------------------------------------- 1 | //package br.com.generate.config.jms_aws_sqs; 2 | // 3 | //import br.com.generate.helpers.FileHelper; 4 | // 5 | //import java.io.IOException; 6 | // 7 | //public class MessageListenerGenerator extends FileHelper { 8 | // 9 | // @Override 10 | // public String getLayer() { 11 | // return "consumer"; 12 | // } 13 | // 14 | // @Override 15 | // public String operationGenerate(String javaStrings, String nameClass, String parameters) { 16 | // return javaStrings.replace("${package}", getPackage() + ".consumer"); 17 | // } 18 | // 19 | // public static void main(String[] args) throws IOException { 20 | // new MessageListenerGenerator().generateConfig("MessageListener", "jms_aws_sqs/template-message-listener.txt"); 21 | // } 22 | // 23 | //} 24 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/helpers/FileHelper.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.helpers; 2 | 3 | import br.com.generate.Generator; 4 | import br.com.generate.validators.GenerateValidator; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * @author NetoDevel 10 | */ 11 | public abstract class FileHelper extends Generator { 12 | 13 | public abstract String operationGenerate(String javaStrings, String nameClass, String parameters); 14 | 15 | private GenerateValidator validatorGenerate = new GenerateValidator(); 16 | 17 | @Override 18 | public boolean generate(String nameClass, String parameters, String fileNameTemplate) throws IOException { 19 | if (validatorGenerate.validate(nameClass, parameters, getLayer())) { 20 | String javaStrings = readTemplateFile(fileNameTemplate); 21 | String newStrings = operationGenerate(javaStrings, nameClass, parameters); 22 | outPutFile(newStrings, nameClass); 23 | return true; 24 | } 25 | return false; 26 | } 27 | 28 | public void generateConfig(String filename, String pathTemplate) throws IOException { 29 | if (validatorGenerate.validate(filename, null, getLayer())) { 30 | String javaStrings = readConfigTemplate(pathTemplate); 31 | String newStrings = operationGenerate(javaStrings, null, null); 32 | outPutFile(newStrings, filename); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/helpers/ModelGenerateHelper.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.helpers; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.util.StringUtils; 7 | 8 | /** 9 | * @author NetoDevel 10 | */ 11 | public class ModelGenerateHelper { 12 | 13 | private final static String TAB = " "; 14 | 15 | private String importVariable; 16 | 17 | private String nameVariable; 18 | 19 | public ModelGenerateHelper(String importVariable, String nameVariable) { 20 | super(); 21 | this.setImportVariable(importVariable); 22 | this.setNameVariable(nameVariable); 23 | } 24 | 25 | public ModelGenerateHelper(){ 26 | } 27 | 28 | public static List listGenerateImports() { 29 | return Arrays.asList( 30 | new ModelGenerateHelper("java.lang.String", "String"), 31 | new ModelGenerateHelper("java.lang.Integer", "Integer"), 32 | new ModelGenerateHelper("java.lang.Double", "Double"), 33 | new ModelGenerateHelper("java.lang.Float", "Float"), 34 | new ModelGenerateHelper("java.lang.Long", "Long"), 35 | new ModelGenerateHelper("java.lang.Short", "Short"), 36 | new ModelGenerateHelper("java.lang.Byte", "Byte"), 37 | new ModelGenerateHelper("java.lang.Char", "Char"), 38 | new ModelGenerateHelper("java.lang.Boolean", "Boolean"), 39 | new ModelGenerateHelper("java.lang.Object", "Object"), 40 | new ModelGenerateHelper("java.util.Date", "Date"), 41 | new ModelGenerateHelper("java.math.BigDecimal", "BigDecimal")); 42 | } 43 | 44 | public static String generateImports(String parameters) { 45 | String[] separator = parameters.split(" "); 46 | String imports = ""; 47 | for (int i = 0; i < separator.length; i++) { 48 | String [] nameAndType = separator[i].split(":"); 49 | 50 | for (int j = 0; j < listGenerateImports().size(); j++) { 51 | if (nameAndType[1].equals(listGenerateImports().get(j).getNameVariable())) { 52 | imports += "import " + listGenerateImports().get(j).getImportVariable() + "; \n"; 53 | } 54 | } 55 | 56 | } 57 | return imports; 58 | } 59 | 60 | public static String generateGettersAndSetters(String parameters) { 61 | String[] separator = parameters.split(" "); 62 | String gettersAndSetters = ""; 63 | for (int i = 0; i < separator.length; i++) { 64 | String [] nameAndType = separator[i].split(":"); 65 | String name = nameAndType[0]; 66 | String type = nameAndType[1]; 67 | 68 | //SETTER 69 | gettersAndSetters += TAB + "public void set" + StringUtils.capitalize(name) + "(" + type + " " + name + ") {" ; 70 | gettersAndSetters += "this." + name + " = " + name + ";"; 71 | gettersAndSetters += "}"; 72 | 73 | gettersAndSetters += "\n"; 74 | 75 | //GETTER 76 | gettersAndSetters += TAB + "public " + type + " get" + StringUtils.capitalize(name) + "() {" ; 77 | gettersAndSetters += "return " + name + ";"; 78 | gettersAndSetters += "}"; 79 | 80 | gettersAndSetters += "\n"; 81 | } 82 | return gettersAndSetters; 83 | } 84 | 85 | public String getNameVariable() { 86 | return nameVariable; 87 | } 88 | 89 | public void setNameVariable(String nameVariable) { 90 | this.nameVariable = nameVariable; 91 | } 92 | 93 | public String getImportVariable() { 94 | return importVariable; 95 | } 96 | 97 | public void setImportVariable(String importVariable) { 98 | this.importVariable = importVariable; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/resources/GeneratorProperties.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.resources; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.apache.commons.io.IOUtils; 8 | 9 | import br.com.generate.helpers.ScaffoldInfoHelper; 10 | 11 | public class GeneratorProperties extends ScaffoldInfoHelper { 12 | 13 | public GeneratorProperties() throws IOException { 14 | if (validate()) { 15 | generate(); 16 | } 17 | } 18 | 19 | public void generate() throws IOException { 20 | String strings = IOUtils.toString(getClass().getResourceAsStream("/templates/resources/template-application.properties.txt"), null); 21 | 22 | String nameDatabase = getNameDatabase(); 23 | String userDataBase = getUserDatabase(); 24 | String passwordDatabase = getPassWordDatabase(); 25 | 26 | strings = strings.replace("{nameDatabase}", nameDatabase); 27 | strings = strings.replace("{userDatabase}", userDataBase); 28 | strings = strings.replace("{passwordDatabase}", passwordDatabase); 29 | 30 | File newFile = new File(getUserDir() + "/src/main/resources/application.properties"); 31 | FileUtils.writeStringToFile(newFile, strings); 32 | System.out.println("create /src/main/resources/application.properties"); 33 | } 34 | 35 | public boolean validate() throws IOException { 36 | String pathFile = "/src/main/resources/application.properties"; 37 | File f = new File(getUserDir() + pathFile); 38 | if(f.exists()) { 39 | String strings = FileUtils.readFileToString(f); 40 | if (strings.equals("") || strings == null) { 41 | return true; 42 | } 43 | } else { 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/setup/SetupGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.setup; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.PrintWriter; 6 | import java.io.UnsupportedEncodingException; 7 | 8 | import br.com.generate.helpers.ScaffoldInfoHelper; 9 | 10 | /** 11 | * @author NetoDevel 12 | * @since 0.0.1 13 | */ 14 | public class SetupGenerator extends ScaffoldInfoHelper { 15 | 16 | public SetupGenerator(String...params) { 17 | generate(params); 18 | } 19 | 20 | public void generate(String... params) { 21 | PrintWriter writer = null; 22 | try { 23 | File file = new File(getUserDir() + "/src/main/resources/scaffold.info"); 24 | file.getParentFile().mkdirs(); 25 | writer = new PrintWriter(file, "UTF-8"); 26 | String namePackage = params[0] != null ? params[0] : "com.example"; 27 | String dataBaseName = params[1] != null ? params[1] : "mydb"; 28 | String userDataBase = params[2] != null ? params[2] : "root"; 29 | String passWordDatabase = params[3] != null ? params[3] : "root"; 30 | String springVersion = params[4] != null ? params[4] : "1.x"; 31 | writer.println("package:" + namePackage); 32 | writer.println("dataBaseName:" + dataBaseName); 33 | writer.println("username:" + userDataBase); 34 | writer.println("password:" + passWordDatabase); 35 | writer.println("springVersion:" + springVersion); 36 | writer.close(); 37 | System.out.println("create /src/main/resources/scaffold.info"); 38 | } catch (FileNotFoundException e) { 39 | } catch (UnsupportedEncodingException e) { 40 | } 41 | } 42 | 43 | public boolean validateFile(String nameFile) { 44 | File f = new File(getUserDir() + "/src/main/resources/scaffold.info"); 45 | if(f.exists()) { 46 | System.out.println("scaffold.info already exists!"); 47 | return false; 48 | } else { 49 | return true; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/controller/ControllerCleanGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.controller; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class ControllerCleanGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.CONTROLLER; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | return javaStrings.replace("${package}", getPackage() + ".controller") 18 | .replace("${path}", nameClass.toLowerCase()) 19 | .replace("${className}", nameClass); 20 | } 21 | 22 | public static void main(String[] args) throws IOException { 23 | new ControllerCleanGenerator().generate("Credential", null, "template-clean-controller.txt"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/controller/ControllerGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.controller; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class ControllerGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.CONTROLLER; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | return javaStrings.replace("${package}", getPackage() + ".controller") 18 | .replace("${package_model}", getPackage() + ".model") 19 | .replace("${package_service}", getPackage() + ".service") 20 | .replace("${className}", nameClass) 21 | .replace("${paramClassName}", nameClass.toLowerCase()) 22 | .replace("${url_path}", nameClass.toLowerCase() + "s"); 23 | } 24 | 25 | public static void main(String[] args) throws IOException { 26 | new ControllerGenerator().generate("User", null, "template-controller.txt"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/model/ModelGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.model; 2 | 3 | import br.com.generate.Layers; 4 | import br.com.generate.helpers.FileHelper; 5 | import br.com.generate.helpers.ModelGenerateHelper; 6 | 7 | /** 8 | * @author NetoDevel 9 | */ 10 | public class ModelGenerator extends FileHelper { 11 | 12 | @Override 13 | public String getLayer() { 14 | return Layers.MODEL; 15 | } 16 | 17 | @Override 18 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 19 | return javaStrings.replace("${package}", getPackage() + ".model") 20 | .replace("${imports}", ModelGenerateHelper.generateImports(parameters)) 21 | .replace("${className}", nameClass) 22 | .replace("${name_table}", nameClass.toLowerCase() + "s") 23 | .replace("${parameters}", generateParams(parameters)) 24 | .replace("${getters}", ModelGenerateHelper.generateGettersAndSetters(parameters)); 25 | } 26 | 27 | public String generateParams(String params) { 28 | String[] variablesSplits = params.split(" "); 29 | String finalParameters = ""; 30 | for (int i = 0; i < variablesSplits.length; i++) { 31 | 32 | String [] typeAndNameVars = variablesSplits[i].split(":"); 33 | 34 | String column = " @Column(name = \"" + typeAndNameVars[0] + "\")"; 35 | String lineVariables = " private " + typeAndNameVars[1] + " " + typeAndNameVars[0] + ";"; 36 | String lineClean = "\n"; 37 | 38 | finalParameters += lineClean; 39 | finalParameters += column; 40 | finalParameters += lineClean; 41 | finalParameters += lineVariables; 42 | finalParameters += lineClean; 43 | } 44 | return finalParameters; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/repository/RepositoryCleanGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.repository; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class RepositoryCleanGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.REPOSITORY; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | return javaStrings.replace("${package}", getPackage() + ".repository") 18 | .replace("${className}", nameClass); 19 | } 20 | 21 | public static void main(String[] args) throws IOException { 22 | new RepositoryCleanGenerator().generate("User", null, "template-clean-repository.txt"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/repository/RepositoryGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.repository; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class RepositoryGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.REPOSITORY; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | return javaStrings.replace("${package}", getPackage() + ".repository") 18 | .replace("${package_model}", getPackage() + ".model") 19 | .replace("${className}", nameClass); 20 | } 21 | 22 | 23 | public static void main(String[] args) throws IOException { 24 | new RepositoryGenerator().generate("User", null, "template-repository.txt"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/service/ServiceCleanGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.service; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class ServiceCleanGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.SERVICE; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | return javaStrings.replace("${package}", getPackage() + ".service") 18 | .replace("${className}", nameClass); 19 | } 20 | 21 | public static void main(String[] args) throws IOException { 22 | new ServiceCleanGenerator().generate("User", null, "template-clean-service.txt"); 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/source/service/ServiceGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.source.service; 2 | 3 | import java.io.IOException; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.FileHelper; 7 | 8 | public class ServiceGenerator extends FileHelper { 9 | 10 | @Override 11 | public String getLayer() { 12 | return Layers.SERVICE; 13 | } 14 | 15 | @Override 16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) { 17 | if ( getSpringVersion().equals("2.x") ) { 18 | javaStrings = javaStrings.replace(".findOne(id)", ".findById(id).get()"); 19 | } 20 | return javaStrings.replace("${package}", getPackage() + ".service") 21 | .replace("${package_model}", getPackage() + ".model") 22 | .replace("${package_repository}", getPackage() + ".repository") 23 | .replace("${className}", nameClass) 24 | .replace("${paramClassName}", nameClass.toLowerCase()); 25 | } 26 | 27 | public static void main(String[] args) throws IOException { 28 | new ServiceGenerator().generate("User", null, "template-service.txt"); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/thymeleaf/AbstractThymeleafGenerate.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.thymeleaf; 2 | 3 | import org.springframework.util.StringUtils; 4 | 5 | import br.com.generate.helpers.ScaffoldInfoHelper; 6 | 7 | 8 | /** 9 | * @author NetoDevel 10 | */ 11 | public abstract class AbstractThymeleafGenerate extends ScaffoldInfoHelper { 12 | 13 | private static final String TABS_INDEX = " "; 14 | private static final String TABS_FORM = " "; 15 | private static final String TABS_SHOW = " "; 16 | 17 | public String generateThParameters(String parameters) { 18 | String [] params = parameters.split(" "); 19 | String thParameters = ""; 20 | 21 | for (int i = 0; i < params.length; i++) { 22 | String [] nameAndType = params[i].split(":"); 23 | thParameters += TABS_INDEX + "" + StringUtils.capitalize(nameAndType[0]) + " \n"; 24 | } 25 | 26 | thParameters += TABS_INDEX + "Action"; 27 | return thParameters; 28 | } 29 | 30 | 31 | 32 | public String generateTdParameters(String className, String parameters) { 33 | String [] params = parameters.split(" "); 34 | String tdParameters = ""; 35 | for (int i = 0; i < params.length; i++) { 36 | String [] nameAndType = params[i].split(":"); 37 | tdParameters += TABS_INDEX + " \n"; 38 | } 39 | 40 | tdParameters += TABS_INDEX + "\n"; 41 | tdParameters += TABS_INDEX + " Show \n"; 42 | tdParameters += TABS_INDEX + " Edit \n"; 43 | tdParameters += TABS_INDEX + " Destroy \n"; 44 | tdParameters += TABS_INDEX + ""; 45 | return tdParameters; 46 | } 47 | 48 | public String generateInputParameters(String parameters) { 49 | String inputParameters = ""; 50 | String [] params = parameters.split(" "); 51 | for (int i = 0; i < params.length; i++) { 52 | String [] nameAndType = params[i].split(":"); 53 | 54 | inputParameters += TABS_FORM + "
\n"; 55 | inputParameters += TABS_FORM + " \n"; 56 | inputParameters += TABS_FORM + " \n"; 57 | inputParameters += TABS_FORM + "
\n"; 58 | } 59 | 60 | return inputParameters; 61 | } 62 | 63 | public String generateShowParameters(String paramClassName, String parameters) { 64 | String inputParameters = ""; 65 | String [] params = parameters.split(" "); 66 | for (int i = 0; i < params.length; i++) { 67 | String [] nameAndType = params[i].split(":"); 68 | inputParameters += TABS_SHOW + "
\n"; 69 | inputParameters += TABS_SHOW + " \n"; 70 | inputParameters += TABS_SHOW + " \n"; 71 | inputParameters += TABS_SHOW + "
\n"; 72 | } 73 | return inputParameters; 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/thymeleaf/ThymeleafCleanGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.thymeleaf; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.apache.commons.io.IOUtils; 8 | 9 | public class ThymeleafCleanGenerator extends AbstractThymeleafGenerate { 10 | 11 | public void index(String className, String parameters) throws IOException { 12 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-clean-index.html"), null); 13 | String template = "layout"; 14 | String classNameParam = className; 15 | String paramClassName = className.toLowerCase(); 16 | String pathUrl = "/" + className.toLowerCase() + "s"; 17 | String eachParam = "list" + className; 18 | 19 | htmlString = htmlString.replace("${template}", template); 20 | htmlString = htmlString.replace("${className}", classNameParam); 21 | htmlString = htmlString.replace("paramClassName", paramClassName); 22 | htmlString = htmlString.replace("eachParam", eachParam); 23 | htmlString = htmlString.replace("url_path", pathUrl); 24 | 25 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/index.html"); 26 | 27 | FileUtils.writeStringToFile(newHtmlFile, htmlString); 28 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/index.html"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/thymeleaf/ThymeleafGenerator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.thymeleaf; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.apache.commons.io.IOUtils; 8 | 9 | public class ThymeleafGenerator extends AbstractThymeleafGenerate { 10 | 11 | public ThymeleafGenerator(String className, String parameters) throws IOException { 12 | if (validateLayoutHtml()) { 13 | generateTemplateLayout(); 14 | } 15 | generateIndexHtml(className, parameters); 16 | generateFormHtml(className, parameters); 17 | generateShowHtml(className, parameters); 18 | } 19 | 20 | public void generateTemplateLayout() throws IOException { 21 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-layout.html"), null); 22 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/layout.html"); 23 | FileUtils.writeStringToFile(newHtmlFile, htmlString); 24 | System.out.println("create /src/main/resources/templates/layout.html"); 25 | } 26 | 27 | public void generateIndexHtml(String className, String parameters) throws IOException { 28 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-index.html"), null); 29 | String template = "layout"; 30 | String classNameParam = className; 31 | String paramClassName = className.toLowerCase(); 32 | String pathUrl = "/" + className.toLowerCase() + "s"; 33 | String thAttributes = generateThParameters(parameters); 34 | String tdAttributes = generateTdParameters(className, parameters); 35 | String eachParam = "list" + className; 36 | 37 | htmlString = htmlString.replace("${template}", template); 38 | htmlString = htmlString.replace("${className}", classNameParam); 39 | htmlString = htmlString.replace("paramClassName", paramClassName); 40 | htmlString = htmlString.replace("eachParam", eachParam); 41 | htmlString = htmlString.replace("url_path", pathUrl); 42 | htmlString = htmlString.replace("${th_attributes}", thAttributes); 43 | htmlString = htmlString.replace("${td_attributes}", tdAttributes); 44 | 45 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/index.html"); 46 | 47 | FileUtils.writeStringToFile(newHtmlFile, htmlString); 48 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/index.html"); 49 | } 50 | 51 | public void generateFormHtml(String className, String parameters) throws IOException { 52 | String htmlString =IOUtils.toString(getClass().getResourceAsStream("/templates/template-form.html"), null); 53 | 54 | String template = "layout"; 55 | String paramClassName = className.toLowerCase(); 56 | String pathUrl = "/" + className.toLowerCase() + "s"; 57 | String inputParameters = generateInputParameters(parameters); 58 | 59 | htmlString = htmlString.replace("${template}", template); 60 | htmlString = htmlString.replace("${className}", className); 61 | htmlString = htmlString.replace("paramClassName", paramClassName); 62 | htmlString = htmlString.replace("url_path", pathUrl); 63 | htmlString = htmlString.replace("${input_parameters}", inputParameters); 64 | 65 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/form.html"); 66 | 67 | FileUtils.writeStringToFile(newHtmlFile, htmlString); 68 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/form.html"); 69 | } 70 | 71 | public void generateShowHtml(String className, String parameters) throws IOException { 72 | String htmlString =IOUtils.toString(getClass().getResourceAsStream("/templates/template-show.html"), null); 73 | 74 | String template = "layout"; 75 | String paramClassName = className.toLowerCase(); 76 | String pathUrl = "/" + className.toLowerCase() + "s"; 77 | String showAttributes = generateShowParameters(paramClassName, parameters); 78 | 79 | htmlString = htmlString.replace("${template}", template); 80 | htmlString = htmlString.replace("${className}", className); 81 | htmlString = htmlString.replace("paramClassName", paramClassName); 82 | htmlString = htmlString.replace("/path_url", pathUrl); 83 | htmlString = htmlString.replace("${showAttributes}", showAttributes); 84 | 85 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/show.html"); 86 | 87 | FileUtils.writeStringToFile(newHtmlFile, htmlString); 88 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/show.html"); 89 | } 90 | 91 | public boolean validateLayoutHtml() throws IOException { 92 | String pathFile = "/src/main/resources/templates/layout.html"; 93 | File f = new File(getUserDir() + pathFile); 94 | if(f.exists()) { 95 | return false; 96 | } 97 | return true; 98 | } 99 | 100 | public static void main(String[] args) throws IOException { 101 | new ThymeleafGenerator("User", "name:String email:String"); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/validators/GenerateValidator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.validators; 2 | 3 | import java.io.File; 4 | 5 | import br.com.generate.Layers; 6 | import br.com.generate.helpers.ScaffoldInfoHelper; 7 | import org.springframework.util.StringUtils; 8 | 9 | /** 10 | * @author Jose 11 | */ 12 | public class GenerateValidator extends ScaffoldInfoHelper { 13 | 14 | private TypeValidator typeValidator = new TypeValidator(); 15 | 16 | public boolean validate(String nameClass, String parameters, String layer) { 17 | if (typeValidator.validate(parameters, layer) && getSetupDone() && !validateFileExists(nameClass, layer)) { 18 | return true; 19 | } 20 | return false; 21 | } 22 | 23 | public boolean validateFileExists(String nameClass, String layer) { 24 | String pathFile = ""; 25 | if (layer.equals(Layers.MODEL) || layer.equals("consumer")) { 26 | pathFile = "/" + getPathPackage() + layer + "/" + nameClass + ".java"; 27 | } else { 28 | pathFile = "/" + getPathPackage() + layer + "/" + nameClass + getCapitalize(layer) + ".java"; 29 | } 30 | File f = new File(getUserDir() + pathFile); 31 | if (f.exists()) { 32 | System.out.println("Error: file " + nameClass + getCapitalize(layer) + ".java" + " already exists."); 33 | return true; 34 | } else { 35 | return false; 36 | } 37 | } 38 | 39 | private String getCapitalize(String layer) { 40 | if (!layer.equals(Layers.MODEL) && !layer.equals("consumer")) { 41 | return StringUtils.capitalize(layer); 42 | } 43 | return ""; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/java/br/com/generate/validators/TypeValidator.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.validators; 2 | 3 | import br.com.generate.Layers; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * @author NetoDevel 11 | */ 12 | public class TypeValidator { 13 | 14 | public List typesSupported = Arrays.asList("String", "Double", "Float", "Long", "Integer", "Short", "Byte", "Char", "Boolean", "Object", "BigDecimal", "Date"); 15 | 16 | public boolean validate(String parameters, String layer) { 17 | if (layer.equals(Layers.MODEL)) { 18 | String[] separator = parameters.split(" "); 19 | for (int i = 0; i < separator.length; i++) { 20 | String [] nameAndType = separator[i].split(":"); 21 | if (!typesSupported.contains(nameAndType[1].trim())) { 22 | System.out.println("Error: type " + nameAndType[1] + " not supported."); 23 | return false; 24 | } 25 | } 26 | } 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/scaffold.info: -------------------------------------------------------------------------------- 1 | package:br.com.example 2 | user-database:root 3 | password-database:root 4 | springVersion:1.x 5 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/config/jms_aws_sqs/template-message-listener.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | public interface MessageListener { 4 | void queueListener(String String); 5 | } 6 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/controller/template-clean-controller.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | import org.springframework.stereotype.Controller; 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | @RequestMapping("/${path}") 8 | public class ${className}Controller { 9 | 10 | @GetMapping 11 | public String index() { 12 | return "${path}/index"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/controller/template-controller.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.Valid; 6 | 7 | import org.hibernate.service.spi.ServiceException; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.validation.BindingResult; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.ModelAttribute; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 20 | import ${package_model}.${className}; 21 | import ${package_service}.${className}Service; 22 | 23 | @Controller 24 | @RequestMapping("/${paramClassName}s") 25 | public class ${className}Controller { 26 | 27 | private static final String MSG_SUCESS_INSERT = "${className} inserted successfully."; 28 | private static final String MSG_SUCESS_UPDATE = "${className} successfully changed."; 29 | private static final String MSG_SUCESS_DELETE = "Deleted ${className} successfully."; 30 | private static final String MSG_ERROR = "Error."; 31 | 32 | @Autowired 33 | private ${className}Service ${paramClassName}Service; 34 | 35 | @GetMapping 36 | public String index(Model model) { 37 | List<${className}> all = ${paramClassName}Service.findAll(); 38 | model.addAttribute("list${className}", all); 39 | return "${paramClassName}/index"; 40 | } 41 | 42 | @GetMapping("/{id}") 43 | public String show(Model model, @PathVariable("id") Integer id) { 44 | if (id != null) { 45 | ${className} ${paramClassName} = ${paramClassName}Service.findOne(id); 46 | model.addAttribute("${paramClassName}", ${paramClassName}); 47 | } 48 | return "${paramClassName}/show"; 49 | } 50 | 51 | @GetMapping(value = "/new") 52 | public String create(Model model, @ModelAttribute ${className} entity) { 53 | model.addAttribute("${paramClassName}", entity); 54 | return "${paramClassName}/form"; 55 | } 56 | 57 | @PostMapping 58 | public String create(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) { 59 | ${className} ${paramClassName} = null; 60 | try { 61 | ${paramClassName} = ${paramClassName}Service.save(entity); 62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT); 63 | } catch (Exception e) { 64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 65 | e.printStackTrace(); 66 | } 67 | return "redirect:/${url_path}/" + ${paramClassName}.getId(); 68 | } 69 | 70 | @GetMapping("/{id}/edit") 71 | public String update(Model model, @PathVariable("id") Integer id) { 72 | try { 73 | if (id != null) { 74 | ${className} entity = ${paramClassName}Service.findOne(id); 75 | model.addAttribute("${paramClassName}", entity); 76 | } 77 | } catch (Exception e) { 78 | throw new ServiceException(e.getMessage()); 79 | } 80 | return "${paramClassName}/form"; 81 | } 82 | 83 | @PutMapping 84 | public String update(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) { 85 | ${className} ${paramClassName} = null; 86 | try { 87 | ${paramClassName} = ${paramClassName}Service.save(entity); 88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE); 89 | } catch (Exception e) { 90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 91 | e.printStackTrace(); 92 | } 93 | return "redirect:/${url_path}/" + ${paramClassName}.getId(); 94 | } 95 | 96 | @DeleteMapping("/{id}") 97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) { 98 | try { 99 | if (id != null) { 100 | ${className} entity = ${paramClassName}Service.findOne(id); 101 | ${paramClassName}Service.delete(entity); 102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE); 103 | } 104 | } catch (Exception e) { 105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 106 | throw new ServiceException(e.getMessage()); 107 | } 108 | return "redirect:/${url_path}/index"; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/model/template-model.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | import javax.persistence.Entity; 3 | import javax.persistence.GenerationType; 4 | import javax.persistence.Table; 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import java.io.Serializable; 9 | ${imports} 10 | 11 | @Entity 12 | @Table(name = "${name_table}") 13 | public class ${className} implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | @Id @GeneratedValue(strategy = GenerationType.AUTO) 18 | private Integer id; 19 | ${parameters} 20 | ${getters} 21 | public Integer getId() { return id; } 22 | public void setId(Integer id) { this.id = id; } 23 | 24 | } -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/repository/template-clean-repository.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | import org.springframework.stereotype.Repository; 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | @Repository 6 | public interface ${className}Repository { //extends JpaRepository { 7 | 8 | } -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/repository/template-repository.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | import org.springframework.stereotype.Repository; 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import ${package_model}.${className}; 5 | 6 | @Repository 7 | public interface ${className}Repository extends JpaRepository<${className}, Integer> { 8 | 9 | } -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/service/template-clean-service.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | import org.springframework.stereotype.Service; 3 | import org.springframework.transaction.annotation.Transactional; 4 | 5 | @Service 6 | @Transactional(readOnly = true) 7 | public class ${className}Service { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/java/service/template-service.txt: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Service; 6 | import ${package_model}.${className}; 7 | import ${package_repository}.${className}Repository; 8 | import org.springframework.transaction.annotation.Transactional; 9 | import java.util.List; 10 | 11 | @Service 12 | @Transactional(readOnly = true) 13 | public class ${className}Service { 14 | 15 | @Autowired 16 | private ${className}Repository ${paramClassName}Repository; 17 | 18 | public List<${className}> findAll() { 19 | return ${paramClassName}Repository.findAll(); 20 | } 21 | 22 | public ${className} findOne(Integer id) { 23 | return ${paramClassName}Repository.findOne(id); 24 | } 25 | 26 | @Transactional(readOnly = false) 27 | public ${className} save(${className} entity) { 28 | return ${paramClassName}Repository.save(entity); 29 | } 30 | 31 | @Transactional(readOnly = false) 32 | public void delete(${className} entity) { 33 | ${paramClassName}Repository.delete(entity); 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/resources/template-application.properties.txt: -------------------------------------------------------------------------------- 1 | # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) 2 | spring.datasource.url = jdbc:mysql://localhost/{nameDatabase} 3 | spring.datasource.username={userDatabase} 4 | spring.datasource.password={passwordDatabase} 5 | 6 | spring.datasource.tomcat.test-on-borrow=true 7 | spring.datasource.tomcat.validation-query=SELECT 1 8 | spring.datasource.sql-script-encoding=UTF-8 9 | 10 | # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration) 11 | spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy 12 | spring.jpa.openInView=true 13 | spring.jpa.show-sql=false 14 | spring.jpa.hibernate.ddl-auto=create-drop 15 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/template-clean-index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

${className}

15 |
16 |
17 | 18 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/template-form.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | New ${className} 12 | 13 | 14 |
15 |

New ${className}

16 |

Edit ${className}

17 |
18 |
20 | 21 | 22 | ${input_parameters} 23 | 24 | Back 25 |
26 |
27 | 28 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/template-index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

List ${className}

15 |
16 | New ${className}

17 | 18 | 19 | 20 | 21 | ${th_attributes} 22 | 23 | 24 | 25 | 26 | ${td_attributes} 27 | 28 | 29 |
30 |
31 | 32 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/template-layout.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | Template Layout 10 | 11 | 12 | 13 | 14 | 15 | 16 | 35 | 36 |
37 | 38 | 39 | 40 |
41 |

Page content goes here

42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /spring-boot-generate/src/main/resources/templates/template-show.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | Show ${className} 12 | 13 | 14 |
15 |

Show ${className}

16 |
17 | ${showAttributes} 18 | Edit this record
19 | Delete this record
20 | Back to list ${className}
21 |
22 | 23 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/test/ControllerGenerateTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.test; 2 | 3 | import br.com.generate.Layers; 4 | import br.com.generate.source.controller.ControllerGenerator; 5 | import br.com.generate.utils.LoadTemplateHelper; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class ControllerGenerateTest { 13 | 14 | @Test 15 | public void shouldGenerateController() throws IOException { 16 | ControllerGenerator controllerGenerator = new ControllerGenerator(); 17 | String javaStrings = controllerGenerator.readTemplateFile("template-controller.txt"); 18 | 19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.CONTROLLER, "UserController.txt"); 20 | String generatedValue = controllerGenerator.operationGenerate(javaStrings, "User", "name:String"); 21 | 22 | assertEquals(expectedValue, generatedValue); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/test/RepositoryCleanGeneratorBoundaryTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.test; 2 | 3 | import br.com.generate.Layers; 4 | import br.com.generate.source.repository.RepositoryCleanGenerator; 5 | import br.com.generate.utils.LoadTemplateHelper; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class RepositoryCleanGeneratorBoundaryTest { 13 | 14 | @Test 15 | public void shouldGenerateRepository() throws IOException { 16 | RepositoryCleanGenerator repositoryGenerator = new RepositoryCleanGenerator(); 17 | String javaStrings = repositoryGenerator.readTemplateFile("template-clean-repository.txt"); 18 | 19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.REPOSITORY,"UserCleanRepository.txt"); 20 | String generatedValue = repositoryGenerator.operationGenerate(javaStrings, "User", "name:String"); 21 | 22 | assertEquals(expectedValue, generatedValue); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/test/RepositoryGenerateTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.test; 2 | 3 | import br.com.generate.Layers; 4 | import br.com.generate.source.repository.RepositoryGenerator; 5 | import br.com.generate.utils.LoadTemplateHelper; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class RepositoryGenerateTest { 13 | 14 | @Test 15 | public void repositoryGeneratorTest() throws IOException { 16 | RepositoryGenerator repositoryGenerator = new RepositoryGenerator(); 17 | String javaStrings = repositoryGenerator.readTemplateFile("template-repository.txt"); 18 | 19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.REPOSITORY, "UserRepository.txt"); 20 | String generatedValue = repositoryGenerator.operationGenerate(javaStrings, "User", "name:String"); 21 | 22 | assertEquals(expectedValue, generatedValue); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/test/ServiceGenerateTest.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.test; 2 | 3 | import br.com.generate.Layers; 4 | import br.com.generate.source.service.ServiceGenerator; 5 | import br.com.generate.utils.LoadTemplateHelper; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class ServiceGenerateTest { 13 | 14 | @Test 15 | public void shouldGeneratorService() throws IOException { 16 | ServiceGenerator serviceGenerator = new ServiceGenerator(); 17 | String javaStrings = serviceGenerator.readTemplateFile("template-service.txt"); 18 | 19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.SERVICE, "UserService.txt"); 20 | String generatedValue = serviceGenerator.operationGenerate(javaStrings, "User", "name:String"); 21 | 22 | assertEquals(expectedValue, generatedValue); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/utils/FileGeneratorTestUtils.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | import org.apache.commons.io.FileDeleteStrategy; 10 | import org.apache.commons.io.FileUtils; 11 | import org.apache.commons.io.IOUtils; 12 | 13 | public class FileGeneratorTestUtils { 14 | 15 | public static File convertJavaToText(File file, String layer, String outPutFileName) throws FileNotFoundException, IOException { 16 | InputStream in = new FileInputStream(file); 17 | String theString = IOUtils.toString(in, "UTF-8"); 18 | File newTextFile = new File("src/test/resources/templates/java/" + layer + "/" + outPutFileName); 19 | FileUtils.writeStringToFile(newTextFile, theString); 20 | return newTextFile; 21 | } 22 | 23 | public static void deleteFileAndDirectory(File... files) throws IOException { 24 | for (File file : files) { 25 | FileDeleteStrategy.FORCE.delete(file); 26 | } 27 | // FileUtils.forceDelete(new File("src/main/java/br/com/example")); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/java/br/com/generate/utils/LoadTemplateHelper.java: -------------------------------------------------------------------------------- 1 | package br.com.generate.utils; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class LoadTemplateHelper { 9 | 10 | public String loadDataset(String layer, String fileNameTemplate) throws IOException { 11 | InputStream in = getClass().getResourceAsStream("/templates/java/" + layer + "/" + fileNameTemplate); 12 | String theString = IOUtils.toString(in, "UTF-8"); 13 | return theString; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/resources/templates/java/controller/UserController.txt: -------------------------------------------------------------------------------- 1 | package br.com.example.controller; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.Valid; 6 | 7 | import org.hibernate.service.spi.ServiceException; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.validation.BindingResult; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.ModelAttribute; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 20 | import br.com.example.model.User; 21 | import br.com.example.service.UserService; 22 | 23 | @Controller 24 | @RequestMapping("/users") 25 | public class UserController { 26 | 27 | private static final String MSG_SUCESS_INSERT = "User inserted successfully."; 28 | private static final String MSG_SUCESS_UPDATE = "User successfully changed."; 29 | private static final String MSG_SUCESS_DELETE = "Deleted User successfully."; 30 | private static final String MSG_ERROR = "Error."; 31 | 32 | @Autowired 33 | private UserService userService; 34 | 35 | @GetMapping 36 | public String index(Model model) { 37 | List all = userService.findAll(); 38 | model.addAttribute("listUser", all); 39 | return "user/index"; 40 | } 41 | 42 | @GetMapping("/{id}") 43 | public String show(Model model, @PathVariable("id") Integer id) { 44 | if (id != null) { 45 | User user = userService.findOne(id); 46 | model.addAttribute("user", user); 47 | } 48 | return "user/show"; 49 | } 50 | 51 | @GetMapping(value = "/new") 52 | public String create(Model model, @ModelAttribute User entity) { 53 | model.addAttribute("user", entity); 54 | return "user/form"; 55 | } 56 | 57 | @PostMapping 58 | public String create(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 59 | User user = null; 60 | try { 61 | user = userService.save(entity); 62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT); 63 | } catch (Exception e) { 64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 65 | e.printStackTrace(); 66 | } 67 | return "redirect:/users/" + user.getId(); 68 | } 69 | 70 | @GetMapping("/{id}/edit") 71 | public String update(Model model, @PathVariable("id") Integer id) { 72 | try { 73 | if (id != null) { 74 | User entity = userService.findOne(id); 75 | model.addAttribute("user", entity); 76 | } 77 | } catch (Exception e) { 78 | throw new ServiceException(e.getMessage()); 79 | } 80 | return "user/form"; 81 | } 82 | 83 | @PutMapping 84 | public String update(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 85 | User user = null; 86 | try { 87 | user = userService.save(entity); 88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE); 89 | } catch (Exception e) { 90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 91 | e.printStackTrace(); 92 | } 93 | return "redirect:/users/" + user.getId(); 94 | } 95 | 96 | @DeleteMapping("/{id}") 97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) { 98 | try { 99 | if (id != null) { 100 | User entity = userService.findOne(id); 101 | userService.delete(entity); 102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE); 103 | } 104 | } catch (Exception e) { 105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 106 | throw new ServiceException(e.getMessage()); 107 | } 108 | return "redirect:/users/index"; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/resources/templates/java/controller/UserControllerTest.txt: -------------------------------------------------------------------------------- 1 | package br.com.example.controller; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.Valid; 6 | 7 | import org.hibernate.service.spi.ServiceException; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.validation.BindingResult; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.ModelAttribute; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 20 | import br.com.example.model.User; 21 | import br.com.example.service.UserService; 22 | 23 | @Controller 24 | @RequestMapping("/users") 25 | public class UserController { 26 | 27 | private static final String MSG_SUCESS_INSERT = "User inserted successfully."; 28 | private static final String MSG_SUCESS_UPDATE = "User successfully changed."; 29 | private static final String MSG_SUCESS_DELETE = "Deleted User successfully."; 30 | private static final String MSG_ERROR = "Error."; 31 | 32 | @Autowired 33 | private UserService userService; 34 | 35 | @GetMapping 36 | public String index(Model model) { 37 | List all = userService.findAll(); 38 | model.addAttribute("listUser", all); 39 | return "user/index"; 40 | } 41 | 42 | @GetMapping("/{id}") 43 | public String show(Model model, @PathVariable("id") Integer id) { 44 | if (id != null) { 45 | User user = userService.findOne(id); 46 | model.addAttribute("user", user); 47 | } 48 | return "user/show"; 49 | } 50 | 51 | @GetMapping(value = "/new") 52 | public String create(Model model, @ModelAttribute User entity) { 53 | model.addAttribute("user", entity); 54 | return "user/form"; 55 | } 56 | 57 | @PostMapping 58 | public String create(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 59 | User user = null; 60 | try { 61 | user = userService.save(entity); 62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT); 63 | } catch (Exception e) { 64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 65 | e.printStackTrace(); 66 | } 67 | return "redirect:/users/" + user.getId(); 68 | } 69 | 70 | @GetMapping("/{id}/edit") 71 | public String update(Model model, @PathVariable("id") Integer id) { 72 | try { 73 | if (id != null) { 74 | User entity = userService.findOne(id); 75 | model.addAttribute("user", entity); 76 | } 77 | } catch (Exception e) { 78 | throw new ServiceException(e.getMessage()); 79 | } 80 | return "user/form"; 81 | } 82 | 83 | @PutMapping 84 | public String update(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) { 85 | User user = null; 86 | try { 87 | user = userService.save(entity); 88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE); 89 | } catch (Exception e) { 90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 91 | e.printStackTrace(); 92 | } 93 | return "redirect:/users/" + user.getId(); 94 | } 95 | 96 | @DeleteMapping("/{id}") 97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) { 98 | try { 99 | if (id != null) { 100 | User entity = userService.findOne(id); 101 | userService.delete(entity); 102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE); 103 | } 104 | } catch (Exception e) { 105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR); 106 | throw new ServiceException(e.getMessage()); 107 | } 108 | return "redirect:/users/index"; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /spring-boot-generate/src/test/resources/templates/java/repository/UserCleanRepository.txt: -------------------------------------------------------------------------------- 1 | package br.com.example.repository; 2 | import org.springframework.stereotype.Repository; 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | @Repository 6 | public interface UserRepository { //extends JpaRepository { 7 | 8 | } -------------------------------------------------------------------------------- /spring-boot-generate/src/test/resources/templates/java/repository/UserRepository.txt: -------------------------------------------------------------------------------- 1 | package br.com.example.repository; 2 | import org.springframework.stereotype.Repository; 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import br.com.example.model.User; 5 | 6 | @Repository 7 | public interface UserRepository extends JpaRepository { 8 | 9 | } -------------------------------------------------------------------------------- /spring-boot-generate/src/test/resources/templates/java/service/UserService.txt: -------------------------------------------------------------------------------- 1 | package br.com.example.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Service; 6 | import br.com.example.model.User; 7 | import br.com.example.repository.UserRepository; 8 | import org.springframework.transaction.annotation.Transactional; 9 | import java.util.List; 10 | 11 | @Service 12 | @Transactional(readOnly = true) 13 | public class UserService { 14 | 15 | @Autowired 16 | private UserRepository userRepository; 17 | 18 | public List findAll() { 19 | return userRepository.findAll(); 20 | } 21 | 22 | public User findOne(Integer id) { 23 | return userRepository.findOne(id); 24 | } 25 | 26 | @Transactional(readOnly = false) 27 | public User save(User entity) { 28 | return userRepository.save(entity); 29 | } 30 | 31 | @Transactional(readOnly = false) 32 | public void delete(User entity) { 33 | userRepository.delete(entity); 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /spring-scaffold-cli/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | br.com.netodevel 5 | spring-scaffold-cli 6 | 1.1.0.BUILD-SNAPSHOT 7 | 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 2.1.3.RELEASE 12 | 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-cli 18 | 2.1.3.RELEASE 19 | 20 | 21 | 22 | junit 23 | junit 24 | 25 | 26 | 27 | br.com 28 | spring-boot-generate 29 | 1.1.0.BUILD-SNAPSHOT 30 | 31 | 32 | 33 | br.com.netodevel 34 | templates 35 | 1.1.0.BUILD-SNAPSHOT 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/ScaffoldFactoryCommands.java: -------------------------------------------------------------------------------- 1 | package br.com.command; 2 | 3 | import br.com.command.controller.ControllerCommand; 4 | import br.com.command.controller.ControllerHandler; 5 | import br.com.command.model.ModelCommand; 6 | import br.com.command.model.ModelHandler; 7 | import br.com.command.repository.RepositoryCommand; 8 | import br.com.command.repository.RepositoryHandler; 9 | import br.com.command.scaffold.ScaffoldCommand; 10 | import br.com.command.scaffold.ScaffoldHandler; 11 | import br.com.command.service.ServiceCommand; 12 | import br.com.command.service.ServiceHandler; 13 | import br.com.command.setup.SetupScaffoldCommand; 14 | import br.com.command.setup.SetupScaffoldHandler; 15 | import br.com.command.template.TemplateCommand; 16 | import br.com.command.template.TemplateHandler; 17 | import br.com.generate.helpers.ScaffoldInfoHelper; 18 | import org.springframework.boot.cli.command.Command; 19 | import org.springframework.boot.cli.command.CommandFactory; 20 | 21 | import java.util.Arrays; 22 | import java.util.Collection; 23 | 24 | /** 25 | * all commands scaffold 26 | * 27 | * @author NetoDevel 28 | * @since 0.0.1 29 | */ 30 | public class ScaffoldFactoryCommands implements CommandFactory { 31 | 32 | public Collection getCommands() { 33 | ScaffoldInfoHelper scaffoldInfoHelper = new ScaffoldInfoHelper(); 34 | return Arrays.asList( 35 | new ModelCommand("model", "generate entities", new ModelHandler(scaffoldInfoHelper)), 36 | new RepositoryCommand("repository", "generate repositories", new RepositoryHandler()), 37 | new ServiceCommand("service", "generate services", new ServiceHandler()), 38 | new ControllerCommand("controller", "generate controllers", new ControllerHandler()), 39 | new ScaffoldCommand("scaffold", "generate api scaffold", new ScaffoldHandler()), 40 | new SetupScaffoldCommand("setup:scaffold", "setup scaffold", new SetupScaffoldHandler()), 41 | new TemplateCommand("template", "generate setup project", new TemplateHandler(scaffoldInfoHelper))); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/controller/ControllerCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.controller; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | import org.springframework.boot.cli.command.HelpExample; 8 | import org.springframework.boot.cli.command.OptionParsingCommand; 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | 11 | /** 12 | * @author NetoDevel 13 | * @since 0.0.1 14 | */ 15 | public class ControllerCommand extends OptionParsingCommand { 16 | 17 | public ControllerCommand(String name, String description, OptionHandler handler) { 18 | super(name, description, handler); 19 | } 20 | 21 | @Override 22 | public String getUsageHelp() { 23 | return "[name-model]"; 24 | } 25 | 26 | @Override 27 | public Collection getExamples() { 28 | List list = new ArrayList(); 29 | list.add(new HelpExample("create controller kotlin", "controller -n User -l kotlin")); 30 | list.add(new HelpExample("create controller java", "controller -n User -l java")); 31 | return list; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/controller/ControllerHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.controller; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | 6 | import org.springframework.boot.cli.command.options.OptionHandler; 7 | import org.springframework.boot.cli.command.status.ExitStatus; 8 | 9 | import br.com.generate.source.controller.ControllerCleanGenerator; 10 | import br.com.generate.thymeleaf.ThymeleafCleanGenerator; 11 | import joptsimple.OptionSet; 12 | import joptsimple.OptionSpec; 13 | 14 | /** 15 | * @author NetoDevel 16 | * @since 0.0.1 17 | */ 18 | public class ControllerHandler extends OptionHandler { 19 | 20 | @SuppressWarnings("unused") 21 | private OptionSpec nameEntity; 22 | 23 | @Override 24 | protected void options() { 25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate controller").withRequiredArg(); 26 | } 27 | 28 | @Override 29 | protected ExitStatus run(OptionSet options) throws Exception { 30 | String nameClass = (String) options.valueOf("n"); 31 | generateControllerJava(nameClass.trim()); 32 | return ExitStatus.OK; 33 | } 34 | 35 | private void generateControllerJava(String nameClass) throws IOException { 36 | new ControllerCleanGenerator().generate(nameClass, null, "template-clean-controller.txt"); 37 | new ThymeleafCleanGenerator().index(nameClass, null); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/model/ModelCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.model; 2 | 3 | import org.springframework.boot.cli.command.OptionParsingCommand; 4 | import org.springframework.boot.cli.command.options.OptionHandler; 5 | 6 | /** 7 | * command model for generate entitys 8 | * @author NetoDevel 9 | * @since 0.0.1 10 | */ 11 | public class ModelCommand extends OptionParsingCommand { 12 | 13 | public ModelCommand(String name, String description, OptionHandler handler) { 14 | super(name, description, handler); 15 | } 16 | 17 | @Override 18 | public String getUsageHelp() { 19 | return " "; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/model/ModelHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.model; 2 | 3 | import br.com.generate.helpers.ScaffoldInfoHelper; 4 | import br.com.generator.core.GeneratorOptions; 5 | import br.com.templates.entity.EntityCache; 6 | import br.com.templates.entity.EntityExecutor; 7 | import br.com.templates.entity.EntityGenerator; 8 | import br.com.templates.entity.LombokDependencyGenerator; 9 | import joptsimple.OptionSet; 10 | import joptsimple.OptionSpec; 11 | import org.springframework.boot.cli.command.options.OptionHandler; 12 | import org.springframework.boot.cli.command.status.ExitStatus; 13 | 14 | import java.io.IOException; 15 | import java.util.Arrays; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | /** 20 | * @author NetoDevel 21 | * @since 0.0.1 22 | */ 23 | public class ModelHandler extends OptionHandler { 24 | 25 | @SuppressWarnings("unused") 26 | private OptionSpec nameEntity; 27 | 28 | @SuppressWarnings("unused") 29 | private OptionSpec parametersEntity; 30 | 31 | private ScaffoldInfoHelper scaffoldInfoHelper; 32 | 33 | public ModelHandler() { 34 | } 35 | 36 | public ModelHandler(ScaffoldInfoHelper scaffoldInfoHelper) { 37 | this.scaffoldInfoHelper = scaffoldInfoHelper; 38 | } 39 | 40 | @Override 41 | protected void options() { 42 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity").withRequiredArg(); 43 | this.parametersEntity = option(Arrays.asList("parameterEntity", "p"), "Parameters of entity").withRequiredArg(); 44 | } 45 | 46 | @Override 47 | protected ExitStatus run(OptionSet options) throws Exception { 48 | String nameClass = (String) options.valueOf("n"); 49 | String parametersClass = (String) options.valueOf("p"); 50 | 51 | if (nameClass == null || nameClass.replace(" ", "").isEmpty()) { 52 | System.out.println("[INFO] - name of entity is required. use: -n ${entity_name}"); 53 | return ExitStatus.ERROR; 54 | } 55 | if (parametersClass == null || parametersClass.replace(" ", "").isEmpty()){ 56 | System.out.println("[INFO] - parameters of entity is required. use: -p ${parameters}"); 57 | return ExitStatus.ERROR; 58 | } 59 | 60 | generateModelJava(nameClass, parametersClass); 61 | return ExitStatus.OK; 62 | } 63 | 64 | private void generateModelJava(String nameClass, String parameters) throws IOException { 65 | EntityExecutor entityExecutor = new EntityExecutor(); 66 | entityExecutor.run(nameClass, parameters); 67 | 68 | lombokGenerate(); 69 | 70 | for (EntityCache entity : entityExecutor.getEntities()) { 71 | GeneratorOptions generatorOptions = new GeneratorOptions(); 72 | generatorOptions.setName(entity.getName().concat(".java")); 73 | generatorOptions.setDestination(scaffoldInfoHelper.getPathPackage().concat("models")); 74 | 75 | Map keyValue = new HashMap<>(); 76 | keyValue.put("${content}", entity.getContent()); 77 | keyValue.put("${package}", scaffoldInfoHelper.getPackage().concat(".models")); 78 | 79 | generatorOptions.setKeyValue(keyValue); 80 | 81 | EntityGenerator entityGenerator = new EntityGenerator(generatorOptions); 82 | entityGenerator.runGenerate(); 83 | } 84 | 85 | } 86 | 87 | private void lombokGenerate() throws IOException { 88 | GeneratorOptions lombokDepsOptions = new GeneratorOptions(); 89 | lombokDepsOptions.setTemplatePath(scaffoldInfoHelper.getPomPath()); 90 | lombokDepsOptions.setDestination(scaffoldInfoHelper.getPomDest()); 91 | 92 | LombokDependencyGenerator lombokDependencyGenerator = new LombokDependencyGenerator(lombokDepsOptions); 93 | lombokDependencyGenerator.runGenerate(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/repository/RepositoryCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.repository; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | import org.springframework.boot.cli.command.HelpExample; 8 | import org.springframework.boot.cli.command.OptionParsingCommand; 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | 11 | /** 12 | * @author NetoDevel 13 | * @since 0.0.1 14 | */ 15 | public class RepositoryCommand extends OptionParsingCommand { 16 | 17 | public RepositoryCommand(String name, String description,OptionHandler handler) { 18 | super(name, description, handler); 19 | } 20 | 21 | @Override 22 | public String getUsageHelp() { 23 | return "[name-model]"; 24 | } 25 | 26 | @Override 27 | public Collection getExamples() { 28 | List list = new ArrayList(); 29 | list.add(new HelpExample("create repository kotlin", "repository -n User -l kotlin")); 30 | list.add(new HelpExample("create repository java", "repository -n User -l java")); 31 | return list; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/repository/RepositoryHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.repository; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | 6 | import joptsimple.OptionSet; 7 | import joptsimple.OptionSpec; 8 | 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | import org.springframework.boot.cli.command.status.ExitStatus; 11 | 12 | import br.com.generate.source.repository.RepositoryCleanGenerator; 13 | 14 | /** 15 | * @author NetoDevel 16 | * @since 0.0.1 17 | */ 18 | public class RepositoryHandler extends OptionHandler { 19 | 20 | @SuppressWarnings("unused") 21 | private OptionSpec nameEntity; 22 | 23 | @Override 24 | protected void options() { 25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate repository").withRequiredArg(); 26 | } 27 | 28 | @Override 29 | protected ExitStatus run(OptionSet options) throws Exception { 30 | String nameClass = (String) options.valueOf("n"); 31 | generateRepositoryJava(nameClass.trim()); 32 | return ExitStatus.OK; 33 | } 34 | 35 | private void generateRepositoryJava(String nameClass) throws IOException { 36 | new RepositoryCleanGenerator().generate(nameClass, null, "template-clean-repository.txt"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/scaffold/ScaffoldCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.scaffold; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | import org.springframework.boot.cli.command.HelpExample; 8 | import org.springframework.boot.cli.command.OptionParsingCommand; 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | 11 | /** 12 | * @author NetoDevel 13 | * @since 0.0.1 14 | */ 15 | public class ScaffoldCommand extends OptionParsingCommand{ 16 | 17 | public ScaffoldCommand(String name, String description, OptionHandler handler) { 18 | super(name, description, handler); 19 | } 20 | 21 | @Override 22 | public String getUsageHelp() { 23 | return "[name-model] [parameters-model]"; 24 | } 25 | 26 | @Override 27 | public Collection getExamples() { 28 | List list = new ArrayList(); 29 | list.add(new HelpExample("scaffold", "scaffold -n User -p name:String")); 30 | return list; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/scaffold/ScaffoldHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.scaffold; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | 6 | import org.springframework.boot.cli.command.options.OptionHandler; 7 | import org.springframework.boot.cli.command.status.ExitStatus; 8 | 9 | import br.com.generate.source.controller.ControllerGenerator; 10 | import br.com.generate.source.model.ModelGenerator; 11 | import br.com.generate.source.repository.RepositoryGenerator; 12 | import br.com.generate.source.service.ServiceGenerator; 13 | import br.com.generate.thymeleaf.ThymeleafGenerator; 14 | import joptsimple.OptionSet; 15 | import joptsimple.OptionSpec; 16 | 17 | /** 18 | * @author NetoDevel 19 | * @since 0.0.1 20 | */ 21 | public class ScaffoldHandler extends OptionHandler { 22 | 23 | @SuppressWarnings("unused") 24 | private OptionSpec nameEntity; 25 | 26 | @SuppressWarnings("unused") 27 | private OptionSpec parametersEntity; 28 | 29 | @SuppressWarnings("unused") 30 | private OptionSpec language; 31 | 32 | @Override 33 | protected void options() { 34 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate scaffold").withRequiredArg(); 35 | this.parametersEntity = option(Arrays.asList("parameterEntity", "p"), "Parameter of entity to generate scaffold").withRequiredArg(); 36 | } 37 | 38 | @Override 39 | protected ExitStatus run(OptionSet options) throws Exception { 40 | String nameClass = (String) options.valueOf("n"); 41 | String parametersClass = (String) options.valueOf("p"); 42 | generateJava(nameClass.trim(), parametersClass); 43 | return ExitStatus.OK; 44 | } 45 | 46 | private void generateJava(String nameClass, String parametersClass) throws IOException { 47 | generateScaffoldJava(nameClass, parametersClass); 48 | } 49 | 50 | private void generateScaffoldJava(String nameClass, String parametersClass) throws IOException { 51 | try { 52 | if (new ModelGenerator().generate(nameClass, parametersClass, "template-model.txt")) { 53 | new RepositoryGenerator().generate(nameClass, null, "template-repository.txt"); 54 | new ServiceGenerator().generate(nameClass, null, "template-service.txt"); 55 | new ControllerGenerator().generate(nameClass, null, "template-controller.txt"); 56 | new ThymeleafGenerator(nameClass, parametersClass); 57 | //new Migrations().create(nameClass, parametersClass); 58 | } 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/service/ServiceCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | import org.springframework.boot.cli.command.HelpExample; 8 | import org.springframework.boot.cli.command.OptionParsingCommand; 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | 11 | /** 12 | * @author NetoDevel 13 | * @since 0.0.1 14 | */ 15 | public class ServiceCommand extends OptionParsingCommand { 16 | 17 | public ServiceCommand(String name, String description, OptionHandler handler) { 18 | super(name, description, handler); 19 | } 20 | 21 | @Override 22 | public String getUsageHelp() { 23 | return "[name-model]"; 24 | } 25 | 26 | @Override 27 | public Collection getExamples() { 28 | List list = new ArrayList(); 29 | list.add(new HelpExample("create service kotlin", "service -n User -l kotlin")); 30 | list.add(new HelpExample("create service java", "service -n User -l java")); 31 | return list; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/service/ServiceHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.service; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | 6 | import joptsimple.OptionSet; 7 | import joptsimple.OptionSpec; 8 | 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | import org.springframework.boot.cli.command.status.ExitStatus; 11 | 12 | import br.com.generate.source.service.ServiceCleanGenerator; 13 | 14 | /** 15 | * @author NetoDevel 16 | * @since 0.0.1 17 | */ 18 | public class ServiceHandler extends OptionHandler { 19 | 20 | @SuppressWarnings("unused") 21 | private OptionSpec nameEntity; 22 | 23 | @Override 24 | protected void options() { 25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate service").withRequiredArg(); 26 | } 27 | 28 | @Override 29 | protected ExitStatus run(OptionSet options) throws Exception { 30 | String nameClass = (String) options.valueOf("n"); 31 | generateServiceJava(nameClass.trim()); 32 | return ExitStatus.OK; 33 | } 34 | 35 | private void generateServiceJava(String nameClass) throws IOException { 36 | new ServiceCleanGenerator().generate(nameClass, null, "template-clean-service.txt"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/setup/SetupScaffoldCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.setup; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | import org.springframework.boot.cli.command.HelpExample; 8 | import org.springframework.boot.cli.command.OptionParsingCommand; 9 | import org.springframework.boot.cli.command.options.OptionHandler; 10 | 11 | public class SetupScaffoldCommand extends OptionParsingCommand { 12 | 13 | public SetupScaffoldCommand(String name, String description, OptionHandler handler) { 14 | super(name, description, handler); 15 | } 16 | 17 | @Override 18 | public String getUsageHelp() { 19 | return "[namepackage][user-database][password-database][spring-version]"; 20 | } 21 | 22 | @Override 23 | public Collection getExamples() { 24 | List list = new ArrayList(); 25 | list.add(new HelpExample("setup scaffold", "spring setup:scaffold")); 26 | list.add(new HelpExample("setup scaffold with parameters", "spring setup:scaffold -p com.example -u root -p root")); 27 | return list; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/setup/SetupScaffoldHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.command.setup; 2 | 3 | import java.util.Arrays; 4 | 5 | import joptsimple.OptionSet; 6 | import joptsimple.OptionSpec; 7 | 8 | import org.springframework.boot.cli.command.options.OptionHandler; 9 | import org.springframework.boot.cli.command.status.ExitStatus; 10 | 11 | import br.com.generate.resources.GeneratorProperties; 12 | import br.com.generate.setup.SetupGenerator; 13 | 14 | /** 15 | * @author NetoDevel 16 | * @since 0.0.1 17 | */ 18 | public class SetupScaffoldHandler extends OptionHandler { 19 | 20 | @SuppressWarnings("unused") 21 | private OptionSpec namePackage; 22 | 23 | @SuppressWarnings("unused") 24 | private OptionSpec dataBase; 25 | 26 | @SuppressWarnings("unused") 27 | private OptionSpec userDatabase; 28 | 29 | @SuppressWarnings("unused") 30 | private OptionSpec passwordDatabase; 31 | 32 | @SuppressWarnings("unused") 33 | private OptionSpec springVersion; 34 | 35 | @Override 36 | protected void options() { 37 | this.namePackage = option(Arrays.asList("namePackage", "n"), "name of package to create scaffolds").withOptionalArg(); 38 | this.dataBase = option(Arrays.asList("dataBaseName", "d"), "name of database").withOptionalArg(); 39 | this.userDatabase = option(Arrays.asList("userDatabase", "u"), "username database for migrates").withOptionalArg(); 40 | this.passwordDatabase = option(Arrays.asList("passwordDatabase", "p"), "password database for migrates").withOptionalArg(); 41 | this.springVersion = option(Arrays.asList("springVersion", "s"), "spring version: 1.x or 2.x").withOptionalArg(); 42 | } 43 | 44 | @Override 45 | protected ExitStatus run(OptionSet options) throws Exception { 46 | String namePackage = (String) options.valueOf("n"); 47 | String nameDataBase = (String) options.valueOf("d"); 48 | String userNameDatabase = (String) options.valueOf("u"); 49 | String passwordDatabase = (String) options.valueOf("p"); 50 | String springVersion = (String) options.valueOf("s"); 51 | 52 | namePackage = namePackage != null ? namePackage.trim() : namePackage; 53 | nameDataBase = nameDataBase != null ? nameDataBase.trim() : nameDataBase; 54 | userNameDatabase = userNameDatabase != null ? userNameDatabase.trim() : userNameDatabase; 55 | passwordDatabase = passwordDatabase != null ? passwordDatabase.trim() : passwordDatabase; 56 | springVersion = springVersion != null ? springVersion.trim() : springVersion; 57 | 58 | new SetupGenerator(namePackage, nameDataBase, userNameDatabase, passwordDatabase, springVersion); 59 | new GeneratorProperties(); 60 | 61 | return ExitStatus.OK; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /spring-scaffold-cli/src/main/java/br/com/command/template/TemplateCommand.java: -------------------------------------------------------------------------------- 1 | package br.com.command.template; 2 | 3 | import org.springframework.boot.cli.command.OptionParsingCommand; 4 | import org.springframework.boot.cli.command.options.OptionHandler; 5 | 6 | public class TemplateCommand extends OptionParsingCommand { 7 | 8 | public TemplateCommand(String name, String description, OptionHandler handler) { 9 | super(name, description, handler); 10 | } 11 | 12 | @Override 13 | public String getUsageHelp() { 14 | return "[options]