2 package org
.de
.metux
.unitool
.db
;
4 import org
.de
.metux
.propertylist
.*;
5 import org
.de
.metux
.util
.Environment
;
6 import java
.util
.Enumeration
;
7 import java
.util
.Properties
;
9 import org
.de
.metux
.util
.StrUtil
;
10 import org
.de
.metux
.unitool
.base
.ToolConfig
;
11 import org
.de
.metux
.datasource
.Cached_TextDB_Loader
;
13 public class UnitoolConf
15 // public static final String default_tool_config = "/etc/unitool/tools.cf";
17 static Cached_TextDB_Loader textdb_loader
= new Cached_TextDB_Loader();
19 static public IPropertylist
LoadToolConfig()
21 return LoadToolConfig((String
)null);
24 static public ToolConfig
getToolConfig()
26 return new ToolConfig(LoadToolConfig((String
)null));
28 static public ToolConfig
getToolConfig(File fn
)
30 return new ToolConfig(LoadToolConfig(fn
));
33 static public IPropertylist
LoadToolConfig(String fn
)
35 if (StrUtil
.isEmpty(fn
))
36 fn
= Environment
.getenv("UNITOOL_CONFIG");
38 if (StrUtil
.isEmpty(fn
))
39 throw new RuntimeException("missing $UNITOOL_CONFIG");
41 return LoadToolConfig(new File(fn
));
44 static public IPropertylist
LoadToolConfig(File fn
)
46 Propertylist props
= new Propertylist();
47 props
.loadProperties_top(textdb_loader
.load(fn
));
48 loadEnvironment(props
);
51 if (StrUtil
.isEmpty(props
.get_str("target-configured")))
52 throw new RuntimeException("missing or broken unitool config file: "+fn
);
55 throw new RuntimeException(e
);
60 private static void loadEnvironment(IPropertylist pr
)
62 Environment env
= new Environment();
63 for (Enumeration names
= env
.propertyNames(); names
.hasMoreElements();)
65 String n
= (String
)names
.nextElement();
66 pr
.set("@ENV/"+n
,env
.getProperty(n
));