Skip to content

Commit

Permalink
Added minify and createTests flags for generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tdl-jturner committed Aug 20, 2019
1 parent 43ab4b3 commit 16b054a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ else if(column.getValue().getType().getProtocolCode()==48) {
}

generate("Entity.ftl", input, entityName);
generate("EntityTest.ftl",input,entityTestName);
if(casquatchGeneratorConfiguration.getCreateTests()) {
generate("EntityTest.ftl", input, entityTestName);
}
}

/**
Expand Down Expand Up @@ -452,6 +454,8 @@ protected Map<String,Object> inputStart(String name) {
input.put("class", casquatchGeneratorConfiguration.getPackageName()+"."+CasquatchNamingConvention.cqlToJavaClass(name));
input.put("name", name);
input.put("naming", new CasquatchNamingConvention());
input.put("minify",casquatchGeneratorConfiguration.getMinify());
input.put("createTests",casquatchGeneratorConfiguration.getCreateTests());
return input;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class CasquatchGeneratorConfiguration {
String packageName;
@Optional
Boolean overwrite=false;
@Optional
Boolean minify=false;
@Optional
Boolean createTests=true;

/**
* Validate the configuration and throw an exception on failure
Expand Down
9 changes: 8 additions & 1 deletion casquatch-generator/src/main/resources/templates/Entity.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package ${package};

import com.tmobile.opensource.casquatch.AbstractCasquatchEntity;
import com.tmobile.opensource.casquatch.annotation.CasquatchEntity;
<#if !minify>
import com.tmobile.opensource.casquatch.annotation.CasquatchIgnore;
</#if>
<#if clusteringColumns?has_content>
import com.tmobile.opensource.casquatch.annotation.ClusteringColumn;
</#if>
Expand All @@ -21,7 +23,9 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

<#if !minify || createTests>
import org.apache.commons.text.TextStringBuilder;
</#if>

@CasquatchEntity
@Getter @Setter @NoArgsConstructor
Expand All @@ -46,6 +50,7 @@ public class ${naming.classToSimpleClass(class)} extends AbstractCasquatchEntity
</#list>
</#if>

<#if !minify>
/**
* Generated: Initialize with Partition Keys
<#list partitionKeys as cql,col>
Expand Down Expand Up @@ -92,7 +97,8 @@ public class ${naming.classToSimpleClass(class)} extends AbstractCasquatchEntity
</#list>
return ${naming.classToVar(naming.classToSimpleClass(class))};
}

</#if>
<#if !minify || createTests>
/**
* Generated: Returns DDL
* @return DDL for table
Expand All @@ -107,5 +113,6 @@ public class ${naming.classToSimpleClass(class)} extends AbstractCasquatchEntity
ddl.appendln("${ddl}");
return ddl.toString();
}
</#if>
}

2 changes: 2 additions & 0 deletions manual/content/features/casquatchgenerator.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Properties can be passed either through a -D parameter or in a properties file a
| casquatch.generator.overwrite | Boolean | No | false | Toggle overwriting of files in outputFolder |
| casquatch.generator.createPackage | Boolean | No | false | If createPackage=true then pom.xml and src folder structure will be added |
| casquatch.generator.packageName | String | No | com.tmobile.opensource.casquatch.models | Package name for source files |
| casquatch.minify | Boolean | No | false | Create entity with minimal amount of code by excluding convenience methods |
| casquatch.createTests | String | No | true | Create test entities as well |
| config.file | String | No | Specify a path to a config file to place parameters |

0 comments on commit 16b054a

Please sign in to comment.