From 3ffb7047970a5743b1cd3db1af52ff4ae077404f Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Thu, 30 Apr 2020 12:52:58 +0200 Subject: [PATCH 1/9] updated next snapshot version --- cobigen-cli/class-loader-agent/pom.xml | 2 +- cobigen-cli/cli/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cobigen-cli/class-loader-agent/pom.xml b/cobigen-cli/class-loader-agent/pom.xml index ff40eb08d7..23f7ea74bb 100644 --- a/cobigen-cli/class-loader-agent/pom.xml +++ b/cobigen-cli/class-loader-agent/pom.xml @@ -1,7 +1,7 @@ 4.0.0 class-loader-agent - 1.2.0 + 1.3.0-SNAPSHOT Class loader agent Class loader agent for CobiGen CLI diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index 48ab671804..ca8d7bdc6f 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -1,7 +1,7 @@ 4.0.0 cli - 1.2.0 + 1.3.0-SNAPSHOT cobigen-cli Command Line Interface for CobiGen From 1435490e36b260e3c05b94a3dfb8222191928944 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 12 May 2020 10:18:37 +0200 Subject: [PATCH 2/9] #1112 improve error logging --- .../com/devonfw/cobigen/cli/commands/GenerateCommand.java | 5 +++-- .../java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java index 73713a411e..d4462320bf 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java @@ -350,11 +350,12 @@ public void generate(File inputFile, File inputProject, List Date: Wed, 17 Jun 2020 15:45:31 +0200 Subject: [PATCH 3/9] Bugfix/1176 error formatting generated code (#1186) * formatting only generated java files * add test generating non-java files from java input file --- .../cobigen/cli/commands/GenerateCommand.java | 28 ++++++++++++------- .../cli/commandtests/GenerateCommandTest.java | 23 +++++++++++++++ .../logic/api/to/SampleDataEto.java | 5 ++++ 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/src/main/java/com/maven/project/sampledatamanagement/logic/api/to/SampleDataEto.java diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java index d4462320bf..ba408388ca 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java @@ -14,9 +14,12 @@ import java.util.List; import java.util.Map; import java.util.Scanner; +import java.util.Set; import java.util.concurrent.Callable; +import java.util.stream.Collectors; import org.apache.commons.text.similarity.JaccardDistance; +import org.apache.maven.shared.utils.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -303,9 +306,9 @@ public void generate(File inputFile, File inputProject, List generatedJavaFiles = report.getGeneratedFiles().stream() + .filter(e -> FileUtils.getExtension(e.toAbsolutePath().toString()).equals("java")) + .collect(Collectors.toSet()); + if (!generatedJavaFiles.isEmpty()) { + try { + ParsingUtils.formatJavaSources(generatedJavaFiles); + } catch (FormatterException e) { + LOG.info( + "Generation was successful but we were not able to format your code. Maybe you will see strange formatting.", + LOG.isDebugEnabled() ? e : null); + } } } } catch (InputReaderException e) { diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/GenerateCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/GenerateCommandTest.java index 7334c0d1e3..948047d074 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/GenerateCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/GenerateCommandTest.java @@ -72,6 +72,29 @@ public void generateFromEntityTest() { generatedList.clear(); } + /** + * Test generating non-java files from java input + */ + @Test + public void generateNonJavaFilesFromJavaInputTest() { + File inputFile = new File(testFileRootPath + + "localmavenproject/maven.project/api/src/main/java/com/maven/project/sampledatamanagement/logic/api/to/SampleDataEto.java"); + + String args[] = new String[4]; + args[0] = "generate"; + args[1] = inputFile.getAbsolutePath(); + args[2] = "--increments"; + args[3] = "16"; + + commandLine.execute(args); + + // clean up generated files + File generatedFiles = new File(testFileRootPath + "localmavenproject/devon4ng-application-template"); + generatedList.add(generatedFiles); + GenerateCommandTest.deleteGeneratedFiles(generatedList); + generatedList.clear(); + } + /** * Integration test of the generation of templates from a Java Entity. It will generate all the templates * in the output root path passed. diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/src/main/java/com/maven/project/sampledatamanagement/logic/api/to/SampleDataEto.java b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/src/main/java/com/maven/project/sampledatamanagement/logic/api/to/SampleDataEto.java new file mode 100644 index 0000000000..ecfda0f799 --- /dev/null +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/src/main/java/com/maven/project/sampledatamanagement/logic/api/to/SampleDataEto.java @@ -0,0 +1,5 @@ +package com.maven.project.sampledatamanagement.logic.api.to; + +public class SampleDataEto { + +} From 45759da87c12ee3fccf3eca29b30be2c40420f85 Mon Sep 17 00:00:00 2001 From: "Sandesh, Pallapati Immanuel Prabhu" Date: Mon, 27 Jul 2020 16:42:04 +0530 Subject: [PATCH 4/9] CLI increments to search based on both name and description of the (#1184) * CLI increments to search based on both name and description of the templates #1170 * Fixed the formatting. #1170 * Modified to start generation if search string directly equals a name or description.#1170 * Modified the documentation. #1170 Co-authored-by: Malte Brunnlieb --- .../cobigen/cli/commands/GenerateCommand.java | 51 +++++++++++++++---- .../howto_Cobigen-CLI-generation.asciidoc | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java index ba408388ca..642874db70 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java @@ -570,25 +570,54 @@ private ArrayList search(String userInput, List scores = new HashMap<>(); for (int i = 0; i < matching.size(); i++) { - String description = isIncrements ? ((IncrementTo) matching.get(i)).getDescription() - : ((TemplateTo) matching.get(i)).getId(); - JaccardDistance distance = new JaccardDistance(); - scores.put(matching.get(i), distance.apply(description.toUpperCase(), userInput.toUpperCase())); + if (!isIncrements) { + String description = ((TemplateTo) matching.get(i)).getId(); + JaccardDistance distance = new JaccardDistance(); + scores.put(matching.get(i), distance.apply( + description.toUpperCase(), userInput.toUpperCase())); + } else { + String description = + ((IncrementTo) matching.get(i)).getDescription(); + String id = ((IncrementTo) matching.get(i)).getId(); + JaccardDistance distance = new JaccardDistance(); + Double descriptionDistance = distance.apply( + description.toUpperCase(), userInput.toUpperCase()); + Double idDistance = distance.apply(id.toUpperCase(), + userInput.toUpperCase()); + scores.put(matching.get(i), + Math.min(idDistance, descriptionDistance)); + } } - Map sorted = scores.entrySet().stream().sorted(comparingByValue()) - .collect(toMap(e -> e.getKey(), e -> e.getValue(), (e1, e2) -> e2, LinkedHashMap::new)); + Map sorted = + scores.entrySet().stream().sorted(comparingByValue()) + .collect(toMap(e -> e.getKey(), e -> e.getValue(), + (e1, e2) -> e2, LinkedHashMap::new)); ArrayList chosen = new ArrayList<>(); for (Object artifact : sorted.keySet()) { GenerableArtifact tmp; tmp = isIncrements ? (IncrementTo) artifact : (TemplateTo) artifact; - String description = - isIncrements ? ((IncrementTo) artifact).getDescription() : ((TemplateTo) artifact).getId(); - if (description.toUpperCase().contains(userInput.toUpperCase()) - || sorted.get(artifact) <= SELECTION_THRESHOLD) { - chosen.add(tmp); + if (!isIncrements) { + String description = ((TemplateTo) artifact).getId(); + if (description.toUpperCase().contains(userInput.toUpperCase()) + || sorted.get(artifact) <= SELECTION_THRESHOLD) { + chosen.add(tmp); + } + } else { + String description = ((IncrementTo) artifact).getDescription(); + String id = ((IncrementTo) artifact).getId(); + if (description.equalsIgnoreCase(userInput) + || id.equalsIgnoreCase(userInput)) { + chosen.add(tmp); + return (ArrayList) chosen; + } + if ((description.toUpperCase().contains(userInput.toUpperCase()) + || id.toUpperCase().contains(userInput.toUpperCase())) + || sorted.get(artifact) <= SELECTION_THRESHOLD) { + chosen.add(tmp); + } } } diff --git a/documentation/howto_Cobigen-CLI-generation.asciidoc b/documentation/howto_Cobigen-CLI-generation.asciidoc index 81a47afd15..14ccb49185 100644 --- a/documentation/howto_Cobigen-CLI-generation.asciidoc +++ b/documentation/howto_Cobigen-CLI-generation.asciidoc @@ -18,7 +18,7 @@ Using the following command and option you will be able to customize your genera ** `InputGlob`: Glob pattern of the input file or the whole path of the input file from which the code will be generated. -** `< --increment, -i >` : Specifies an increment ID to be generated. You can also search increments by name and CobiGen will output the resultant list. +** `< --increment, -i >` : Specifies an increment ID to be generated. You can also search increments by name and CobiGen will output the resultant list. If an exact match found, code generation will happen. ** `< --template, -t >` : specifies a template ID to be generated. You can also search templates by name and CobiGen will output the resultant list. From f11fe89cbc7f377843cc98e866172981504e15a5 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Thu, 10 Sep 2020 09:48:28 +0200 Subject: [PATCH 5/9] #1215 updating core dependency to latest --- cobigen-cli/class-loader-agent/pom.xml | 2 +- cobigen-cli/cli/pom.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cobigen-cli/class-loader-agent/pom.xml b/cobigen-cli/class-loader-agent/pom.xml index 23f7ea74bb..5aaba59c22 100644 --- a/cobigen-cli/class-loader-agent/pom.xml +++ b/cobigen-cli/class-loader-agent/pom.xml @@ -1,7 +1,7 @@ 4.0.0 class-loader-agent - 1.3.0-SNAPSHOT + 7.0.0-SNAPSHOT Class loader agent Class loader agent for CobiGen CLI diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index ca8d7bdc6f..d66b5d3ccc 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -1,7 +1,7 @@ 4.0.0 cli - 1.3.0-SNAPSHOT + 7.0.0-SNAPSHOT cobigen-cli Command Line Interface for CobiGen @@ -24,12 +24,12 @@ com.devonfw.cobigen core - 6.1.0 + 7.0.0-SNAPSHOT com.devonfw.cobigen core-api - 6.1.0 + 7.0.0-SNAPSHOT info.picocli From 735f2f7654da02326d2668d03a5e7a611f830b14 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Thu, 10 Sep 2020 10:34:20 +0200 Subject: [PATCH 6/9] #1228 fixing tests --- .../maven.project/api/pom.xml | 13 +- .../maven.project/core/pom.xml | 15 +-- .../localmavenproject/maven.project/pom.xml | 9 +- .../test/resources/testdata/openAPI file.yml | 111 ++++++++++++++++++ 4 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/pom.xml b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/pom.xml index 6f30820043..59bce52286 100644 --- a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/pom.xml +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/api/pom.xml @@ -1,15 +1,16 @@ - + 4.0.0 testing testing - maven.project - 0.0.1-SNAPSHOT + maven.project + 0.0.1-SNAPSHOT api jar Test_Local_Maven_Project - + 1.8 1.8 @@ -24,8 +25,8 @@ - - + + eclipse diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/core/pom.xml b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/core/pom.xml index 70ade71535..d93a0095f9 100644 --- a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/core/pom.xml +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/core/pom.xml @@ -1,21 +1,22 @@ - + 4.0.0 - testing - maven.project - 0.0.1-SNAPSHOT + testing + maven.project + 0.0.1-SNAPSHOT core jar Test_Local_Maven_Project - + 1.8 1.8 - + testing api 0.0.1-SNAPSHOT @@ -28,7 +29,7 @@ - + eclipse diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml index d061790bff..0389fcad27 100644 --- a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml @@ -1,8 +1,9 @@ - + 4.0.0 maven.project testing - 1.2.0-SNAPSHOT + 0.0.1-SNAPSHOT pom Test_Local_Maven_Project @@ -12,8 +13,8 @@ core - - + + eclipse diff --git a/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml b/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml new file mode 100644 index 0000000000..420efdc81a --- /dev/null +++ b/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml @@ -0,0 +1,111 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' + description: Just some data +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.angular.test +paths: + /shopmanagement/v1/shop/{shopId}: + x-component: shopmanagement + get: + operationId: findShop + parameters: + - name: shopId + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/Shop' + text/plain: + schema: + type: string + '404': + description: Not found + /salemanagement/v1/sale/{saleId}: + x-component: salemanagement + get: + operationId: findSale + parameters: + - name: saleId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Any + /salemanagement/v1/sale/: + x-component: salemanagement + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SaleData' + tags: + - searchCriteria + /shopmanagement/v1/shop/new: + x-component: shopmanagement + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/ShopData' +components: + schemas: + Shop: + x-component: shopmanagement + description: Entity definiton of Shop + type: object + properties: + shopExample: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + sales: + type: array # Many to One relationship + items: + $ref: '#/components/schemas/Sale' + Sale: + x-component: salemanagement + description: Entity definiton of Shop + type: object + properties: + saleExample: + type: number + format: int64 + maximum: 100 + minimum: 0 + required: + - saleExample + + requestBodies: + ShopData: + content: + application/json: + schema: + $ref: '#/components/schemas/Shop' + required: true + SaleData: + content: + application/json: + schema: + $ref: '#/components/schemas/Sale' + required: true + + \ No newline at end of file From 494f89810be2271de57d71e5ad49761d6ea541f1 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 15 Sep 2020 07:44:35 +0200 Subject: [PATCH 7/9] #1215 set latest released versions to test poms --- cobigen-cli/cli/pom.xml | 4 ++-- cobigen-cli/cli/src/main/resources/pom.xml | 28 +++++++++------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index d66b5d3ccc..6a22374f30 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -24,12 +24,12 @@ com.devonfw.cobigen core - 7.0.0-SNAPSHOT + 7.0.0 com.devonfw.cobigen core-api - 7.0.0-SNAPSHOT + 7.0.0 info.picocli diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index 0843abea37..1c299b1e63 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.devonfw.cobigen cli - 1.2.0-SNAPSHOT + 7.0.0-SNAPSHOT cobigen-cli @@ -13,58 +13,52 @@ com.devonfw.cobigen javaplugin - 2.1.0 + 7.0.0 com.devonfw.cobigen tsplugin - 2.4.2 + 7.0.0 com.devonfw.cobigen xmlplugin - 4.1.0 + 7.0.0 com.devonfw.cobigen textmerger - 2.0.0 + 7.0.0 com.devonfw.cobigen openapiplugin - 2.3.0 - - - org.freemarker - freemarker - 2.3.23 - compile + 7.0.0 com.devonfw.cobigen tempeng-freemarker - 2.0.0 + 7.0.0 com.devonfw.cobigen htmlplugin - 2.0.1 + 7.0.0 com.devonfw.cobigen propertyplugin - 2.0.0 + 7.0.0 com.devonfw.cobigen jsonplugin - 2.0.0 + 7.0.0 com.devonfw.cobigen templates-devon4j - 3.1.8 + 20.08.001 net.sf.m-m-m From 22b385713240324613362df07f04b260db6fd536 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 15 Sep 2020 08:28:57 +0200 Subject: [PATCH 8/9] #1215 set release snapshot version --- .../testdata/localmavenproject/maven.project/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml index 0389fcad27..0c6050a074 100644 --- a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml @@ -1,9 +1,8 @@ - + 4.0.0 maven.project testing - 0.0.1-SNAPSHOT + 7.0.0-SNAPSHOT pom Test_Local_Maven_Project From a0a15df3f16a1d2d9938b09b13440d91cdfda84f Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 15 Sep 2020 08:30:44 +0200 Subject: [PATCH 9/9] #1215 Set release version --- cobigen-cli/class-loader-agent/pom.xml | 2 +- cobigen-cli/cli/pom.xml | 2 +- cobigen-cli/cli/src/main/resources/pom.xml | 2 +- .../resources/testdata/localmavenproject/maven.project/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cobigen-cli/class-loader-agent/pom.xml b/cobigen-cli/class-loader-agent/pom.xml index 5aaba59c22..d421d04289 100644 --- a/cobigen-cli/class-loader-agent/pom.xml +++ b/cobigen-cli/class-loader-agent/pom.xml @@ -1,7 +1,7 @@ 4.0.0 class-loader-agent - 7.0.0-SNAPSHOT + 7.0.0 Class loader agent Class loader agent for CobiGen CLI diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index 6a22374f30..ebea40b507 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -1,7 +1,7 @@ 4.0.0 cli - 7.0.0-SNAPSHOT + 7.0.0 cobigen-cli Command Line Interface for CobiGen diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index 1c299b1e63..68ab14466b 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.devonfw.cobigen cli - 7.0.0-SNAPSHOT + 7.0.0 cobigen-cli diff --git a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml index 0c6050a074..0ba6f1e091 100644 --- a/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml +++ b/cobigen-cli/cli/src/test/resources/testdata/localmavenproject/maven.project/pom.xml @@ -2,7 +2,7 @@ 4.0.0 maven.project testing - 7.0.0-SNAPSHOT + 7.0.0 pom Test_Local_Maven_Project