use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class MockOsgiInstaller method registerResources.
/**
* @see org.apache.sling.installer.api.OsgiInstaller#registerResources(java.lang.String, org.apache.sling.installer.api.InstallableResource[])
*/
public void registerResources(String urlScheme, final InstallableResource[] data) {
// Sort the data to allow comparing the recorded calls reliably
final List<InstallableResource> sorted = new LinkedList<InstallableResource>();
for (final InstallableResource r : data) {
sorted.add(r);
}
Collections.sort(sorted, new InstallableResourceComparator());
for (InstallableResource r : sorted) {
urls.add(urlScheme + ':' + r.getId());
recordCall("register", urlScheme, r);
}
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class Installer method updated.
/**
* @see org.apache.sling.installer.provider.file.impl.FileChangesListener#updated(java.util.List, java.util.List, java.util.List)
*/
public void updated(List<File> added, List<File> changed, List<File> removed) {
final List<InstallableResource> updated;
if ((added != null && added.size() > 0) || (changed != null && changed.size() > 0)) {
updated = new ArrayList<InstallableResource>();
if (added != null) {
for (final File f : added) {
logger.debug("Added file {}", f);
final InstallableResource resource = this.createResource(f);
if (resource != null) {
updated.add(resource);
}
}
}
if (changed != null) {
for (final File f : changed) {
logger.debug("Changed file {}", f);
final InstallableResource resource = this.createResource(f);
if (resource != null) {
updated.add(resource);
}
}
}
} else {
updated = null;
}
final String[] removedUrls;
if (removed != null && removed.size() > 0) {
removedUrls = new String[removed.size()];
int index = 0;
for (final File f : removed) {
removedUrls[index] = f.getAbsolutePath();
logger.debug("Removed file {}", removedUrls[index]);
index++;
}
} else {
removedUrls = null;
}
if (updated != null || removedUrls != null) {
this.installer.updateResources(this.scheme, updated == null ? null : updated.toArray(new InstallableResource[updated.size()]), removedUrls);
}
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class FileNodeConverter method convert.
private InstallableResource convert(final Node n, final String path, final int priority) throws IOException, RepositoryException {
final String digest = String.valueOf(n.getProperty(JCR_CONTENT_LAST_MODIFIED).getDate().getTimeInMillis());
final InputStream is = n.getProperty(JCR_CONTENT_DATA).getStream();
final Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(InstallableResource.INSTALLATION_HINT, n.getParent().getName());
return new InstallableResource(path, is, dict, digest, null, priority);
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class ConfigInstallTest method testInstallUpdateRemoveTemplateConfig.
@Test
public void testInstallUpdateRemoveTemplateConfig() throws Exception {
final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
cfgData.put("foo", "bar");
cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
// install config
final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
// get config
final Configuration cfg = waitForConfigValue("After installing", cfgPid, "foo", "bar");
// update configuration
final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
secondData.put("foo", "bla");
cfg.update(secondData);
waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED);
// get updated config
final Configuration secondCfg = waitForConfigValue("After updating", cfgPid, "foo", "bla");
// remove config
secondCfg.delete();
// we have to wait here as no state change is happening
sleep(200);
waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED);
waitForConfiguration("After deleting", cfgPid, false);
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class ConfigInstallTest method testDeferredConfigInstall.
@Test
public void testDeferredConfigInstall() throws Exception {
// get config admin bundle and wait for service
final Bundle configAdmin = this.getConfigAdminBundle();
assertNotNull("ConfigAdmin bundle must be found", configAdmin);
waitForConfigAdmin(true);
// check that configuration is not available
final String cfgPid = getClass().getSimpleName() + ".deferred." + uniqueID();
assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
// create new configuration object
final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
cfgData.put("foo", "bar");
// Configuration installs must be deferred if ConfigAdmin service is stopped
configAdmin.stop();
waitForConfigAdmin(false);
// add new configuration
final InstallableResource[] rsrc = getInstallableResource(cfgPid, cfgData);
installationEvents = 0;
installer.updateResources(URL_SCHEME, rsrc, null);
waitForInstallationEvents(2);
configAdmin.start();
waitForConfigAdmin(true);
waitForConfiguration("Config must be installed once ConfigurationAdmin restarts", cfgPid, true);
// Remove config and check
installer.updateResources(URL_SCHEME, null, new String[] { rsrc[0].getId() });
waitForConfiguration("Config must be removed once ConfigurationAdmin restarts", cfgPid, false);
}
Aggregations