Creating custom propertis plugin

Daniel Tihelka <[email protected]> Wed, 27 Jul 2011 09:14:55 +0200
Newsgroups gmane.comp.java.cruise-control.devel
Organization KKY
Message-ID <[email protected]>
Dear developers,

I would like to create properties reader which will be able to parse general 
files and extract properties from them based on regular expressions. The aim is 
to make our build projects more robust, since they use many various (mostly 
python and C++) command line utilities with options set like:

--keep-feats 'unit:dur:IPS:score'

Of course, the individual strings are defined as constants to avoid their 
repeating in the source files of the utilities. For example:

#define KEY_UNIT "unit"
...

if (item[i] == KEY_UNIT) {
    ...
}


So, it would be nice to have a set of properties in CC holding the values. 
Currently, we define such properties "manually" in the CC project, facing build 
failures everywhere someone decides to change the name. However, the property 
values could fairly easily be parsed automatically from the appropriate file(s) 
(and the automatic properties update framework 
http://jira.public.thoughtworks.org/browse/CC-952, which I helped to made 
before, would keep it up-to-date).

Well, to build such a general properties reader, I have created a class:

class RegexProperties implements PropertiesPlugin, ResolverUser
{
  ....
}

and implemented it. To test it, I have created a test project like:

<cruisecontrol>
  <plugin name='regexproperties' classname='zcu.kky.RegexProperties' />
  <project name="regex_properties" buildafterfailed="true">
    <regexproperties file="regexproperties.txt"  pattern="\s*([^\s]+)\s*::
\s*([^\s+])" name="try.\1" value="\2"/>
    <schedule interval="600" >
      <exec  command="echo"  args="WE HAVE: try.prop1 = ${try.prop1}"/>
    </schedule>
  </project>
</cruisecontrol>

and the regexproperties.txt file like:

prop1   :: WORKING!


But, project loading fails with the following message:

net.sourceforge.cruisecontrol.CruiseControlException: error configuring project 
pokus_regex_properties
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.handleProject(CruiseControlConfig.java:422)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.parse(CruiseControlConfig.java:171)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.<init>(CruiseControlConfig.java:187)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.add(CruiseControlConfig.java:303)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.handleIncludedProjects(CruiseControlConfig.java:202)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.parse(CruiseControlConfig.java:160)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.<init>(CruiseControlConfig.java:187)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.add(CruiseControlConfig.java:303)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.handleIncludedProjects(CruiseControlConfig.java:202)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.parse(CruiseControlConfig.java:160)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.<init>(CruiseControlConfig.java:132)
        at 
net.sourceforge.cruisecontrol.config.XMLConfigManager.loadConfig(XMLConfigManager.java:86)
        at 
net.sourceforge.cruisecontrol.config.XMLConfigManager.<init>(XMLConfigManager.java:78)
        at 
net.sourceforge.cruisecontrol.CruiseControlController.setConfigFile(CruiseControlController.java:93)
        at net.sourceforge.cruisecontrol.Main.createController(Main.java:146)
        at net.sourceforge.cruisecontrol.Main.start(Main.java:113)
        at 
net.sourceforge.cruisecontrol.launch.Launcher.run(Launcher.java:259)
        at 
net.sourceforge.cruisecontrol.launch.Launcher.main(Launcher.java:117)
Caused by: net.sourceforge.cruisecontrol.CruiseControlException: Nested 
element: 'regexproperties' is not supported for the <project> tag.
        at 
net.sourceforge.cruisecontrol.PluginXMLHelper.configureObject(PluginXMLHelper.java:215)
        at 
net.sourceforge.cruisecontrol.PluginXMLHelper.configure(PluginXMLHelper.java:134)
        at 
net.sourceforge.cruisecontrol.PluginXMLHelper.configure(PluginXMLHelper.java:92)
        at 
net.sourceforge.cruisecontrol.ProjectXMLHelper.configurePlugin(ProjectXMLHelper.java:95)
        at 
net.sourceforge.cruisecontrol.CruiseControlConfig.handleProject(CruiseControlConfig.java:420)
        ... 17 more


Examining it more deeply, I have found that the problem is in 
PluginXMLHelper#configureObject(Element, Object, boolean), around lines 
200-220, where there is no "added" found. I have look at what "adders" are, 
and realized that they are "add*" methods from ProjectConfig, like 
add(LabelIncrementer), add(Listeners), but there is no valid 
add(PropertiesPlugin) or similar method.


So, the question is - is it intended behavior (i.e. properties cannot have 
form of a plugin) or a kind of bug? Where and how to fix it? If possible, 
please, give me some suggestions and will try to implement it.

I believe that it could be handy to have a possibility to create custom 
properties plugins. I can, for example, image the situation, when properties 
are stored in a database.

Thank you for your help.
Best regards,
Dan T.

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey

_______________________________________________
Cruisecontrol-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cruisecontrol-devel
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)

iEYEABECAAYFAk4vuvEACgkQuYlVhxo/P1HeoQCgs4O9sgWjadLr0s9KwlD/giGS
HsUAnjcAjfLiJmP5BwUAb1otGRmkMgj3
=Y+Wg
-----END PGP SIGNATURE-----