[lsc-changes] r308 - lsc/branches/v1.1/src/main/java/org/lsc lsc/branches/v1.1/src/main/java/org/lsc/persistence lsc/branches/v1.1/src/main/java/org/lsc/service lsc-sample/branches/v1.1 lsc-sample/branches/v1.1/misc lsc-sample/branches/v1.1/src/install/resources

jclarke at lsc-project.org jclarke at lsc-project.org
Tue Jul 21 19:09:52 CEST 2009


Author: jclarke
Date: 2009-07-21 19:09:52 +0200 (Tue, 21 Jul 2009)
New Revision: 308

Modified:
   lsc-sample/branches/v1.1/build.xml
   lsc-sample/branches/v1.1/misc/lsc.properties.sample
   lsc-sample/branches/v1.1/src/install/resources/build-generator.xml
   lsc/branches/v1.1/src/main/java/org/lsc/AbstractGenerator.java
   lsc/branches/v1.1/src/main/java/org/lsc/Generator.java
   lsc/branches/v1.1/src/main/java/org/lsc/persistence/DaoConfig.java
   lsc/branches/v1.1/src/main/java/org/lsc/persistence/SqlMapXmlFileGenerator.java
   lsc/branches/v1.1/src/main/java/org/lsc/service/JdbcSrcServiceObjectGenerator.java
Log:
Fixes #40. Generation now places files in the etc/ directory.

Modified: lsc/branches/v1.1/src/main/java/org/lsc/AbstractGenerator.java
===================================================================
--- lsc/branches/v1.1/src/main/java/org/lsc/AbstractGenerator.java	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc/branches/v1.1/src/main/java/org/lsc/AbstractGenerator.java	2009-07-21 17:09:52 UTC (rev 308)
@@ -105,7 +105,7 @@
      * name.
      */
     public AbstractGenerator() {
-        this.separator = System.getProperty("file.separator");
+        this.separator = Configuration.getSeparator();
     }
 
     /**

Modified: lsc/branches/v1.1/src/main/java/org/lsc/Generator.java
===================================================================
--- lsc/branches/v1.1/src/main/java/org/lsc/Generator.java	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc/branches/v1.1/src/main/java/org/lsc/Generator.java	2009-07-21 17:09:52 UTC (rev 308)
@@ -165,8 +165,6 @@
      * @throws NamingException DOCUMENT ME!
      */
     public static void main(final String[] args) throws NamingException {
-        PropertyConfigurator.configure(LOG4J_CONFIGURATION_FILE);
-
         Generator instance = new Generator();
 
         if (instance.parseArgs(args) == 0) {

Modified: lsc/branches/v1.1/src/main/java/org/lsc/persistence/DaoConfig.java
===================================================================
--- lsc/branches/v1.1/src/main/java/org/lsc/persistence/DaoConfig.java	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc/branches/v1.1/src/main/java/org/lsc/persistence/DaoConfig.java	2009-07-21 17:09:52 UTC (rev 308)
@@ -46,6 +46,7 @@
 package org.lsc.persistence;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Properties;
@@ -121,12 +122,23 @@
 					reader = Resources.getResourceAsReader(IBATIS_SQLMAP_CONFIGURATION_FILE);
 				}
 
+				Properties props = new Properties();
+				
 				// read the database configuration file to pass to sql-map-config XML file
-				Properties props = Configuration.getPropertiesFromFileInConfigDir(Configuration.DATABASE_PROPERTIES_FILENAME);
-
+				// this is maintained for backwards compatibility, although the database.properties file no longer exists
+				try
+				{
+					props.putAll(Configuration.getPropertiesFromFileInConfigDir(Configuration.DATABASE_PROPERTIES_FILENAME));
+				}
+				catch (FileNotFoundException e) {} 
+				// ignore this, it probably just means that we're not using database.properties file anymore
+				
+				// add the database configuration properties from lsc.properties
+				props.putAll(Configuration.getAsProperties("src.database"));
+				
 				// add the configuration directory to properties so that sql-map-config can use relative paths
-				props.put("lsc.config.sqlmapdir", Configuration.getConfigurationDirectory() + IBATIS_SQLMAP_FILES_DIRNAME);
-
+				props.put("lsc.config", Configuration.getConfigurationDirectory());
+				
 				sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader, props);
 
 				// clean up

Modified: lsc/branches/v1.1/src/main/java/org/lsc/persistence/SqlMapXmlFileGenerator.java
===================================================================
--- lsc/branches/v1.1/src/main/java/org/lsc/persistence/SqlMapXmlFileGenerator.java	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc/branches/v1.1/src/main/java/org/lsc/persistence/SqlMapXmlFileGenerator.java	2009-07-21 17:09:52 UTC (rev 308)
@@ -48,6 +48,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.net.MalformedURLException;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
@@ -61,6 +62,7 @@
 import org.apache.log4j.Logger;
 import org.apache.xerces.parsers.DOMParser;
 import org.lsc.AbstractGenerator;
+import org.lsc.Configuration;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
@@ -107,16 +109,40 @@
 	 * @return the generation status
 	 */
 	protected final boolean generate(final String unused) {
-		if (getDestination() != null && getDestination().length() > 0) {
-			sqlMapConfigFullFilename = getDestination() + getSeparator()
-			+ SQL_MAP_CONFIG_FILENAME;
-			// Then remove the destination from the filename
-			if(xmlFilename.indexOf(getDestination()) == 0) {
-				xmlFilename = xmlFilename.substring(getDestination().length()+1);
+		
+		// Test if we have a IBATIS_SQLMAP_CONFIGURATION_FILENAME file in the global config dir.
+		// This test is for backwards compatibility since the IBATIS_SQLMAP_CONFIGURATION_FILENAME
+		// file always used to be in a JAR file. It should be removed in the future.
+		try
+		{
+			File configFile = new File(Configuration.getConfigurationDirectory() + DaoConfig.IBATIS_SQLMAP_CONFIGURATION_FILENAME);
+			if (configFile.exists())
+			{
+				// set sql-map-config.xml file path
+				sqlMapConfigFullFilename = configFile.toURI().toURL().getPath();
+				
+				// adapt the generated .xml file name to be relative to the config dir
+				xmlFilename = xmlFilename.substring(Configuration.getConfigurationDirectory().length());
+			} else {
+				// revert back to old behavior - this should be removed soon!
+				LOGGER.warn("Falling back to old-style configuration files");
+
+				if (getDestination() != null && getDestination().length() > 0) {
+					sqlMapConfigFullFilename = getDestination() + getSeparator()
+					+ SQL_MAP_CONFIG_FILENAME;
+					// Then remove the destination from the filename
+					if(xmlFilename.indexOf(getDestination()) == 0) {
+						xmlFilename = xmlFilename.substring(getDestination().length()+1);
+					}
+				} else {
+					sqlMapConfigFullFilename = SQL_MAP_CONFIG_FILENAME;
+				}
 			}
-		} else {
-			sqlMapConfigFullFilename = SQL_MAP_CONFIG_FILENAME;
 		}
+		catch (MalformedURLException e)
+		{
+			throw new ExceptionInInitializerError("Error reading the IBatis SQLMap configuration file");
+		}
 
 		String content = generateContent();
 
@@ -168,11 +194,11 @@
 			NamedNodeMap newSqlMapAttributes = newSqlMapEntry.getAttributes();
 
 			// Create a new resource attribute ...
-			Attr resource = doc.createAttribute("resource");
+			Attr url = doc.createAttribute("url");
 			// ... with the xml ibatis description filename as value
-			resource.setValue(xmlFilename);
+			url.setValue("file://${lsc.config}/" + xmlFilename);
 			// Set the attribute in the new object attributes
-			newSqlMapAttributes.setNamedItem(resource);
+			newSqlMapAttributes.setNamedItem(url);
 			// Append the new node as the new last node
 			try {
 				last.appendChild(newSqlMapEntry);

Modified: lsc/branches/v1.1/src/main/java/org/lsc/service/JdbcSrcServiceObjectGenerator.java
===================================================================
--- lsc/branches/v1.1/src/main/java/org/lsc/service/JdbcSrcServiceObjectGenerator.java	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc/branches/v1.1/src/main/java/org/lsc/service/JdbcSrcServiceObjectGenerator.java	2009-07-21 17:09:52 UTC (rev 308)
@@ -46,8 +46,10 @@
 package org.lsc.service;
 
 import org.lsc.AbstractGenerator;
+import org.lsc.Configuration;
 import org.lsc.jndi.parser.LdapAttributeType;
 import org.lsc.jndi.parser.LdapObjectClass;
+import org.lsc.persistence.DaoConfig;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -55,6 +57,7 @@
 import java.io.IOException;
 
 import java.lang.reflect.Field;
+import java.net.MalformedURLException;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -205,23 +208,36 @@
      * @return the xml persistence filename
      */
     public final String getMyXMLFileName() {
-        String myXMLPackage = this.getClass().getPackage().getName();
-        myXMLPackage = myXMLPackage.substring(0, myXMLPackage.lastIndexOf("."))
-                       + ".persistence.xml";
-
-        String mainLocation = null;
-
-        if (getDestination() != null) {
-            mainLocation = getDestination();
-        } else {
-            mainLocation = System.getProperty("user.dir") + getSeparator()
-                           + "src" + getSeparator() + "main" + getSeparator()
-                           + "java";
-        }
-
-        return mainLocation + getSeparator()
-               + myXMLPackage.replaceAll("\\.", getSeparator())
-               + getSeparator() + this.objectName + ".xml";
+    	
+		// Test if we have a IBATIS_SQLMAP_CONFIGURATION_FILENAME file in the global config dir.
+		// This test is for backwards compatibility since the IBATIS_SQLMAP_CONFIGURATION_FILENAME
+		// file always used to be in a JAR file. It should be removed in the future.
+		File configFile = new File(Configuration.getConfigurationDirectory() + DaoConfig.IBATIS_SQLMAP_CONFIGURATION_FILENAME);
+		if (configFile.exists())
+		{
+			String xmlFileName = Configuration.getConfigurationDirectory() + DaoConfig.IBATIS_SQLMAP_FILES_DIRNAME + Configuration.getSeparator() + this.objectName + ".xml";
+			return xmlFileName;
+		} else {
+			// revert back to old behavior - this should be removed soon!
+			LOGGER.warn("Falling back to old-style configuration files");
+			
+			String myXMLPackage = this.getClass().getPackage().getName();
+			myXMLPackage = myXMLPackage.substring(0, myXMLPackage.lastIndexOf(".")) + ".persistence.xml";
+			
+			String mainLocation = null;
+			
+			if (getDestination() != null) {
+			    mainLocation = getDestination();
+			} else {
+			    mainLocation = System.getProperty("user.dir") + getSeparator()
+			                   + "src" + getSeparator() + "main" + getSeparator()
+			                   + "java";
+			}
+			
+			return mainLocation + getSeparator()
+			       + myXMLPackage.replaceAll("\\.", getSeparator())
+			       + getSeparator() + this.objectName + ".xml";
+		}
     }
 
     /**

Modified: lsc-sample/branches/v1.1/build.xml
===================================================================
--- lsc-sample/branches/v1.1/build.xml	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc-sample/branches/v1.1/build.xml	2009-07-21 17:09:52 UTC (rev 308)
@@ -43,6 +43,8 @@
 
 	<property name="resources.path" value="${src.main.path}/resources" />
 
+	<property name="config.dir" value="etc" />
+
 	<property name="generator.parameters" value="" />
 
 	<property name="manifest-version" value="0.0" />
@@ -108,10 +110,12 @@
 	<target name="lsc::prepare-env" depends="lsc::init" description="Prepare the environment for local execution">
 		<mkdir dir="${build.dir}/classes" />
 		<echo message="Copying xml and properties files" />
+		<copy overwrite="false" tofile="${config.dir}/lsc.properties" file="${config.dir}/lsc.properties-sample" />
 		<copy todir="${build.classes.dir}">
 			<fileset dir="${src.main.path}/java" excludes="resources/*" includes="${properties.files},${ldif.files},${xml.files}" />
 			<fileset dir="${src.impl.path}/java" excludes="resources/*" includes="${properties.files},${ldif.files},${xml.files}" />
 			<fileset dir="${src.main.path}/resources" includes="${properties.files},${ldif.files},${xml.files}" />
+			<fileset dir="${config.dir}" includes="lsc.properties" />
 		</copy>
 		<copy todir="${build.test-classes.dir}">
 			<fileset dir="${src.test.path}/java" excludes="resources/*" includes="${properties.files},${ldif.files},${xml.files}" />
@@ -187,9 +191,7 @@
 		<mkdir dir="${src.impl.path}/java/org/lsc/persistence" />
 		<mkdir dir="${src.impl.path}/java/org/lsc/persistence/xml" />
 		<mkdir dir="${src.impl.path}/java/org/lsc/service" />
-		<copy overwrite="false" tofile="${src.impl.path}/java/org/lsc/persistence/xml/sql-map-config.xml">
-			<fileset dir="${src.main.path}/java/org/lsc/persistence/xml" includes="sql-map-config.xml-sample"/>
-		</copy>
+		<copy overwrite="false" tofile="${config.dir}/sql-map-config.xml" file="${config.dir}/sql-map-config.xml-sample" />
 		<java classname="org.lsc.Generator" classpathref="execution.path" fork="true" maxmemory="512M" dir="${build.classes.dir}"
 			failonerror="true">
 			<arg line="${generator.parameters}" />
@@ -198,11 +200,11 @@
 			<format property="tstamp" pattern="yyyyMMddHHmmss" />
 		</tstamp>
 		<echo message="Backuping lsc.properties to lsc.properties-${tstamp}"/>
-		<copy overwrite="false" tofile="${src.test.path}/resources/lsc.properties-${tstamp}">
-			<fileset dir="${src.test.path}/resources" includes="lsc.properties" />
+		<copy overwrite="false" tofile="${config.dir}/lsc.properties-${tstamp}">
+			<fileset dir="${config.dir}" includes="lsc.properties" />
 		</copy>
 		<echo message="Rewriting lsc.properties with latest settings" />
-		<copy overwrite="true" todir="${src.test.path}/resources">
+		<copy overwrite="true" todir="${config.dir}">
 			<fileset dir="${build.classes.dir}" includes="lsc.properties" />
 			<filterchain>
 				<filterreader classname="org.lsc.utils.SortingFilterReader" classpathref="execution.path">
@@ -317,6 +319,7 @@
 	<target name="lsc::generateWizard" depends="lsc::init">
 		<available file="${lib.dir}/${ant.project.name}-generator.jar" type="file" property="GenerateWizard.ok" />
 		<fail unless="GenerateWizard.ok" message="No GenerateWizard found! Did you mean to download a dist archive from http://tools.lsc-project.org/files?  If you have AntInstaller you can generate it using ant lsc::buildGenerateWizard" />
+		<copy overwrite="false" tofile="${config.dir}/lsc.properties" file="${config.dir}/lsc.properties-sample" />
 		<java jar="${lib.dir}/${ant.project.name}-generator.jar" fork="true"/>
 	</target>
 

Modified: lsc-sample/branches/v1.1/misc/lsc.properties.sample
===================================================================
--- lsc-sample/branches/v1.1/misc/lsc.properties.sample	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc-sample/branches/v1.1/misc/lsc.properties.sample	2009-07-21 17:09:52 UTC (rev 308)
@@ -1,3 +1,20 @@
+###################
+# Source database #
+###################
+# This section can safely be deleted if you are not using db2ldap synchronization.
+
+# Java class name of the JDBC driver to use for this database
+src.database.driver = org.hsqldb.jdbcDriver
+
+# Connection URL. This must include the database name.
+src.database.url = jdbc:hsqldb:file:hsqldb/lsc
+
+# User name to connect to the database with
+src.database.username = sa
+
+# Password to connect to the database with
+src.database.password =
+
 dst.java.naming.factory.initial = com.sun.jndi.ldap.LdapCtxFactory
 dst.java.naming.ldap.derefAliases = never
 dst.java.naming.ldap.version = 3

Modified: lsc-sample/branches/v1.1/src/install/resources/build-generator.xml
===================================================================
--- lsc-sample/branches/v1.1/src/install/resources/build-generator.xml	2009-07-21 15:03:37 UTC (rev 307)
+++ lsc-sample/branches/v1.1/src/install/resources/build-generator.xml	2009-07-21 17:09:52 UTC (rev 308)
@@ -7,7 +7,7 @@
 	<property name="workdir" value="${user.dir}" />
 
 	<property name="test.dir" value="${user.dir}/src/test" />
-	<property name="conf.dir" value="${test.dir}/resources" />
+	<property name="conf.dir" value="${user.dir}/etc" />
 
 	<property file="${workdir}/ant.install.properties" />
 	<property file="${basedir}/ant.install.properties" />
@@ -68,11 +68,11 @@
 	</target>
 
 	<target name="updateDatabaseProperties" if="install.type.db">
-		<propertyfile file="${conf.dir}/database.properties" comment="Reset the database properties">
-			<entry key="driver" value="${jdbc.driver}" />
-			<entry key="url" value="${jdbc.url}" />
-			<entry key="username" value="${jdbc.username}" />
-			<entry key="password" value="${jdbc.password}" />
+		<propertyfile file="${conf.dir}/lsc.properties" comment="Reset the database properties">
+			<entry key="src.database.driver" value="${jdbc.driver}" />
+			<entry key="src.database.url" value="${jdbc.url}" />
+			<entry key="src.database.username" value="${jdbc.username}" />
+			<entry key="src.database.password" value="${jdbc.password}" />
 		</propertyfile>
 	</target>
 
@@ -91,14 +91,13 @@
 	<target name="replaceSpecialChars">
 		<replaceregexp file="${conf.dir}/lsc.properties" match="\\\:" replace=":" flags="g" byline="true" />
 		<replaceregexp file="${conf.dir}/log4j.properties"  match="\\\:" replace=":" flags="g" byline="true"/>
-		<replaceregexp file="${conf.dir}/database.properties" match="\\\:" replace=":" flags="g" byline="true" />
 		<replaceregexp file="${conf.dir}/lsc.properties" match="\\=" replace="=" flags="g" byline="true" />
 	</target>
 
 	<target name="_generate">
-		<echo message="Launching generation from ${workdir} with following command line options : -dir '${generated.dir}' -doc ${dst.objectclass.name} -name '${task.name}' ${extraParams}" />
+		<echo message="Launching generation from ${workdir} with following command line options : -f '${conf.dir}' -dir '${generated.dir}' -doc ${dst.objectclass.name} -name '${task.name}' ${extraParams}" />
 		<ant antfile="build.xml" target="lsc::_generator" dir="${workdir}">
-			<property name="generator.parameters" value="-dir '${generated.dir}' -doc ${dst.objectclass.name} -name '${task.name}' ${extraParams}" />
+			<property name="generator.parameters" value="-f '${user.dir}/etc' -dir '${generated.dir}' -doc ${dst.objectclass.name} -name '${task.name}' ${extraParams}" />
 		</ant>
 	</target>
 </project>



More information about the lsc-changes mailing list