further refactor of IRepositoryConfig as part FELIX-1355
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@988983 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/core.tests/src/org/apache/felix/sigil/common/core/ConfigTest.java b/sigil/common/core.tests/src/org/apache/felix/sigil/common/core/ConfigTest.java
index f9c353d..4b196b3 100644
--- a/sigil/common/core.tests/src/org/apache/felix/sigil/common/core/ConfigTest.java
+++ b/sigil/common/core.tests/src/org/apache/felix/sigil/common/core/ConfigTest.java
@@ -27,6 +27,7 @@
import org.apache.felix.sigil.common.config.BldFactory;
import org.apache.felix.sigil.common.config.IBldProject;
+import org.apache.felix.sigil.common.config.IRepositoryConfig;
import org.apache.felix.sigil.common.core.internal.model.osgi.PackageImport;
import org.apache.felix.sigil.common.model.eclipse.ISigilBundle;
import org.apache.felix.sigil.common.model.osgi.IBundleModelElement;
@@ -98,4 +99,17 @@
// assertEquals( VersionRange.parseVersionRange("2.0.0"), i.getVersions() );
}
+ public void testDefinition() throws IOException
+ {
+ IRepositoryConfig project = BldFactory.getConfig(base.resolve("repository/foo/sigil.properties"));
+
+ URI def = project.getRepositoryDefinition("foo");
+ assertNotNull(def);
+ assertTrue(def.toString().endsWith("repository/sigil-defaults.properties"));
+
+ def = project.getRepositoryDefinition("baz");
+ assertNotNull(def);
+ assertTrue(def.toString().endsWith("repository/foo/sigil.properties"));
+ }
+
}
diff --git a/sigil/common/core.tests/test/ConfigTest/repository/foo/sigil.properties b/sigil/common/core.tests/test/ConfigTest/repository/foo/sigil.properties
new file mode 100644
index 0000000..08cd12c
--- /dev/null
+++ b/sigil/common/core.tests/test/ConfigTest/repository/foo/sigil.properties
@@ -0,0 +1,6 @@
+-bundles: org.foo
+-imports: org.bar
+
+-repositoryPath: foo, bar, baz
+
+baz;provider: system
\ No newline at end of file
diff --git a/sigil/common/core.tests/test/ConfigTest/repository/sigil-defaults.properties b/sigil/common/core.tests/test/ConfigTest/repository/sigil-defaults.properties
new file mode 100644
index 0000000..612bebe
--- /dev/null
+++ b/sigil/common/core.tests/test/ConfigTest/repository/sigil-defaults.properties
@@ -0,0 +1,4 @@
+-repositories: foo, bar, baz
+
+foo;provider: system
+bar;provider: system
\ No newline at end of file
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 e43409e..e4fc736 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
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -89,13 +90,21 @@
private Properties unknown = new Properties();
private String comment = "";
+ private final URI location;
public BldConfig()
{
+ this.location = null;
+ }
+
+ public BldConfig(URI loc)
+ {
+ this.location = loc;
}
public BldConfig(Properties p) throws IOException
{
+ this.location = null;
merge(p);
}
@@ -114,6 +123,31 @@
return unknown;
}
+ /**
+ * @param name
+ * @return
+ */
+ public URI getDefinition(String id, String key)
+ {
+ URI def = null;
+ if (dflt != null)
+ def = dflt.getDefinition(id, key);
+
+ if ( def == null ) {
+ if (property.containsKey(key)) {
+ def = location;
+ }
+ else if (id != null && config.containsKey(id))
+ {
+ Properties p2 = config.get(id).getProps(null, key);
+ if (p2 != null)
+ def = location;
+ }
+ }
+
+ return def;
+ }
+
public String getString(String id, String key)
{
if (id != null && config.containsKey(id))
@@ -559,5 +593,4 @@
return "STRING: " + string + " LIST:" + list + " MAP: " + map + " PROPERTY: "
+ property + " CONFIG:" + config + "\nDFLT{ " + dflt + "}";
}
-
}
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 0efcf6d..9543928 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,7 +36,6 @@
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;
@@ -64,7 +63,7 @@
private static final String OVERRIDE_PREFIX = "sigil.";
private static final int MAX_HEADER = 10240;
// cache to avoid loading the same default config for each project
- private static Map<URL, BldConfig> defaultsCache = new HashMap<URL, BldConfig>();
+ private static Map<URI, BldConfig> defaultsCache = new HashMap<URI, BldConfig>();
private static Properties sysOverrides;
private Properties bldOverrides;
@@ -80,9 +79,9 @@
/* package */BldProject(URI relLoc, Properties overrides)
{
- config = new BldConfig();
- convert = new BldConverter(config);
loc = new File(".").toURI().resolve(relLoc).normalize();
+ config = new BldConfig(loc);
+ convert = new BldConverter(config);
File f = new File(loc);
lastModified = f.lastModified();
baseDir = f.getParentFile();
@@ -187,22 +186,22 @@
}
file = file.getCanonicalFile();
- URL url = file.toURI().toURL();
+ URI uri = file.toURI();
BldProperties bp = new BldProperties(file.getParentFile(), bldOverrides);
if (dflt == null)
{
- dflt = defaultsCache.get(url);
+ dflt = defaultsCache.get(uri);
if (dflt != null)
return dflt;
- dflt = new BldConfig();
- defaultsCache.put(url, dflt);
+ dflt = new BldConfig(uri);
+ defaultsCache.put(uri, dflt);
cached = true;
}
Properties p = new Properties();
- InputStream stream = url.openStream();
+ InputStream stream = uri.toURL().openStream();
p.load(stream);
stream.close();
@@ -659,26 +658,37 @@
return ids;
}
- public Map<String, Properties> getRepositoryConfig()
+ public Properties getRepositoryConfig(String name)
{
- LinkedHashMap<String, Properties> map = new LinkedHashMap<String, Properties>();
BldProperties bp = new BldProperties(baseDir, bldOverrides);
- for (String name : config.getList(null, BldConfig.C_REPOSITORIES))
+ Properties repo = config.getProps(null, name);
+
+ for (Object k : repo.keySet())
{
- Properties repo = config.getProps(null, name);
-
- for (Object k : repo.keySet())
- {
- String key = (String) k;
- String value = repo.getProperty(key);
- repo.setProperty(key, BldUtil.expand(value, bp));
- }
-
- map.put(name, repo);
+ String key = (String) k;
+ String value = repo.getProperty(key);
+ repo.setProperty(key, BldUtil.expand(value, bp));
}
- return map;
+
+ return repo;
}
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.sigil.common.config.IRepositoryConfig#getAllRepositories()
+ */
+ public List<String> getAllRepositories()
+ {
+ return config.getList(null, BldConfig.C_REPOSITORIES);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.sigil.common.config.IRepositoryConfig#getRepositoryDefinition(java.lang.String)
+ */
+ public URI getRepositoryDefinition(String name)
+ {
+ return config.getDefinition(null, name);
+ }
public Properties getOptions()
{
@@ -1021,5 +1031,4 @@
{
return lastModified;
}
-
}
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 319ce7d..79a8de7 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,8 +19,8 @@
package org.apache.felix.sigil.common.config;
+import java.net.URI;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
public interface IRepositoryConfig
@@ -28,6 +28,8 @@
static final String REPOSITORY_PROVIDER = "provider";
static final String WILD_CARD = "*";
+ URI getRepositoryDefinition(String name);
+
/**
* Return the ordered list of repositories to search
* for dependencies.
@@ -41,5 +43,10 @@
* The key REPOSITORY_PROVIDER will be set to the fully qualified class name of the IRepositoryProvider.
* @return
*/
- Map<String, Properties> getRepositoryConfig();
+ Properties getRepositoryConfig(String name);
+
+ /**
+ * @return
+ */
+ List<String> getAllRepositories();
}
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 fc8d3dd..5d3fa9b 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
@@ -35,6 +35,7 @@
public class BldRepositoryManager extends AbstractRepositoryManager
{
private static Map<String, String> aliases = new HashMap<String, String>();
+ private final IRepositoryConfig config;
static
{
@@ -46,53 +47,49 @@
"org.apache.felix.sigil.common.core.repository.SystemRepositoryProvider");
};
- private final Map<String, Properties> repos;
- private final List<String> repositoryPath;
-
- public BldRepositoryManager(List<String> repositoryPath, Map<String, Properties> repos)
+ /**
+ * @param config
+ */
+ public BldRepositoryManager(IRepositoryConfig config)
{
- System.out.println("RepositoryPath=" + repositoryPath);
- System.out.println("Repos=" + repos);
- this.repositoryPath = repositoryPath;
- this.repos = repos;
+ this.config = config;
}
@Override
protected void loadRepositories()
{
- scanRepositories(repositoryPath, repos, 0);
+ scanRepositories(config.getRepositoryPath(), 0);
}
/**
- * @param repos2
- * @param repositoryPath2
+ * @param list
+ * @param config2
+ * @param i
*/
- private int scanRepositories(List<String> repositoryPath, Map<String, Properties> repos, int start)
+ private int scanRepositories(List<String> path, int start)
{
int count = start;
- for (String name : repositoryPath)
+ for (String name : path)
{
- System.out.println("Building repository for " + name);
if ( IRepositoryConfig.WILD_CARD.equals(name) ) {
HashSet<String> defined = new HashSet<String>();
- for (String n : repositoryPath) {
+ for (String n : path) {
if (!IRepositoryConfig.WILD_CARD.equals(n)) {
defined.add(n);
}
}
- List<String> path = new LinkedList<String>();
- for (String key : repos.keySet()) {
+ List<String> subpath = new LinkedList<String>();
+ for (String key : config.getAllRepositories()) {
if (!defined.contains(key))
{
- path.add(key);
+ subpath.add(key);
}
}
- count = scanRepositories(path, repos, start + 1);
+ count = scanRepositories(subpath, start + 1);
}
else {
- Properties props = repos.get(name);
+ Properties props = config.getRepositoryConfig(name);
IBundleRepository repo = buildRepository(name, props);
- System.out.println("Built repository " + repo + " for " + name + " at " + count);
if ( repo != null ) {
addRepository(repo, count++);
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 99dad6d..f8a96fd 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
@@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Properties;
+import org.apache.felix.sigil.common.config.IRepositoryConfig;
import org.apache.felix.sigil.common.core.BldCore;
import org.apache.felix.sigil.common.model.IModelElement;
import org.apache.felix.sigil.common.model.eclipse.ISigilBundle;
@@ -33,10 +34,8 @@
public class BldResolver implements IBldResolver
{
- private final Map<String, Properties> repos;
- private final List<String> repositoryPath;
-
private BldRepositoryManager manager;
+ private final IRepositoryConfig config;
static
{
@@ -51,10 +50,12 @@
}
};
- public BldResolver(List<String> repositoryPath, Map<String, Properties> repos)
+ /**
+ * @param project
+ */
+ public BldResolver(IRepositoryConfig config)
{
- this.repositoryPath = repositoryPath;
- this.repos = repos;
+ this.config = config;
}
public IResolution resolve(IModelElement element, boolean transitive)
@@ -90,7 +91,7 @@
{
if (manager == null)
{
- manager = new BldRepositoryManager(repositoryPath, repos);
+ manager = new BldRepositoryManager(this.config);
}
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 7fbd2d7..a4b4c57 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
@@ -123,9 +123,7 @@
}
IRepositoryConfig project = BldFactory.getConfig(uri);
- List<String> repositoryPath = project.getRepositoryPath();
- Map<String, Properties> repositories = project.getRepositoryConfig();
- resolver = new BldResolver(repositoryPath, repositories);
+ resolver = new BldResolver(project);
}
catch (IOException e)
{