repository config is now managed via a repository path approach (part of work for FELIX-1355)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@988131 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/bldcommon/sigil-repos.properties b/sigil/bldcommon/sigil-repos.properties
index b458ff4..db142d4 100644
--- a/sigil/bldcommon/sigil-repos.properties
+++ b/sigil/bldcommon/sigil-repos.properties
@@ -2,35 +2,29 @@
# repository config
--repositories: system, project, bld-ant, bld-common, felix, spring
+-repositories: system, project, bld-common, felix, spring, bld-ant
system;provider: system
-system;level: -1
project;provider: project
-project;level: 0
project;pattern: \
${..}/common/**/[sigilproject] \
${..}/eclipse/**/[sigilproject] \
bld-ant;provider: filesystem
-bld-ant;level: 5
bld-ant;recurse: true
bld-ant;dir: ${cache.dir:-${..}/cache}/ant/lib
bld-common;provider: filesystem
-bld-common;level: 2
bld-common;recurse: true
bld-common;dir: ${cache.dir:-${..}/cache}/all
felix;provider: obr
-felix;level: 4
felix;url: http://felix.apache.org/obr/releases.xml
felix;index: ${..}/build/felix.obr
felix;cache: ${..}/build/obr-cache
spring;provider: obr
-spring;level: 4
spring;url: http://sigil.codecauldron.org/spring-external.obr
spring;index: ${..}/build/spring-external.obr
spring;cache: ${..}/build/obr-cache
diff --git a/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java b/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
index 499af0d..e43409e 100644
--- a/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
+++ b/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
@@ -36,6 +36,7 @@
// control properties
public static final String C_BUNDLES = "-bundles";
public static final String C_REPOSITORIES = "-repositories";
+ public static final String C_REPOSITORY_PATH = "-repositorypath";
// string properties
public static final String S_ACTIVATOR = "-activator";
@@ -75,7 +76,7 @@
private static final String MAPATTR_REGEX = ";\\s*";
private static final String MAPATTR_SEP = ";";
private static final String SUBKEY_SEP = ";";
-
+
// configuration is stored in typed maps
private Map<String, String> string = new TreeMap<String, String>();
private Map<String, List<String>> list = new TreeMap<String, List<String>>();
diff --git a/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java b/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
index 705b2b9..0efcf6d 100644
--- a/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
+++ b/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
@@ -36,6 +36,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -648,11 +649,19 @@
return list;
}
- // Implement IBldConfig: getRepositoryConfig
-
+ public List<String> getRepositoryPath()
+ {
+ List<String> ids = config.getList(null, BldConfig.C_REPOSITORY_PATH);
+
+ if (ids.isEmpty())
+ return Collections.singletonList(IRepositoryConfig.WILD_CARD);
+
+ return ids;
+ }
+
public Map<String, Properties> getRepositoryConfig()
{
- HashMap<String, Properties> map = new HashMap<String, Properties>();
+ LinkedHashMap<String, Properties> map = new LinkedHashMap<String, Properties>();
BldProperties bp = new BldProperties(baseDir, bldOverrides);
for (String name : config.getList(null, BldConfig.C_REPOSITORIES))
diff --git a/sigil/common/core/src/org/apache/felix/sigil/common/config/IRepositoryConfig.java b/sigil/common/core/src/org/apache/felix/sigil/common/config/IRepositoryConfig.java
index 39beab2..319ce7d 100644
--- a/sigil/common/core/src/org/apache/felix/sigil/common/config/IRepositoryConfig.java
+++ b/sigil/common/core/src/org/apache/felix/sigil/common/config/IRepositoryConfig.java
@@ -19,18 +19,26 @@
package org.apache.felix.sigil.common.config;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
public interface IRepositoryConfig
{
static final String REPOSITORY_PROVIDER = "provider";
- static final String REPOSITORY_LEVEL = "level";
+ static final String WILD_CARD = "*";
+
+ /**
+ * Return the ordered list of repositories to search
+ * for dependencies.
+ *
+ * @return
+ */
+ List<String> getRepositoryPath();
/**
* get properties with which to instantiate repositories.
* The key REPOSITORY_PROVIDER will be set to the fully qualified class name of the IRepositoryProvider.
- * The key REPOSITORY_LEVEL indicates repository search order.
* @return
*/
Map<String, Properties> getRepositoryConfig();
diff --git a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldRepositoryManager.java b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldRepositoryManager.java
index 28d3e36..fc8d3dd 100644
--- a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldRepositoryManager.java
+++ b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldRepositoryManager.java
@@ -21,6 +21,9 @@
import java.io.File;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -43,78 +46,123 @@
"org.apache.felix.sigil.common.core.repository.SystemRepositoryProvider");
};
- private Map<String, Properties> repos;
+ private final Map<String, Properties> repos;
+ private final List<String> repositoryPath;
- public BldRepositoryManager(Map<String, Properties> repos)
+ public BldRepositoryManager(List<String> repositoryPath, Map<String, Properties> repos)
{
+ System.out.println("RepositoryPath=" + repositoryPath);
+ System.out.println("Repos=" + repos);
+ this.repositoryPath = repositoryPath;
this.repos = repos;
}
@Override
protected void loadRepositories()
{
- for (String name : repos.keySet())
+ scanRepositories(repositoryPath, repos, 0);
+ }
+
+ /**
+ * @param repos2
+ * @param repositoryPath2
+ */
+ private int scanRepositories(List<String> repositoryPath, Map<String, Properties> repos, int start)
+ {
+ int count = start;
+ for (String name : repositoryPath)
{
- Properties repo = repos.get(name);
- if (Boolean.parseBoolean(repo.getProperty("disabled", "false")))
- {
- continue;
- }
-
- String optStr = repo.getProperty("optional", "false");
- boolean optional = Boolean.parseBoolean(optStr.trim());
-
- String alias = repo.getProperty(IRepositoryConfig.REPOSITORY_PROVIDER);
- if (alias == null)
- {
- Log.error("provider not specified for repository: " + name);
- continue;
- }
-
- String provider = (aliases.containsKey(alias) ? aliases.get(alias) : alias);
-
- if (alias.equals("obr"))
- {
- // cache is directory where synchronized bundles are stored;
- // not needed in ivy.
- repo.setProperty("cache", "/no-cache");
- String index = repo.getProperty("index");
-
- if (index == null)
- {
- // index is created to cache OBR url
- File indexFile = new File(System.getProperty("java.io.tmpdir"),
- "obr-index-" + name);
- indexFile.deleteOnExit();
- repo.setProperty("index", indexFile.getAbsolutePath());
- }
- else
- {
- if (!new File(index).getParentFile().mkdirs())
- {
- // ignore - but keeps findbugs happy
+ System.out.println("Building repository for " + name);
+ if ( IRepositoryConfig.WILD_CARD.equals(name) ) {
+ HashSet<String> defined = new HashSet<String>();
+ for (String n : repositoryPath) {
+ if (!IRepositoryConfig.WILD_CARD.equals(n)) {
+ defined.add(n);
}
}
+ List<String> path = new LinkedList<String>();
+ for (String key : repos.keySet()) {
+ if (!defined.contains(key))
+ {
+ path.add(key);
+ }
+ }
+ count = scanRepositories(path, repos, start + 1);
}
-
- int level = Integer.parseInt(repo.getProperty(
- IRepositoryConfig.REPOSITORY_LEVEL,
- Integer.toString(IBundleRepository.NORMAL_PRIORITY)));
-
- try
- {
- IRepositoryProvider instance = (IRepositoryProvider) (Class.forName(provider).newInstance());
- IBundleRepository repository = instance.createRepository(name, repo);
- addRepository(repository, level);
- Log.verbose("added repository: " + repository + " : " + level);
- }
- catch (Exception e)
- {
- String msg = "failed to create repository: ";
- if (!optional)
- throw new Error(msg + repo + " " + e, e);
- System.err.println("WARNING: " + msg + e);
+ else {
+ Properties props = repos.get(name);
+ IBundleRepository repo = buildRepository(name, props);
+ System.out.println("Built repository " + repo + " for " + name + " at " + count);
+
+ if ( repo != null ) {
+ addRepository(repo, count++);
+ }
}
}
+
+ return count;
+ }
+
+ /**
+ * @param repo
+ * @return
+ */
+ private static IBundleRepository buildRepository(String name, Properties repo)
+ {
+ String optStr = repo.getProperty("optional", "false");
+ boolean optional = Boolean.parseBoolean(optStr.trim());
+
+ String alias = repo.getProperty(IRepositoryConfig.REPOSITORY_PROVIDER);
+ if (alias == null)
+ {
+ String msg = "provider not specified for repository: " + name;
+
+ if (!optional)
+ throw new IllegalStateException(msg);
+
+ Log.warn(msg);
+ }
+
+ String provider = (aliases.containsKey(alias) ? aliases.get(alias) : alias);
+
+ if (alias.equals("obr"))
+ {
+ // cache is directory where synchronized bundles are stored;
+ // not needed in ivy.
+ repo.setProperty("cache", "/no-cache");
+ String index = repo.getProperty("index");
+
+ if (index == null)
+ {
+ // index is created to cache OBR url
+ File indexFile = new File(System.getProperty("java.io.tmpdir"),
+ "obr-index-" + name);
+ indexFile.deleteOnExit();
+ repo.setProperty("index", indexFile.getAbsolutePath());
+ }
+ else
+ {
+ if (!new File(index).getParentFile().mkdirs())
+ {
+ // ignore - but keeps findbugs happy
+ }
+ }
+ }
+
+ try
+ {
+ IRepositoryProvider instance = (IRepositoryProvider) (Class.forName(provider).newInstance());
+ IBundleRepository repository = instance.createRepository(name, repo);
+ return repository;
+ }
+ catch (Exception e)
+ {
+ String msg = "failed to create repository: ";
+ if (!optional)
+ throw new IllegalStateException(msg + repo + " " + e, e);
+ Log.warn(msg + e);
+ }
+
+ return null;
}
}
\ No newline at end of file
diff --git a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldResolver.java b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldResolver.java
index 1e33b66..99dad6d 100644
--- a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldResolver.java
+++ b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/BldResolver.java
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.ivy;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -32,9 +33,11 @@
public class BldResolver implements IBldResolver
{
- private Map<String, Properties> repos;
- private BldRepositoryManager manager;
+ private final Map<String, Properties> repos;
+ private final List<String> repositoryPath;
+ private BldRepositoryManager manager;
+
static
{
try
@@ -48,8 +51,9 @@
}
};
- public BldResolver(Map<String, Properties> repos)
+ public BldResolver(List<String> repositoryPath, Map<String, Properties> repos)
{
+ this.repositoryPath = repositoryPath;
this.repos = repos;
}
@@ -86,7 +90,7 @@
{
if (manager == null)
{
- manager = new BldRepositoryManager(repos);
+ manager = new BldRepositoryManager(repositoryPath, repos);
}
IResolutionMonitor ivyMonitor = new IResolutionMonitor()
diff --git a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java
index 6404ef9..7fbd2d7 100644
--- a/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java
+++ b/sigil/ivy/resolver/src/org/apache/felix/sigil/ivy/SigilResolver.java
@@ -30,6 +30,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.jar.JarEntry;
@@ -37,6 +38,7 @@
import java.util.jar.Manifest;
import org.apache.felix.sigil.common.config.BldFactory;
+import org.apache.felix.sigil.common.config.IRepositoryConfig;
import org.apache.felix.sigil.common.model.IModelElement;
import org.apache.felix.sigil.common.model.ModelElementFactory;
import org.apache.felix.sigil.common.model.eclipse.ISigilBundle;
@@ -120,8 +122,10 @@
uri = cwd.resolve(config);
}
- Map<String, Properties> repositories = BldFactory.getConfig(uri).getRepositoryConfig();
- resolver = new BldResolver(repositories);
+ IRepositoryConfig project = BldFactory.getConfig(uri);
+ List<String> repositoryPath = project.getRepositoryPath();
+ Map<String, Properties> repositories = project.getRepositoryConfig();
+ resolver = new BldResolver(repositoryPath, repositories);
}
catch (IOException e)
{