1 package org
.argeo
.slc
.ant
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.IOException
;
6 import java
.util
.Properties
;
7 import java
.util
.StringTokenizer
;
9 import org
.apache
.tools
.ant
.Project
;
11 /** Load reference to directories from an slcRoot.properties file */
12 public class SlcAntConfig
{
13 // SLC ROOT PROPERTIES
14 public final static String ROOT_DIR_PROPERTY
= "org.argeo.slc.ant.rootDir";
15 public final static String CONF_DIR_PROPERTY
= "org.argeo.slc.ant.confDir";
16 public final static String WORK_DIR_PROPERTY
= "org.argeo.slc.ant.workDir";
18 * Comma-separated list of property file names to load from the conf dir and
19 * add to project user properties
21 public final static String PROPERTY_FILE_NAMES_PROPERTY
= "org.argeo.slc.ant.propertyFileNames";
23 // SLC CONF PROPERTIES
24 /** Path to the root Spring application context */
25 public static String APPLICATION_CONTEXT_PROPERTY
= "org.argeo.slc.ant.applicationContext";
27 // SLC LOCAL PROPERTIES
28 public static String DIR_DESCRIPTION_PROPERTY
= "org.argeo.slc.ant.dirDescription";
30 /** Retrieve all properties and set them as project user properties */
31 public static void initProject(Project project
, File slcRootFile
) {
32 Properties p
= loadFile(slcRootFile
.getAbsolutePath());
37 final File rootDir
= slcRootFile
.getParentFile();
38 project
.setUserProperty(ROOT_DIR_PROPERTY
, rootDir
.getAbsolutePath());
41 if (project
.getUserProperty(CONF_DIR_PROPERTY
) == null) {
42 confDir
= new File(p
.getProperty(CONF_DIR_PROPERTY
, rootDir
44 + "/../conf")).getAbsoluteFile();
45 project
.setUserProperty(CONF_DIR_PROPERTY
, confDir
48 confDir
= new File(project
.getUserProperty(CONF_DIR_PROPERTY
))
53 if (project
.getUserProperty(WORK_DIR_PROPERTY
) == null) {
54 workDir
= new File(p
.getProperty(WORK_DIR_PROPERTY
, rootDir
56 + "/../work")).getAbsoluteFile();
57 project
.setUserProperty(WORK_DIR_PROPERTY
, workDir
60 workDir
= new File(project
.getUserProperty(WORK_DIR_PROPERTY
))
64 // Properties from the conf dir files
65 Properties properties
= new Properties();
66 StringTokenizer st
= new StringTokenizer(p
.getProperty(
67 PROPERTY_FILE_NAMES_PROPERTY
, "slc.properties"), ",");
68 while (st
.hasMoreTokens()) {
69 String fileName
= st
.nextToken();
70 properties
.putAll(loadFile(confDir
.getAbsolutePath() + "/"
74 for (Object o
: properties
.keySet()) {
75 String key
= o
.toString();
76 if (project
.getUserProperty(key
) == null) {// not already set
77 project
.setUserProperty(key
, properties
.getProperty(key
));
81 // Default application context
82 if (project
.getUserProperty(APPLICATION_CONTEXT_PROPERTY
) == null) {
83 project
.setUserProperty(APPLICATION_CONTEXT_PROPERTY
, confDir
85 + "/applicationContext.xml");
89 public static Properties
loadFile(String path
) {
90 Properties p
= new Properties();
92 FileInputStream in
= new FileInputStream(path
);
95 } catch (IOException e
) {
96 throw new SlcAntException("Cannot read SLC root file", e
);