diff --git a/.gitignore b/.gitignore
index 978e10ba4f..16466648c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,5 @@ cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateP
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
+cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/downloaded/crud-java-server-app-1.0.0.jar
+cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar
diff --git a/cobigen-eclipse/cobigen-eclipse-test/pom.xml b/cobigen-eclipse/cobigen-eclipse-test/pom.xml
index 8fc4f9cf42..d8f4c8b78f 100644
--- a/cobigen-eclipse/cobigen-eclipse-test/pom.xml
+++ b/cobigen-eclipse/cobigen-eclipse-test/pom.xml
@@ -13,6 +13,8 @@
${surefireArgLineIntegration} -Xms512m -Xmx2048m -XX:+DisableExplicitGC
true
+ src\main\resources\AdaptTemplatesTest\template-sets\adapted\crud-openapi-java-server-app
+
@@ -58,6 +60,34 @@
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.0.0
+
+
+ Install test adaptTemplatesTests1
+ test-compile
+
+ exec
+
+
+ mvn
+ ${maven.test.AdaptTemplatesTest1}
+
+ install
+
+ -Djansi.force=true
+ -Djansi.passthrough=true
+ -B
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+
+
+
+
+
org.apache.maven.plugins
maven-clean-plugin
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java
index 7536ade8d6..ca19d15133 100644
--- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java
+++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java
@@ -4,6 +4,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
@@ -16,6 +19,7 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -44,6 +48,9 @@ public class AdaptTemplatesTest extends SystemTest {
/** Line separator, e.g. for windows '\r\n' */
public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator");
+ /* Root path for templateSets jar */
+ private static final String testResource = "src/main/resources/AdaptTemplatesTest/template-sets/downloaded";
+
/**
* Setup workbench appropriately for tests
*
@@ -60,7 +67,92 @@ public static void setupClass() throws Exception {
*
* @throws Exception test fails
*/
- public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
+ public void testBasicOpenAPIGenerationWithAdaptTemplateSets() throws Exception {
+
+ // copy sample project to external location and import it into the workspace
+ String testProjName = "ExtTestProj";
+ IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName);
+ FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"),
+ project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile());
+ project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ this.tmpMavenProjectRule.updateProject();
+
+ /**
+ * TODO Before the templates are made available online, the update (download) command cannot be tested.
+ */
+ // EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot);
+ EclipseCobiGenUtils.runAndCaptureAdaptTemplatesSets(bot);
+ EclipseUtils.openErrorsTreeInProblemsView(bot);
+ // expand the new file in the package explorer
+ SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
+ SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml");
+ javaClassItem.select();
+
+ // execute CobiGen
+ EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
+ bot.waitUntil(new AllJobsAreFinished(), 10000);
+ // increase timeout as the openAPI parser is slow on initialization
+ EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);
+
+ bot.waitUntil(new AllJobsAreFinished(), 10000);
+ IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(testProjName);
+ IFile generationResult = proj.getFile(
+ "src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java");
+
+ assertThat(generationResult.exists()).isTrue();
+ }
+
+ /**
+ * Test for external projects (not in workspace) taken as input for generation
+ *
+ * @throws Exception test fails
+ */
+ public void testAdaptTemplatesAndImportIntoEclipse() throws Exception {
+
+ // copy sample project to external location and import it into the workspace
+ String testProjName = "ExtTestProj";
+ IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName);
+ FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"),
+ project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile());
+ project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ this.tmpMavenProjectRule.updateProject();
+
+ EclipseCobiGenUtils.runAndCaptureAdaptTemplatesSets(bot);
+
+ // EclipseUtils.updateMavenProject(bot, ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);
+
+ // expand the new file in the package explorer
+ SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
+ SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml");
+ javaClassItem.select();
+
+ // execute CobiGen
+ EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
+ bot.waitUntil(new AllJobsAreFinished(), 10000);
+ // increase timeout as the openAPI parser is slow on initialization
+ EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);
+ bot.waitUntil(new AllJobsAreFinished(), 10000);
+
+ // EclipseUtils.openErrorsTreeInProblemsView(bot);
+
+ IProject generatorProjOfTempltesSets = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);
+ bot.waitUntil(new AllJobsAreFinished(), 10000);
+
+ Path adaptedFolder = Paths.get(generatorProjOfTempltesSets.getLocationURI())
+ .resolve(ResourceConstants.TEMPLATE_SETS_ADAPTED);
+
+ assertThat(generatorProjOfTempltesSets.exists()).isTrue();
+ assertThat(Files.exists(adaptedFolder)).isTrue();
+
+ }
+
+ /**
+ * Test for external projects (not in workspace) taken as input for generation
+ *
+ * @throws Exception test fails
+ */
+ public void testBasicOpenAPIGenerationWithAdaptMonolithicTemplates() throws Exception {
// copy sample project to external location and import it into the workspace
String testProjName = "ExtTestProj";
@@ -72,15 +164,9 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
// retrieve CobiGen home directory (overwritten through environment variables)
File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile();
-
// create templates directory as this should be present in this scenario
- this.tempFolder.newFolder("playground", "project", "templates");
-
- // download latest monolithic templates to simulate existing template jars
TemplatesJarUtil.downloadLatestDevon4jTemplates(true, templatesDirectory);
TemplatesJarUtil.downloadLatestDevon4jTemplates(false, templatesDirectory);
-
- // adapt template jars into CobiGen_Templates project
EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot);
EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME);
@@ -93,7 +179,6 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
// execute CobiGen
EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "CRUD devon4j Server>CRUD REST services");
-
bot.waitUntil(new AllJobsAreFinished(), 10000);
// increase timeout as the openAPI parser is slow on initialization
EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);
@@ -104,19 +189,57 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
"src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java");
assertThat(generationResult.exists()).isTrue();
+ }
+
+ /*
+ *
+ * Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
+ *
+ */
+ @Test
+ public void testAdaptMonolithicTemplatesAndGenerate() throws Exception {
+ File tmpProject = this.tempFolder.newFolder("playground", "project");
+ withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
+ .execute(() -> testBasicOpenAPIGenerationWithAdaptMonolithicTemplates());
}
/**
- * Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
+ * TODO Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom template-sets after adapt the jar files
*
* @throws Exception test fails
*/
@Test
- public void testAdaptTemplatesAndGenerate() throws Exception {
+ @Ignore
+ public void testAdaptTemplateSetsAndGenerate() throws Exception {
+
+ Path devTemplatesPath = new File(
+ AdaptTemplatesTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
+ .getParentFile().toPath().resolve("cobigen-templates").resolve("crud-openapi-java-server-app")
+ .resolve("target").resolve("crud-openapi-java-server-app-2021.12.007-SNAPSHOT.jar");
File tmpProject = this.tempFolder.newFolder("playground", "project");
+ File downloaded = this.tempFolder.newFolder("playground", "project", "template-sets", "downloaded");
+ FileUtils.copyFileToDirectory(devTemplatesPath.toFile(), downloaded);
withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
- .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates());
+ .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplateSets());
+ }
+
+ /**
+ * Test adaption of template-sets/downloaded/.jar files and importing the project into Eclipse
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAdaptTemplateSetsAndImport() throws Exception {
+
+ File tmpProject = this.tempFolder.newFolder("playground", "project");
+ File downloaded = this.tempFolder.newFolder("playground", "project", "template-sets", "downloaded");
+
+ FileUtils.copyDirectory(new File(testResource), downloaded);
+
+ withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
+ .execute(() -> testAdaptTemplatesAndImportIntoEclipse());
+
}
}
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java
index 992b7cbb56..64f8616277 100644
--- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java
+++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java
@@ -3,6 +3,7 @@
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -361,7 +362,8 @@ private static void captureAdvancedHealthCheck(SWTWorkbenchBot bot) {
*/
public static void runAndCaptureUpdateTemplates(SWTWorkbenchBot bot) throws Exception {
- ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time
SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
@@ -402,6 +404,26 @@ public static void runAndCaptureAdaptTemplates(SWTWorkbenchBot bot) throws Excep
informationDialog.bot().button("Ok").click();
}
+ /**
+ * Checks the CobiGen Adapt TemplateSets and takes screenshots of it.
+ *
+ * @param bot to process the Adapt Templates command
+ * @throws Exception test fails
+ */
+ public static void runAndCaptureAdaptTemplatesSets(SWTWorkbenchBot bot) throws Exception {
+
+ ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time
+
+ SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
+ view.bot().tree().contextMenu("CobiGen").menu("Adapt Templates...").click();
+
+ SWTBotShell informationDialog = bot.shell("Information");
+ bot.waitUntil(new AnyShellIsActive("Information"), DEFAULT_TIMEOUT);
+ takeScreenshot(bot, "Adapt Templates Information");
+ informationDialog.bot().button("Ok").click();
+ }
+
/**
* Takes a screenshot (*.jpeg) of the current screen encoding test method and class and appends the given identifier
* to the file name
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/pom.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/pom.xml
new file mode 100644
index 0000000000..3558920d14
--- /dev/null
+++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-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-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/java/com/test.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/java/com/test.java
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/functions.ftl b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/functions.ftl
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/template-set.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/template-set.xml
new file mode 100644
index 0000000000..f0d54fa334
--- /dev/null
+++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/template-set.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-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-eclipse/cobigen-eclipse-test/src/main/resources/AdaptTemplatesTest/template-sets/adapted/crud-openapi-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-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/external/ResourceConstants.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/external/ResourceConstants.java
index 726ed6e605..d515161532 100644
--- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/external/ResourceConstants.java
+++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/external/ResourceConstants.java
@@ -10,4 +10,19 @@ public class ResourceConstants {
*/
public static final String CONFIG_PROJECT_NAME = "CobiGen_Templates";
+ /**
+ * Generator Configuration Project Name of template-sets
+ */
+ public static final String TEMPLATE_SETS_CONFIG_PROJECT_NAME = "template-sets";
+
+ /**
+ * Name of template-sets/downloaded folder
+ */
+ public static final String TEMPLATE_SETS_DOWNLOADED = "downloaded";
+
+ /**
+ * Name of template-sets/adapted folder
+ */
+ public static final String TEMPLATE_SETS_ADAPTED = "adapted";
+
}
diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java
index 0b842712b7..76eae149f4 100644
--- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java
+++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java
@@ -7,6 +7,7 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IProject;
@@ -105,43 +106,18 @@ public static void refreshConfigurationProject() {
*/
public static IProject getGeneratorConfigurationProject() throws GeneratorProjectNotExistentException, CoreException {
- File templatesDirectory = getTemplatesDirectory();
-
- generatorProj = ResourcesPlugin.getWorkspace().getRoot().getProject(ResourceConstants.CONFIG_PROJECT_NAME);
-
- if (!generatorProj.exists()) {
- if (!isUpdateDialogShown) {
- if (templatesDirectory.exists()) {
- Path jarFilePath = TemplatesJarUtil.getJarFile(false, templatesDirectory.toPath());
- // If we don't find at least one jar, then we do need to download new templates
- if (jarFilePath == null || !Files.exists(jarFilePath)) {
- int result = createUpdateTemplatesDialog();
- isUpdateDialogShown = true;
- if (result == 1) {
- // User does not want to download templates.
- userWantsToDownloadTemplates = false;
- } else {
- userWantsToDownloadTemplates = true;
- }
- }
-
- } else {
- int result = createUpdateTemplatesDialog();
- isUpdateDialogShown = true;
- if (result == 1) {
- // User does not want to download templates.
- userWantsToDownloadTemplates = false;
- } else {
- userWantsToDownloadTemplates = true;
- }
- }
- }
- }
- if (userWantsToDownloadTemplates) {
+ generatorProj = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);
+ if (generatorProj.exists()) {
return generatorProj;
} else {
- return null;
+ generatorProj = ResourcesPlugin.getWorkspace().getRoot().getProject(ResourceConstants.CONFIG_PROJECT_NAME);
+ if (generatorProj.exists()) {
+ return generatorProj;
+ }
}
+
+ return null;
}
/**
@@ -207,7 +183,7 @@ public static String getJarPath(boolean isSource) {
*
* @return the templateDirectory
*/
- private static File getTemplatesDirectory() {
+ public static File getTemplatesDirectory() {
return CobiGenPaths.getTemplatesFolderPath().toFile();
}
@@ -217,9 +193,9 @@ private static File getTemplatesDirectory() {
*
* @return the templateDirectory
*/
- private static File getTemplateSetDirectory() {
+ public static Path getTemplateSetDirectory() {
- return CobiGenPaths.getTemplateSetsFolderPath().toFile();
+ return CobiGenPaths.getTemplateSetsFolderPath();
}
/**
@@ -234,6 +210,7 @@ public static void processJar(String fileName) throws MalformedURLException, IOE
String pathForCobigenTemplates = "";
IPath ws = ResourcesPluginUtil.getWorkspaceLocation();
+ Path templateDirectory = ResourcesPluginUtil.getTemplatesDirectory().toPath();
try {
pathForCobigenTemplates = ws.toPortableString()
@@ -260,7 +237,7 @@ public static void processJar(String fileName) throws MalformedURLException, IOE
try {
TemplateAdapter templateAdapter = new TemplateAdapterImpl(null);
- templateAdapter.adaptMonolithicTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES),
+ templateAdapter.adaptMonolithicTemplates(templateDirectory.resolve(ConfigurationConstants.COBIGEN_TEMPLATES),
false);
} catch (Exception e) {
LOG.error("An exception occurred while processing Jar files to create CobiGen_Templates folder", e);
@@ -269,6 +246,29 @@ public static void processJar(String fileName) throws MalformedURLException, IOE
}
}
+ /**
+ * Process Jar method is responsible for unzip the Jar files of templateSets from downloaded to adapted
+ *
+ * @param fileName Name of source jar file downloaded
+ * @throws IOException {@link IOException} occurred
+ * @throws MalformedURLException {@link MalformedURLException} occurred
+ */
+ public static void adaptTemplateSet(Path templateSetsLocation) {
+
+ try {
+ TemplateAdapter templateAdapter = new TemplateAdapterImpl(templateSetsLocation);
+ List jarFilePath = TemplatesJarUtil
+ .getJarFiles(templateSetsLocation.resolve(ResourceConstants.TEMPLATE_SETS_DOWNLOADED));
+ templateAdapter.adaptTemplateSets(jarFilePath,
+ templateSetsLocation.resolve(ResourceConstants.TEMPLATE_SETS_ADAPTED), false);
+
+ } catch (Exception e) {
+ LOG.error("An exception occurred while processing Jar files to create CobiGen_Templates folder", e);
+ PlatformUIUtil
+ .openErrorDialog("An exception occurred while processing Jar file to create CobiGen_Templates folder", e);
+ }
+ }
+
/**
* @return workspace location
*/
diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java
index be0e80590e..b6b5e99068 100644
--- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java
+++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java
@@ -216,7 +216,6 @@ private static CobiGen initializeGenerator(boolean allowMonolithicConfiguration)
throws InvalidConfigurationException, GeneratorCreationException {
try {
- ResourcesPluginUtil.refreshConfigurationProject();
generatorProj = ResourcesPluginUtil.getGeneratorConfigurationProject();
return initializeCobiGen(generatorProj, allowMonolithicConfiguration);
diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/AdaptTemplatesHandler.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/AdaptTemplatesHandler.java
index 6bf1bdc853..033758709b 100644
--- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/AdaptTemplatesHandler.java
+++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/AdaptTemplatesHandler.java
@@ -2,10 +2,10 @@
import java.io.File;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
+import java.util.List;
import java.util.UUID;
import org.eclipse.core.commands.AbstractHandler;
@@ -27,11 +27,15 @@
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
+import com.devonfw.cobigen.api.TemplateAdapter;
+import com.devonfw.cobigen.api.constants.ConfigurationConstants;
+import com.devonfw.cobigen.api.exception.TemplateSelectionForAdaptionException;
+import com.devonfw.cobigen.api.exception.UpgradeTemplatesNotificationException;
import com.devonfw.cobigen.eclipse.common.constants.InfrastructureConstants;
import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants;
import com.devonfw.cobigen.eclipse.common.tools.ExceptionHandler;
-import com.devonfw.cobigen.eclipse.common.tools.PlatformUIUtil;
import com.devonfw.cobigen.eclipse.common.tools.ResourcesPluginUtil;
+import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl;
/**
* Handler for the Package-Explorer EventfimportProjectIntoWorkspace
@@ -54,52 +58,80 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());
IProject generatorProj = ResourcesPlugin.getWorkspace().getRoot().getProject(ResourceConstants.CONFIG_PROJECT_NAME);
- if (generatorProj.exists()) {
- MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Info!", null,
- "CobiGen_Templates folder is already imported, click on Update templates button to update with latest. ",
- MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
- dialog.setBlockOnOpen(true);
- dialog.open();
- } else {
- MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Warning!", null,
- "Clicking on ok button will override existing CobiGen_Templates in workspace.", MessageDialog.WARNING,
- new String[] { "Ok", "Cancel" }, 1);
- dialog.setBlockOnOpen(true);
- int result = dialog.open();
+ Path templateSet = ResourcesPluginUtil.getTemplateSetDirectory();
+ File template = ResourcesPluginUtil.getTemplatesDirectory();
- if (result == 0) {
- try {
- String fileName = ResourcesPluginUtil.getJarPath(true);
- if (fileName.equals("")) {
- result = createUpdateTemplatesDialog();
- if (result == 1) {
- MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
- "Templates have not been found, please download them!");
- throw new NullPointerException("Templates have not been found!");
- } else {
- fileName = ResourcesPluginUtil.downloadJar(true);
- }
+ TemplateAdapter templateAdapter;
+ if (Files.exists(templateSet)) {
+ templateAdapter = new TemplateAdapterImpl(templateSet);
+ } else if (template.exists()) {
+ templateAdapter = new TemplateAdapterImpl(template.toPath());
+ } else {
+ LOG.debug("No configuration project was found");
+ return null;
+ }
+ try {
+ templateAdapter.adaptTemplates();
+
+ if (generatorProj.exists()) {
+ MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Info!", null,
+ "CobiGen_Templates folder is already imported, click on Update templates button to update with latest. ",
+ MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
+ dialog.setBlockOnOpen(true);
+ dialog.open();
+ } else {
+
+ MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Warning!", null,
+ "Clicking on ok button will override existing CobiGen_Templates in workspace.", MessageDialog.WARNING,
+ new String[] { "Ok", "Cancel" }, 1);
+ dialog.setBlockOnOpen(true);
+ int result = dialog.open();
+
+ if (result == 0) {
+ try {
+ importProjectIntoWorkspace(ResourceConstants.CONFIG_PROJECT_NAME,
+ ResourcesPluginUtil.getTemplatesDirectory().toPath());
+ dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Information", null,
+ "CobiGen_Templates folder is imported sucessfully", MessageDialog.INFORMATION, new String[] { "Ok" },
+ 1);
+ dialog.setBlockOnOpen(true);
+ dialog.open();
+ } catch (Throwable e) {
+ ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event));
}
- ResourcesPluginUtil.processJar(fileName);
+ }
+ MDC.remove(InfrastructureConstants.CORRELATION_ID);
+ }
+
+ } catch (TemplateSelectionForAdaptionException e) {
+ List templateJars = e.getTemplateSets();
+ if (!templateJars.isEmpty()) {
- importProjectIntoWorkspace();
- dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Information", null,
+ try {
+ // Adapt process
+ templateAdapter.adaptTemplateSets(templateJars, false);
+
+ // B. Import into Eclipse
+ importProjectIntoWorkspace(ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME, templateSet);
+ MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Information", null,
"CobiGen_Templates folder is imported sucessfully", MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
dialog.setBlockOnOpen(true);
dialog.open();
- } catch (MalformedURLException e) {
- LOG.error("An exception with download url of maven central", e);
- PlatformUIUtil.openErrorDialog("An exception with download url of maven central", e);
- } catch (IOException e) {
- LOG.error("An exception occurred while writing Jar files to .metadata folder", e);
- PlatformUIUtil.openErrorDialog("An exception occurred while writing Jar files to .metadata folder", e);
- } catch (Throwable e) {
- ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event));
+
+ } catch (IOException e1) {
+ LOG.debug("Adapt was not possible", e1);
}
+
+ } else {
+ LOG.info("No template set jars found to extract.");
}
- MDC.remove(InfrastructureConstants.CORRELATION_ID);
+ } catch (IOException e) {
+ LOG.debug("Error occur", e);
+ } catch (UpgradeTemplatesNotificationException e) {
+ LOG.debug("Upgrade Process", e);
}
+
return null;
}
@@ -107,7 +139,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
/**
* CobiGen_Templates folder created at main folder using source jar will be imported into workspace
*/
- private void importProjectIntoWorkspace() {
+ private void importProjectIntoWorkspace(String projectName, Path projectPath) {
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
@@ -117,9 +149,13 @@ private void importProjectIntoWorkspace() {
progressMonitor.open();
progressMonitor.getProgressMonitor().beginTask("Importing templates...", 0);
try {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ResourceConstants.CONFIG_PROJECT_NAME);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
- description.setLocation(new org.eclipse.core.runtime.Path(this.ws.toPortableString() + "/CobiGen_Templates"));
+ if (projectName == ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME) {
+ description.setLocationURI(projectPath.toUri());
+ } else {
+ description.setLocationURI(projectPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES).toUri());
+ }
project.create(description, null);
// We set the current project to be converted to a Maven project
@@ -127,16 +163,16 @@ private void importProjectIntoWorkspace() {
mavenConverter.selectionChanged(null, sel);
project.open(null);
-
// Converts the current project to a Maven project
- mavenConverter.run(null);
+ if (projectName == ResourceConstants.CONFIG_PROJECT_NAME)
+ mavenConverter.run(null);
progressMonitor.close();
} catch (CoreException e) {
progressMonitor.close();
e.printStackTrace();
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
- "Some Exception occurred while importing CobiGen_Templates into workspace");
+ "Some Exception occurred while importing " + projectName + " into workspace");
}
}
diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java
index 06ecd109e7..32a55384a9 100644
--- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java
+++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java
@@ -95,8 +95,7 @@ public static Path getTemplatesFolderPath(Path home) {
Path templatesPath = home.resolve(ConfigurationConstants.TEMPLATES_FOLDER);
- return templatesPath;
-
+ return createFolder(templatesPath);
}
/**
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 0f243f08d3..ba862ce298 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
@@ -80,7 +80,6 @@ public void adaptTemplates()
if (isMonolithicTemplatesConfiguration()) {
Path destinationPath = this.templatesLocation.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
adaptMonolithicTemplates(destinationPath, false);
- throw new UpgradeTemplatesNotificationException();
} else {
throw new TemplateSelectionForAdaptionException(getTemplateSetJars());
}