Skip to content

Commit

Permalink
devonfw#1518 Implemented requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MansourD committed Oct 19, 2022
1 parent 3a8482d commit 190bcf7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void upgradeAndGenerateFromEntityTest() throws Exception {
args[1] = this.entityInputFile.getAbsolutePath();
args[2] = "--increments";
args[3] = "0";
args[4] = "--upgrade";
args[4] = "--upgrade-configuration";
args[5] = "-tp";
args[6] = monolithicConfiguration.getAbsolutePath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public class AdaptTemplatesCommand extends CommandCommons {
@Override
public Integer doAction() throws Exception {

TemplateAdapter templateAdapter= new TemplateAdapterImpl(this.templatesProject);
TemplateAdapter templateAdapter = new TemplateAdapterImpl(this.templatesProject);

try {
templateAdapter.adaptTemplates();
} catch (UpgradeTemplatesNotificationException e) {
if (askUserToContinueWithUpgrade(e)) {

// TODO call the Upgrader here
templateAdapter.upgradeMonolithicTemplates(this.templatesProject);
}
} catch (TemplateSelectionForAdaptionException e) {
List<Path> templateJars = e.getTemplateSets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class CommandCommons implements Callable<Integer> {
/**
* If this option is enabled, the old monolithic templates will be upgraded to the new template-set structure.
*/
@Option(names = { "--upgrade", "-u" }, description = MessagesConstants.UPGRADE_CONFIGURATION_OPTION)
@Option(names = { "--upgrade-configuration" }, description = MessagesConstants.UPGRADE_CONFIGURATION_OPTION)
boolean upgradeConfiguration;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ public Integer doAction() throws Exception {

LOG.debug("Input files and output root path confirmed to be valid.");

if (PostponeUtil.isTimePassed())
if (!this.forceMonolithicConfiguration) {
checkMonolithicConfigurationException();
}
if ((PostponeUtil.isTimePassed()) && (!this.forceMonolithicConfiguration))
checkMonolithicConfigurationException();

CobiGen cg = CobiGenUtils.initializeCobiGen(this.templatesProject, true);

Expand Down Expand Up @@ -272,16 +270,13 @@ private void checkMonolithicConfigurationException() {
try {
CobiGenUtils.initializeCobiGen(this.templatesProject, false);
} catch (DeprecatedMonolithicConfigurationException e) {
String monolithicConfigurationMessage = "Found monolithic configuration at:";
if (this.templatesProject == null)
LOG.warn(monolithicConfigurationMessage.concat("{} {}"), ConfigurationFinder.findTemplatesLocation(),
e.getMessage());
else
LOG.warn(monolithicConfigurationMessage.concat("{} {}"), this.templatesProject, e.getMessage());
if (this.upgradeConfiguration) {
LOG.warn("Found monolithic configuration at: {} {}",
DeprecatedMonolithicConfigurationException.getMonolithicConfiguration(), e.getMessage());

if (this.upgradeConfiguration || askUserToUpgradeTemplates()) {
startTemplatesUpgrader();
} else {
askUserToUpgradeTemplates();
askUserToPostponeUpgrade();
}
}

Expand All @@ -291,7 +286,7 @@ private void checkMonolithicConfigurationException() {
* Opens a looping prompt with a yes/no question and upgrades the templates to the newest version.
*
*/
private void askUserToUpgradeTemplates() {
private boolean askUserToUpgradeTemplates() {

LOG.info(
"Would you like to upgrade your templates to the newest version? \n"
Expand All @@ -302,9 +297,9 @@ private void askUserToUpgradeTemplates() {
MessagesConstants.INVALID_YES_NO_ANSWER_DESCRIPTION, "Continue generation with monolithic templates...");

if (setToUserDir) {
startTemplatesUpgrader();
return true;
} else {
askUserToPostponeUpgrade();
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
Expand All @@ -36,19 +34,9 @@ public class UpgradeMonolithicTemplatesTest extends SystemTest {
/** Root path of the Test Resources */
private static final String resourcesRootPath = "src/main/resources/UpgradeMonolithicTemplatesTest/";

/** Temporary files rule to create temporary folders or files */
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

/** Current home directory */
protected Path currentHome;

/**
* Setup home path for cobigen to isolate the test
*
* @throws Exception
*/

/**
* Setup workbench appropriately for tests
*
Expand All @@ -68,13 +56,14 @@ public static void setupClass() throws Exception {
/**
* Tests if the Upgrader will work properly and generate after that
*
* Setup home path for cobigen to isolate the test (withEnvironmentVariable)
*
* @throws Exception Test fails
*/
@Test
public void testUpgradeAndGenerateFromTemplateSet() throws Exception {

this.currentHome = this.tempFolder.newFolder("cobigen-test-home").toPath();
this.currentHome = this.tmpFolderRule.newFolder("cobigen-test-home").toPath();
withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, this.currentHome.toString()).execute(() -> {

// create a new temporary java project and copy java class used as an input for CobiGen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException;
import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog;
import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl;
import com.devonfw.cobigen.impl.util.ConfigurationFinder;
import com.devonfw.cobigen.impl.util.FileSystemUtil;

/** Util for NPE save access of {@link ResourcesPlugin} utils */
public class ResourcesPluginUtil {
Expand Down Expand Up @@ -198,18 +196,6 @@ private static File getTemplatesDirectory() {
return CobiGenPaths.getTemplatesFolderPath().toFile();
}

/**
* The method finds location of templates. It could be CobiGen_Templates folder or a template artifact
*
* @return the templateDirectory
*/
private static File findTemplatesLocation() {

URI findTemplatesLocation = ConfigurationFinder.findTemplatesLocation();
Path templatesPath = FileSystemUtil.createFileSystemDependentPath(findTemplatesLocation);
return templatesPath.toFile();
}

/**
* Gets or creates a new templates directory from the template-set structure
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Objects;

import org.slf4j.Logger;
Expand Down Expand Up @@ -96,7 +97,7 @@ public static CobiGen create(URI configFileOrFolder, boolean allowMonolithicConf
PluginRegistry.notifyPlugins(configurationHolder.getConfigurationPath());

if (!allowMonolithicConfiguration && !configurationHolder.isTemplateSetConfiguration()) {
throw new DeprecatedMonolithicConfigurationException();
throw new DeprecatedMonolithicConfigurationException(Paths.get(configFileOrFolder));
}
// install Template Sets defined in .properties file
if (configurationHolder.isTemplateSetConfiguration()) {
Expand Down

0 comments on commit 190bcf7

Please sign in to comment.