use of org.apache.felix.fileinstall.ArtifactInstaller in project felix by apache.
the class DirectoryWatcher method update.
private Bundle update(Artifact artifact) {
Bundle bundle = null;
try {
File path = artifact.getPath();
// If the listener is an installer, ask for an update
if (artifact.getListener() instanceof ArtifactInstaller) {
((ArtifactInstaller) artifact.getListener()).update(path);
} else // if the listener is an url transformer
if (artifact.getListener() instanceof ArtifactUrlTransformer) {
URL transformed = artifact.getTransformedUrl();
bundle = context.getBundle(artifact.getBundleId());
if (bundle == null) {
log(Logger.LOG_WARNING, "Failed to update bundle: " + path + " with ID " + artifact.getBundleId() + ". The bundle has been uninstalled", null);
return null;
}
Util.log(context, Logger.LOG_INFO, "Updating bundle " + bundle.getSymbolicName() + " / " + bundle.getVersion(), null);
stopTransient(bundle);
Util.storeChecksum(bundle, artifact.getChecksum(), context);
InputStream in = (transformed != null) ? transformed.openStream() : new FileInputStream(path);
try {
bundle.update(in);
} finally {
in.close();
}
} else // else we need to ask for an update on the bundle
if (artifact.getListener() instanceof ArtifactTransformer) {
File transformed = artifact.getTransformed();
bundle = context.getBundle(artifact.getBundleId());
if (bundle == null) {
log(Logger.LOG_WARNING, "Failed to update bundle: " + path + " with ID " + artifact.getBundleId() + ". The bundle has been uninstalled", null);
return null;
}
Util.log(context, Logger.LOG_INFO, "Updating bundle " + bundle.getSymbolicName() + " / " + bundle.getVersion(), null);
stopTransient(bundle);
Util.storeChecksum(bundle, artifact.getChecksum(), context);
InputStream in = new FileInputStream(transformed != null ? transformed : path);
try {
bundle.update(in);
} finally {
in.close();
}
}
} catch (Throwable t) {
log(Logger.LOG_WARNING, "Failed to update artifact " + artifact.getPath(), t);
}
return bundle;
}
Aggregations