]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcAntConfig.java
Introduce end to end testing with logging of results
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / SlcAntConfig.java
index 04e8e163b1d324cb00bd9a2a91a6d2aa5a700898..755c063bc34ae35618df78c165d037007f3f690b 100644 (file)
@@ -11,25 +11,43 @@ import org.apache.tools.ant.Project;
 /** 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
        // SLC LOCAL PROPERTIES\r
-       public static String DIR_DESCRIPTION_PROPERTY = "org.argeo.slc.ant.dirDescription";\r
-       \r
-       /** Retrieve all properties and set them as project user 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
+               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
+               Properties rootProps = loadFile(slcRootFile.getAbsolutePath());\r
 \r
                final File confDir;\r
                final File workDir;\r
@@ -39,7 +57,7 @@ public class SlcAntConfig {
 \r
                // Conf dir\r
                if (project.getUserProperty(CONF_DIR_PROPERTY) == null) {\r
-                       confDir = new File(p.getProperty(CONF_DIR_PROPERTY, rootDir\r
+                       confDir = new File(rootProps.getProperty(CONF_DIR_PROPERTY, rootDir\r
                                        .getAbsolutePath()\r
                                        + "/../conf")).getAbsoluteFile();\r
                        project.setUserProperty(CONF_DIR_PROPERTY, confDir\r
@@ -51,7 +69,7 @@ public class SlcAntConfig {
 \r
                // Work dir\r
                if (project.getUserProperty(WORK_DIR_PROPERTY) == null) {\r
-                       workDir = new File(p.getProperty(WORK_DIR_PROPERTY, rootDir\r
+                       workDir = new File(rootProps.getProperty(WORK_DIR_PROPERTY, rootDir\r
                                        .getAbsolutePath()\r
                                        + "/../work")).getAbsoluteFile();\r
                        project.setUserProperty(WORK_DIR_PROPERTY, workDir\r
@@ -63,7 +81,7 @@ public class SlcAntConfig {
 \r
                // Properties from the conf dir files\r
                Properties properties = new Properties();\r
-               StringTokenizer st = new StringTokenizer(p.getProperty(\r
+               StringTokenizer st = new StringTokenizer(rootProps.getProperty(\r
                                PROPERTY_FILE_NAMES_PROPERTY, "slc.properties"), ",");\r
                while (st.hasMoreTokens()) {\r
                        String fileName = st.nextToken();\r
@@ -84,6 +102,85 @@ public class SlcAntConfig {
                                        .getAbsolutePath()\r
                                        + "/applicationContext.xml");\r
                }\r
+               // Default test run\r
+               if (project.getUserProperty(DEFAULT_TEST_RUN_PROPERTY) == null) {\r
+                       project\r
+                                       .setUserProperty(DEFAULT_TEST_RUN_PROPERTY,\r
+                                                       "defaultTestRun");\r
+               }\r
+               */\r
+       }\r
+\r
+       public static Properties prepareAllProperties() {\r
+               Properties all = new Properties();\r
+               all.putAll(System.getProperties());\r
+\r
+               if (all.getProperty(ROOT_FILE_PROPERTY) == null) {\r
+                       throw new RuntimeException("System Property " + ROOT_FILE_PROPERTY\r
+                                       + " has to be set.");\r
+               }\r
+\r
+               File slcRootFile = new File(all.getProperty(ROOT_FILE_PROPERTY))\r
+                               .getAbsoluteFile();\r
+               Properties rootProps = loadFile(slcRootFile.getAbsolutePath());\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.getAbsolutePath());\r
+\r
+               // Conf dir\r
+               if (all.getProperty(CONF_DIR_PROPERTY) == null) {\r
+                       confDir = new File(rootProps.getProperty(CONF_DIR_PROPERTY, rootDir\r
+                                       .getAbsolutePath()\r
+                                       + "/../conf")).getAbsoluteFile();\r
+                       all.setProperty(CONF_DIR_PROPERTY, confDir.getAbsolutePath());\r
+               } else {\r
+                       confDir = new File(all.getProperty(CONF_DIR_PROPERTY))\r
+                                       .getAbsoluteFile();\r
+               }\r
+\r
+               // Work dir\r
+               if (all.getProperty(WORK_DIR_PROPERTY) == null) {\r
+                       workDir = new File(rootProps.getProperty(WORK_DIR_PROPERTY, rootDir\r
+                                       .getAbsolutePath()\r
+                                       + "/../work")).getAbsoluteFile();\r
+                       all.setProperty(WORK_DIR_PROPERTY, workDir.getAbsolutePath());\r
+               } else {\r
+                       workDir = new File(all.getProperty(WORK_DIR_PROPERTY))\r
+                                       .getAbsoluteFile();\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() + "/"\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
+               return all;\r
        }\r
 \r
        public static Properties loadFile(String path) {\r