]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java
Introduce directory based structure
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / SlcProjectHelper.java
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