[ https://issues.apache.org/jira/browse/CONFIGURATION-181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oliver Heger resolved CONFIGURATION-181. ---------------------------------------- Resolution: Won't Fix Fix Version/s: 1.4 This issue has been hanging around for a long time now. Committers seem to agree that the proposed addition should not be added to Commons Configuration, so I am closing this ticket as wont' fix. > [configuration] Conditional directives in property files > -------------------------------------------------------- > > Key: CONFIGURATION-181 > URL: https://issues.apache.org/jira/browse/CONFIGURATION-181 > Project: Commons Configuration > Issue Type: Improvement > Environment: Operating System: other > Platform: Other > Reporter: Bogdan Calmac > Priority: Minor > Fix For: 1.4 > > Attachments: conditional_properties.patch > > > This patch adds conditional directives to property files similar to C macros: > %if, %elseif, %else, %end. > To illustrate the necessity and the syntax I will take as example a section of > my hibernate configuration file. Switching between databases normally requires > to comment/uncomment a lot of properties, and more importantly, cannot be done > automatically at runtime. > ## JNDI Datasource > #hibernate.connection.datasource = jdbc/test > #hibernate.connection.username = db2 > #hibernate.connection.password = db2 > ## HypersonicSQL > hibernate.dialect = net.sf.hibernate.dialect.HSQLDialect > hibernate.connection.driver_class = org.hsqldb.jdbcDriver > hibernate.connection.username = sa > hibernate.connection.url = jdbc:hsqldb:hsql://localhost > ## PostgreSQL > #hibernate.dialect = net.sf.hibernate.dialect.PostgreSQLDialect > #hibernate.connection.driver_class = org.postgresql.Driver > #hibernate.connection.url = jdbc:postgresql:template1 > #hibernate.connection.username = pg > #hibernate.connection.password > ## JTA transactions > #hibernate.transaction.factory_class = > net.sf.hibernate.transaction.JTATransactionFactory > #jta.UserTransaction = jta/usertransaction > #jta.UserTransaction = javax.transaction.UserTransaction > #jta.UserTransaction = UserTransaction > ## JDBC transactions > hibernate.transaction.factory_class = > net.sf.hibernate.transaction.JDBCTransactionFactory > Here is now how it would look like with conditional directives. The only thing > to change now is the property at the top of the file (which could be defined > as > a system property if you don't want to touch the file at all). Note that it > uses > nested directives. > db = jndi > %if db = jndi > ## JNDI Datasource > hibernate.connection.datasource = jdbc/test > hibernate.connection.username = db2 > hibernate.connection.password = db2 > ## JTA transactions > hibernate.transaction.factory_class = > net.sf.hibernate.transaction.JTATransactionFactory > jta.UserTransaction = jta/usertransaction > jta.UserTransaction = javax.transaction.UserTransaction > jta.UserTransaction = UserTransaction > %else > ## JDBC transactions > hibernate.transaction.factory_class = > net.sf.hibernate.transaction.JDBCTransactionFactory > %if db = hypersonic > ## HypersonicSQL > hibernate.dialect = net.sf.hibernate.dialect.HSQLDialect > hibernate.connection.driver_class = org.hsqldb.jdbcDriver > hibernate.connection.username = sa > hibernate.connection.url = jdbc:hsqldb:hsql://localhost > %elseif db = postgres > ## PostgreSQL > hibernate.dialect = net.sf.hibernate.dialect.PostgreSQLDialect > hibernate.connection.driver_class = org.postgresql.Driver > hibernate.connection.url = jdbc:postgresql:template1 > hibernate.connection.username = pg > hibernate.connection.password > %end > %end > The directives used are: > %if condition > %elseif condition > %else > %end > The condition can be: > property (true if the property is defined) > property = value (values are interpolated) > property != value > For the implementation, I've replaced in PropertiesConfiguration.java the call > to read a line from the file with a new getNextLine() method which processes > the conditional directives and returns the next property line. The method is > noop unless the line starts with '%', so it should work just fine with files > that do not use the directives. > I've also added the TestPropertiesConfiguration.testConditionalDirectives() > unit > test which uses properties added at the end of test.properties. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]