Introduce directory based structure
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 27 Oct 2007 21:48:19 +0000 (21:48 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 27 Oct 2007 21:48:19 +0000 (21:48 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@665 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcAntConfig.java
org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java
org.argeo.slc/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java
org.argeo.slc/src/test/slc/conf/log4j.properties
org.argeo.slc/src/test/slc/root/Category1/SubCategory2/slcLocal.properties [new file with mode: 0644]
org.argeo.slc/src/test/slc/root/Category1/slcLocal.properties [new file with mode: 0644]

index 7fedff747840feadd7e1c95ca7b0f4f0cf89118b..04e8e163b1d324cb00bd9a2a91a6d2aa5a700898 100644 (file)
@@ -24,6 +24,9 @@ public class SlcAntConfig {
        /** Path to the root Spring application context */\r
        public static String APPLICATION_CONTEXT_PROPERTY = "org.argeo.slc.ant.applicationContext";\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 void initProject(Project project, File slcRootFile) {\r
                Properties p = loadFile(slcRootFile.getAbsolutePath());\r
@@ -83,7 +86,7 @@ public class SlcAntConfig {
                }\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
index 34373437d7cd2af7b5dfe99a03cbb4435a38bb62..6bdb5bf16867cc5b3c8275232ca4d332661db2e8 100644 (file)
@@ -3,7 +3,9 @@ package org.argeo.slc.ant;
 import java.io.File;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
+import java.util.List;\r
 import java.util.Properties;\r
+import java.util.Vector;\r
 \r
 import org.springframework.context.ApplicationContext;\r
 import org.springframework.context.support.FileSystemXmlApplicationContext;\r
@@ -15,6 +17,7 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.helper.ProjectHelperImpl;\r
 \r
 import org.argeo.slc.core.structure.DefaultSRegistry;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSElement;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 \r
@@ -27,8 +30,10 @@ public class SlcProjectHelper extends ProjectHelperImpl {
 \r
        public static String REF_ROOT_CONTEXT = "slcApplicationContext";\r
        public static String REF_STRUCTURE_REGISTRY = "slcStructureRegistry";\r
+       public static String REF_PROJECT_PATH = "slcProjectPath";\r
 \r
        private String slcRootFileName = "slcRoot.properties";\r
+       private String slcLocalFileName = "slcLocal.properties";\r
 \r
        @Override\r
        public void parse(Project project, Object source) throws BuildException {\r
@@ -58,15 +63,59 @@ public class SlcProjectHelper extends ProjectHelperImpl {
                addSlcTasks(project);\r
 \r
                // create structure root\r
-               TreeSElement element = new TreeSElement(project.getDescription(),\r
-                               "Root");\r
-               registry.register(getProjectPath(project), element);\r
+               registerProjectAndParents(project);\r
 \r
+               // TreeSElement element = new TreeSElement(project.getDescription(),\r
+               // "Root");\r
+               // registry.register(getProjectPath(project), element);\r
+\r
+       }\r
+\r
+       private void registerProjectAndParents(Project project) {\r
+               StructureRegistry registry = (StructureRegistry) project\r
+                               .getReference(REF_STRUCTURE_REGISTRY);\r
+               File rootDir = new File(project\r
+                               .getUserProperty(SlcAntConfig.ROOT_DIR_PROPERTY))\r
+                               .getAbsoluteFile();\r
+               File baseDir = project.getBaseDir().getAbsoluteFile();\r
+\r
+               List<File> dirs = new Vector<File>();\r
+               File currentDir = baseDir;\r
+               do {\r
+                       dirs.add(currentDir);\r
+                       currentDir = currentDir.getParentFile();\r
+                       log.trace("List " + currentDir);\r
+               } while (!currentDir.equals(rootDir.getParentFile()));\r
+\r
+               TreeSPath currPath = null;\r
+               for (int i = dirs.size() - 1; i >= 0; i--) {\r
+                       File dir = dirs.get(i);\r
+\r
+                       String description = dir.getName();\r
+                       File slcLocal = new File(dir.getPath() + File.separator\r
+                                       + slcLocalFileName);\r
+                       if (slcLocal.exists()) {\r
+                               Properties properties = SlcAntConfig.loadFile(slcLocal\r
+                                               .getAbsolutePath());\r
+                               description = properties\r
+                                               .getProperty(SlcAntConfig.DIR_DESCRIPTION_PROPERTY);\r
+                       }\r
+                       TreeSElement element = new TreeSElement(description);\r
+\r
+                       if (dir.equals(rootDir)) {\r
+                               currPath = TreeSPath.createRootPath(rootDir.getName());\r
+                       } else {\r
+                               currPath = currPath.createChild(dir.getName());\r
+                       }\r
+                       registry.register(currPath, element);\r
+               }\r
+               project.addReference(REF_PROJECT_PATH, currPath);\r
        }\r
 \r
        /** Get the path of a project (root). */\r
        public static TreeSPath getProjectPath(Project project) {\r
-               return TreeSPath.createRootPath(getProjectPathName(project));\r
+               // return TreeSPath.createRootPath(getProjectPathName(project));\r
+               return (TreeSPath) project.getReference(REF_PROJECT_PATH);\r
        }\r
 \r
        private static String getProjectPathName(Project project) {\r
index 1cca17be4dc553434a307507cda89f1b6e436920..b9d84effe3dcec871560eb6049d365fbc3a264dd 100644 (file)
@@ -28,8 +28,8 @@ public class DefaultSRegistry implements StructureRegistry {
                StructureElement treeSElement = element;\r
                elements.add(treeSElement);\r
                paths.add( path);\r
-               log.debug("Registered " + path + " (desc: "\r
-                               + treeSElement.getDescription() + " position: "\r
+               log.debug("Registered " + path + " (desc: '"\r
+                               + treeSElement.getDescription() + "', position: "\r
                                + elements.size() + ")");\r
        }\r
 \r
index 4b1d97429082b1a9cf17d15c6c6727c46293c1cc..8a70a33f48a6bc70fe5df4bc190aca956facda9b 100644 (file)
@@ -1,5 +1,5 @@
 # Set root logger level to DEBUG and its only appender to A1.\r
-log4j.rootLogger=DEBUG, console\r
+log4j.rootLogger=TRACE, console\r
 \r
 ## Levels\r
 # Spring\r
diff --git a/org.argeo.slc/src/test/slc/root/Category1/SubCategory2/slcLocal.properties b/org.argeo.slc/src/test/slc/root/Category1/SubCategory2/slcLocal.properties
new file mode 100644 (file)
index 0000000..eef4086
--- /dev/null
@@ -0,0 +1 @@
+org.argeo.slc.ant.dirDescription=Second sub Category
\ No newline at end of file
diff --git a/org.argeo.slc/src/test/slc/root/Category1/slcLocal.properties b/org.argeo.slc/src/test/slc/root/Category1/slcLocal.properties
new file mode 100644 (file)
index 0000000..c7cdb34
--- /dev/null
@@ -0,0 +1 @@
+org.argeo.slc.ant.dirDescription=First Category
\ No newline at end of file