use of org.apache.felix.fileinstall.ArtifactTransformer in project felix by apache.
the class DirectoryWatcher method install.
/**
* Install an artifact and return the bundle object.
* It uses {@link Artifact#getPath()} as location
* of the new bundle. Before installing a file,
* it sees if the file has been identified as a bad file in
* earlier run. If yes, then it compares to see if the file has changed
* since then. It installs the file if the file has changed.
* If the file has not been identified as a bad file in earlier run,
* then it always installs it.
*
* @param artifact the artifact to be installed
* @return Bundle object that was installed
*/
private Bundle install(Artifact artifact) {
File path = artifact.getPath();
Bundle bundle = null;
AtomicBoolean modified = new AtomicBoolean();
try {
// If the listener is an installer, ask for an update
if (artifact.getListener() instanceof ArtifactInstaller) {
((ArtifactInstaller) artifact.getListener()).install(path);
} else // if the listener is an url transformer
if (artifact.getListener() instanceof ArtifactUrlTransformer) {
Artifact badArtifact = installationFailures.get(path);
if (badArtifact != null && badArtifact.getChecksum() == artifact.getChecksum()) {
// Don't attempt to install it; nothing has changed.
return null;
}
URL transformed = artifact.getTransformedUrl();
String location = transformed.toString();
BufferedInputStream in = new BufferedInputStream(transformed.openStream());
bundle = installOrUpdateBundle(location, in, artifact.getChecksum(), modified);
artifact.setBundleId(bundle.getBundleId());
} else // if the listener is an artifact transformer
if (artifact.getListener() instanceof ArtifactTransformer) {
Artifact badArtifact = installationFailures.get(path);
if (badArtifact != null && badArtifact.getChecksum() == artifact.getChecksum()) {
// Don't attempt to install it; nothing has changed.
return null;
}
File transformed = artifact.getTransformed();
String location = path.toURI().normalize().toString();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(transformed != null ? transformed : path));
bundle = installOrUpdateBundle(location, in, artifact.getChecksum(), modified);
artifact.setBundleId(bundle.getBundleId());
}
installationFailures.remove(path);
setArtifact(path, artifact);
} catch (Exception e) {
log(Logger.LOG_ERROR, "Failed to install artifact: " + path, e);
// Add it our bad jars list, so that we don't
// attempt to install it again and again until the underlying
// jar has been modified.
installationFailures.put(path, artifact);
}
return modified.get() ? bundle : null;
}
use of org.apache.felix.fileinstall.ArtifactTransformer 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