From c64dafc5558a9f8f97598cf6240671559df345bc Mon Sep 17 00:00:00 2001 From: Cedric Betom Date: Fri, 17 Feb 2023 14:53:49 +0100 Subject: [PATCH] #1509 Fixed-the-bug-when-using-AdaptTemplate-in-eclipse #1622 --- .../cobigen/eclipse/test/AdaptTemplatesTest.java | 3 ++- .../test/common/utils/EclipseCobiGenUtils.java | 4 ++-- .../eclipse/common/tools/ResourcesPluginUtil.java | 11 ++++------- .../com/devonfw/cobigen/api/util/CobiGenPaths.java | 4 +++- .../cobigen/impl/adapter/TemplateAdapterImpl.java | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) 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 92a0ace483..7dc430c555 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 @@ -80,7 +80,8 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services"); + 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); 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 4496365a04..1175f3e229 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,8 +3,6 @@ import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive; import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled; -import java.util.concurrent.TimeoutException; - import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -18,6 +16,8 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.swtbot.swt.finder.widgets.TimeoutException; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.devonfw.cobigen.eclipse.common.constants.external.CobiGenDialogConstants; 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 ac34c79203..0b842712b7 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 @@ -13,9 +13,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; -import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; -import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; @@ -24,12 +21,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - import com.devonfw.cobigen.api.TemplateAdapter; import com.devonfw.cobigen.api.constants.ConfigurationConstants; import com.devonfw.cobigen.api.util.CobiGenPaths; import com.devonfw.cobigen.api.util.TemplatesJarUtil; +import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; +import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; +import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog; import com.devonfw.cobigen.impl.CobiGenFactory; import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; @@ -261,7 +259,7 @@ public static void processJar(String fileName) throws MalformedURLException, IOE } try { - TemplateAdapter templateAdapter = new TemplateAdapterImpl(cobigenFolderPath); + TemplateAdapter templateAdapter = new TemplateAdapterImpl(null); templateAdapter.adaptMonolithicTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES), false); } catch (Exception e) { @@ -298,7 +296,6 @@ public static void startTemplatesUpgrader(Path configurationPath) { setTemplateSetPathAfterUpgrade(CobiGenFactory.startTemplatesUpgrader(configurationPath)); - // FIXME after the upgrade adapt the new template-set folder. should be done in #1587 } 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 c2178fb3b2..964ad964ac 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 @@ -75,7 +75,9 @@ public static Path getTemplatesFolderPath() { 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 cb26287905..16f25f7b81 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 @@ -60,7 +60,7 @@ public TemplateAdapterImpl(Path templatesLocation) { if (templatesLocation == null) { URI templatesLocationPath = ConfigurationFinder.findTemplatesLocation(); if (Files.exists(Paths.get(templatesLocationPath))) { - this.templatesLocation = Paths.get(templatesLocationPath); + this.templatesLocation = Paths.get(templatesLocationPath).getParent(); } } else { this.templatesLocation = templatesLocation;