Skip to content

Commit

Permalink
devonfw#1518 Integrated the context upgrader into TemplatesAdapterImpl
Browse files Browse the repository at this point in the history
and Into the CLI
  • Loading branch information
MansourD committed Jul 5, 2022
1 parent 7b6bf79 commit 74e7a0c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.devonfw.cobigen.cli.utils.CobiGenUtils;
import com.devonfw.cobigen.cli.utils.ParsingUtils;
import com.devonfw.cobigen.cli.utils.ValidationUtils;
import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl;
import com.devonfw.cobigen.impl.config.constant.WikiConstants;
import com.devonfw.cobigen.impl.util.ConfigurationFinder;
import com.devonfw.cobigen.impl.util.FileSystemUtil;
Expand Down Expand Up @@ -287,7 +288,8 @@ private void askUserToUpgradeTemplates() {
MessagesConstants.INVALID_YES_NO_ANSWER_DESCRIPTION, "Continue generation with old templates...");

if (setToUserDir) {
// TODO Use the Upgrader from Ticket #1502
TemplateAdapterImpl templateAdapterImpl = new TemplateAdapterImpl();
templateAdapterImpl.upgradeMonolithicTemplates(this.templatesProject);
} else {
// Do Nothing, continue with old templates generation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public void adaptTemplateSets(List<Path> templateSetJars, Path destinationPath,
/**
* Upgrade an adapted monolithic template structure to the new template structure consisting of template sets.
*/
public void upgradeMonolithicTemplates();
public static void upgradeMonolithicTemplates() {
// TODO Auto-generated method stub

}

/**
* Get the parent location of the templates.
Expand All @@ -92,4 +95,11 @@ public void adaptTemplateSets(List<Path> templateSetJars, Path destinationPath,
* @return Returns {@code true} if the template set is already adapted. Otherwise false.
*/
public boolean isTemplateSetAlreadyAdapted(Path templateSetJar);

/**
* Upgrade an adapted monolithic template structure to the new template structure consisting of template sets.
*
* @param templatesProject path to the templates which should be upgraded.
*/
void upgradeMonolithicTemplates(Path templatesProject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
Expand All @@ -22,12 +23,17 @@
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.TemplateAdapter;
import com.devonfw.cobigen.api.constants.BackupPolicy;
import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.api.exception.CobiGenRuntimeException;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
import com.devonfw.cobigen.api.exception.TemplateSelectionForAdaptionException;
import com.devonfw.cobigen.api.exception.UpgradeTemplatesNotificationException;
import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.api.util.TemplatesJarUtil;
import com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader;
import com.devonfw.cobigen.impl.config.upgrade.TemplateConfigurationUpgrader;
import com.devonfw.cobigen.impl.util.ConfigurationFinder;
import com.devonfw.cobigen.impl.util.FileSystemUtil;

/**
Expand Down Expand Up @@ -361,11 +367,32 @@ private boolean isEmpty(final Path directory) throws IOException {
}

@Override
public void upgradeMonolithicTemplates() {
public void upgradeMonolithicTemplates(Path templatesProject) {

if (!isMonolithicTemplatesConfiguration()) {
return;
}
// TODO The upgrade needs to be implemented. Will be done in #1502

templatesProject = Paths.get(".cobigen\\templates");

URI configFileOrFolder = ConfigurationFinder.findTemplatesLocation();
Path templatesProject1 = Paths.get(configFileOrFolder);
if (configFileOrFolder == null) {
throw new InvalidConfigurationException(
"No valid templates can be found. Please configure your cobigen configuration file properly or place the templates in cobigen home directory. Creating CobiGen instance aborted.");
}
// resolve(ConfigurationConstants.COBIGEN_TEMPLATES).resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER);

// Path context_xml = templates.resolve(ConfigurationConstants.CONTEXT_CONFIG_FILENAME);
// Path templates_xml = templates.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME);
// ConfigurationHolder configHolder = new ConfigurationHolder(templates.toUri());
ContextConfigurationUpgrader contextUpgraderObject = new ContextConfigurationUpgrader();
TemplateConfigurationUpgrader templateUpgraderObject = new TemplateConfigurationUpgrader();

// ContextConfigurationVersion contextVersion =
// contextUpgraderObject.resolveLatestCompatibleSchemaVersion(templates);
// TemplatesConfigurationVersion templatesVersion = templateUpgraderObject
// .resolveLatestCompatibleSchemaVersion(templates);

contextUpgraderObject.upgradeConfigurationToLatestVersion(templatesProject, BackupPolicy.ENFORCE_BACKUP);
// templateUpgraderObject.upgradeConfigurationToLatestVersion(templatesProject, BackupPolicy.ENFORCE_BACKUP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -36,8 +35,6 @@ public class TemplateConfigurationUpgraderTest extends AbstractUnitTest {
*
* @throws Exception test fails
*/

@Ignore
@Test
public void testCorrectUpgrade_v1_2_TO_LATEST() throws Exception {

Expand Down Expand Up @@ -72,7 +69,6 @@ public void testCorrectUpgrade_v1_2_TO_LATEST() throws Exception {
*
* @throws Exception test fails
*/
@Ignore
@Test
public void testCorrectUpgrade_v2_1_TO_LATEST() throws Exception {

Expand Down

0 comments on commit 74e7a0c

Please sign in to comment.