blob: a02adccc78d97afd1112217d5263825ef9779d05 [file] [log] [blame]
Richard S. Hall85bafab2009-07-13 13:25:46 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package org.cauldron.bld.config;
21
22import java.io.File;
23import java.io.IOException;
24import java.net.URI;
25import java.util.HashMap;
26import java.util.Map;
27import java.util.Properties;
28
29public class BldFactory {
30 private static Map<URI, BldProject> projects = new HashMap<URI, BldProject>();
31
32 public static IBldProject getProject(URI uri) throws IOException {
33 return getProject(uri, false);
34 }
35
36 public static IBldProject getProject(URI uri, boolean ignoreCache) throws IOException {
37 return load(uri, ignoreCache);
38 }
39
40 public static IRepositoryConfig getConfig(URI uri) throws IOException {
41 return load(uri, false);
42 }
43
44 /**
45 * creates a new project file, initialised with defaults.
46 * @param uri where the file will be saved - used to resolve relative paths.
47 * @param defaults relative path to defaults file - default ../sigil.properties.
48 * @return
49 * @throws IOException
50 */
51 public static IBldProject newProject(URI uri, String defaults) throws IOException {
52 BldProject project = new BldProject(uri);
53 Properties p = new Properties();
54 if (defaults != null)
55 p.setProperty(BldConfig.S_DEFAULTS, defaults);
56 project.loadDefaults(p);
57 return project;
58 }
59
60 private static BldProject load(URI uri, boolean ignoreCache) throws IOException {
61 BldProject p = null;
62 if (!ignoreCache) {
63 p = projects.get(uri);
64 }
65
66 if (p == null) {
67 p = new BldProject(uri);
68 p.load();
69 projects.put(uri, p);
70
71 if (Boolean.getBoolean("org.cauldron.bld.config.test")) {
72 File path = new File(uri.getPath() + ".tmp");
73 System.out.println("XXX: config.test writing: " + path);
74 p.saveAs(path);
75 }
76 }
77 return p;
78 }
79
80}