Skip to content

Commit

Permalink
devonfw#1494 added projects and a test to work around main pom and te…
Browse files Browse the repository at this point in the history
…mplatesproject pom
  • Loading branch information
Ali7223 committed Nov 15, 2022
1 parent fcddc2c commit 05ba40c
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.devonfw.cobigen.maven.systemtest;

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

import java.io.File;
import java.nio.file.Files;

import org.junit.Test;

import com.devonfw.cobigen.maven.systemtest.config.constant.MavenMetadata;
import com.devonfw.cobigen.maven.test.AbstractMavenTest;

/**
* TODO alsaad This type ...
*
*/
public class TemplatePluginLoadtest extends AbstractMavenTest {

public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/systemtest/Devon4JTemplateTest/";

@Test
public void testPluginsFromPom() throws Exception {

File testProject = new File(TEST_RESOURCES_ROOT + "TestProject/");
File templatesProject = new File(TEST_RESOURCES_ROOT, "TestTemplatesProjectForPom");
File testProjectRoot = runMavenInvoker(testProject, templatesProject, MavenMetadata.LOCAL_REPO);

assertThat(testProjectRoot.list()).containsOnly("pom.xml", "src", "target");
long numFilesInSrc = Files.walk(testProjectRoot.toPath().resolve("src")).filter(Files::isRegularFile).count();
// 1 from tos
assertThat(numFilesInSrc).isEqualTo(1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devonfw.test</groupId>
<artifactId>Devon4JTemplateTest-TestEntityInputDataaccessGeneration</artifactId>
<version>dev-SNAPSHOT</version>
<properties>
<!-- < JDK 8 not supported -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>cobigen-maven-plugin</artifactId>
<version>${pluginVersion}</version>
<executions>
<execution>
<id>generate</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<configurationFolder>${templatesProject}/</configurationFolder>
<inputFiles>
<inputFile>src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java</inputFile>
</inputFiles>
<increments>
<increment>tos</increment>
</increments>
</configuration>
<dependencies>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.devonfw.cobigen.generator.dataaccess.api;

public class InputEntity {

private String input;

private int complexity;

public String getInput() {
return input;
}

public void setInput(String input) {
this.input = input;
}

public int getComplexity() {
return complexity;
}

public void setComplexity(int complexity) {
this.complexity = complexity;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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.test</groupId>
<artifactId>templates-devon4j</artifactId>
<version>3.1.8</version>
<name>CobiGen devon4j Templates</name>
<description>CobiGen devon4j Templates</description>
<url>https://github.com/devonfw/cobigen/templates-parent/templates-devon4j</url>

<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>javaplugin</artifactId>
<version>${pluginVersion}</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>${pluginVersion}</version>
</dependency>
</dependencies>

<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contextConfiguration xmlns="http://capgemini.com/devonfw/cobigen/ContextConfiguration" version="2.1">

<trigger id="crud_java_server_app" type="java" templateFolder="crud_java_server_app">
<containerMatcher type="package" value="((.+\.)?([^\.]+))\.([^\.]+)\.dataaccess\.api"
retrieveObjectsRecursively="false"/>
<matcher type="fqn" value="((.+\.)?([^\.]+))\.([^\.]+)\.dataaccess\.api\.([^\.]+)Entity">
<variableAssignment type="regex" key="rootPackage" value="1"/>
<variableAssignment type="regex" key="domain" value="3"/>
<variableAssignment type="regex" key="component" value="4"/>
<variableAssignment type="regex" key="entityName" value="5"/>
</matcher>
</trigger>
</contextConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<#-- -------------------- -->
<#-- devonfw SPECIFIC MACROS -->
<#-- -------------------- -->

<#--
Generates all field declaration whereas Entity references will be converted to appropriate id references
-->
<#macro generateFieldDeclarations_withRespectTo_entityObjectToIdReferenceConversion isSearchCriteria=false>
<#list pojo.fields as field>
<#if field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references -->
<#if !JavaUtil.isCollection(classObject, field.name)> <#-- do not generate field for multiple relation -->
private ${field.type?replace("[^<>,]+Entity","Long","r")} ${DevonfwUtil.resolveIdVariableName(classObject,field)};
</#if>
<#elseif field.type?contains("Embeddable")>
<#if isSearchCriteria>
private ${field.type?replace("Embeddable","SearchCriteriaTo")} ${field.name};
<#else>
private ${field.type?replace("Embeddable","Eto")} ${field.name};
</#if>
<#elseif isSearchCriteria && JavaUtil.equalsJavaPrimitive(classObject,field.name)>
private ${JavaUtil.boxJavaPrimitives(classObject,field.name)} ${field.name};
<#elseif !isSearchCriteria || !JavaUtil.isCollection(classObject, field.name)>
private ${field.type} ${field.name};
</#if>
</#list>
<#-- Used to generate StringSearchConfigTo for each field -->
<#if isSearchCriteria>
<#list pojo.fields as field>
<#if field.type="String">
private StringSearchConfigTo ${field.name}Option;
</#if>
</#list>
</#if>
</#macro>

<#--
Generates all setter and getter for the fields whereas for Entity fields it will generate setter and getter for id references
-->
<#macro generateSetterAndGetter_withRespectTo_entityObjectToIdReferenceConversion implementsInterface=true, isInterface=false, isSearchCriteria=false>
<#list pojo.fields as field>
<#if field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references -->
<#if !JavaUtil.isCollection(classObject, field.name)> <#-- do not generate getters & setters for multiple relation -->
<#assign idVar = DevonfwUtil.resolveIdVariableName(classObject,field)>
<#if !implementsInterface>
/**
* getter for ${field.name}Id attribute
* @return ${field.name}Id
*/
</#if>
<#if implementsInterface>@Override</#if>
public ${DevonfwUtil.getSimpleEntityTypeAsLongReference(field)} ${DevonfwUtil.resolveIdGetter(field,false,"")} <#if isInterface>;<#else>{
return ${idVar};
}</#if>
<#if !implementsInterface>
/**
* @param ${field.name}
* setter for ${field.name} attribute
*/
</#if>
<#if implementsInterface>@Override</#if>
public void ${DevonfwUtil.resolveIdSetter(field,false,"")}(${DevonfwUtil.getSimpleEntityTypeAsLongReference(field)} ${idVar}) <#if isInterface>;<#else>{
this.${idVar} = ${idVar};
}</#if>
</#if>
<#elseif field.type?contains("Embeddable")>
<#if isSearchCriteria>
/**
* @return ${field.name}
*/
public ${field.type?replace("Embeddable","SearchCriteriaTo")} get${field.name?cap_first}() <#if isInterface>;<#else>{
return ${field.name};
}</#if>

/**
* @param ${field.name}
* setter for ${field.name} attribute
*/
public void set${field.name?cap_first}(${field.type?replace("Embeddable","SearchCriteriaTo")} ${field.name}) <#if isInterface>;<#else>{
this.${field.name} = ${field.name};
}</#if>
<#else>
/**
* @return ${field.name}Id
*/
public ${field.type?replace("Embeddable","")} <#if field.type=='boolean'>is<#else>get</#if>${field.name?cap_first}() <#if isInterface>;<#else>{
return ${field.name};
}</#if>

/**
* @param ${field.name}
* setter for ${field.name} attribute
*/
public void set${field.name?cap_first}(${field.type?replace("Embeddable","")} ${field.name}) <#if isInterface>;<#else>{
this.${field.name} = ${field.name};
}</#if>
</#if>
<#elseif !isSearchCriteria || !JavaUtil.isCollection(classObject, field.name)>
<#if !implementsInterface>
/**
* @return ${field.name}Id
*/
</#if>
<#if implementsInterface>@Override</#if>
public <#if isSearchCriteria>${JavaUtil.boxJavaPrimitives(classObject,field.name)} get${field.name?cap_first}() <#else>${field.type} <#if field.type=='boolean'>is<#else>get</#if>${field.name?cap_first}()</#if> <#if isInterface>;<#else>{
return ${field.name};
}</#if>
<#if !implementsInterface>
/**
* @param ${field.name}
* setter for ${field.name} attribute
*/
</#if>
<#if implementsInterface>@Override</#if>
public void set${field.name?cap_first}(<#if isSearchCriteria>${JavaUtil.boxJavaPrimitives(classObject,field.name)}<#else>${field.type}</#if> ${field.name}) <#if isInterface>;<#else>{
this.${field.name} = ${field.name};
}</#if>
</#if>
</#list>
<#if isSearchCriteria>
<#list pojo.fields as field>
<#if field.type="String">
/**
* @return the {@link StringSearchConfigTo} used to search for {@link #get${field.name?cap_first}<#if field.type?contains("Entity")>Entity</#if>() ${field.name}}.
*/
public StringSearchConfigTo get${field.name?cap_first}Option() {

return this.${field.name}Option;
}

/**
* @param ${field.name}Option new value of {@link #get${field.name?cap_first}Option()}.
*/
public void set${field.name?cap_first}Option(StringSearchConfigTo ${field.name}Option) {

this.${field.name}Option =${field.name}Option;
}
</#if>
</#list>
</#if>
</#macro>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<templatesConfiguration xmlns="http://capgemini.com/devonfw/cobigen/TemplatesConfiguration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">

<templates>
<templateExtension ref="${variables.entityName}Eto.java" mergeStrategy="javamerge"/>
</templates>

<templateScans>
<templateScan templatePath="templates" destinationPath="src/main"/>
</templateScans>

<increments>
<increment name="tos" description="TO's">
<templateRef ref="${variables.entityName}Eto.java"/>
</increment>
</increments>
</templatesConfiguration>
Loading

0 comments on commit 05ba40c

Please sign in to comment.