blob: ce5d9db0c9de1e0cbfaf6f6f4a6ec532e32c8a07 [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.ivy;
21
22import java.io.File;
23import java.util.HashMap;
24import java.util.Map;
25import java.util.Properties;
26
27import org.cauldron.bld.config.IRepositoryConfig;
28import org.cauldron.sigil.repository.AbstractRepositoryManager;
29import org.cauldron.sigil.repository.IBundleRepository;
30import org.cauldron.sigil.repository.IRepositoryProvider;
31
32public class BldRepositoryManager extends AbstractRepositoryManager {
33 private static Map<String, String> aliases = new HashMap<String, String>();
34
35 static {
36 aliases.put("filesystem", "org.cauldron.bld.core.repository.FileSystemRepositoryProvider");
37 aliases.put("obr", "org.cauldron.bld.obr.OBRRepositoryProvider");
38 aliases.put("project", "org.cauldron.bld.ivy.ProjectRepositoryProvider");
39 aliases.put("system", "org.cauldron.bld.core.repository.SystemRepositoryProvider");
40 };
41
42 private Map<String, Properties> repos;
43
44 public BldRepositoryManager(Map<String, Properties> repos) {
45 this.repos = repos;
46 }
47
48 @Override
49 protected void loadRepositories() {
50 for (String name : repos.keySet()) {
51 Properties repo = repos.get(name);
52
53 String alias = repo.getProperty(IRepositoryConfig.REPOSITORY_PROVIDER);
54 if (alias == null) {
55 Log.error("provider not specified for repository: " + name);
56 continue;
57 }
58
59 String provider = (aliases.containsKey(alias) ? aliases.get(alias) : alias);
60
61 if (alias.equals("obr")) {
62 // cache is directory where synchronized bundles are stored;
63 // not needed in ivy.
64 repo.setProperty("cache", "/no-cache");
65
66 if (!repo.containsKey("index")) {
67 // index is created as copy of url
68 File indexFile = new File(System.getProperty("java.io.tmpdir"), "obr-index-" + name);
69 indexFile.deleteOnExit();
70 repo.setProperty("index", indexFile.getAbsolutePath());
71 }
72 }
73
74 int level = Integer.parseInt(repo.getProperty(IRepositoryConfig.REPOSITORY_LEVEL,
75 IBundleRepository.NORMAL_PRIORITY + ""));
76
77 try {
78 IRepositoryProvider instance = (IRepositoryProvider) (Class.forName(provider).newInstance());
79 IBundleRepository repository = instance.createRepository(name, repo);
80 addRepository(repository, level);
81 Log.verbose("added repository: " + repository);
82 } catch (Exception e) {
83 throw new Error("createRepository() failed: " + repo + " : " + e, e);
84 }
85 }
86 }
87}