Commit 97c1cba4 authored by l-gu's avatar l-gu
Browse files

Target new methods about ouptut file

parent ca1c111e
......@@ -15,6 +15,7 @@
*/
package org.telosys.tools.generator.context;
import java.io.File;
import java.util.HashMap;
import org.telosys.tools.commons.FileUtil;
......@@ -50,10 +51,12 @@ public class Target {
private final TelosysToolsCfg telosysToolsCfg ;
private final VariablesManager variablesManager ;
// Target definition in templates bundle :
private final String targetName ; // Col 1
private final String originalFileDefinition ; // Col 2
private final String originalFolderDefinition; // Col 3
private final String template ; // Col 4
private final String type ; // Col 5
private final String entityName ;
private String forcedEntityName = null ;
......@@ -71,6 +74,13 @@ public class Target {
this.originalFileDefinition = targetDefinition.getFile() ;
this.originalFolderDefinition = targetDefinition.getFolder();
this.template = targetDefinition.getTemplate();
if ( targetDefinition.isResource() ) {
this.type = "R" ;
} else if ( targetDefinition.isOnce() ) {
this.type = "1" ;
} else {
this.type = "*" ;
}
//--- Specialization for the given entity
this.entityName = entityName ;
......@@ -298,6 +308,31 @@ public class Target {
getOutputFileNameInProject()) ;
}
//-------------------------------------------------------------------------------------
@VelocityMethod(
text = {
"Returns true if the file to generate already exists",
" "
},
since = "3.3.0"
)
public boolean outputFileExists() {
File file = new File(getOutputFileFullPath());
return file.exists();
}
//-------------------------------------------------------------------------------------
@VelocityMethod(
text = {
"Returns the target type as in templates configuration file ",
"The type is '*', '1' or 'R'",
" "
},
since = "3.3.0"
)
public String getType() {
return this.type;
}
//-------------------------------------------------------------------------------------
// END OF VELOCITY METHODS
......
......@@ -13,10 +13,17 @@ import junit.env.telosys.tools.generator.TestsEnv;
import junit.env.telosys.tools.generator.fakemodel.FakeEntity;
public class TargetTest {
private void println(String s) {
System.out.println( s );
}
private TelosysToolsCfg getTelosysToolsCfg() {
File projectFolder = TestsEnv.getTestFolder("proj-target-tests");
return TestsEnv.loadTelosysToolsCfg(projectFolder);
TelosysToolsCfg telosysToolsCfg = TestsEnv.loadTelosysToolsCfg(projectFolder);
println( "TelosysToolsCfg loaded from : " + telosysToolsCfg.getCfgFileAbsolutePath() );
assertEquals("/src", telosysToolsCfg.getSRC() );
return telosysToolsCfg;
}
// private Variable[] getVariables() {
......@@ -39,19 +46,16 @@ public class TargetTest {
"${SRC}/${ROOT_PKG}/persistence/services",
"bean.vm",
"*");
// Target target = new Target( targetDef, buildEntity("AUTHOR", "Author"), getVariables() ); // v 3.0.0
TelosysToolsCfg telosysToolsCfg = getTelosysToolsCfg();
System.out.println( telosysToolsCfg.getCfgFileAbsolutePath() );
assertEquals("/src", telosysToolsCfg.getSRC() );
Target target = new Target( telosysToolsCfg, targetDef, buildEntity("AUTHOR", "Author") ); // v 3.0.0
Target target = new Target( telosysToolsCfg, targetDef, buildEntity("AUTHOR", "Author") ); // v 3.3.0
print(target);
print(target);
assertEquals("Target 1", target.getTargetName());
assertEquals("${BEANNAME}.java", target.getOriginalFileDefinition());
assertEquals("${SRC}/${ROOT_PKG}/persistence/services", target.getOriginalFolderDefinition());
assertEquals("bean.vm", target.getTemplate());
assertEquals("*", target.getType());
// current entity :
assertEquals("Author", target.getEntityName());
......@@ -62,7 +66,6 @@ public class TargetTest {
assertEquals("/src/org/demo/foo/bar/persistence/services", target.getFolder());
assertEquals("src/org/demo/foo/bar/persistence/services/Author.java",target.getOutputFileNameInProject());
System.out.println( target.getOutputFileFullPath() ); // v 3.3.0
assertEquals("C:\\FOO\\BAR/src/org/demo/foo/bar/persistence/services/Author.java", target.getOutputFileFullPath());
// force entity name :
......@@ -84,24 +87,44 @@ public class TargetTest {
"${SRC}/${ENTITY_PKG}",
"bean.vm",
"*");
// Target target = new Target( targetDef, buildEntity("AUTHOR", "Author"), getVariables() ); // v 3.0.0
Target target = new Target( getTelosysToolsCfg(), targetDef, buildEntity("AUTHOR", "Author") ); // v 3.3.0
Target target = new Target( getTelosysToolsCfg(), targetDef, buildEntity("BOOK", "Book") ); // v 3.3.0
print(target);
assertEquals("Author.java", target.getFile());
assertEquals("Book.java", target.getFile());
assertEquals("/src/org/demo/foo/bar/bean", target.getFolder());
}
@Test
public void testTargetCreation3() {
TargetDefinition targetDef = new TargetDefinition(
"Target 3",
"config.xml",
"${RES}/foo",
"config_xml.vm",
"1");
Target target = new Target( getTelosysToolsCfg(), targetDef ); // v 3.3.0
print(target);
assertEquals("config.xml", target.getFile());
assertEquals("src/main/resources/foo", target.getFolder());
assertEquals("1", target.getType());
assertEquals("C:\\FOO\\BAR/src/main/resources/foo/config.xml", target.getOutputFileFullPath());
}
private void print(Target target) {
System.out.println("Target : " );
System.out.println(" . targetName = " + target.getTargetName() );
System.out.println(" . originalFileDefinition = " + target.getOriginalFileDefinition() );
System.out.println(" . file = " + target.getFile() );
System.out.println(" . folder = " + target.getFolder() );
System.out.println(" . template = " + target.getTemplate() );
println("Target : " );
println(" . targetName = " + target.getTargetName() );
println(" . originalFileDefinition = " + target.getOriginalFileDefinition() );
println(" . originalFolderDefinition = " + target.getOriginalFolderDefinition() );
println(" . template = " + target.getTemplate() );
println(" . type = " + target.getType() );
println(" . folder = " + target.getFolder() );
println(" . file = " + target.getFile() );
println(" . full path = " + target.getOutputFileFullPath() ); // v 3.3.0
println(" . exists ? = " + target.outputFileExists() ); // v 3.3.0
}
private Entity buildEntity(String tableName, String className) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment