add support for offline=<true|false> config to obr (FELIX-2585)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@994943 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
index bd75a88..524fc8b 100644
--- a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
+++ b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/OBRRepositoryProvider.java
@@ -38,6 +38,7 @@
private static final String AUTH_FILE = "auth";
public static final String CACHE_DIRECTORY = "cache";
public static final String INDEX_CACHE_FILE = "index";
+ public static final String OFFLINE = "offline";
public IBundleRepository createRepository(String id, Properties preferences)
throws RepositoryException
@@ -58,8 +59,10 @@
File authFile = auth == null ? null : new File(auth);
Long up = preferences.containsKey(UPDATE_PERIOD) ? Long.parseLong(preferences.getProperty(UPDATE_PERIOD))
: 60 * 60 * 24 * 7;
+
+ boolean offline = preferences.containsKey(OFFLINE) ? Boolean.parseBoolean(preferences.getProperty(OFFLINE)) : false;
- if (testURL.openConnection().getLastModified() == 0)
+ if (!offline && testURL.openConnection().getLastModified() == 0)
{
String msg = "Failed to read OBR index: ";
if (!indexCache.exists())
@@ -71,12 +74,12 @@
if (preferences.getProperty(IN_MEMORY) == null)
{
return new NonCachingOBRBundleRepository(id, repositoryURL, indexCache,
- localCache, updatePeriod, authFile);
+ localCache, updatePeriod, authFile, offline);
}
else
{
return new CachingOBRBundleRepository(id, repositoryURL, indexCache,
- localCache, updatePeriod, authFile);
+ localCache, updatePeriod, authFile, offline);
}
}
catch (IOException e)
diff --git a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
index 564a176..b8599e2 100644
--- a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
+++ b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/AbstractOBRBundleRepository.java
@@ -41,15 +41,17 @@
{
private static SAXParserFactory factory = SAXParserFactory.newInstance();
- private URL obrURL;
- private File obrlCache;
- private File bundleCache;
- private long updatePeriod;
+ private final URL obrURL;
+ private final File obrlCache;
+ private final File bundleCache;
+ private final long updatePeriod;
private final File authFile;
private final Properties authMap = new Properties();
- private long authLastModified;
+ private final boolean offline;
- public AbstractOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile)
+ private long authLastModified;
+
+ public AbstractOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile, boolean offline)
{
super(id);
this.obrURL = repositoryURL;
@@ -57,6 +59,7 @@
this.bundleCache = bundleCache;
this.updatePeriod = updatePeriod;
this.authFile = authFile;
+ this.offline = offline;
}
public void refresh()
@@ -104,6 +107,8 @@
{
authMap.clear();
authMap.load(new FileInputStream(authFile));
+
+ authLastModified = authFile.lastModified();
}
String authKey = "";
@@ -232,7 +237,7 @@
if (!getObrlCache().exists())
return true;
- return getObrlCache().lastModified() + getUpdatePeriod() < System.currentTimeMillis();
+ return !offline && getObrlCache().lastModified() + getUpdatePeriod() < System.currentTimeMillis();
}
private URL getObrURL()
diff --git a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
index fca06f0..14e3687 100644
--- a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
+++ b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/CachingOBRBundleRepository.java
@@ -33,9 +33,9 @@
private SoftReference<List<ISigilBundle>> bundles;
- public CachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile)
+ public CachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile, boolean offline)
{
- super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile);
+ super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile, offline);
}
@Override
diff --git a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
index 340a184..06a6806 100644
--- a/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
+++ b/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/NonCachingOBRBundleRepository.java
@@ -43,9 +43,9 @@
});
} */
- public NonCachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile)
+ public NonCachingOBRBundleRepository(String id, URL repositoryURL, File obrCache, File bundleCache, long updatePeriod, File authFile, boolean offline)
{
- super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile);
+ super(id, repositoryURL, obrCache, bundleCache, updatePeriod, authFile, offline);
}
@Override