* /org/argeo/slc/ant/taskdefs.properties\r
*/\r
private static String SLC_TASKDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/taskdefs.properties";\r
+ private static String SLC_TYPEDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/typedefs.properties";\r
\r
@Override\r
public void parse(Project project, Object source) throws BuildException {\r
// create structure root\r
registerProjectAndParents(project, slcAntConfig);\r
\r
- addSlcTasks(project);\r
+ addCustomTaskAndTypes(project);\r
\r
}\r
\r
// FIXME: workaround to the removal of leading '/' by Spring\r
// use URL instead?\r
AbstractApplicationContext context = new FileSystemXmlApplicationContext(\r
- '/'+acPath);\r
+ '/' + acPath);\r
context.registerShutdownHook();\r
project.addReference(REF_ROOT_CONTEXT, context);\r
}\r
\r
/** Loads the SLC specific Ant tasks. */\r
- private void addSlcTasks(Project project) {\r
- Properties taskdefs = new Properties();\r
- try {\r
- InputStream in = project.getClass().getResourceAsStream(\r
- SLC_TASKDEFS_RESOURCE_PATH);\r
- taskdefs.load(in);\r
- in.close();\r
- } catch (IOException e) {\r
- throw new SlcAntException("Cannot load task definitions", e);\r
- }\r
-\r
+ private void addCustomTaskAndTypes(Project project) {\r
+ Properties taskdefs = getDefs(project, SLC_TASKDEFS_RESOURCE_PATH);\r
for (Object o : taskdefs.keySet()) {\r
String name = o.toString();\r
try {\r
log.error("Unknown class for task " + name, e);\r
}\r
}\r
+ Properties typedefs = getDefs(project, SLC_TYPEDEFS_RESOURCE_PATH);\r
+ for (Object o : typedefs.keySet()) {\r
+ String name = o.toString();\r
+ try {\r
+ project.addDataTypeDefinition(name, Class.forName(typedefs\r
+ .getProperty(name)));\r
+ } catch (ClassNotFoundException e) {\r
+ log.error("Unknown class for type " + name, e);\r
+ }\r
+ }\r
+ }\r
+\r
+ private Properties getDefs(Project project, String path) {\r
+ Properties defs = new Properties();\r
+ try {\r
+ InputStream in = project.getClass().getResourceAsStream(path);\r
+ defs.load(in);\r
+ in.close();\r
+ } catch (IOException e) {\r
+ throw new SlcAntException("Cannot load task definitions", e);\r
+ }\r
+ return defs;\r
}\r
}\r
\r
import org.springframework.beans.BeanWrapper;\r
import org.springframework.beans.BeanWrapperImpl;\r
+import org.springframework.beans.factory.InitializingBean;\r
import org.springframework.context.ApplicationContext;\r
\r
+import org.apache.commons.logging.LogFactory;\r
import org.apache.tools.ant.types.DataType;\r
\r
import org.argeo.slc.ant.SlcProjectHelper;\r
+import org.argeo.slc.core.SlcException;\r
\r
/** Abstract Ant type wrapping a Spring bean. */\r
public abstract class AbstractSpringArg extends DataType {\r
\r
BeanWrapper wrapper = new BeanWrapperImpl(beanInstance);\r
for (OverrideArg override : overrides) {\r
+ LogFactory.getLog(getClass()).debug("Prop "+override.getName());\r
wrapper.setPropertyValue(override.getName(), override\r
.getObject());\r
}\r
+\r
+ if (beanInstance instanceof InitializingBean) {\r
+ try {\r
+ ((InitializingBean) beanInstance).afterPropertiesSet();\r
+ } catch (Exception e) {\r
+ throw new SlcException("Could not initialize bean", e);\r
+ }\r
+ }\r
}\r
return beanInstance;\r
}\r
--- /dev/null
+package org.argeo.slc.ant.spring;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+import java.util.Vector;\r
+\r
+import org.argeo.slc.core.SlcException;\r
+\r
+public class MapArg {\r
+ private List<EntryArg> entries = new Vector<EntryArg>();\r
+ private Map<String, Object> map = new TreeMap<String, Object>();\r
+\r
+ public EntryArg createEntry() {\r
+ EntryArg arg = new EntryArg();\r
+ entries.add(arg);\r
+ return arg;\r
+ }\r
+\r
+ public Map<String, Object> getMap() {\r
+ if (map.size() == 0) {\r
+ for (EntryArg arg : entries) {\r
+ String key = arg.getKey();\r
+ if (map.containsKey(key)) {\r
+ throw new SlcException("Key '" + key + "' already set.");\r
+ } else {\r
+ map.put(key, arg.getValue());\r
+ }\r
+ }\r
+ }\r
+ return map;\r
+ }\r
+\r
+ public static class EntryArg {\r
+ private String key;\r
+ private Object value;\r
+\r
+ public String getKey() {\r
+ return key;\r
+ }\r
+\r
+ public void setKey(String key) {\r
+ this.key = key;\r
+ }\r
+\r
+ public Object getValue() {\r
+ return value;\r
+ }\r
+\r
+ public void setValue(String value) {\r
+ this.value = value;\r
+ }\r
+\r
+ }\r
+}\r
\r
import org.apache.tools.ant.BuildException;\r
\r
+import org.argeo.slc.core.SlcException;\r
+\r
/** Ant type allowing to override bean properties. */\r
public class OverrideArg extends AbstractSpringArg {\r
private String name;\r
private Object value;\r
private OverrideList overrideList;\r
+ private String antref;\r
\r
/** The name of the property to override. */\r
public String getName() {\r
this.name = name;\r
}\r
\r
+ /** Sets a reference to an ant data type. */\r
+ public void setAntref(String antref) {\r
+ if (value != null || overrideList != null || getBean() != null) {\r
+ throw new BuildException("Value already set.");\r
+ }\r
+ this.antref = antref;\r
+ }\r
+\r
/** Both value and bean cannot be set. */\r
public void setValue(String value) {\r
- if (getBean() != null || overrideList != null) {\r
+ if (getBean() != null || overrideList != null || antref != null) {\r
throw new BuildException("Value already set.");\r
}\r
this.value = value;\r
\r
@Override\r
public void setBean(String bean) {\r
- if (value != null || overrideList != null) {\r
+ if (value != null || overrideList != null || antref != null) {\r
throw new BuildException("Value already set.");\r
}\r
super.setBean(bean);\r
return getBeanInstance();\r
} else if (overrideList != null) {\r
return overrideList.getAsObjectList();\r
+ } else if (antref != null) {\r
+ Object obj = getProject().getReference(antref);\r
+ if (obj == null) {\r
+ throw new SlcException("No object found for reference "\r
+ + antref);\r
+ }\r
+ return obj;\r
} else {\r
throw new BuildException("Value or bean not set.");\r
}\r
--- /dev/null
+package org.argeo.slc.ant.test;\r
+\r
+import java.util.Collection;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+import java.util.Vector;\r
+\r
+import org.apache.tools.ant.types.DataType;\r
+\r
+import org.argeo.slc.ant.spring.MapArg;\r
+import org.argeo.slc.core.SlcException;\r
+import org.argeo.slc.core.test.context.ContextAware;\r
+import org.argeo.slc.core.test.context.ParentContextAware;\r
+\r
+public class ParentContextArg extends DataType implements ParentContextAware {\r
+ private MapArg values = null;\r
+ private MapArg expectedValues = null;\r
+\r
+ private List<ContextAware> children = new Vector<ContextAware>();\r
+\r
+ public MapArg createValues() {\r
+ values = new MapArg();\r
+ return values;\r
+ }\r
+\r
+ public MapArg createExpectedValues() {\r
+ expectedValues = new MapArg();\r
+ return expectedValues;\r
+ }\r
+\r
+ public void addChildContext(ContextAware contextAware) {\r
+ children.add(contextAware);\r
+ }\r
+\r
+ public Collection<ContextAware> getChildContexts() {\r
+ return children;\r
+ }\r
+\r
+ public String getContextAnyFlag() {\r
+ return DEFAULT_ANY_FLAG;\r
+ }\r
+\r
+ public String getContextSkipFlag() {\r
+ return DEFAULT_SKIP_FLAG;\r
+ }\r
+\r
+ public Map<String, Object> getExpectedValues() {\r
+ if (expectedValues == null)\r
+ expectedValues = new MapArg();\r
+ return expectedValues.getMap();\r
+ }\r
+\r
+ public Map<String, Object> getValues() {\r
+ if (values == null)\r
+ values = new MapArg();\r
+ return values.getMap();\r
+ }\r
+\r
+ public void setValues(Map<String, Object> values) {\r
+ throw new SlcException("Cannot override values map.");\r
+ }\r
+\r
+}\r
+++ /dev/null
-package org.argeo.slc.core.test.context;\r
-\r
-import org.argeo.slc.core.test.TestData;\r
-import org.argeo.slc.core.test.TestDataProvider;\r
-import org.argeo.slc.core.test.TestDataUtils;\r
-\r
-public class AbstractContextTestData extends SimpleContextAware implements\r
- TestData, TestDataProvider {\r
-\r
- public <T extends TestData> T getTestData(Class<T> clss, String key) {\r
- return TestDataUtils.getItSelf(clss, this);\r
- }\r
-\r
-}\r
import java.util.Map;\r
\r
public interface ContextAware {\r
+ public final static String DEFAULT_SKIP_FLAG = "!";\r
+ public final static String DEFAULT_ANY_FLAG = "*";\r
+\r
public Map<String, Object> getValues();\r
\r
public void setValues(Map<String, Object> values);\r
\r
public Map<String, Object> getExpectedValues();\r
\r
- public void setExpectedValues(Map<String, Object> expectedValues);\r
-\r
public String getContextSkipFlag();\r
\r
public String getContextAnyFlag();\r
--- /dev/null
+package org.argeo.slc.core.test.context;\r
+\r
+import org.argeo.slc.core.test.TestData;\r
+import org.argeo.slc.core.test.TestDataProvider;\r
+import org.argeo.slc.core.test.TestDataUtils;\r
+\r
+public class DefaultContextTestData extends SimpleContextAware implements\r
+ TestData, TestDataProvider {\r
+\r
+ public <T extends TestData> T getTestData(Class<T> clss, String key) {\r
+ return TestDataUtils.getItSelf(clss, this);\r
+ }\r
+\r
+}\r
private Map<String, Object> values = new TreeMap<String, Object>();\r
private Map<String, Object> expectedValues = new TreeMap<String, Object>();\r
\r
- private String contextSkipFlag = "!";\r
- private String contextAnyFlag = "*";\r
+ private String contextSkipFlag = DEFAULT_SKIP_FLAG;\r
+ private String contextAnyFlag = DEFAULT_ANY_FLAG;\r
\r
public Map<String, Object> getValues() {\r
return values;\r
syncPath(registry, localRegistry, parent);\r
}\r
\r
- if (log.isDebugEnabled())\r
- log.debug("Synchronize path " + path);\r
+ if (log.isTraceEnabled())\r
+ log.trace("Synchronize path " + path);\r
\r
if (registry.getElement(path) == null) {\r
if (localRegistry != null) {\r
--- /dev/null
+# Types\r
+slc.context=org.argeo.slc.ant.test.ParentContextArg\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<beans xmlns="http://www.springframework.org/schema/beans"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">\r
-\r
- <bean id="parentContext.pc1" parent="parentContext.template">\r
- <property name="values">\r
- <map>\r
- <entry key="rootvar" value="text" />\r
- </map>\r
- </property>\r
- <property name="expectedValues">\r
- <map>\r
- <entry key="reference" value="20" />\r
- </map>\r
- </property>\r
- </bean>\r
-\r
- <bean id="context.c1" parent="context.template">\r
- <property name="parentContext" ref="parentContext.pc1" />\r
- <property name="values">\r
- <map>\r
- <entry key="reference" value="20" />\r
- <entry key="any" value="999" />\r
- <entry key="skipped" value="999" />\r
- </map>\r
- </property>\r
- <property name="expectedValues">\r
- <map>\r
- <entry key="reference" value="21" />\r
- <entry key="any" value="*" />\r
- <entry key="skipped" value="!" />\r
- </map>\r
- </property>\r
- </bean>\r
-\r
- <bean id="context.c2" parent="context.template">\r
- <property name="parentContext" ref="parentContext.pc1" />\r
- <property name="values">\r
- <map>\r
- <entry key="var" value="37" />\r
- <entry key="bad" value="56" />\r
- </map>\r
- </property>\r
- <property name="expectedValues">\r
- <map>\r
- <entry key="var" value="37" />\r
- <entry key="bad" value="57" />\r
- </map>\r
- </property>\r
- </bean>\r
-\r
- <bean id="parentContext.pc2" parent="parentContext.template">\r
- <property name="parentContext" ref="parentContext.pc1" />\r
- <property name="expectedValues">\r
- <map>\r
- <entry key="reference" value="40" />\r
- </map>\r
- </property>\r
- </bean>\r
-\r
- <bean id="context.c3" parent="context.template">\r
- <property name="parentContext" ref="parentContext.pc2" />\r
- <property name="values">\r
- <map>\r
- <entry key="reference" value="41" />\r
- <entry key="rootvar" value="textX" />\r
- </map>\r
- </property>\r
- <property name="expectedValues">\r
- <map>\r
- <entry key="reference" value="40" />\r
- <entry key="rootvar" value="text" />\r
- </map>\r
- </property>\r
- </bean>\r
-\r
-\r
- <bean id="parentContext.template"\r
- class="org.argeo.slc.core.test.context.SimpleParentContextAware"\r
- abstract="true">\r
- </bean>\r
-\r
- <bean id="context.template"\r
- class="org.argeo.slc.core.test.context.SimpleContextAware"\r
- abstract="true">\r
- </bean>\r
-</beans>
\ No newline at end of file
\r
## Levels\r
# Slc\r
-log4j.logger.org.argeo.slc=TRACE\r
+log4j.logger.org.argeo.slc=DEBUG\r
# Spring\r
log4j.logger.org.springframework=INFO\r
# Hibernate\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">\r
+\r
+ <bean id="parentContext.pc1" parent="parentContext.template">\r
+ <property name="values">\r
+ <map>\r
+ <entry key="rootvar" value="text" />\r
+ </map>\r
+ </property>\r
+ <property name="expectedValues">\r
+ <map>\r
+ <entry key="reference" value="20" />\r
+ </map>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="context.c1" parent="context.template">\r
+ <property name="parentContext" ref="parentContext.pc1" />\r
+ <property name="values">\r
+ <map>\r
+ <entry key="reference" value="20" />\r
+ <entry key="any" value="999" />\r
+ <entry key="skipped" value="999" />\r
+ </map>\r
+ </property>\r
+ <property name="expectedValues">\r
+ <map>\r
+ <entry key="reference" value="21" />\r
+ <entry key="any" value="*" />\r
+ <entry key="skipped" value="!" />\r
+ </map>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="context.c2" parent="context.template">\r
+ <property name="parentContext" ref="parentContext.pc1" />\r
+ <property name="values">\r
+ <map>\r
+ <entry key="var" value="37" />\r
+ <entry key="bad" value="56" />\r
+ </map>\r
+ </property>\r
+ <property name="expectedValues">\r
+ <map>\r
+ <entry key="var" value="37" />\r
+ <entry key="bad" value="57" />\r
+ </map>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="parentContext.pc2" parent="parentContext.template">\r
+ <property name="parentContext" ref="parentContext.pc1" />\r
+ <property name="expectedValues">\r
+ <map>\r
+ <entry key="reference" value="40" />\r
+ </map>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="context.c3" parent="context.template">\r
+ <property name="parentContext" ref="parentContext.pc2" />\r
+ <property name="values">\r
+ <map>\r
+ <entry key="reference" value="41" />\r
+ <entry key="rootvar" value="textX" />\r
+ </map>\r
+ </property>\r
+ <property name="expectedValues">\r
+ <map>\r
+ <entry key="reference" value="40" />\r
+ <entry key="rootvar" value="text" />\r
+ </map>\r
+ </property>\r
+ </bean>\r
+\r
+\r
+ <bean id="parentContext.template"\r
+ class="org.argeo.slc.core.test.context.SimpleParentContextAware"\r
+ abstract="true">\r
+ </bean>\r
+\r
+ <bean id="context.template"\r
+ class="org.argeo.slc.core.test.context.SimpleContextAware"\r
+ abstract="true">\r
+ </bean>\r
+</beans>
\ No newline at end of file