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;
}
Aggregations