diff --git a/.gitignore b/.gitignore
index 1a14279e5f..978e10ba4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,3 +41,11 @@ objectdb
/cobigen/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar
cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar
cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set1-test-test.jar
+cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0.jar
+cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar
+cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0.jar
+cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0-sources.jar
+cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-1.0.0.jar
+cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar
+cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-complex-1.0.0.jar
+cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-complex-1.0.0-sources.jar
diff --git a/cobigen-cli/cli-systemtest/pom.xml b/cobigen-cli/cli-systemtest/pom.xml
index 7f04c1a53a..d1d14b8730 100644
--- a/cobigen-cli/cli-systemtest/pom.xml
+++ b/cobigen-cli/cli-systemtest/pom.xml
@@ -12,7 +12,9 @@
src\test\resources\testdata\localmavenproject\maven.project
src\test\resources\testdata\templatesproject\templates-devon4j
- src\test\resources\testdata\templatesproject\template-sets/downloaded/crud-java-server-app
+ src\test\resources\testdata\templatesproject\template-sets\downloaded\crud-java-server-app
+ src\test\resources\testdata\AdaptTemplatesCommandIT\template-sets\adapted\crud-java-server-app
+ src\test\resources\testdata\AdaptTemplatesCommandIT\template-sets\adapted\crud-java-server-app-complex
@@ -131,6 +133,44 @@
+
+ Install AdaptTemplatesCommandIT downloaded project1
+ test-compile
+
+ exec
+
+
+ mvn
+ ${maven.test.AdaptTemplatesCommandIT.downloaded.path1}
+
+ install
+
+ -Djansi.force=true
+ -Djansi.passthrough=true
+ -B
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+
+
+
+
+ Install AdaptTemplatesCommandIT downloaded project2
+ test-compile
+
+ exec
+
+
+ mvn
+ ${maven.test.AdaptTemplatesCommandIT.downloaded.path2}
+
+ install
+
+ -Djansi.force=true
+ -Djansi.passthrough=true
+ -B
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+
+
+
diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java
index 256dee2ba3..ec4a308673 100644
--- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java
+++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java
@@ -6,7 +6,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
-import org.junit.Ignore;
+import org.apache.commons.io.FileUtils;
import org.junit.Test;
import com.devonfw.cobigen.api.constants.ConfigurationConstants;
@@ -17,28 +17,23 @@
*/
public class AdaptTemplatesCommandIT extends AbstractCliTest {
+ /** Test resources root path */
+ private static String testFileRootPath = "src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded";
+
/**
* Checks if adapt-templates command successfully created adapted folder and its sub folders
*
* @throws Exception test fails
*/
@Test
- @Ignore // TODO: re-enable when template set adaptation is implemented
public void adaptTemplateSetTest() throws Exception {
- Path cliSystemTestPath = new File(
- AdaptTemplatesCommandIT.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
- .getParentFile().toPath();
- Path templateJar = cliSystemTestPath.resolve("src/test/resources/testdata/crud-java-server-app.jar");
- if (Files.exists(templateJar)) {
- Path downloadedTemplateSetsPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)
- .resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
- if (!Files.exists(downloadedTemplateSetsPath)) {
- Files.createDirectories(downloadedTemplateSetsPath);
- }
- Files.copy(templateJar, downloadedTemplateSetsPath.resolve(templateJar.getFileName()));
+ Path downloadedTemplateSetsPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
+ if (!Files.exists(downloadedTemplateSetsPath)) {
+ Files.createDirectories(downloadedTemplateSetsPath);
}
-
+ FileUtils.copyDirectory(new File(testFileRootPath), downloadedTemplateSetsPath.toFile());
String args[] = new String[2];
args[0] = "adapt-templates";
args[1] = "--all";
@@ -54,14 +49,49 @@ public void adaptTemplateSetTest() throws Exception {
assertThat(downloadedTemplateSetsFolderPath).exists();
assertThat(adaptedTemplateSetsFolderPath).exists();
+ Path templateSetSimple = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-1.0.0");
+ Path templateSetComplex = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-complex-1.0.0");
+
// check if adapted template set exists
- Path templateSet = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app");
- assertThat(templateSet).exists();
- // check if context configuration exists
- assertThat(templateSet.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)).exists();
- assertThat(templateSet.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)
+ assertThat(templateSetSimple).exists();
+ assertThat(templateSetComplex).exists();
+
+ Path templateSetResourcesPath = templateSetSimple
+ .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
+ Path templateSetResourcesPathComplex = templateSetComplex
+ .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
+
+ // check if templates folder exists
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
+ .exists();
+ assertThat(
+ templateSetComplex.resolve(templateSetResourcesPathComplex).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
+ .exists();
+
+ // check if template-set.xml exists
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
+ assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex)
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
+ // validate correct folder structure
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();
+ assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();
+
+ // check if template set utility resource folder exists
+ assertThat(templateSetSimple.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
+ assertThat(templateSetComplex.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
+
+ // validate maven specific contents
+ assertThat(templateSetSimple.resolve("pom.xml")).exists();
+ assertThat(templateSetComplex.resolve("pom.xml")).exists();
+
+ // check if META-INF was deleted
+ assertThat(templateSetResourcesPath.resolve("META-INF")).doesNotExist();
+ assertThat(templateSetResourcesPathComplex.resolve("META-INF")).doesNotExist();
+
}
/**
@@ -69,17 +99,16 @@ public void adaptTemplateSetTest() throws Exception {
*
* @throws Exception test fails
*/
+
@Test
public void adaptTemplatesTest() throws Exception {
- Path cliSystemTestPath = new File(
- AdaptTemplatesCommandIT.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
- .getParentFile().toPath();
Path templatesPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATES_FOLDER);
Path CobigenTemplatesPath = templatesPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
if (!Files.exists(templatesPath)) {
Files.createDirectories(templatesPath);
}
+
TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", false, templatesPath.toFile());
TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", true, templatesPath.toFile());
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml
new file mode 100644
index 0000000000..3c69a2539d
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+ com.devonfw.test
+ crud-java-server-app-complex
+ 1.0.0
+ jar
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
+ ${skip.deployment}
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.7
+
+ UTF-8
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ generate-maven-properties-class
+
+ filter-sources
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+ prepare-package
+
+ run
+
+
+
+ Integrate POM manually
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml
new file mode 100644
index 0000000000..5cfe219789
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
new file mode 100644
index 0000000000..0c233890ea
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
@@ -0,0 +1 @@
+package test;
\ No newline at end of file
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml
new file mode 100644
index 0000000000..3558920d14
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+ com.devonfw.test
+ crud-java-server-app
+ 1.0.0
+ jar
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
+ ${skip.deployment}
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.7
+
+ UTF-8
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ generate-maven-properties-class
+
+ filter-sources
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+ prepare-package
+
+ run
+
+
+
+ Integrate POM manually
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml
new file mode 100644
index 0000000000..4515b452ec
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
new file mode 100644
index 0000000000..0c233890ea
--- /dev/null
+++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
@@ -0,0 +1 @@
+package test;
\ No newline at end of file
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 aeb5789ef3..7ceceef9d1 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
@@ -25,7 +25,6 @@
@Command(description = MessagesConstants.ADAPT_TEMPLATES_DESCRIPTION, name = "adapt-templates", aliases = {
"a" }, mixinStandardHelpOptions = true)
public class AdaptTemplatesCommand extends CommandCommons {
-
/**
* Logger to output useful information to the user
*/
@@ -48,7 +47,6 @@ public class AdaptTemplatesCommand extends CommandCommons {
public Integer doAction() throws Exception {
TemplateAdapter templateAdapter = new TemplateAdapterImpl(this.templatesProject);
-
try {
templateAdapter.adaptTemplates();
} catch (UpgradeTemplatesNotificationException e) {
@@ -57,7 +55,7 @@ public Integer doAction() throws Exception {
}
} catch (TemplateSelectionForAdaptionException e) {
List templateJars = e.getTemplateSets();
- if (templateJars != null && !templateJars.isEmpty()) {
+ if (!templateJars.isEmpty()) {
List templateJarsToAdapt = getJarsToAdapt(templateAdapter, templateJars);
if (!templateJarsToAdapt.isEmpty()) {
templateAdapter.adaptTemplateSets(templateJarsToAdapt, false);
@@ -66,7 +64,6 @@ public Integer doAction() throws Exception {
LOG.info("No template set jars found to extract.");
}
}
-
return 0;
}
@@ -81,9 +78,7 @@ private List getJarsToAdapt(TemplateAdapter templateAdapter, List te
List jarsToAdapt = new ArrayList<>();
if (templateJars != null && templateJars.size() > 0) {
printJarsForSelection(templateAdapter, templateJars);
-
List userSelection = new ArrayList<>();
-
if (this.adaptAll) {
userSelection.add("0");
} else {
@@ -91,7 +86,6 @@ private List getJarsToAdapt(TemplateAdapter templateAdapter, List te
userSelection.add(templateSelection);
}
}
-
if (userSelection.contains("0")) {
jarsToAdapt = templateJars;
} else {
@@ -100,7 +94,6 @@ private List getJarsToAdapt(TemplateAdapter templateAdapter, List te
}
}
}
-
return jarsToAdapt;
}
@@ -135,4 +128,4 @@ private boolean askUserToContinueWithUpgrade(UpgradeTemplatesNotificationExcepti
}
return false;
}
-}
+}
\ No newline at end of file
diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/TemplateAdapter.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/TemplateAdapter.java
index ccd21eaa73..77570f0d9f 100644
--- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/TemplateAdapter.java
+++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/TemplateAdapter.java
@@ -9,7 +9,6 @@
/** The TemplateAdapter implements methods for adapting template jars */
public interface TemplateAdapter {
-
/**
* Adapt the templates. Can either adapt an old monolithic template structure or independent template sets.
*
@@ -95,4 +94,4 @@ public void adaptTemplateSets(List templateSetJars, Path destinationPath,
* @return the new path to the new template-sets
*/
Path upgradeMonolithicTemplates(Path templatesProject);
-}
+}
\ No newline at end of file
diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/constants/ConfigurationConstants.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/constants/ConfigurationConstants.java
index 97cdbaabf1..5c498b8c2d 100644
--- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/constants/ConfigurationConstants.java
+++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/constants/ConfigurationConstants.java
@@ -23,6 +23,9 @@ public class ConfigurationConstants {
/** Template Set configuration file name */
public static final String TEMPLATE_SET_CONFIG_FILENAME = "template-set.xml";
+ /** Template Set filename for Freemarker functions */
+ public static final String TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME = "functions.ftl";
+
/** Filename of the {@link Properties} used to customize cobigen properties and template relocation. */
public static final String COBIGEN_PROPERTIES = "cobigen.properties";
diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/TemplateSelectionForAdaptionException.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/TemplateSelectionForAdaptionException.java
index f3ba1dde1d..841b2939cc 100644
--- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/TemplateSelectionForAdaptionException.java
+++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/exception/TemplateSelectionForAdaptionException.java
@@ -8,7 +8,6 @@
* adapted.
*/
public class TemplateSelectionForAdaptionException extends Exception {
-
/** Generated serial version UID */
private static final long serialVersionUID = 1;
@@ -34,4 +33,4 @@ public List getTemplateSets() {
return this.templateSets;
}
-}
+}
\ No newline at end of file
diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/TemplatesJarUtil.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/TemplatesJarUtil.java
index 5b7d7ebb9e..25da633bbf 100644
--- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/TemplatesJarUtil.java
+++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/TemplatesJarUtil.java
@@ -292,7 +292,7 @@ public static List getJarFiles(Path templatesDirectory) {
return jarPaths;
} else {
// There are no jars downloaded
- return null;
+ return jarPaths;
}
}
diff --git a/cobigen/cobigen-core-systemtest/pom.xml b/cobigen/cobigen-core-systemtest/pom.xml
index ee0458ccbe..ddbba0de87 100644
--- a/cobigen/cobigen-core-systemtest/pom.xml
+++ b/cobigen/cobigen-core-systemtest/pom.xml
@@ -7,6 +7,8 @@
src\test\resources\testdata\systemtest\GenerationTestTemplateSetsXml\template-sets\downloaded\downloaded1-test
src\test\resources\testdata\systemtest\GenerationTestTemplateSetsXml\template-sets\downloaded\downloaded2-test
+ src\test\resources\testdata\systemtest\TemplateProcessingTest\template-sets\adapted\crud-java-server-app
+ src\test\resources\testdata\systemtest\TemplateProcessingTest\template-sets\adapted\crud-java-server-app-complex
@@ -95,6 +97,44 @@
+
+ Install TemplateProcessingTest downloaded1 template set test project
+ test-compile
+
+ exec
+
+
+ mvn
+ ${maven.test.TemplateProcessingTest.adapted.path1}
+
+ install
+
+ -Djansi.force=true
+ -Djansi.passthrough=true
+ -B
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+
+
+
+
+ Install TemplateProcessingTest downloaded2 template set test project
+ test-compile
+
+ exec
+
+
+ mvn
+ ${maven.test.TemplateProcessingTest.adapted.path2}
+
+ install
+
+ -Djansi.force=true
+ -Djansi.passthrough=true
+ -B
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+
+
+
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
index dbcd8c4b8a..0ca72b57be 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
@@ -5,12 +5,11 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -27,86 +26,106 @@
*/
public class TemplateProcessingTest extends AbstractApiTest {
- // TODO jars has to be updated
- /**
- * Root path to all resources used in tests that test the structure of the template sets.
- */
- private static String testFileRootPathTemplateSets = apiTestsRootPath + "AdaptTemplateSetsTest/";
-
- /**
- * Root path to all resources used in tests that test the old monolithic template structure.
- */
- private static String testFileRootPathMonolithicTemplates = apiTestsRootPath + "AdaptMonolithicTemplatesTest/";
-
/** Temporary files rule to create temporary folders or files */
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
/**
- * temporary project to store CobiGen home for a project with the new template structure consisting of template sets.
- */
- Path cobiGenHomeTemplateSets;
-
- /**
- * temporary project to store CobiGen home for a project with the old template structure consisting of a monolitihic
- * template set
- */
- Path cobiGenHomeMonolithicTemplates;
-
- /**
- * Creates a temporary CobiGen home directory for each test. A separate directory to test the old and new structure.
- *
- * @throws IOException if an Exception occurs
- */
- @Before
- public void prepare() throws IOException {
-
- this.cobiGenHomeTemplateSets = this.tempFolder.newFolder("playground", "templateSetsHome").toPath();
- this.cobiGenHomeMonolithicTemplates = this.tempFolder.newFolder("playground", "templatesMonolithicHome").toPath();
- }
-
- /**
- * Tests if template sets can be extracted properly
+ * Tests if template sets can be adapted properly
*
* @throws IOException if an Exception occurs
+ * @throws Exception test fails
*/
@Test
- @Ignore // TODO: re-enable when template sets adaptation is implemented
- public void extractTemplateSetsTest() throws IOException {
-
- FileUtils.copyDirectory(new File(testFileRootPathTemplateSets), this.cobiGenHomeTemplateSets.toFile());
-
- Path templateSetsFolder = this.cobiGenHomeTemplateSets.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER);
- Path adaptedFolder = templateSetsFolder.resolve(ConfigurationConstants.ADAPTED_FOLDER);
- TemplateAdapter templateAdapter = new TemplateAdapterImpl(templateSetsFolder);
+ public void adaptTemplateSetsTest() throws IOException, Exception {
+
+ Path cobiGenHomeTemplateSets = this.tempFolder.newFolder("playground", "templateSetsHome").toPath();
+ Path downloadedTemplateSetsPath = cobiGenHomeTemplateSets.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
+ if (!Files.exists(downloadedTemplateSetsPath)) {
+ Files.createDirectories(downloadedTemplateSetsPath);
+ }
+ String testFileRootPath = "src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded";
+ FileUtils.copyDirectory(new File(testFileRootPath), downloadedTemplateSetsPath.toFile());
+
+ // Prepare the test directories
+ Path cobigenTemplateSetsFolderPath = cobiGenHomeTemplateSets.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER);
+ Path downloadedTemplateSetsFolderPath = cobigenTemplateSetsFolderPath
+ .resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
+ Path adaptedTemplateSetsFolderPath = cobigenTemplateSetsFolderPath.resolve(ConfigurationConstants.ADAPTED_FOLDER);
+
+ // Adapt the templates
+ TemplateAdapter templateAdapter = new TemplateAdapterImpl(cobigenTemplateSetsFolderPath);
Exception exception = assertThrows(TemplateSelectionForAdaptionException.class, () -> {
templateAdapter.adaptTemplates();
});
List templateSetJars = ((TemplateSelectionForAdaptionException) exception).getTemplateSets();
- templateAdapter.adaptTemplateSets(templateSetJars, adaptedFolder, false);
- // sources jar is needed or we remove the functionality
- Path extractedJar1 = adaptedFolder.resolve("template-test1-0.0.1")
- .resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER);
- Path extractedJar2 = adaptedFolder.resolve("template-test2-0.0.1")
- .resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER);
- assertThat(extractedJar1).exists().isDirectory();
- assertThat(extractedJar2).exists().isDirectory();
+ templateAdapter.adaptTemplateSets(templateSetJars, adaptedTemplateSetsFolderPath, false);
+
+ assertThat(cobigenTemplateSetsFolderPath).exists();
+ assertThat(downloadedTemplateSetsFolderPath).exists();
+ assertThat(adaptedTemplateSetsFolderPath).exists();
+
+ Path templateSetSimple = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-1.0.0");
+ Path templateSetComplex = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-complex-1.0.0");
+
+ // check if adapted template set exists
+ assertThat(templateSetSimple).exists();
+ assertThat(templateSetComplex).exists();
+
+ Path templateSetResourcesPath = templateSetSimple
+ .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
+ Path templateSetResourcesPathComplex = templateSetComplex
+ .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
+
+ // check if templates folder exists
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
+ .exists();
+ assertThat(
+ templateSetComplex.resolve(templateSetResourcesPathComplex).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
+ .exists();
+
+ // check if template-set.xml exists
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
+ assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
+
+ // validate correct folder structure
+ assertThat(templateSetSimple.resolve(templateSetResourcesPath)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();
+ assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex)
+ .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();
+
+ // check if template set utility resource folder exists
+ assertThat(templateSetSimple.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
+ assertThat(templateSetComplex.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
+
+ // validate maven specific contents
+ assertThat(templateSetSimple.resolve("pom.xml")).exists();
+ assertThat(templateSetComplex.resolve("pom.xml")).exists();
+
+ // check if META-INF was deleted
+ assertThat(templateSetResourcesPath.resolve("META-INF")).doesNotExist();
+ assertThat(templateSetResourcesPathComplex.resolve("META-INF")).doesNotExist();
}
/**
- * Test of extract templates with old CobiGen_Templates project existing
+ * Test of adapt templates with old CobiGen_Templates project existing
*
* @throws IOException if an Exception occurs
*/
@Test
- public void extractTemplatesWithOldConfiguration() throws IOException {
+ public void adaptTemplatesWithOldConfiguration() throws IOException {
+
+ String testFileRootPathMonolithicTemplates = apiTestsRootPath + "AdaptMonolithicTemplatesTest/";
+ Path cobiGenHomeMonolithicTemplates = this.tempFolder.newFolder("playground", "templatesMonolithicHome").toPath();
- FileUtils.copyDirectory(new File(testFileRootPathMonolithicTemplates),
- this.cobiGenHomeMonolithicTemplates.toFile());
+ FileUtils.copyDirectory(new File(testFileRootPathMonolithicTemplates), cobiGenHomeMonolithicTemplates.toFile());
- Path cobigenTemplatesParent = this.cobiGenHomeMonolithicTemplates
+ Path cobigenTemplatesParent = cobiGenHomeMonolithicTemplates
.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH);
Path cobigenTemplatesProject = cobigenTemplatesParent.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/pom.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/pom.xml
new file mode 100644
index 0000000000..3c69a2539d
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+ com.devonfw.test
+ crud-java-server-app-complex
+ 1.0.0
+ jar
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
+ ${skip.deployment}
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.7
+
+ UTF-8
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ generate-maven-properties-class
+
+ filter-sources
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+ prepare-package
+
+ run
+
+
+
+ Integrate POM manually
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml
new file mode 100644
index 0000000000..5cfe219789
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
new file mode 100644
index 0000000000..0c233890ea
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
@@ -0,0 +1 @@
+package test;
\ No newline at end of file
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/pom.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/pom.xml
new file mode 100644
index 0000000000..3558920d14
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+ com.devonfw.test
+ crud-java-server-app
+ 1.0.0
+ jar
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
+ ${skip.deployment}
+ ../../downloaded
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.7
+
+ UTF-8
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ generate-maven-properties-class
+
+ filter-sources
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+ prepare-package
+
+ run
+
+
+
+ Integrate POM manually
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml
new file mode 100644
index 0000000000..4515b452ec
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
new file mode 100644
index 0000000000..0c233890ea
--- /dev/null
+++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl
@@ -0,0 +1 @@
+package test;
\ No newline at end of file
diff --git a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/adapter/TemplateAdapterImpl.java b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/adapter/TemplateAdapterImpl.java
index 7fa04f4573..bbb91ae75e 100644
--- a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/adapter/TemplateAdapterImpl.java
+++ b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/adapter/TemplateAdapterImpl.java
@@ -14,9 +14,13 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
@@ -41,7 +45,6 @@
* template structure.
*/
public class TemplateAdapterImpl implements TemplateAdapter {
-
/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(TemplateAdapterImpl.class);
@@ -127,17 +130,34 @@ private void processTemplateSetJars(List templateSetJarsToAdapt, Path dest
}
if (extract) {
- if (Files.exists(destination) && forceOverride) {
+ if (!isEmpty(destination) && forceOverride) {
LOG.info("Override the existing destination folder {}", destination);
deleteDirectoryRecursively(destination);
}
- extractArchive(templateSetJar, destination);
- // com folder with precompiled util classes is not needed. The utils compiled at first generation into the
- // target folder
- if (Files.exists(destination.resolve("com"))) {
- FileUtils.deleteDirectory(destination.resolve("com").toFile());
+ Path resourcesDestinationPath = destination.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
+ // extract sources jar to target directory
+ String sourcesFileName = templateSetJar.getFileName().toString().replace(".jar", "-sources.jar");
+
+ extractArchive(templateSetJar.getParent().resolve(sourcesFileName), resourcesDestinationPath);
+
+ // delete META-INF folder
+ if (resourcesDestinationPath.resolve("META-INF").toFile().exists()) {
+ FileUtils.deleteDirectory(resourcesDestinationPath.resolve("META-INF").toFile());
+ }
+
+ // create src/main/java directory
+ Files.createDirectories(destination.resolve("src/main/java"));
+
+ // move com folder to src/main/java/com
+ Files.move(resourcesDestinationPath.resolve("com"), destination.resolve("src/main/java/com"),
+ StandardCopyOption.REPLACE_EXISTING);
+
+ URI zipFile = URI.create("jar:file:" + templateSetJar.toUri().getPath());
+ try (FileSystem fs = FileSystemUtil.getOrCreateFileSystem(zipFile)) {
+ Files.copy(fs.getPath("pom.xml"), destination.resolve("pom.xml"), StandardCopyOption.REPLACE_EXISTING);
}
+
}
}
}
@@ -175,56 +195,73 @@ private void extractMonolithicJar(Path destinationPath, boolean forceOverride) t
LOG.info("Override the existing destination folder {}", destinationPath);
deleteDirectoryRecursively(destinationPath);
}
-
Path sourcesJarPath = TemplatesJarUtil.getJarFile(true, this.templatesLocation);
Path classesJarPath = TemplatesJarUtil.getJarFile(false, this.templatesLocation);
-
if (sourcesJarPath == null && classesJarPath == null) {
LOG.info("No monolithic jar found in {}!", this.templatesLocation);
return;
}
-
LOG.debug("Processing jar file @ {}", sourcesJarPath);
-
// extract sources jar to target directory
extractArchive(sourcesJarPath, destinationPath);
-
// create src/main/java directory
Files.createDirectory(destinationPath.resolve("src/main/java"));
-
// move com folder to src/main/java/com
Files.move(destinationPath.resolve("com"), destinationPath.resolve("src/main/java/com"),
StandardCopyOption.REPLACE_EXISTING);
-
// create src/main/resources directory
Files.createDirectory(destinationPath.resolve("src/main/resources"));
-
// move META-INF folder to src/main/resources
Files.move(destinationPath.resolve("META-INF"), destinationPath.resolve("src/main/resources/META-INF"),
StandardCopyOption.REPLACE_EXISTING);
-
// delete MANIFEST.MF
Files.deleteIfExists(destinationPath.resolve("src/main/resources/META-INF/MANIFEST.MF"));
-
URI zipFile = URI.create("jar:file:" + classesJarPath.toUri().getPath());
-
// extract classes jar pom.xml
try (FileSystem fs = FileSystemUtil.getOrCreateFileSystem(zipFile)) {
Files.copy(fs.getPath("pom.xml"), destinationPath.resolve("pom.xml"), StandardCopyOption.REPLACE_EXISTING);
}
-
LOG.info("Successfully extracted templates to @ {}", destinationPath);
}
@Override
public List getTemplateSetJars() {
+ List resultJars = new ArrayList<>();
+
Path downloadedJarsFolder = this.templatesLocation.resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
if (!Files.exists(downloadedJarsFolder)) {
LOG.info("No template set jars found. Folder {} does not exist.", downloadedJarsFolder);
- return null;
+ return resultJars;
+ }
+
+ List JarFiles = TemplatesJarUtil.getJarFiles(downloadedJarsFolder);
+ Map> jarMap = JarFiles.stream()
+ .collect(Collectors.partitioningBy(f -> f.getFileName().toString().contains("-sources.jar")));
+ List templateSetJars = jarMap.get(false);
+ List templateSetJarsSources = jarMap.get(true);
+
+ for (Path templateSetjar : templateSetJars) {
+ String fileName = templateSetjar.getFileName().toString().replace(".jar", "");
+ Iterator sourcesJarsIterator = templateSetJarsSources.iterator();
+ while (sourcesJarsIterator.hasNext()) {
+ if (sourcesJarsIterator.next().getFileName().toString().contains(fileName)) {
+ sourcesJarsIterator.remove();
+ resultJars.add(templateSetjar);
+ break;
+ }
+ }
+ }
+
+ templateSetJars.removeAll(resultJars);
+ if (!templateSetJars.isEmpty()) {
+ for (Path jarWithMissingSource : templateSetJars) {
+ LOG.error("Missing Source for Jar: " + jarWithMissingSource.getFileName());
+ // no matching source file found either download or handle somehow
+ // TODO throw Exception or download the missing source
+ }
}
- return TemplatesJarUtil.getJarFiles(downloadedJarsFolder);
+ return resultJars;
}
@Override
@@ -273,7 +310,6 @@ private void extractArchive(Path sourcePath, Path targetPath) throws IOException
if (FileSystemUtil.isZipFile(sourcePath.toUri())) {
// Important cast for jdk 17 compatibility
FileSystem fs = FileSystems.newFileSystem(sourcePath, (ClassLoader) null);
-
Path path = fs.getPath("/");
Files.walkFileTree(path, new SimpleFileVisitor() {
@Override
@@ -314,12 +350,10 @@ private boolean validatePaths(Path destinationPath, boolean forceOverride) throw
Objects.requireNonNull(this.templatesLocation, "Templates location cannot be null");
Objects.requireNonNull(destinationPath, "Destination path cannot be null");
-
if (!Files.exists(this.templatesLocation)) {
LOG.info("Templates location {} does not exist.", this.templatesLocation);
return false;
}
-
if (!Files.isDirectory(destinationPath)) {
try {
Files.createDirectories(destinationPath);
@@ -327,11 +361,9 @@ private boolean validatePaths(Path destinationPath, boolean forceOverride) throw
throw new CobiGenRuntimeException("Unable to create directory " + destinationPath);
}
}
-
if (!isEmpty(destinationPath) && !forceOverride) {
throw new DirectoryNotEmptyException(destinationPath.toString());
}
-
return true;
}
@@ -373,13 +405,10 @@ public Path upgradeMonolithicTemplates(Path templatesProject) {
CobigenTemplates = CobiGenPaths.getPomLocation(templatesPath);
}
AbstractConfigurationUpgrader contextUpgraderObject = new ContextConfigurationUpgrader();
-
// Upgrade the context.xml to the new template-set with latest version
contextUpgraderObject.upgradeConfigurationToLatestVersion(templatesPath, BackupPolicy.NO_BACKUP);
-
LOG.info("context.xml upgraded successfully. {}", templatesPath);
LOG.info("Templates successfully upgraded. \n ");
-
// check the new Path to the template-set after the upgrade
Path newTemplates;
if (templatesProject == null) {
@@ -389,7 +418,6 @@ public Path upgradeMonolithicTemplates(Path templatesProject) {
newTemplates = Paths.get(ConfigurationFinder.findTemplatesLocation());
} else {
// 2. otherwise check in the given customTemplates
-
// check renaming
// 2.1 renaming from CobiGen_Templates to template-sets occurred
if (Files.exists(CobigenTemplates.getParent().resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)))
@@ -403,4 +431,4 @@ public Path upgradeMonolithicTemplates(Path templatesProject) {
LOG.info("New templates location: {} ", newTemplates);
return newTemplates;
}
-}
+}
\ No newline at end of file
diff --git a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplateSetConfigurationManager.java b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplateSetConfigurationManager.java
index be3cb11068..e32b478389 100644
--- a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplateSetConfigurationManager.java
+++ b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/TemplateSetConfigurationManager.java
@@ -115,8 +115,9 @@ protected List loadTemplateSetFilesDownloaded(Path configRoot) {
// We need to empty this list to prevent duplicates from being added
this.templateSetPaths.clear();
+ // TODO: add check for valid templatesetjar util
List templateJars = TemplatesJarUtil.getJarFiles(configRoot);
- if (templateJars != null) {
+ if (!templateJars.isEmpty()) {
for (Path jarPath : templateJars) {
Path configurationPath = FileSystemUtil.createFileSystemDependentPath(jarPath.toUri());
Path templateSetFilePath = configurationPath.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME);
diff --git a/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/adapter/TemplateAdapterTest.java b/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/adapter/TemplateAdapterTest.java
index c3f2d931ba..e7713f1a01 100644
--- a/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/adapter/TemplateAdapterTest.java
+++ b/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/adapter/TemplateAdapterTest.java
@@ -7,7 +7,6 @@
import java.nio.file.Path;
import java.util.List;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -21,87 +20,132 @@
*/
public class TemplateAdapterTest {
- /**
- * Root Path for tests with the monolithic template structure
- */
- private static Path rootTestPathMonolithicTemplates;
-
- /**
- * Root Path for tests with the template set structure
- */
- private static Path rootTestPathTemplateSets;
-
/** Temporary files rule to create temporary folders or files */
@ClassRule
public static TemporaryFolder tempFolder = new TemporaryFolder();
/**
- * Creates a temporary directory structure for the tests
+ * Tests if the {@link TemplateAdapter} isMonolithicTemplatesConfiguration() recognizes that it is an old monolithic
+ * template structure
+ *
+ * @throws IOException test fails
*
- * @throws IOException if an Exception occurs
*/
- @BeforeClass
- public static void prepare() throws IOException {
+ @Test
+ public void testIsMonolithicTemplatesConfigurationWithOldConfig() throws IOException {
- rootTestPathMonolithicTemplates = tempFolder
+ Path rootTestPathMonolithicTemplates = tempFolder
.newFolder("homeMonolithicTemplates", ConfigurationConstants.TEMPLATES_FOLDER).toPath();
- Files.createFile(rootTestPathMonolithicTemplates.resolve("template.jar"));
- rootTestPathTemplateSets = tempFolder.newFolder("homeTemplateSets", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathMonolithicTemplates);
+ assertThat(templateAdapter.isMonolithicTemplatesConfiguration()).isTrue();
+ }
+
+ /**
+ * Tests if the {@link TemplateAdapter} isMonolithicTemplatesConfiguration() recognizes that it is a new template
+ * structure
+ *
+ * @throws IOException test fails
+ *
+ */
+ @Test
+ public void testIsMonolithicTemplatesConfigurationWithNewConfig() throws IOException {
+
+ Path rootTestPathTemplateSets = tempFolder.newFolder("NotMonolithic", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
.toPath();
- Path downloadedFolder = Files
- .createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
- Files.createFile(downloadedFolder.resolve("template-set-1.jar"));
- Files.createFile(downloadedFolder.resolve("template-set-2.jar"));
- Path adaptedFolder = Files.createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.ADAPTED_FOLDER));
- Files.createDirectory(adaptedFolder.resolve("template-set-1"));
+ Files.createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
+
+ TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathTemplateSets);
+ assertThat(templateAdapter.isMonolithicTemplatesConfiguration()).isFalse();
}
/**
- * Tests if the {@link TemplateAdapter} recognizes that it is an old monolithic template structure
+ * Tests if the {@link TemplateAdapter} getTemplateSetJars() is able to get two adaptable template sets (consisting of
+ * classes and sources)
+ *
+ * @throws IOException test fails
*
*/
@Test
- public void testIsMonolithicTemplatesConfigurationWithOldConfig() {
+ public void testGetTemplateJarsToAdaptFindsTwoAdaptableTemplateSets() throws IOException {
- TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathMonolithicTemplates);
- assertThat(templateAdapter.isMonolithicTemplatesConfiguration()).isTrue();
+ Path rootTestPathTemplateSets = tempFolder.newFolder("TwoAdaptable", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .toPath();
+
+ Path downloadedFolder = Files
+ .createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
+ Files.createFile(downloadedFolder.resolve("template-set-1.jar"));
+ Files.createFile(downloadedFolder.resolve("template-set-1-sources.jar"));
+ Files.createFile(downloadedFolder.resolve("template-set-2.jar"));
+ Files.createFile(downloadedFolder.resolve("template-set-2-sources.jar"));
+ TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathTemplateSets);
+ List templateJars = templateAdapter.getTemplateSetJars();
+ assertThat(templateJars.size()).isEqualTo(2);
}
/**
- * Tests if the {@link TemplateAdapter} recognizes that it is a new template structure
+ * Tests if the {@link TemplateAdapter} getTemplateSetJars() returns an empty list if no adaptable template set was
+ * found (missing sources)
*
+ * @throws IOException test fails
*/
@Test
- public void testIsMonolithicTemplatesConfigurationWithNewConfig() {
+ public void testGetTemplateJarsToAdaptWithMissingSourceFileReturnsEmptyList() throws IOException {
+
+ Path rootTestPathTemplateSets = tempFolder.newFolder("MissingSource", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .toPath();
+ Path downloadedFolder = Files
+ .createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
+ Files.createFile(downloadedFolder.resolve("template-set-1.jar"));
TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathTemplateSets);
- assertThat(templateAdapter.isMonolithicTemplatesConfiguration()).isFalse();
+ List templateJars = templateAdapter.getTemplateSetJars();
+ assertThat(templateJars).isEmpty();
}
/**
- * Tests if the {@link TemplateAdapter} is able to get the list of available template jars
+ * Tests if the {@link TemplateAdapter} getTemplateSetJars() returns an empty list if no adaptable template set was
+ * found (empty folder)
*
+ * @throws IOException test fails
*/
@Test
- public void testGetTemplateJarsToAdapt() {
+ public void testGetTemplateJarsToAdaptReturnsEmptyListForEmptyFolder() throws IOException {
+
+ Path rootTestPathTemplateSets = tempFolder.newFolder("EmptyFolder", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .toPath();
+ Files.createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathTemplateSets);
List templateJars = templateAdapter.getTemplateSetJars();
- assertThat(templateJars.size()).isEqualTo(2);
+ assertThat(templateJars).isEmpty();
}
/**
- * Tests if the {@link TemplateAdapter} recognizes which template sets are already adapted
+ * Tests if the {@link TemplateAdapter} isTemplateSetAlreadyAdapted() recognizes which template sets are already
+ * adapted
+ *
+ * @throws IOException test fails
*
*/
@Test
- public void testIsTemplateSetAlreadyAdapted() {
+ public void testIsTemplateSetAlreadyAdapted() throws IOException {
+
+ Path rootTestPathTemplateSets = tempFolder.newFolder("AlreadyAdapted", ConfigurationConstants.TEMPLATE_SETS_FOLDER)
+ .toPath();
+ Path downloadedFolder = Files
+ .createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER));
+ Files.createFile(downloadedFolder.resolve("template-set-1.jar"));
+ Files.createFile(downloadedFolder.resolve("template-set-1-sources.jar"));
+ Files.createFile(downloadedFolder.resolve("template-set-2.jar"));
+ Path adaptedFolder = Files.createDirectory(rootTestPathTemplateSets.resolve(ConfigurationConstants.ADAPTED_FOLDER));
+ Files.createDirectory(adaptedFolder.resolve("template-set-1"));
TemplateAdapter templateAdapter = new TemplateAdapterImpl(rootTestPathTemplateSets);
Path templateJarAdapted = rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER)
.resolve("template-set-1.jar");
+
Path templateJarNotAdapted = rootTestPathTemplateSets.resolve(ConfigurationConstants.DOWNLOADED_FOLDER)
.resolve("template-set-2.jar");