]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcAntConfig.java
Revert HSQL DB changes (still force shutdown, but reuse connection)
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / SlcAntConfig.java
index 7fedff747840feadd7e1c95ca7b0f4f0cf89118b..124aa0d216744d5fadb345dd3fe1583904ffb0c3 100644 (file)
@@ -6,84 +6,138 @@ import java.io.IOException;
 import java.util.Properties;\r
 import java.util.StringTokenizer;\r
 \r
+import org.springframework.util.Log4jConfigurer;\r
+\r
 import org.apache.tools.ant.Project;\r
 \r
 /** Load reference to directories from an slcRoot.properties file */\r
 public class SlcAntConfig {\r
        // SLC ROOT PROPERTIES\r
-       public final static String ROOT_DIR_PROPERTY = "org.argeo.slc.ant.rootDir";\r
-       public final static String CONF_DIR_PROPERTY = "org.argeo.slc.ant.confDir";\r
-       public final static String WORK_DIR_PROPERTY = "org.argeo.slc.ant.workDir";\r
+       public final static String ROOT_FILE_PROPERTY = "slc.rootFile";\r
+       public final static String ROOT_DIR_PROPERTY = "slc.rootDir";\r
+       public final static String CONF_DIR_PROPERTY = "slc.confDir";\r
+       public final static String WORK_DIR_PROPERTY = "slc.workDir";\r
        /**\r
         * Comma-separated list of property file names to load from the conf dir and\r
         * add to project user properties\r
         */\r
-       public final static String PROPERTY_FILE_NAMES_PROPERTY = "org.argeo.slc.ant.propertyFileNames";\r
-       \r
+       public final static String PROPERTY_FILE_NAMES_PROPERTY = "slc.propertyFileNames";\r
+\r
        // SLC CONF PROPERTIES\r
        /** Path to the root Spring application context */\r
-       public static String APPLICATION_CONTEXT_PROPERTY = "org.argeo.slc.ant.applicationContext";\r
+       public static String APPLICATION_CONTEXT_PROPERTY = "slc.applicationContext";\r
+       /** Name of the Spring bean used by default */\r
+       public static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";\r
 \r
-       /** Retrieve all properties and set them as project user properties */\r
+       // SLC LOCAL PROPERTIES\r
+       public static String DIR_DESCRIPTION_PROPERTY = "slc.dirDescription";\r
+\r
+       /**\r
+        * Retrieve all properties and set them as project user properties. Root\r
+        * properties (that is from slcRoot file) are added to System properties\r
+        * (e.g. in order to be used by Spring)\r
+        */\r
        public static void initProject(Project project, File slcRootFile) {\r
-               Properties p = loadFile(slcRootFile.getAbsolutePath());\r
-\r
-               final File confDir;\r
-               final File workDir;\r
-               // Root dir\r
-               final File rootDir = slcRootFile.getParentFile();\r
-               project.setUserProperty(ROOT_DIR_PROPERTY, rootDir.getAbsolutePath());\r
-\r
-               // Conf dir\r
-               if (project.getUserProperty(CONF_DIR_PROPERTY) == null) {\r
-                       confDir = new File(p.getProperty(CONF_DIR_PROPERTY, rootDir\r
-                                       .getAbsolutePath()\r
-                                       + "/../conf")).getAbsoluteFile();\r
-                       project.setUserProperty(CONF_DIR_PROPERTY, confDir\r
-                                       .getAbsolutePath());\r
-               } else {\r
-                       confDir = new File(project.getUserProperty(CONF_DIR_PROPERTY))\r
-                                       .getAbsoluteFile();\r
+               System.getProperties().putAll(project.getUserProperties());\r
+               System.setProperty(ROOT_FILE_PROPERTY, slcRootFile.getAbsolutePath());\r
+               Properties all = prepareAllProperties();\r
+               for (Object o : all.keySet()) {\r
+                       String key = o.toString();\r
+                       if (project.getUserProperty(key) == null) {// not already set\r
+                               project.setUserProperty(key, all.getProperty(key));\r
+                       }\r
                }\r
+       }\r
+\r
+       public static Properties prepareAllProperties() {\r
+               try {\r
+                       Properties all = new Properties();\r
+                       all.putAll(System.getProperties());\r
 \r
-               // Work dir\r
-               if (project.getUserProperty(WORK_DIR_PROPERTY) == null) {\r
-                       workDir = new File(p.getProperty(WORK_DIR_PROPERTY, rootDir\r
-                                       .getAbsolutePath()\r
-                                       + "/../work")).getAbsoluteFile();\r
-                       project.setUserProperty(WORK_DIR_PROPERTY, workDir\r
-                                       .getAbsolutePath());\r
-               } else {\r
-                       workDir = new File(project.getUserProperty(WORK_DIR_PROPERTY))\r
+                       if (all.getProperty(ROOT_FILE_PROPERTY) == null) {\r
+                               throw new RuntimeException("System Property "\r
+                                               + ROOT_FILE_PROPERTY + " has to be set.");\r
+                       }\r
+\r
+                       File slcRootFile = new File(all.getProperty(ROOT_FILE_PROPERTY))\r
                                        .getAbsoluteFile();\r
-               }\r
+                       Properties rootProps = loadFile(slcRootFile.getAbsolutePath());\r
 \r
-               // Properties from the conf dir files\r
-               Properties properties = new Properties();\r
-               StringTokenizer st = new StringTokenizer(p.getProperty(\r
-                               PROPERTY_FILE_NAMES_PROPERTY, "slc.properties"), ",");\r
-               while (st.hasMoreTokens()) {\r
-                       String fileName = st.nextToken();\r
-                       properties.putAll(loadFile(confDir.getAbsolutePath() + "/"\r
-                                       + fileName));\r
-               }\r
+                       final File confDir;\r
+                       final File workDir;\r
+                       // Root dir\r
+                       final File rootDir = slcRootFile.getParentFile();\r
+                       all.setProperty(ROOT_DIR_PROPERTY, rootDir.getCanonicalPath());\r
 \r
-               for (Object o : properties.keySet()) {\r
-                       String key = o.toString();\r
-                       if (project.getUserProperty(key) == null) {// not already set\r
-                               project.setUserProperty(key, properties.getProperty(key));\r
+                       // Conf dir\r
+                       if (all.getProperty(CONF_DIR_PROPERTY) == null) {\r
+                               confDir = new File(rootProps.getProperty(CONF_DIR_PROPERTY,\r
+                                               rootDir.getAbsolutePath() + "/../conf"))\r
+                                               .getCanonicalFile();\r
+                               all.setProperty(CONF_DIR_PROPERTY, confDir.getAbsolutePath());\r
+                       } else {\r
+                               confDir = new File(all.getProperty(CONF_DIR_PROPERTY))\r
+                                               .getCanonicalFile();\r
+                       }\r
+\r
+                       // Work dir\r
+                       if (all.getProperty(WORK_DIR_PROPERTY) == null) {\r
+                               workDir = new File(rootProps.getProperty(WORK_DIR_PROPERTY,\r
+                                               rootDir.getAbsolutePath() + "/../work"))\r
+                                               .getCanonicalFile();\r
+                               all.setProperty(WORK_DIR_PROPERTY, workDir.getAbsolutePath());\r
+                       } else {\r
+                               workDir = new File(all.getProperty(WORK_DIR_PROPERTY))\r
+                                               .getCanonicalFile();\r
+                       }\r
+\r
+                       // Properties from the conf dir files\r
+                       Properties properties = new Properties();\r
+                       StringTokenizer st = new StringTokenizer(rootProps.getProperty(\r
+                                       PROPERTY_FILE_NAMES_PROPERTY, "slc.properties"), ",");\r
+                       while (st.hasMoreTokens()) {\r
+                               String fileName = st.nextToken();\r
+                               properties.putAll(loadFile(confDir.getAbsolutePath() + File.separator\r
+                                               + fileName));\r
+                       }\r
+\r
+                       for (Object o : properties.keySet()) {\r
+                               String key = o.toString();\r
+                               if (all.getProperty(key) == null) {// not already set\r
+                                       all.setProperty(key, properties.getProperty(key));\r
+                               }\r
+                       }\r
+\r
+                       // Default application context\r
+                       if (all.getProperty(APPLICATION_CONTEXT_PROPERTY) == null) {\r
+                               all.setProperty(APPLICATION_CONTEXT_PROPERTY, confDir\r
+                                               .getAbsolutePath()\r
+                                               + "/applicationContext.xml");\r
+                       }\r
+                       // Default test run\r
+                       if (all.getProperty(DEFAULT_TEST_RUN_PROPERTY) == null) {\r
+                               all.setProperty(DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun");\r
+                       }\r
+\r
+                       // Default log4j\r
+                       if (all.getProperty("log4j.configuration") == null) {\r
+                               System.setProperty("log4j.configuration",confDir\r
+                                               .getCanonicalPath()\r
+                                               + File.separator + "log4j.properties" );\r
+                               // TODO: fix dependency to log4j\r
+                               Log4jConfigurer.initLogging(confDir\r
+                                               .getCanonicalPath()\r
+                                               + File.separator + "log4j.properties");\r
                        }\r
-               }\r
 \r
-               // Default application context\r
-               if (project.getUserProperty(APPLICATION_CONTEXT_PROPERTY) == null) {\r
-                       project.setUserProperty(APPLICATION_CONTEXT_PROPERTY, confDir\r
-                                       .getAbsolutePath()\r
-                                       + "/applicationContext.xml");\r
+                       return all;\r
+               } catch (Exception e) {\r
+                       throw new SlcAntException("Unexpected exception while configuring",\r
+                                       e);\r
                }\r
        }\r
 \r
-       private static Properties loadFile(String path) {\r
+       public static Properties loadFile(String path) {\r
                Properties p = new Properties();\r
                try {\r
                        FileInputStream in = new FileInputStream(path);\r