From 97b45c850addc3ad834690599908bee30ca752e4 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Tue, 15 Sep 2020 08:35:53 +0200 Subject: [PATCH 01/19] #1215 Set next development 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 d421d04289..4d4421e0dd 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 + 7.1.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 ebea40b507..2919d8fa67 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -1,7 +1,7 @@ 4.0.0 cli - 7.0.0 + 7.1.0-SNAPSHOT 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 68ab14466b..474425fb48 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 + 7.1.0-SNAPSHOT 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 0ba6f1e091..bf1c159042 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 + 7.1.0-SNAPSHOT pom Test_Local_Maven_Project From 366a68db23a47cc542669b500aa083878d2e8a0c Mon Sep 17 00:00:00 2001 From: Lilli Date: Tue, 6 Oct 2020 15:35:09 +0200 Subject: [PATCH 02/19] search for maven home properly --- .../cobigen/cli/utils/CobiGenUtils.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java index 7ff93aa4f6..307056aa68 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java @@ -157,10 +157,10 @@ private void buildCobiGenDependencies(File pomFile) { t1.start(); try { - invoker.setMavenHome(new File(System.getenv("MAVEN_HOME"))); + invoker.setMavenHome(new File(getMavenHome())); } catch (NullPointerException e) { LOG.error( - "MAVEN_HOME environment variable has not been set on your machine. CobiGen CLI needs Maven correctly configured.", + "Could not determine maven home from environment variables MAVEN_HOME or M2_HOME. CobiGen CLI needs Maven correctly configured.", e); } result = invoker.execute(request); @@ -382,4 +382,19 @@ private boolean checkTemplateDepencency(String jarToAdd) { return jarToAdd.contains(TemplatesJarConstants.DEVON4J_TEMPLATES_ARTIFACTID); } + /** + * Get the maven home + * @return maven home + */ + private String getMavenHome() { + String m2Home = System.getenv().get("MAVEN_HOME"); + if (m2Home == null) { + m2Home = System.getenv().get("M2_HOME"); + if (m2Home == null && "true".equals(System.getenv("TRAVIS"))) { + m2Home = "/usr/local/maven"; // travis only + } + } + return m2Home; + } + } From 5c3190a8801722236437c59a13e037e885214832 Mon Sep 17 00:00:00 2001 From: Lilli Date: Wed, 7 Oct 2020 10:46:34 +0200 Subject: [PATCH 03/19] remove Sytem.exit and add check return code from picocli --- .../cobigen/cli/commands/GenerateCommand.java | 11 ++++---- .../cobigen/cli/utils/ValidationUtils.java | 2 +- .../cli/commandtests/GenerateCommandTest.java | 25 +++++++++++++------ 3 files changed, 24 insertions(+), 14 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 642874db70..d6b9c7904d 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 @@ -10,6 +10,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; +import java.util.InputMismatchException; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -436,12 +437,12 @@ private List generableArtifactSelection(ArrayList generableArtifactSelection(ArrayList artifactStringSelection(List } catch (NumberFormatException e) { LOG.error("Error parsing your input. You need to specify {}s using numbers separated by comma (2,5,6).", artifactType); - System.exit(1); + throw (e); } catch (ArrayIndexOutOfBoundsException e) { LOG.error("Error parsing your input. Please give a valid number from the list above."); - System.exit(1); + throw (e); } } return userSelection; diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java index b1bf06be1e..904552a369 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java @@ -188,7 +188,7 @@ public static void printNoTriggersMatched(File inputFile, Boolean isJavaInput, B LOG.error("Validate your OpenAPI specification, check that is following 3.0 standard. " + "More info here https://github.com/devonfw/cobigen/wiki/cobigen-openapiplugin#usage"); } - System.exit(1); + throw new IllegalArgumentException("Your input file is invalid"); } } 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 948047d074..5c2cb15f84 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 @@ -63,7 +63,7 @@ public void generateFromEntityTest() { args[2] = "--increments"; args[3] = "8"; - commandLine.execute(args); + execute(args); File generatedFiles = baseProject.toPath() .resolve("src/main/java/com/maven/project/sampledatamanagement/dataaccess/api/repo").toFile(); @@ -86,7 +86,7 @@ public void generateNonJavaFilesFromJavaInputTest() { args[2] = "--increments"; args[3] = "16"; - commandLine.execute(args); + execute(args); // clean up generated files File generatedFiles = new File(testFileRootPath + "localmavenproject/devon4ng-application-template"); @@ -111,7 +111,7 @@ public void generateFromEntityWithOutputRootPathTest() { args[4] = "--increments"; args[5] = "0"; - commandLine.execute(args); + execute(args); File generatedFiles = outputRootPath.toPath() .resolve("src/main/java/com/maven/project/sampledatamanagement/dataaccess/api/repo").toFile(); @@ -143,7 +143,7 @@ public void generateFromOpenApiTest() { args[4] = "--increments"; args[5] = "1,15,22"; - commandLine.execute(args); + execute(args); Path rootPath = outputRootFile.toPath(); File generatedFiles = rootPath.resolve("src/main/java/com/devonfw/angular/test/salemanagement").toFile(); @@ -190,7 +190,7 @@ public void generateTemplatesFromEntityTest() { args[2] = "-t"; args[3] = "1"; - commandLine.execute(args); + execute(args); File generatedFiles = baseProject.toPath().resolve("src/main/java/com/maven/project/general/").toFile(); generatedList.add(generatedFiles); @@ -214,7 +214,7 @@ public void generateFromMultipleTypeInputTest() { args[4] = "--increments"; args[5] = "1"; - commandLine.execute(args); + execute(args); Path rootPath = outputRootFile.toPath(); File generatedFiles = rootPath.resolve("src/main/java/com/devonfw/angular/test/salemanagement").toFile(); @@ -247,7 +247,7 @@ public void generateFromTsFileTest() { args[4] = "--increments"; args[5] = "1,2,3,4,5,6"; - commandLine.execute(args); + execute(args); Path rootPath = new File(testFileRootPath).toPath(); File generatedFiles = rootPath.resolve("devon4ng-application-template/src/app").toFile(); @@ -286,7 +286,7 @@ public void generateFromArgsWithQuote() throws IOException { args[4] = "--increments"; args[5] = "15"; - commandLine.execute(args); + execute(args); Path rootPath = outputRootFile.toPath(); generatedList.add(rootPath.resolve("docs").toFile()); @@ -294,4 +294,13 @@ public void generateFromArgsWithQuote() throws IOException { openApiFile.delete(); generatedList.clear(); } + + /** + * This method check the return code from picocli + * @param args + */ + private void execute(String[] args) { + int exitCode = commandLine.execute(args); + assertTrue(exitCode == 0); + } } From b905fe7017ab53335f7bb18c10b3e6934b4e5d3a Mon Sep 17 00:00:00 2001 From: Lilli Date: Wed, 7 Oct 2020 14:48:10 +0200 Subject: [PATCH 04/19] update plugins before GenerateCommandTest --- .../devonfw/cobigen/cli/commands/UpdateCommand.java | 13 +++++++++---- .../cli/commandtests/GenerateCommandTest.java | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java index 1b25f6ace2..c61908620a 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java @@ -58,8 +58,12 @@ public Integer call() throws Exception { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(pomFile)); List localPomDependencies = model.getDependencies(); - printOutdatedPlugin(localPomDependencies, centralMavenVersionList, updatePluginVersions, listOfArtifacts); + boolean isAllUpdated = printOutdatedPlugin(localPomDependencies, centralMavenVersionList, + updatePluginVersions, listOfArtifacts); + if (isAllUpdated) { + return 0; + } if (updateAll) { userInputPluginForUpdate.add("0"); LOG.info("(0) ALL is selected!"); @@ -69,7 +73,7 @@ public Integer call() throws Exception { if (userInputPluginForUpdate.size() == 1) { if (!StringUtils.isNumeric(userInputPluginForUpdate.get(0))) { LOG.info("Nothing selected to update..."); - System.exit(0); + return 0; } } } @@ -110,7 +114,7 @@ private void userInputPluginSelection(ArrayList userInputPluginForUpdate * @param listOfArtifacts * this hold list of artifact id which is need to update */ - public void printOutdatedPlugin(List localPomDependencies, List centralMavenVersionList, + public boolean printOutdatedPlugin(List localPomDependencies, List centralMavenVersionList, HashMap updatePluginVersions, HashMap listOfArtifacts) { int count = 0; String centralMavenVersion = ""; @@ -142,10 +146,11 @@ public void printOutdatedPlugin(List localPomDependencies, List Date: Tue, 13 Oct 2020 09:02:26 +0200 Subject: [PATCH 05/19] update picocli version and use assertJ for test --- cobigen-cli/cli/pom.xml | 14 ++++++-------- .../commandtests/AdaptTemplatesCommandTest.java | 11 +++++------ .../cli/commandtests/GenerateCommandTest.java | 6 +++--- .../cli/commandtests/UpdateCommandTest.java | 6 +++--- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index 2919d8fa67..a19aba440c 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -31,10 +31,15 @@ core-api 7.0.0 + + com.devonfw.cobigen + core-test + 7.0.0 + info.picocli picocli - 4.0.0-beta-1b + 4.5.1 org.apache.maven.shared @@ -58,13 +63,6 @@ logback-classic 1.1.2 - - - junit - junit - 4.11 - test - org.apache.commons commons-text diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java index eacd54bb62..d7159b5119 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java @@ -1,7 +1,6 @@ package com.devonfw.cobigen.cli.commandtests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -61,7 +60,7 @@ public void adaptTemplatesTest() { Path cobigenTemplatesFolderPath = ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); - assertTrue(Files.exists(cobigenTemplatesFolderPath)); + assertThat(Files.exists(cobigenTemplatesFolderPath)); } /** @@ -82,7 +81,7 @@ public void customTemplatesLocationTest() { Path cobigenTemplatesFolderPath = ConfigurationUtils.getCobigenTemplatesFolderPath(); - assertTrue(Files.exists(cobigenTemplatesFolderPath)); + assertThat(Files.exists(cobigenTemplatesFolderPath)); File generatedFiles = cobigenTemplatesFolderPath.toFile(); @@ -103,7 +102,7 @@ public void customTemplateLocationInvalidInputThrowsErrorTest() { args[1] = "--custom-location"; args[2] = "invalid/path/to/test"; - assertEquals(1, commandLine.execute(args)); + assertThat(commandLine.execute(args)).isEqualTo(1); } /** @@ -114,7 +113,7 @@ public void customTemplateLocationInvalidInputThrowsErrorTest() { private static void deleteGeneratedFiles(ArrayList generateFiles) { for (File generatedFile : generateFiles) { - assertTrue(generatedFile.exists()); + assertThat(generatedFile.exists()); try { FileUtils.deleteDirectory(generatedFile); } catch (IOException 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 93c92b79e6..c347d9d291 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 @@ -1,6 +1,6 @@ package com.devonfw.cobigen.cli.commandtests; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -171,7 +171,7 @@ public void generateFromOpenApiTest() { private static void deleteGeneratedFiles(ArrayList generateFiles) { for (File generatedFile : generateFiles) { - assertTrue(generatedFile.exists()); + assertThat(generatedFile.exists()); try { FileUtils.deleteDirectory(generatedFile); } catch (IOException e) { @@ -305,6 +305,6 @@ public void generateFromArgsWithQuote() throws IOException { */ private void execute(String[] args) { int exitCode = commandLine.execute(args); - assertTrue(exitCode == 0); + assertThat(exitCode).isEqualTo(0); } } diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/UpdateCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/UpdateCommandTest.java index 0c4bf917a2..cb6fbfc8d1 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/UpdateCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/UpdateCommandTest.java @@ -1,6 +1,6 @@ package com.devonfw.cobigen.cli.commandtests; -import static org.junit.Assert.assertNotEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import java.io.File; @@ -175,7 +175,7 @@ public void pluginUpdateTest() throws IOException, XmlPullParserException { File updatedPom = new File(Paths.get(rootCLIPath.toString(), pomFileName).toString()); String newVersion = getArtifactVersion(updatedPom, pluginId); - assertNotNull(newVersion); - assertNotEquals(oldVersion, newVersion); + assertThat(newVersion).isNotNull(); + assertThat(oldVersion).isNotEqualTo(newVersion); } } From f90def718b3e3d2282a7c9b703824937d0184050 Mon Sep 17 00:00:00 2001 From: Lilli Date: Tue, 13 Oct 2020 09:12:41 +0200 Subject: [PATCH 06/19] remove overriding managed surefire version --- cobigen-cli/cli/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index a19aba440c..372654f963 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -180,7 +180,6 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.2 -javaagent:${project.build.directory}/classes/class-loader-agent.jar From 59ac7dd1697d0357b0def3f0ba61f07f21a3d9f7 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> Date: Wed, 14 Oct 2020 12:49:37 +0200 Subject: [PATCH 07/19] Update UpdateCommand.java adjusted comments. --- .../cobigen/cli/commands/UpdateCommand.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java index c61908620a..5b5f5a22a2 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/UpdateCommand.java @@ -27,7 +27,7 @@ import picocli.CommandLine.Option; /** - * This class handle update command + * This class handles the update command */ @Command(description = MessagesConstants.UPDATE_OPTION_DESCRIPTION, name = "update", aliases = { "u" }, mixinStandardHelpOptions = true) @@ -93,9 +93,9 @@ public Integer call() throws Exception { } /** - * This method take user input for update template + * This method takes the user input for updating templates * @param userInputPluginForUpdate - * This parameter hold list of User Input + * This parameter holds the list of User Input */ private void userInputPluginSelection(ArrayList userInputPluginForUpdate) { for (String userArtifact : GenerateCommand.getUserInput().split(",")) { @@ -104,15 +104,15 @@ private void userInputPluginSelection(ArrayList userInputPluginForUpdate } /** - * This method printing the outdated plug-ins + * This method is printing the outdated plug-ins * @param localPomDependencies - * This parameter hold the artificial dependencies + * This parameter holds the artificial dependencies * @param centralMavenVersionList - * This parameter hold version list + * This parameter holds version list * @param updatePluginVersions - * This parameter contain the key ,value pair of version + * This parameter contains the key, value pair of versions * @param listOfArtifacts - * this hold list of artifact id which is need to update + * This holds a list of artifact ids which need to be updated */ public boolean printOutdatedPlugin(List localPomDependencies, List centralMavenVersionList, HashMap updatePluginVersions, HashMap listOfArtifacts) { @@ -154,17 +154,17 @@ public boolean printOutdatedPlugin(List localPomDependencies, List localPomDependencies, HashMap listOfArtifacts, List centralMavenVersionList, Model model, ArrayList userInputPluginForUpdate) { From 839b9b6680c5d97191b215fba4b7fbaf36e5189b Mon Sep 17 00:00:00 2001 From: Lilli Date: Mon, 5 Oct 2020 12:07:43 +0200 Subject: [PATCH 08/19] refactor cli to adapt new template detection mechanism --- cobigen-cli/cli/pom.xml | 4 +- .../cli/commands/AdaptTemplatesCommand.java | 58 +++--- .../cobigen/cli/commands/GenerateCommand.java | 36 +++- .../cobigen/cli/utils/CobiGenUtils.java | 75 +------- .../cobigen/cli/utils/ConfigurationUtils.java | 173 ------------------ .../AdaptTemplatesCommandTest.java | 79 +------- 6 files changed, 58 insertions(+), 367 deletions(-) delete mode 100644 cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ConfigurationUtils.java diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index ca8d7bdc6f..4337e7bb88 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -24,12 +24,12 @@ com.devonfw.cobigen core - 6.1.0 + 7.0.0 com.devonfw.cobigen core-api - 6.1.0 + 7.0.0 info.picocli diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java index b6527e8ac8..1f954ca431 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.FileVisitResult; @@ -15,11 +16,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.api.util.CobiGenPathUtil; import com.devonfw.cobigen.cli.CobiGenCLI; import com.devonfw.cobigen.cli.constants.MessagesConstants; import com.devonfw.cobigen.cli.logger.CLILogger; import com.devonfw.cobigen.cli.utils.CobiGenUtils; -import com.devonfw.cobigen.cli.utils.ConfigurationUtils; +import com.devonfw.cobigen.impl.util.ConfigurationUtil; +import com.devonfw.cobigen.impl.util.TemplatesJarUtil; import ch.qos.logback.classic.Level; import picocli.CommandLine.Command; @@ -45,13 +49,6 @@ public class AdaptTemplatesCommand implements Callable { @Option(names = { "--verbose", "-v" }, negatable = true, description = MessagesConstants.VERBOSE_OPTION_DESCRIPTION) private boolean verbose; - /** - * If this option is provided, we will unpack the templates jar at the given location - */ - @Option(names = { "--custom-location", "-cl" }, arity = "0..1", - description = MessagesConstants.CUSTOM_LOCATION_OPTION_DESCRIPTION) - private Path customTemplatesLocation = null; - /** * Logger to output useful information to the user */ @@ -67,15 +64,15 @@ public class AdaptTemplatesCommand implements Callable { * if no destination path could be set */ public static void processJar(Path destinationPath) throws IOException { - - Path sourcesJarPath = cobigenUtils.getTemplatesJar(true); - Path classesJarPath = cobigenUtils.getTemplatesJar(false); - if (destinationPath == null) { throw new IOException("Cobigen folder path not found!"); } - Path templatesFolderPath = destinationPath.resolve(ConfigurationUtils.COBIGEN_TEMPLATES); + File destinationFile = destinationPath.toFile(); + Path sourcesJarPath = TemplatesJarUtil.getJarFile(true, destinationFile).toPath(); + Path classesJarPath = TemplatesJarUtil.getJarFile(false, destinationFile).toPath(); + + Path templatesFolderPath = destinationPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES); if (templatesFolderPath == null) { throw new IOException("Cobigen templates folder path not found!"); @@ -86,7 +83,7 @@ public static void processJar(Path destinationPath) throws IOException { extractArchive(sourcesJarPath, templatesFolderPath); deleteDirectoryRecursively(templatesFolderPath.resolve("META-INF")); - extractArchive(classesJarPath, templatesFolderPath.resolve(ConfigurationUtils.COBIGEN_UTILITY_CLASSES_FOLDER)); + extractArchive(classesJarPath, templatesFolderPath.resolve("target/classes")); Files.deleteIfExists(templatesFolderPath.resolve("pom.xml")); // If we are unzipping a sources jar, we need to get the pom.xml from the normal jar Files.copy(templatesFolderPath.resolve("target/classes/pom.xml"), templatesFolderPath.resolve("pom.xml")); @@ -154,33 +151,20 @@ public Integer call() throws Exception { CLILogger.setLevel(Level.DEBUG); } - Path cobigenTemplatesDirectory = null; - if (customTemplatesLocation != null) { + URI templatesLocationUri = ConfigurationUtil.findTemplatesLocation(); + if (templatesLocationUri == null) { LOG.info( - "CobiGen is attempting to download the latest CobiGen_Templates.jar and will extract it to a target directory of your choice. please wait..."); - ConfigurationUtils.createConfigFile(customTemplatesLocation); - // sets custom templates directory path from configuration file property - cobigenTemplatesDirectory = ConfigurationUtils.getCustomTemplatesLocation(); - LOG.info("Creating custom templates folder at custom location @ {}", cobigenTemplatesDirectory); - } else { - LOG.info( - "CobiGen is attempting to download the latest CobiGen_Templates.jar and will extract it to a default target directory. please wait..."); - // sets default templates directory path from CLI location - cobigenTemplatesDirectory = ConfigurationUtils.getCobigenCliRootPath(); - ConfigurationUtils.createConfigFile(cobigenTemplatesDirectory); - LOG.info("Creating custom templates folder next to the CLI @ {}", cobigenTemplatesDirectory); - } - - if (Files.exists(cobigenTemplatesDirectory)) { - processJar(cobigenTemplatesDirectory); - } else { - LOG.error("Could not find target directory to extract templates @ {}", cobigenTemplatesDirectory); - return 1; + "CobiGen is attempting to download the latest CobiGen_Templates.jar and will extract it to cobigen home directory {}. please wait...", + ConfigurationConstants.COBIGEN_HOME_FOLDER); + File templatesDirectory = CobiGenPathUtil.getTemplatesFolderPath().toFile(); + TemplatesJarUtil.downloadLatestDevon4jTemplates(true, templatesDirectory); + TemplatesJarUtil.downloadLatestDevon4jTemplates(false, templatesDirectory); + processJar(templatesDirectory.toPath()); + LOG.info("Successfully downloaded and extracted templates to @ {}", + templatesDirectory.toPath().resolve(ConfigurationConstants.COBIGEN_TEMPLATES)); } - LOG.info("Successfully created custom templates folder @ {}", - cobigenTemplatesDirectory.resolve(ConfigurationUtils.COBIGEN_TEMPLATES)); return 0; } } 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 642874db70..3e995fdf8e 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 @@ -4,6 +4,7 @@ import static java.util.stream.Collectors.toMap; import java.io.File; +import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; @@ -33,9 +34,9 @@ import com.devonfw.cobigen.cli.constants.MessagesConstants; import com.devonfw.cobigen.cli.logger.CLILogger; import com.devonfw.cobigen.cli.utils.CobiGenUtils; -import com.devonfw.cobigen.cli.utils.ConfigurationUtils; import com.devonfw.cobigen.cli.utils.ParsingUtils; import com.devonfw.cobigen.cli.utils.ValidationUtils; +import com.devonfw.cobigen.impl.util.ConfigurationUtil; import com.google.googlejavaformat.java.FormatterException; import ch.qos.logback.classic.Level; @@ -125,13 +126,14 @@ public Integer call() throws Exception { LOG.debug("Input files and output root path confirmed to be valid."); CobiGen cg = cobigenUtils.initializeCobiGen(); - Path templateFolder = ConfigurationUtils.getCobigenTemplatesFolderPath(); + URI templatesLocationUri = ConfigurationUtil.findTemplatesLocation(); + Path templateFolder = Paths.get(templatesLocationUri); ClassLoader inputClassLoader; - if (templateFolder != null) { - inputClassLoader = URLClassLoader.newInstance(new URL[] { templateFolder.toUri().toURL() }, - getClass().getClassLoader()); + if (templatesLocationUri != null) { + inputClassLoader = + URLClassLoader.newInstance(new URL[] { templatesLocationUri.toURL() }, getClass().getClassLoader()); } else { inputClassLoader = getClass().getClassLoader(); } @@ -252,7 +254,7 @@ public Boolean areArgumentsValid() { int index = 0; for (File inputFile : inputFiles) { - inputFile = ConfigurationUtils.preprocessInputFile(inputFile); + inputFile = preprocessInputFile(inputFile); // Input file can be: C:\folder\input.java if (inputFile.exists() == false) { LOG.debug( @@ -273,7 +275,7 @@ public Boolean areArgumentsValid() { } if (outputRootPath != null) { - outputRootPath = ConfigurationUtils.preprocessInputFile(outputRootPath); + outputRootPath = preprocessInputFile(outputRootPath); } return ValidationUtils.isOutputRootPathValid(outputRootPath); @@ -303,7 +305,7 @@ public void generate(File inputFile, File inputProject, List c, Path templateFolder) { Boolean isIncrements = c.getSimpleName().equals(IncrementTo.class.getSimpleName()); - inputFile = ConfigurationUtils.preprocessInputFile(inputFile); + inputFile = preprocessInputFile(inputFile); try { Object input; String extension = FileUtils.getExtension(inputFile.getName()); @@ -635,4 +637,22 @@ public static String getUserInput() { return userInput; } + /** + * Processes the input file's path. Strips the quotes from the file path if they are given. + * @param inputFile + * the input file + * @return input file with processed path + */ + public static File preprocessInputFile(File inputFile) { + String path = inputFile.getPath(); + String pattern = "[\\\"|\\'](.+)[\\\"|\\']"; + boolean matches = path.matches(pattern); + if (matches) { + path = path.replace("\"", ""); + path = path.replace("\'", ""); + return new File(path); + } + return inputFile; + } + } diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java index 7ff93aa4f6..905c9cfe4c 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java @@ -28,16 +28,13 @@ import com.devonfw.cobigen.api.CobiGen; import com.devonfw.cobigen.api.InputInterpreter; -import com.devonfw.cobigen.api.constants.TemplatesJarConstants; import com.devonfw.cobigen.api.exception.InputReaderException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.to.IncrementTo; import com.devonfw.cobigen.api.to.TemplateTo; -import com.devonfw.cobigen.api.util.CobiGenPathUtil; import com.devonfw.cobigen.cli.CobiGenCLI; import com.devonfw.cobigen.cli.constants.MavenConstants; import com.devonfw.cobigen.impl.CobiGenFactory; -import com.devonfw.cobigen.impl.util.TemplatesJarUtil; import com.google.common.base.Charsets; import classloader.Agent; @@ -53,41 +50,15 @@ public class CobiGenUtils { */ private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class); - /** - * File of the templates jar - */ - private File templatesJar; - - /** - * Directory where all our templates jar are located - */ - private File jarsDirectory = CobiGenPathUtil.getTemplatesFolderPath().toFile(); - - /** - * Whether the template dependency is given. - */ - private boolean templateDependencyIsGiven = false; - /** * Registers CobiGen plug-ins and instantiates CobiGen * @return object of CobiGen */ public CobiGen initializeCobiGen() { CobiGen cg = null; - // extra check to make sure that configuration file is not pointing to non existing folder - ConfigurationUtils.customTemplatesLocationExists(); try { registerPlugins(); - templatesJar = TemplatesJarUtil.getJarFile(false, jarsDirectory); - Path cobigenTemplatesFolderPath = ConfigurationUtils.getCobigenTemplatesFolderPath(); - - if (cobigenTemplatesFolderPath != null) { - cg = CobiGenFactory.create(cobigenTemplatesFolderPath.toUri()); - } else { - cg = CobiGenFactory.create(templatesJar.toURI()); - } - return cg; - + cg = CobiGenFactory.create(); } catch (InvalidConfigurationException e) { // if the context configuration is not valid LOG.error("Invalid configuration of context", e); @@ -95,9 +66,7 @@ public CobiGen initializeCobiGen() { // If I/O operation failed then it will throw exception LOG.error("I/O operation is failed", e); } - return cg; - } /** @@ -209,12 +178,6 @@ public void addJarsToClassLoader(String allJars) { for (String jarToAdd : jarsToAdd) { JarFile jar = new JarFile(jarToAdd); Agent.appendJarFile(jar); - - // Setting the template jar path - if (checkTemplateDepencency(jarToAdd)) { - jarsDirectory = new File(jarToAdd).getParentFile(); - templateDependencyIsGiven = true; - } } } catch (MalformedURLException e) { LOG.error("Not able to form URL of jar file.", e); @@ -229,32 +192,6 @@ public void addJarsToClassLoader(String allJars) { } - /** - * Tries to find the templates jar. If it was not found, it will download it and then return it. - * @param isSource - * true if we want to get source jar file path - * @return Path of the jar file of the templates - */ - public Path getTemplatesJar(boolean isSource) { - File jarFileDir = jarsDirectory.getAbsoluteFile(); - if (TemplatesJarUtil.getJarFile(isSource, jarFileDir) == null) { - try { - if (!templateDependencyIsGiven) { - TemplatesJarUtil.downloadLatestDevon4jTemplates(isSource, jarFileDir); - } - - } catch (MalformedURLException e) { - // if a path of one of the class path entries is not a valid URL - LOG.error("Problem while downloading the templates, URL not valid. This is a bug", e); - } catch (IOException e) { - // IOException occurred - LOG.error("Problem while downloading the templates, most probably you are facing connection issues.\n\n" - + "Please try again later.", e); - } - } - return TemplatesJarUtil.getJarFile(isSource, jarFileDir).toPath(); - } - /** * For Increments Returns a list that retains only the elements in this list that are contained in the * specified collection (optional operation). In other words, the resultant list removes from this list @@ -372,14 +309,4 @@ public static Object process(InputInterpreter inputInterpreter, File file, Class throw new InputReaderException("The file " + file.getAbsolutePath() + " is not a valid input for CobiGen."); } - /** - * Checks whether the current jar is CobiGen templates - * @param jarToAdd - * jar that we check - * @return true if jar is CobiGen templates - */ - private boolean checkTemplateDepencency(String jarToAdd) { - return jarToAdd.contains(TemplatesJarConstants.DEVON4J_TEMPLATES_ARTIFACTID); - } - } diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ConfigurationUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ConfigurationUtils.java deleted file mode 100644 index 5d00012140..0000000000 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ConfigurationUtils.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.devonfw.cobigen.cli.utils; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.devonfw.cobigen.cli.CobiGenCLI; -import com.devonfw.cobigen.cli.constants.MessagesConstants; - -/** - * Utilities class for CobiGen related operations. Handles everything related to custom templates folder - * destination and configuration file management - */ -public class ConfigurationUtils { - - /** - * Name of templates folder - */ - public static final String COBIGEN_TEMPLATES = "CobiGen_Templates"; - - /** - * Name of configuration file - */ - private static final String COBIGEN_CONFIG = "config.txt"; - - /** - * Folder to store template utility classes in - */ - public static final String COBIGEN_UTILITY_CLASSES_FOLDER = "target/classes"; - - /** - * Name of configuration key for custom templates file path - */ - private static final String COBIGEN_CONFIG_LOCATION_KEY = "cobigen.custom-templates-location"; - - /** - * Logger to output useful information to the user - */ - private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class); - - /** - * Checks if the configuration file exists and returns the path of the custom templates location key - * @return Path of custom templates location or null - */ - public static Path getCustomTemplatesLocation() { - if (Files.exists(getCobigenCliRootPath().resolve(COBIGEN_CONFIG))) { - Properties props = readConfigFileProperties(); - return Paths.get(props.getProperty(COBIGEN_CONFIG_LOCATION_KEY)); - } else { - return null; - } - } - - /** - * @return Path of Cobigen CLI root - */ - public static Path getCobigenCliRootPath() { - Path rootCLIPath = null; - try { - File locationCLI = new File(CobiGenUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()); - rootCLIPath = locationCLI.getParentFile().toPath(); - } catch (URISyntaxException e) { - LOG.error("An URISyntaxException occured while building the URI of the CLI location", e); - } - return rootCLIPath; - } - - /** - * Checks if custom templates location path exists and either returns the path of the default location - * next to the CLI or the custom templates location defined in the configuration - * @return Path of Cobigen templates folder, null if the folder does not exist - */ - public static Path getCobigenTemplatesFolderPath() { - Path pathForCobigenTemplates; - - Path customTemplatesLocation = getCustomTemplatesLocation(); - if (customTemplatesLocation != null) { - pathForCobigenTemplates = getCustomTemplatesLocation(); - } else { - pathForCobigenTemplates = getCobigenCliRootPath(); - } - - Path cobigenTemplatesFolder = null; - if (pathForCobigenTemplates != null) { - cobigenTemplatesFolder = pathForCobigenTemplates.resolve(COBIGEN_TEMPLATES); - } - - if (Files.exists(cobigenTemplatesFolder)) { - return cobigenTemplatesFolder; - } else { - return null; - } - } - - /** - * @return boolean true if the folder specified in configuration file exists, false if not - */ - public static boolean customTemplatesLocationExists() { - - Path pathForCobigenTemplates = getCustomTemplatesLocation(); - - Path cobigenTemplatesFolder = null; - if (pathForCobigenTemplates != null) { - cobigenTemplatesFolder = pathForCobigenTemplates.resolve(COBIGEN_TEMPLATES); - } - - if (pathForCobigenTemplates != null && !Files.exists(cobigenTemplatesFolder)) { - LOG.info("Please check your configuration file as no templates folder was found at the provided path!"); - return false; - } - return true; - } - - /** - * Creates a configuration file next to the CLI executable and stores the location of the custom templates - * folder in it - * @param customTemplatesLocation - * File location to store in configuration file - * @throws IOException - * if the configuration file could not created - */ - public static void createConfigFile(Path customTemplatesLocation) throws IOException { - Path path = getCobigenCliRootPath().resolve(COBIGEN_CONFIG); - Properties props = new Properties(); - props.setProperty(COBIGEN_CONFIG_LOCATION_KEY, customTemplatesLocation.toString()); - props.store(new FileOutputStream(path.toFile()), MessagesConstants.CUSTOM_LOCATION_OPTION_DESCRIPTION); - } - - /** - * Reads the configuration file and returns all of its properties - * @return Properties - */ - public static Properties readConfigFileProperties() { - Properties props = new Properties(); - - Path path = getCobigenCliRootPath().resolve(COBIGEN_CONFIG); - try (BufferedReader reader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { - props.load(reader); - } catch (IOException e) { - LOG.error("An error occured while reading the config file", e); - } - return props; - } - - /** - * Processes the input file's path. Strips the quotes from the file path if they are given. - * @param inputFile - * the input file - * @return input file with processed path - */ - public static File preprocessInputFile(File inputFile) { - String path = inputFile.getPath(); - String pattern = "[\\\"|\\'](.+)[\\\"|\\']"; - boolean matches = path.matches(pattern); - if (matches) { - path = path.replace("\"", ""); - path = path.replace("\'", ""); - return new File(path); - } - - return inputFile; - } -} diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java index eacd54bb62..45866f5e69 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java @@ -1,21 +1,16 @@ package com.devonfw.cobigen.cli.commandtests; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; +import com.devonfw.cobigen.api.util.CobiGenPathUtil; import com.devonfw.cobigen.cli.commands.CobiGenCommand; -import com.devonfw.cobigen.cli.utils.ConfigurationUtils; import com.ea.agentloader.AgentLoader; import classloader.Agent; @@ -44,82 +39,20 @@ public void loadJavaAgent() { AgentLoader.loadAgentClass(Agent.class.getName(), ""); } - /** Declare ArrayList variable for adding generated files */ - private ArrayList generatedFilesList = new ArrayList<>(); - /** - * Checks if adapt-templates command successfully created custom cobigen templates folder + * Checks if adapt-templates command successfully created cobigen templates folder + * @throws IOException */ @Test - public void adaptTemplatesTest() { + public void adaptTemplatesTest() throws IOException { String args[] = new String[1]; args[0] = "adapt-templates"; commandLine.execute(args); - Path cobigenTemplatesFolderPath = - ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); - - assertTrue(Files.exists(cobigenTemplatesFolderPath)); - } - - /** - * Checks if adapt-templates command successfully created a custom cobigen templates folder at a new - * location stored in configuration file - */ - @Test - public void customTemplatesLocationTest() { - - Path outputRootPath = Paths.get(testFileRootPath).resolve("generatedcode/root").toAbsolutePath(); - - String args[] = new String[3]; - args[0] = "adapt-templates"; - args[1] = "--custom-location"; - args[2] = outputRootPath.toString(); - - commandLine.execute(args); - - Path cobigenTemplatesFolderPath = ConfigurationUtils.getCobigenTemplatesFolderPath(); - + Path cobigenTemplatesFolderPath = CobiGenPathUtil.getTemplatesFolderPath(); assertTrue(Files.exists(cobigenTemplatesFolderPath)); - - File generatedFiles = cobigenTemplatesFolderPath.toFile(); - - generatedFilesList.add(generatedFiles); - // If you want to remove the generated files - AdaptTemplatesCommandTest.deleteGeneratedFiles(generatedFilesList); - generatedFilesList.clear(); - } - - /** - * Checks if adapt-templates command throws an error if the input path is faulty/not existing - */ - @Test - public void customTemplateLocationInvalidInputThrowsErrorTest() { - - String args[] = new String[3]; - args[0] = "adapt-templates"; - args[1] = "--custom-location"; - args[2] = "invalid/path/to/test"; - - assertEquals(1, commandLine.execute(args)); - } - - /** - * This method is check whether generated file is exist or not - * @param generateFiles - * list of generated files - */ - private static void deleteGeneratedFiles(ArrayList generateFiles) { - - for (File generatedFile : generateFiles) { - assertTrue(generatedFile.exists()); - try { - FileUtils.deleteDirectory(generatedFile); - } catch (IOException e) { - continue; - } - } + assertTrue(Files.list(cobigenTemplatesFolderPath).count() > 0); } } From c82cfb1e215c8b5f0c532b969b818174e1f41d1b Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Fri, 4 Dec 2020 15:13:04 +0100 Subject: [PATCH 09/19] #1267 updated dependencies --- cobigen-cli/cli/src/main/resources/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index 474425fb48..eb0657bbd1 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -18,7 +18,7 @@ com.devonfw.cobigen tsplugin - 7.0.0 + 7.1.0 com.devonfw.cobigen @@ -28,12 +28,12 @@ com.devonfw.cobigen textmerger - 7.0.0 + 7.1.0 com.devonfw.cobigen openapiplugin - 7.0.0 + 7.1.0 com.devonfw.cobigen From e8f0306efe7698e617ee605aadb6635385b17528 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Fri, 4 Dec 2020 15:47:12 +0100 Subject: [PATCH 10/19] #1267 updated property plugin dependency --- cobigen-cli/cli/src/main/resources/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index eb0657bbd1..db807fb628 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -48,7 +48,7 @@ com.devonfw.cobigen propertyplugin - 7.0.0 + 7.1.0 com.devonfw.cobigen From ea319ced79a535f2d7a5bc7b29b87a3100813518 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Mon, 7 Dec 2020 13:31:31 +0100 Subject: [PATCH 11/19] #1267 updated javaplugin dependency --- cobigen-cli/cli/src/main/resources/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index db807fb628..6dc801eba8 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -13,7 +13,7 @@ com.devonfw.cobigen javaplugin - 7.0.0 + 7.1.0 com.devonfw.cobigen From bc76b2e4c87722e4ddd6b492e9be5e07da53a813 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Mon, 7 Dec 2020 17:01:34 +0100 Subject: [PATCH 12/19] fixed messed up merging --- .../cobigen/cli/commandtests/AdaptTemplatesCommandTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java index 845d1819df..4f21286697 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java @@ -15,6 +15,7 @@ import com.devonfw.cobigen.api.util.CobiGenPathUtil; import com.devonfw.cobigen.cli.commands.CobiGenCommand; +import com.devonfw.cobigen.cli.utils.ConfigurationUtils; import com.ea.agentloader.AgentLoader; import classloader.Agent; From a57402e49c4f83ebc1549b03fddfa161787d6830 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Mon, 7 Dec 2020 17:05:48 +0100 Subject: [PATCH 13/19] attempted to fix merge issues --- .../commandtests/AdaptTemplatesCommandTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java index 4f21286697..6e4aefb9de 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java @@ -1,9 +1,8 @@ package com.devonfw.cobigen.cli.commandtests; -// import static org.junit.Assert.assertTrue; - -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertTrue; +//import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -56,14 +55,14 @@ public void adaptTemplatesTest() throws IOException { commandLine.execute(args); - //Path cobigenTemplatesFolderPath = CobiGenPathUtil.getTemplatesFolderPath(); - //assertTrue(Files.exists(cobigenTemplatesFolderPath)); - //assertTrue(Files.list(cobigenTemplatesFolderPath).count() > 0); + Path cobigenTemplatesFolderPath = CobiGenPathUtil.getTemplatesFolderPath(); + assertTrue(Files.exists(cobigenTemplatesFolderPath)); + assertTrue(Files.list(cobigenTemplatesFolderPath).count() > 0); - Path cobigenTemplatesFolderPath = - ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); + //Path cobigenTemplatesFolderPath = + // ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); - assertThat(Files.exists(cobigenTemplatesFolderPath)); + //assertThat(Files.exists(cobigenTemplatesFolderPath)); } /** From e3a979a1e3b42a68c410495ed1e86a5968b3e0f6 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Mon, 7 Dec 2020 17:11:37 +0100 Subject: [PATCH 14/19] updated core dependencies --- cobigen-cli/cli/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cobigen-cli/cli/pom.xml b/cobigen-cli/cli/pom.xml index 372654f963..1d568bec05 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -24,17 +24,17 @@ com.devonfw.cobigen core - 7.0.0 + 7.1.0 com.devonfw.cobigen core-api - 7.0.0 + 7.1.0 com.devonfw.cobigen core-test - 7.0.0 + 7.1.0 info.picocli From 2a4a40f79b33a02c31addf3f28481b334014f856 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Mon, 7 Dec 2020 17:38:39 +0100 Subject: [PATCH 15/19] removed wrongly merged content --- .../AdaptTemplatesCommandTest.java | 68 +------------------ 1 file changed, 3 insertions(+), 65 deletions(-) diff --git a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java index 6e4aefb9de..b9cebb563e 100644 --- a/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli/src/test/java/com/devonfw/cobigen/cli/commandtests/AdaptTemplatesCommandTest.java @@ -1,10 +1,8 @@ package com.devonfw.cobigen.cli.commandtests; - import static org.junit.Assert.assertTrue; //import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -14,7 +12,6 @@ import com.devonfw.cobigen.api.util.CobiGenPathUtil; import com.devonfw.cobigen.cli.commands.CobiGenCommand; -import com.devonfw.cobigen.cli.utils.ConfigurationUtils; import com.ea.agentloader.AgentLoader; import classloader.Agent; @@ -59,68 +56,9 @@ public void adaptTemplatesTest() throws IOException { assertTrue(Files.exists(cobigenTemplatesFolderPath)); assertTrue(Files.list(cobigenTemplatesFolderPath).count() > 0); - //Path cobigenTemplatesFolderPath = - // ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); - - //assertThat(Files.exists(cobigenTemplatesFolderPath)); - } - - /** - * Checks if adapt-templates command successfully created a custom cobigen templates folder at a new - * location stored in configuration file - */ - @Test - public void customTemplatesLocationTest() { - - Path outputRootPath = Paths.get(testFileRootPath).resolve("generatedcode/root").toAbsolutePath(); - - String args[] = new String[3]; - args[0] = "adapt-templates"; - args[1] = "--custom-location"; - args[2] = outputRootPath.toString(); - - commandLine.execute(args); - - Path cobigenTemplatesFolderPath = ConfigurationUtils.getCobigenTemplatesFolderPath(); - - assertThat(Files.exists(cobigenTemplatesFolderPath)); - - File generatedFiles = cobigenTemplatesFolderPath.toFile(); - - generatedFilesList.add(generatedFiles); - // If you want to remove the generated files - AdaptTemplatesCommandTest.deleteGeneratedFiles(generatedFilesList); - generatedFilesList.clear(); - } - - /** - * Checks if adapt-templates command throws an error if the input path is faulty/not existing - */ - @Test - public void customTemplateLocationInvalidInputThrowsErrorTest() { - - String args[] = new String[3]; - args[0] = "adapt-templates"; - args[1] = "--custom-location"; - args[2] = "invalid/path/to/test"; - - assertThat(commandLine.execute(args)).isEqualTo(1); - } - - /** - * This method is check whether generated file is exist or not - * @param generateFiles - * list of generated files - */ - private static void deleteGeneratedFiles(ArrayList generateFiles) { + // Path cobigenTemplatesFolderPath = + // ConfigurationUtils.getCobigenCliRootPath().resolve(ConfigurationUtils.COBIGEN_TEMPLATES); - for (File generatedFile : generateFiles) { - assertThat(generatedFile.exists()); - try { - FileUtils.deleteDirectory(generatedFile); - } catch (IOException e) { - continue; - } - } + // assertThat(Files.exists(cobigenTemplatesFolderPath)); } } From d6452567741c7148a1a90cc0c1de7c5bd9eb78c1 Mon Sep 17 00:00:00 2001 From: lilliCao Date: Tue, 8 Dec 2020 17:50:10 +0100 Subject: [PATCH 16/19] adapt templates before execute GenerateCommandTest --- .../devonfw/cobigen/cli/commandtests/GenerateCommandTest.java | 4 ++++ 1 file changed, 4 insertions(+) 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 c347d9d291..623dc5900c 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 @@ -51,6 +51,10 @@ public void loadJavaAgent() { args[0] = "update"; args[1] = "--all"; commandLine.execute(args); + + String args2[] = new String[1]; + args2[0] = "adapt-templates"; + commandLine.execute(args2); } /** From cb0cc29359492c429a766f15d40598b6e31bb35d Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Thu, 17 Dec 2020 15:53:11 +0100 Subject: [PATCH 17/19] adjusted test project poms to have proper versioning --- .../testdata/localmavenproject/maven.project/api/pom.xml | 2 +- .../testdata/localmavenproject/maven.project/core/pom.xml | 4 ++-- .../testdata/localmavenproject/maven.project/pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 59bce52286..e2c6027e38 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 @@ -5,7 +5,7 @@ testing maven.project - 0.0.1-SNAPSHOT + dev-SNAPSHOT api jar 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 d93a0095f9..def8047df2 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 @@ -4,7 +4,7 @@ testing maven.project - 0.0.1-SNAPSHOT + dev-SNAPSHOT core jar @@ -19,7 +19,7 @@ testing api - 0.0.1-SNAPSHOT + dev-SNAPSHOT javax.persistence 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 bf1c159042..4e46f9ebda 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.1.0-SNAPSHOT + dev-SNAPSHOT pom Test_Local_Maven_Project From 4024437f894d7b33c8405e7ffa233584a48036dd Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Thu, 17 Dec 2020 15:58:51 +0100 Subject: [PATCH 18/19] #1303 update wiki docs --- .../test/resources/testdata/openAPI file.yml | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml diff --git a/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml b/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml deleted file mode 100644 index 420efdc81a..0000000000 --- a/cobigen-cli/cli/src/test/resources/testdata/openAPI file.yml +++ /dev/null @@ -1,111 +0,0 @@ -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 397b2554e6570b7307955cffb3397cdfc1e6d7ae Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Thu, 17 Dec 2020 15:58:54 +0100 Subject: [PATCH 19/19] #1303 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 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cobigen-cli/class-loader-agent/pom.xml b/cobigen-cli/class-loader-agent/pom.xml index 4d4421e0dd..e8ca4162dc 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.1.0-SNAPSHOT + 7.1.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 1d568bec05..3a2415abbb 100644 --- a/cobigen-cli/cli/pom.xml +++ b/cobigen-cli/cli/pom.xml @@ -1,7 +1,7 @@ 4.0.0 cli - 7.1.0-SNAPSHOT + 7.1.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 6dc801eba8..0f4a8679ba 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.1.0-SNAPSHOT + 7.1.0 cobigen-cli