Skip to content
Snippets Groups Projects
Commit 406b976e authored by Christian Wulf's avatar Christian Wulf
Browse files

fixed bug not renaming the class

parent 491dceca
No related branches found
No related tags found
No related merge requests found
/*
TEMPLATE
PRODUCTLINE default
VARIABLE groupId
cockpit
PRODUCTLINE fm
VARIABLE groupId
fmcockpit
PRODUCTLINE bm
VARIABLE groupId
bmcockpit
TEMPLATE END
*/
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
//driverClassName = "org.h2.Driver"
//username = "sa"
//password = ""
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
production {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
/* Added by the Hibernate Spatial Plugin. */
dataSource {
dialect = org.hibernatespatial.postgis.PostgisDialect
}
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
//driverClassName = "org.h2.Driver"
//username = "sa"
//password = ""
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
production {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432//* groupId */"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
/* Added by the Hibernate Spatial Plugin. */
dataSource {
dialect = org.hibernatespatial.postgis.PostgisDialect
}
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
//driverClassName = "org.h2.Driver"
//username = "sa"
//password = ""
url = "jdbc:postgresql://127.0.0.1:5432/fmcockpit"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432/fmcockpit"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
}
}
production {
dataSource {
dbCreate = "create-drop"
url = "jdbc:postgresql://127.0.0.1:5432/fmcockpit"
username = "postgres"
password = "ESNAdmin2012"
dialect = org.hibernatespatial.postgis.PostgisDialect
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
/* Added by the Hibernate Spatial Plugin. */
dataSource {
dialect = org.hibernatespatial.postgis.PostgisDialect
}
/*
TEMPLATE
PRODUCTLINE default
VARIABLE bootstraps
new CommonInitializer(),
new CockpitInitializer()
PRODUCTLINE fm
VARIABLE bootstraps
new CommonInitializer(),
new TbmInitializer(),
new CockpitInitializer(),
new GISInitializer(),
// new EnergyIndustryInitializer(), // TODO remove...
// new HousingIndustryInitializer(),
new BlueFolderInitializer(),
new DashboardInitializer(),
new DigitalPenInitializer()
PRODUCTLINE bm
VARIABLE bootstraps
new CommonInitializer(),
new CockpitInitializer(),
new BenchmarkInitializer(),
new GISInitializer(),
new WaterAndGroundBenchmarkInitializer(),
new DashboardInitializer()
PRODUCTLINE ee
VARIABLE bootstraps
new CommonInitializer(),
new TbmInitializer(),
new CockpitInitializer(),
new GISInitializer(),
new EnergyIndustryInitializer(),
new DashboardInitializer(),
new DigitalPenInitializer()
TEMPLATE END
*/
import cockpit.common.InitializerInterface
import cockpit.common.shiro.User
class MasterBootStrap_template {
def environmentService
List<InitializerInterface> bootstraps = [ /* bootstraps */
]
def init = { servletContext ->
if (isFirstRun()) {
initMasterData()
}
initTransientData()
}
private isFirstRun() {
User.count() == 0
}
private initTransientData() {
bootstraps.each {
it.initTransientData()
}
}
private initMasterData() {
bootstraps.each {
it.initMasterData()
}
}
}
package de.chw.css.script;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import de.chw.util.unicode.ANTLRFileStreamWithBOM;
public class Ast2VariablesAndContentTransformator {
private static final Logger LOG = LogManager.getLogger(Ast2VariablesAndContentTransformator.class);
private final String chosenProduct;
private String content;
private final Map<String, Map<String, String>> variables = new HashMap<String, Map<String, String>>();
private Map<String, String> productVariables;
public Ast2VariablesAndContentTransformator(String filename, String chosenProduct) throws IOException {
this.chosenProduct = chosenProduct;
this.variables.put("default", new HashMap<String, String>());
CssTemplateEngineLexer lexer = new CssTemplateEngineLexer(new ANTLRFileStreamWithBOM(filename));
CssTemplateEngineParser parser = new CssTemplateEngineParser(new CommonTokenStream(lexer));
try {
CommonTree tree = (CommonTree) parser.file().getTree();
LOG.debug("tokens: " + ((CommonTokenStream) parser.getTokenStream()).getTokens());
traverse(tree);
} catch (RecognitionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
private Object traverse(CommonTree tree) {
if (tree == null)
return null;
LOG.debug("type: " + tree.getType());
LOG.trace("text: " + tree.getText());
LOG.trace("children: " + tree.getChildren());
switch (tree.getType()) {
case CssTemplateEngineParser.FILE:
traverse(getChildOfType(tree, CssTemplateEngineParser.TEMPLATE));
content = (String) traverse(getChildOfType(tree, CssTemplateEngineParser.VALUE));
break;
case CssTemplateEngineParser.TEMPLATE:
traverse(tree.getChildren());
break;
case CssTemplateEngineParser.PRODUCTLINE:
String product = (String) traverse(getChildOfType(tree, CssTemplateEngineParser.VALUE));
LOG.debug("Found product '" + product + "'");
productVariables = new HashMap<String, String>();
traverse(tree.getChildren().subList(1, tree.getChildCount()));
variables.put(product, productVariables);
break;
case CssTemplateEngineParser.VALUE:
return tree.getText();
case CssTemplateEngineParser.VARIABLE:
String variable = (String) traverse((CommonTree) tree.getChild(0));
String value = (String) traverse((CommonTree) tree.getChild(1));
productVariables.put(variable, value);
LOG.debug("Found declaration '" + variable + " = " + value + "'");
break;
default:
break;
}
return null;
}
private CommonTree getChildOfType(CommonTree tree, int type) {
return (CommonTree) tree.getFirstChildWithType(type);
}
private void traverse(List<CommonTree> children) {
for (CommonTree child : children) {
traverse(child);
}
}
public Map<String, String> getVariables() {
return variables.containsKey(chosenProduct) ? variables.get(chosenProduct) : variables.get("default");
}
public String getContent() {
return content;
}
}
package de.chw.css.script;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import de.chw.util.FileHelper;
public class Ast2VariablesAndContentTransformatorTest {
@Test
public void testReadingContentCorrectly() throws IOException {
final String filenamePrefix = "DataSource_template";
final String ext = "groovy";
String filename = "resource/" + filenamePrefix + "." + ext;
String chosenProduct = "fm";
Ast2VariablesAndContentTransformator reader = new Ast2VariablesAndContentTransformator(filename, chosenProduct);
String expected = FileHelper.readTextFile("resource/" + filenamePrefix + "_content_expected" + "." + ext);
assertEquals(expected, reader.getContent());
}
@Test
public void testReadingContentWithBOMCorrectly() throws IOException {
final String filenamePrefix = "jquery.ribbon_template";
final String ext = "js";
String filename = "resource/" + filenamePrefix + "." + ext;
String chosenProduct = "bm";
Ast2VariablesAndContentTransformator reader = new Ast2VariablesAndContentTransformator(filename, chosenProduct);
String expected = FileHelper.readTextFile("resource/" + filenamePrefix + "_content_expected" + "." + ext);
assertEquals(expected, reader.getContent());
}
@Test
public void testDefaultFallback() throws IOException {
final String filenamePrefix = "main_template";
final String ext = "css";
String filename = "resource/" + filenamePrefix + "." + ext;
String chosenProduct = "fm";
Ast2VariablesAndContentTransformator reader = new Ast2VariablesAndContentTransformator(filename, chosenProduct);
Map<String, String> expected = new HashMap<String, String>();
expected.put("widget_header_bg", "#2884C4");
assertEquals(expected, reader.getVariables());
}
@Test
public void testChooseCorrectProduct() throws IOException {
final String filenamePrefix = "two-pls";
final String ext = "css";
String filename = "resource/" + filenamePrefix + "." + ext;
String chosenProduct = "fm";
Ast2VariablesAndContentTransformator reader = new Ast2VariablesAndContentTransformator(filename, chosenProduct);
Map<String, String> expected = new HashMap<String, String>();
expected.put("bgcolor", "#fafafa");
assertEquals(expected, reader.getVariables());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment