use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class ConfigInstallTest method testInstallAndRemoveConfig.
@Test
public void testInstallAndRemoveConfig() throws Exception {
final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
cfgData.put("foo", "bar");
final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
// install config
final InstallableResource[] rsrc = getInstallableResource(cfgPid, cfgData);
installer.updateResources(URL_SCHEME, rsrc, null);
Configuration cfg = waitForConfiguration("After installing", cfgPid, true);
assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
// remove resource
installer.updateResources(URL_SCHEME, null, new String[] { rsrc[0].getId() });
waitForConfiguration("After removing", cfgPid, false);
// Reinstalling with same digest must work
installer.updateResources(URL_SCHEME, rsrc, null);
cfg = waitForConfiguration("After reinstalling", cfgPid, true);
assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
// remove again
installer.updateResources(URL_SCHEME, null, new String[] { rsrc[0].getId() });
waitForConfiguration("After removing for the second time", cfgPid, false);
}
use of org.apache.sling.installer.api.InstallableResource in project stanbol by apache.
the class BundleInstaller method storeConfig.
/**
* Used to stores/overrides the ids of installed resource for a bundle.
* @param bundle
* @param resources
* @throws IOException
*/
private void storeConfig(Bundle bundle, Collection<InstallableResource> resources) throws IOException {
synchronized (configDir) {
File config = new File(configDir, bundle.getBundleId() + ".resources");
if (config.exists()) {
config.delete();
}
FileOutputStream out = new FileOutputStream(config);
List<String> ids = new ArrayList<String>(resources.size());
for (InstallableResource resource : resources) {
ids.add(resource.getId());
}
try {
IOUtils.writeLines(ids, null, out, "UTF-8");
} finally {
IOUtils.closeQuietly(out);
}
}
}
use of org.apache.sling.installer.api.InstallableResource in project stanbol by apache.
the class BundleInstaller method createInstallableResource.
/**
* Creates an {@link InstallableResource} for {@link URL}s of files within
* the parsed bundle.
*
* @param bundle the bundle containing the parsed resource
* @param bundleResource a resource within the bundle that need to be installed
*
* @return the installable resource or <code>null</code> in case of an error
*/
private InstallableResource createInstallableResource(Bundle bundle, String path, URL bundleResource) {
//define the id
String relPath = getInstallableResourceId(path, bundleResource);
String name = FilenameUtils.getName(relPath);
if (name == null || name.isEmpty()) {
//ignore directories!
return null;
}
InstallableResource resource;
try {
/*
* Notes:
* - use <relativepath> as id
* - parse null as type to enable autodetection for configs as
* implemented by InternalReseouce.create(..)
* - we use the symbolic name and the modification date of the bundle as digest
* - the Dictionary will be ignored if an input stream is present
* so it is best to parse null
* - No idea how the priority is used by the Sling Installer. For
* now parse null than the default priority is used.
*/
resource = new InstallableResource(relPath, bundleResource.openStream(), null, String.valueOf(bundle.getSymbolicName() + bundle.getLastModified()), null, null);
log.info(" ... found installable resource " + bundleResource);
} catch (IOException e) {
log.error(String.format("Unable to process configuration File %s from Bundle %s", bundleResource, bundle.getSymbolicName()), e);
return null;
}
return resource;
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class DictionaryDigestTest method testDictionaryOrderDoesNotMatter.
@org.junit.Test
public void testDictionaryOrderDoesNotMatter() throws Exception {
final Dictionary<String, Object> a = new Hashtable<String, Object>();
a.put("one", "A");
a.put("two", "B");
a.put("three", "C");
final Dictionary<String, Object> b = new Hashtable<String, Object>();
b.put("two", "B");
b.put("one", "A");
b.put("three", "C");
assertEquals("Same data in different order must have same digest", create(new InstallableResource("a", null, a, null, null, null)).getDigest(), create(new InstallableResource("a", null, b, null, null, null)).getDigest());
}
use of org.apache.sling.installer.api.InstallableResource in project sling by apache.
the class InternalResourceTest method testSimpleProps.
@Test
public void testSimpleProps() throws IOException {
final String[] types = new String[] { InstallableResource.TYPE_CONFIG, InstallableResource.TYPE_PROPERTIES, null, "zip" };
for (int i = 0; i < types.length; i++) {
final InstallableResource instRes = new InstallableResource("1", null, getSimpleDict(), null, types[i], null);
final InternalResource ir = InternalResource.create(SCHEME, instRes);
assertEquals(SCHEME + ":1", ir.getURL());
assertEquals("1", ir.getId());
assertNotNull(ir.getDictionary());
assertIsSimpleDict(ir.getDictionary());
assertNotNull(ir.getPrivateCopyOfDictionary());
assertIsSimpleDict(ir.getPrivateCopyOfDictionary());
assertNull(ir.getInputStream());
assertNull(ir.getPrivateCopyOfFile());
if ("zip".equals(types[i])) {
assertEquals("zip", ir.getType());
} else {
assertEquals(InstallableResource.TYPE_PROPERTIES, ir.getType());
}
assertNotNull(ir.getDigest());
assertEquals(InstallableResource.DEFAULT_PRIORITY, ir.getPriority());
}
}
Aggregations