Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1502 config upgrade #1528

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f0ac1d5
Adjust documentation (#1491)
GuentherJulian Mar 10, 2022
d50efe5
changed eclipse repository to https
maybeec Mar 23, 2022
c90973d
Merge branch 'template-set-deployables' of https://github.com/devonfw…
GuentherJulian Apr 12, 2022
afa4009
Merge branch 'template-set-deployables' of https://github.com/devonfw…
GuentherJulian Apr 27, 2022
99d0412
Merge branch 'template-set-deployables' of https://github.com/devonfw…
GuentherJulian Apr 27, 2022
ac142b3
implemented draft for template set upgrader
GuentherJulian Apr 27, 2022
de42673
trigger getting converted to xml
EduardKrieger May 3, 2022
e32c2f9
context will be splitted, pom generation in progress
EduardKrieger May 3, 2022
366015c
removed useless fields
EduardKrieger May 3, 2022
00ea9f7
removed some comments
EduardKrieger May 3, 2022
b03f97a
implemented some test
EduardKrieger May 5, 2022
962fc72
upgrader implemented
EduardKrieger May 10, 2022
07df50c
added backup folder for old templates
EduardKrieger May 10, 2022
d4409aa
added ignore to templatesetupgradetests
EduardKrieger May 11, 2022
1414163
added ignore to templatesetupgradetests
EduardKrieger May 11, 2022
deff99f
chaanged upgrading process and changed the tests of the upgrade
EduardKrieger Jun 3, 2022
107583c
test for sucessful backup
EduardKrieger Jun 3, 2022
fed6aeb
changed test to use multiple context files
EduardKrieger Jun 14, 2022
2d85462
#1502 changed context version of reader test files to lates compatible
MikeSchumacherCapgemini Jun 14, 2022
faa4d39
changed context version in the jars from the test files
EduardKrieger Jun 14, 2022
f64a021
reworked upgrade step to work with the upgrade prozess to 3.0
EduardKrieger Jun 14, 2022
f81c815
#1502 fixed latest context version in javaplugin integration test
MikeSchumacherCapgemini Jun 14, 2022
50da8b6
Merge branch '1502_config_upgrade' of https://github.com/EduardKriege…
MikeSchumacherCapgemini Jun 14, 2022
691bffa
#1502 fixed some more context versions in tests
MikeSchumacherCapgemini Jun 14, 2022
46ad6b3
moved template upgrade process out of the abstract class
EduardKrieger Jun 14, 2022
e8dfe31
Merge branch '1502_config_upgrade' of https://github.com/EduardKriege…
EduardKrieger Jun 14, 2022
e5641ca
implemented requested changes
EduardKrieger Jun 15, 2022
7e38e28
removed some files
EduardKrieger Jun 16, 2022
8a22fbb
Merge branch 'master' into 1502_config_upgrade
EduardKrieger Jun 16, 2022
dbf2ac7
the requested changes have been added
EduardKrieger Jun 21, 2022
29bff44
changed use of validate process for the readers
EduardKrieger Jun 21, 2022
0398156
Merge branch 'template-set-deployables' into 1502_config_upgrade
EduardKrieger Jun 21, 2022
35b5b29
removed log
EduardKrieger Jun 21, 2022
541aa4d
removed import
EduardKrieger Jun 21, 2022
e4bb73f
#1502 added tags to template sets
jan-vcapgemini Jun 23, 2022
b3fd84b
used correct formatting for few files
EduardKrieger Jun 23, 2022
ae0b497
#1502 addressed requested changes
MikeSchumacherCapgemini Jun 28, 2022
9f22aeb
#1502 replaced generic exceptions with CobigenRuntimeExceptions
MikeSchumacherCapgemini Jun 28, 2022
bfe0ba2
#1502 applied proper code reformat
jan-vcapgemini Jul 1, 2022
3b2cdce
#1502 fixed template set upgrader and tests
jan-vcapgemini Jul 1, 2022
d5654b2
#1502 fixed template set upgrader and tests
jan-vcapgemini Jul 1, 2022
ef431dc
#1502 fixed template set upgrader and tests
jan-vcapgemini Jul 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package com.devonfw.cobigen.impl.config.upgrade;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.impl.config.entity.io.ContextConfiguration;
import com.devonfw.cobigen.impl.config.entity.io.Trigger;
import com.devonfw.cobigen.impl.config.entity.io.v3_0.ContainerMatcher;
import com.devonfw.cobigen.impl.config.entity.io.v3_0.Matcher;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

public class TemplateSetUpgrader {
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved

private Path templatesLocation;

/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(TemplateSetUpgrader.class);

public TemplateSetUpgrader(Path templatesLocation) {

this.templatesLocation = templatesLocation;
}

public void upradeTemplatesToTemplateSets() throws Exception {
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved

if (this.templatesLocation == null) {
throw new Exception("Templates location cannot be null!");
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved
}

if (this.templatesLocation.endsWith(ConfigurationConstants.TEMPLATES_FOLDER)) {
Path cobigenTemplates = this.templatesLocation.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
if (Files.exists(cobigenTemplates)) {
Path contextFile = cobigenTemplates.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)
.resolve(ConfigurationConstants.CONTEXT_CONFIG_FILENAME);
if (Files.exists(contextFile)) {
ContextConfiguration contextConfiguration = getContextConfiguration(contextFile);
if (contextConfiguration != null) {
// create new template set folder
Path templateSetsPath = Files.createDirectory(
this.templatesLocation.getParent().resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER));
Path adaptedFolder = Files.createDirectory(templateSetsPath.resolve(ConfigurationConstants.ADAPTED_FOLDER));

List<Trigger> triggers = contextConfiguration.getTrigger();
for (Trigger trigger : triggers) {
processTrigger(trigger, cobigenTemplates, adaptedFolder);
}
} else {
LOG.info("Unable to parse context.xml file {}.", contextFile);
}
} else {
LOG.info("No context.xml file found. {}", contextFile);
}
} else {
LOG.info("No CobiGen_Templates folder found. Upgrade needs an adapted templates folder.");
}
} else {
LOG.info("The path {} is no valid templates location.", this.templatesLocation);
}
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param contextFile
* @return
*/
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved
private ContextConfiguration getContextConfiguration(Path contextFile) {

try (InputStream in = Files.newInputStream(contextFile)) {
Unmarshaller unmarschaller = JAXBContext.newInstance(ContextConfiguration.class).createUnmarshaller();

Object rootNode = unmarschaller.unmarshal(in);
if (rootNode instanceof ContextConfiguration) {
return (ContextConfiguration) rootNode;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

private void processTrigger(Trigger trigger, Path cobigenTemplates, Path templateSetsAdapted) throws IOException {
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved

Path templatesPath = cobigenTemplates.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)
.resolve(trigger.getTemplateFolder());
Path templateSetPath = Files.createDirectory(templateSetsAdapted.resolve(trigger.getTemplateFolder()));

// copy template files
FileUtils.copyDirectory(templatesPath.toFile(),
templateSetPath.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER).toFile());

// copy java utils
Path utilsPath = cobigenTemplates.resolve("src/main/java");
FileUtils.copyDirectory(utilsPath.toFile(), templateSetPath.resolve("src/main/java").toFile());

// create context.xml
com.devonfw.cobigen.impl.config.entity.io.v3_0.ContextConfiguration contextConfiguration = new com.devonfw.cobigen.impl.config.entity.io.v3_0.ContextConfiguration();
contextConfiguration.setVersion(new BigDecimal(3.0));



// trigger in die contextconfiguration und dann marshall
List<com.devonfw.cobigen.impl.config.entity.io.v3_0.Trigger> triggerList = contextConfiguration.getTrigger();
com.devonfw.cobigen.impl.config.entity.io.v3_0.Trigger trigger3_0 = new com.devonfw.cobigen.impl.config.entity.io.v3_0.Trigger();
com.devonfw.cobigen.impl.config.entity.io.v3_0.ContextConfiguration config_test = new com.devonfw.cobigen.impl.config.entity.io.v3_0.ObjectFactory().createContextConfiguration();
trigger3_0.setId(trigger.getId());
trigger3_0.setInputCharset(trigger.getInputCharset());
trigger3_0.setType(trigger.getType());
trigger3_0.setTemplateFolder(trigger.getTemplateFolder());
// trigger3_0.getContainerMatcher().addAll((Collection<? extends ContainerMatcher>) trigger.getContainerMatcher());
// List<com.devonfw.cobigen.impl.config.entity.io.v3_0.ContainerMatcher> CMatcherList = trigger.getContainerMatcher();
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().useAutoMapping(true).mapNulls(true).build();
MapperFacade mapper = mapperFactory.getMapperFacade();

//List<com.devonfw.cobigen.impl.config.entity.io.v3_0.ContainerMatcher> v3ListCM = mapper.mapAsList(trigger.getContainerMatcher(),
//com.devonfw.cobigen.impl.config.entity.io.v3_0.ContainerMatcher.class);
//List<Matcher> v3ListMatcher = mapper.mapAsList(trigger.getMatcher(), com.devonfw.cobigen.impl.config.entity.io.v3_0.Matcher.class);
//trigger3_0.getContainerMatcher().addAll(v3ListCM);
for(com.devonfw.cobigen.impl.config.entity.io.ContainerMatcher cm: trigger.getContainerMatcher()) {
trigger3_0.getContainerMatcher().add(mapper.map(cm, com.devonfw.cobigen.impl.config.entity.io.v3_0.ContainerMatcher.class));
}
//trigger3_0.getMatcher().addAll(v3ListMatcher);
triggerList.add(trigger3_0);
//TODO ORIKA MApper
try{
Marshaller marshaller = JAXBContext.newInstance("com.devonfw.cobigen.impl.config.entity.io.v3_0").createMarshaller();
//marshaller.marshal(trigger3_0, System.out);
marshaller.marshal(contextConfiguration, System.out);
}catch(JAXBException e) {
e.printStackTrace();
}
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved
// TODO write trigger in new context.xml
// TODO create pom.xml ... create POM class?
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.devonfw.cobigen.unittest.config.upgrade;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.impl.config.upgrade.TemplateSetUpgrader;
import com.devonfw.cobigen.unittest.config.common.AbstractUnitTest;

/**
* Test suite for {@link TemplateSetUpgrader}
*/
public class TemplateSetUpgraderTest extends AbstractUnitTest {

/** Root path to all resources used in this test case */
private static String testFileRootPath = "src/test/resources/testdata/unittest/config/upgrade/TemplateSetUpgraderTest/";

private Path templateLocation;

/** JUnit Rule to create and automatically cleanup temporarily files/folders */
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

@Before
public void prepare() throws IOException {

Path playground = this.tempFolder.newFolder("playground").toPath();
FileUtils.copyDirectory(new File(testFileRootPath), playground.toFile());
this.templateLocation = playground.resolve(ConfigurationConstants.TEMPLATES_FOLDER);
}

@Test
public void testTemplateSetUprade() throws Exception {
EduardKrieger marked this conversation as resolved.
Show resolved Hide resolved

TemplateSetUpgrader templateSetUpgrader = new TemplateSetUpgrader(this.templateLocation);
templateSetUpgrader.upradeTemplatesToTemplateSets();

Path templateSetsPath = this.templateLocation.getParent().resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER);
Path templateSetsAdapted = templateSetsPath.resolve(ConfigurationConstants.ADAPTED_FOLDER);
assertThat(templateSetsPath).exists();
assertThat(templateSetsAdapted).exists();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>templates-devon4j</artifactId>
<version>2021.12.006</version>
<name>CobiGen - devon4j Templates</name>
<description>A Code-based incremental Generator</description>
<url>https://github.com/devonfw/cobigen/templates-parent/templates-devon4j</url>
<licenses>
<license>
<name>Apache Software License 2.0</name>
<url>https://raw.githubusercontent.com/devonfw/.github/master/LICENSE</url>
<distribution>repo</distribution>
<comments></comments>
</license>
</licenses>
<developers>
<developer>
<name>Malte Brunnlieb</name>
<organization>Capgemini</organization>
</developer>
</developers>
<scm>
<connection>scm:git:[email protected]:devonfw/cobigen.git/templates-parent/templates-devon4j</connection>
<developerConnection>scm:git:[email protected]:devonfw/cobigen.git/templates-parent/templates-devon4j</developerConnection>
<url>[email protected]:devonfw/cobigen.git/templates-parent/templates-devon4j</url>
</scm>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>3.0.9.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.30</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>ossrh</id>
<name>OSSRH Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<resources>
<resource>
<directory>src/main/templates</directory>
<targetPath>src/main/templates</targetPath>
</resource>
</resources>
</build>
</project>
Loading